src/Entity/JournalIssueFile.php line 55

  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. use ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\Get,
  10.     ApiPlatform\Metadata\GetCollection,
  11.     ApiPlatform\Metadata\Post,
  12.     ApiPlatform\Metadata\Put,
  13.     ApiPlatform\Metadata\Delete,
  14.     ApiPlatform\Metadata\ApiFilter,
  15.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  16. use App\Entity\Trait\IdTrait,
  17.     App\Entity\Trait\UuidTrait,
  18.     App\Entity\Trait\OrdStatTrait,
  19.     App\Entity\Trait\TimestampableTrait,
  20.     App\Entity\Trait\TranslatableTrait,
  21.     App\Entity\Trait\Languages\LanguageableChildTrait,
  22.     App\Entity\Interface\TranslatableInterface,
  23.     App\Entity\Interface\OrdStatableInterface,
  24.     App\Entity\Interface\LanguageableChildInterface;
  25. use App\Filter\IriFilter,
  26.     App\Repository\JournalIssueFileRepository;
  27. #[ApiResource(
  28.     description'Journal issue files',
  29.     normalizationContext: ['groups' => [
  30.         'read',
  31.         'read:' self::class,
  32.         'read:' self::class . 'Translation'
  33.     ]],
  34.     denormalizationContext: ['groups' => ['write']],
  35.     security'is_granted("' Journal::class . '")',
  36.     order: ['ord' => 'desc'],
  37.     operations: [
  38.         new GetCollection(),
  39.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  40.         new Get(),
  41.         new Put(),
  42.         new Delete(),
  43.     ],
  44.     extraProperties: ['standard_put' => false],
  45. )]
  46. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  47. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  48. #[ORM\Entity(repositoryClassJournalIssueFileRepository::class)]
  49. class JournalIssueFile implements TranslatableInterfaceOrdStatableInterfaceLanguageableChildInterface
  50. {
  51.     use IdTrait,
  52.         UuidTrait,
  53.         OrdStatTrait,
  54.         TimestampableTrait,
  55.         TranslatableTrait,
  56.         LanguageableChildTrait;
  57.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  58.     #[Groups(['read''post'])]
  59.     #[Assert\NotNull]
  60.     #[ORM\ManyToOne(targetEntityJournalIssue::class, inversedBy'files')]
  61.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  62.     private JournalIssue $parent;
  63.     public function __construct(JournalIssue $parent)
  64.     {
  65.         $this->setUuid();
  66.         $this->parent $parent;
  67.         $this->translations = new ArrayCollection();
  68.         foreach ($this->getParentLanguages() as $lang) {
  69.             new JournalIssueFileTranslation($this$lang);
  70.         }
  71.         $this->createdAt = new \DateTimeImmutable();
  72.         $this->updatedAt = new \DateTimeImmutable();
  73.         $parent->addFile($this);
  74.     }
  75.     public function getParent(): JournalIssue
  76.     {
  77.         return $this->parent;
  78.     }
  79. }