src/Entity/JournalSection.php line 59

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Component\Serializer\Annotation\Groups,
  6.     Symfony\Component\Validator\Constraints as Assert;
  7.     // Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use ApiPlatform\Metadata\ApiResource,
  9.     ApiPlatform\Metadata\ApiProperty,
  10.     ApiPlatform\Metadata\Get,
  11.     ApiPlatform\Metadata\GetCollection,
  12.     ApiPlatform\Metadata\Post,
  13.     ApiPlatform\Metadata\Put,
  14.     ApiPlatform\Metadata\Delete,
  15.     ApiPlatform\Metadata\ApiFilter,
  16.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  17. use App\Entity\Trait\IdTrait,
  18.     App\Entity\Trait\UuidTrait,
  19.     App\Entity\Trait\OrdStatTrait,
  20.     App\Entity\Trait\TimestampableTrait,
  21.     App\Entity\Trait\TranslatableTrait,
  22.     App\Entity\Trait\ImportIdTrait,
  23.     App\Entity\Trait\Languages\LanguageableChildTrait,
  24.     App\Entity\Interface\TranslatableInterface,
  25.     App\Entity\Interface\OrdStatableInterface,
  26.     App\Entity\Interface\LanguageableChildInterface,
  27.     App\Repository\JournalSectionRepository;
  28. use App\Filter\IriFilter;
  29. #[ApiResource(
  30.     description'Journal sections',
  31.     normalizationContext: ['groups' => [
  32.         'read',
  33.         'read:' self::class,
  34.         'read:' self::class . 'Translation'
  35.     ]],
  36.     denormalizationContext: ['groups' => ['write']],
  37.     security'is_granted("' Journal::class . '")',
  38.     order: ['ord' => 'desc'],
  39.     operations: [
  40.         new GetCollection(),
  41.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  42.         new Get(),
  43.         new Put(),
  44.         new Delete(),
  45.     ],
  46.     extraProperties: ['standard_put' => false],
  47. )]
  48. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  49. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  50. // #[UniqueEntity(fields: ['workingTitle', 'parent'], message: 'This working title already exists.')]
  51. // #[ORM\UniqueConstraint(fields: ['parent', 'workingTitle'])]
  52. #[ORM\Entity(repositoryClassJournalSectionRepository::class)]
  53. class JournalSection implements TranslatableInterfaceOrdStatableInterfaceLanguageableChildInterface
  54. {
  55.     use IdTrait,
  56.         UuidTrait,
  57.         OrdStatTrait,
  58.         TimestampableTrait,
  59.         TranslatableTrait,
  60.         LanguageableChildTrait,
  61.         ImportIdTrait;
  62.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  63.     #[Groups(['read''post'])]
  64.     #[Assert\NotNull]
  65.     #[ORM\ManyToOne(targetEntityJournal::class, inversedBy'sections')]
  66.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  67.     private Journal $parent;
  68.     #[ApiProperty(description'Working title')]
  69.     #[Groups(['read''write'])]
  70.     #[Assert\NotBlank]
  71.     #[ORM\Column(type'string'length255)]
  72.     private string $workingTitle;
  73.     public function __construct(Journal $parent)
  74.     {
  75.         $this->setUuid();
  76.         $this->parent $parent;
  77.         $this->translations = new ArrayCollection();
  78.         foreach ($this->parent->getLanguages() as $lang) {
  79.             new JournalSectionTranslation($this$lang);
  80.         }
  81.         $this->createdAt = new \DateTimeImmutable();
  82.         $this->updatedAt = new \DateTimeImmutable();
  83.         $parent->addSection($this);
  84.     }
  85.     public function getParent(): Journal
  86.     {
  87.         return $this->parent;
  88.     }
  89.     public function getWorkingTitle(): string
  90.     {
  91.         return $this->workingTitle;
  92.     }
  93.     public function setWorkingTitle(string $workingTitle): self
  94.     {
  95.         $this->workingTitle $workingTitle;
  96.         return $this;
  97.     }
  98. }