Skip to content

Commit

Permalink
feat(Documents): Added image crop alignment for processable documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Oct 12, 2023
1 parent b9d4500 commit 970d4c6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
13 changes: 1 addition & 12 deletions lib/Documents/src/Models/AdvancedDocumentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,8 @@

namespace RZ\Roadiz\Documents\Models;

interface AdvancedDocumentInterface extends DocumentInterface, SizeableInterface
interface AdvancedDocumentInterface extends DocumentInterface, SizeableInterface, DisplayableInterface
{
/**
* @return string|null
*/
public function getImageAverageColor(): ?string;

/**
* @param string|null $imageAverageColor
* @return $this
*/
public function setImageAverageColor(?string $imageAverageColor): static;

/**
* @return int|null
*/
Expand Down
31 changes: 31 additions & 0 deletions lib/RoadizCoreBundle/migrations/Version20231012154717.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231012154717 extends AbstractMigration
{
public function getDescription(): string
{
return 'Added document image crop alignment';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE documents ADD image_crop_alignment VARCHAR(12) DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE documents DROP image_crop_alignment');
}
}
47 changes: 44 additions & 3 deletions lib/RoadizCoreBundle/src/Entity/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace RZ\Roadiz\CoreBundle\Entity;

use ApiPlatform\Doctrine\Orm\Filter as BaseFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
Expand All @@ -18,7 +18,6 @@
use RZ\Roadiz\CoreBundle\Api\Filter\CopyrightValidFilter;
use RZ\Roadiz\CoreBundle\Repository\DocumentRepository;
use RZ\Roadiz\Documents\Models\AdvancedDocumentInterface;
use RZ\Roadiz\Documents\Models\DisplayableInterface;
use RZ\Roadiz\Documents\Models\DocumentInterface;
use RZ\Roadiz\Documents\Models\DocumentTrait;
use RZ\Roadiz\Documents\Models\FileHashInterface;
Expand Down Expand Up @@ -70,7 +69,7 @@
]),
ApiFilter(CopyrightValidFilter::class)
]
class Document extends AbstractDateTimed implements AdvancedDocumentInterface, HasThumbnailInterface, TimeableInterface, DisplayableInterface, FileHashInterface
class Document extends AbstractDateTimed implements AdvancedDocumentInterface, HasThumbnailInterface, TimeableInterface, FileHashInterface
{
use DocumentTrait;

Expand All @@ -90,6 +89,37 @@ class Document extends AbstractDateTimed implements AdvancedDocumentInterface, H
#[Serializer\Groups(['document_copyright'])]
protected ?\DateTime $copyrightValidUntil = null;

/**
* @var string|null Image crop alignment.
*
* The possible values are:
*
* top-left
* top
* top-right
* left
* center (default)
* right
* bottom-left
* bottom
* bottom-right
*/
#[ORM\Column(name: 'image_crop_alignment', type: 'string', length: 12, nullable: true)]
#[SymfonySerializer\Groups(['document', 'document_display', 'nodes_sources', 'tag', 'attribute'])]
#[Assert\Length(max: 12)]
#[Assert\Choice(choices: [
'top-left',
'top',
'top-right',
'left',
'center',
'right',
'bottom-left',
'bottom',
'bottom-right'
])]
protected ?string $imageCropAlignment = null;

#[ORM\ManyToOne(
targetEntity: Document::class,
cascade: ['all'],
Expand Down Expand Up @@ -810,4 +840,15 @@ public function setEmbedId(?string $embedId): static
$this->embedId = $embedId;
return $this;
}

public function getImageCropAlignment(): ?string
{
return $this->imageCropAlignment;
}

public function setImageCropAlignment(?string $imageCropAlignment): Document
{
$this->imageCropAlignment = $imageCropAlignment;
return $this;
}
}

0 comments on commit 970d4c6

Please sign in to comment.