From 970d4c61046ef01ffb9243a9ec1b3e25e09df1ff Mon Sep 17 00:00:00 2001 From: Ambroise Maupate Date: Thu, 12 Oct 2023 17:48:56 +0200 Subject: [PATCH] feat(Documents): Added image crop alignment for processable documents. --- .../src/Models/AdvancedDocumentInterface.php | 13 +---- .../migrations/Version20231012154717.php | 31 ++++++++++++ lib/RoadizCoreBundle/src/Entity/Document.php | 47 +++++++++++++++++-- 3 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 lib/RoadizCoreBundle/migrations/Version20231012154717.php diff --git a/lib/Documents/src/Models/AdvancedDocumentInterface.php b/lib/Documents/src/Models/AdvancedDocumentInterface.php index 6755df53..f86ca2ba 100644 --- a/lib/Documents/src/Models/AdvancedDocumentInterface.php +++ b/lib/Documents/src/Models/AdvancedDocumentInterface.php @@ -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 */ diff --git a/lib/RoadizCoreBundle/migrations/Version20231012154717.php b/lib/RoadizCoreBundle/migrations/Version20231012154717.php new file mode 100644 index 00000000..9d876ef3 --- /dev/null +++ b/lib/RoadizCoreBundle/migrations/Version20231012154717.php @@ -0,0 +1,31 @@ +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'); + } +} diff --git a/lib/RoadizCoreBundle/src/Entity/Document.php b/lib/RoadizCoreBundle/src/Entity/Document.php index cb7f6971..51c411cd 100644 --- a/lib/RoadizCoreBundle/src/Entity/Document.php +++ b/lib/RoadizCoreBundle/src/Entity/Document.php @@ -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; @@ -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; @@ -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; @@ -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'], @@ -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; + } }