src/Entity/JournalScientificCouncilMember.php line 56

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Serializer\Annotation\Groups,
  7.     Symfony\Component\Validator\Constraints as Assert;
  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\Languages\LanguageableChildTrait,
  23.     App\Entity\Interface\TranslatableInterface,
  24.     App\Entity\Interface\OrdStatableInterface,
  25.     App\Entity\Interface\LanguageableChildInterface,
  26.     App\Repository\JournalScientificCouncilMemberRepository;
  27. use App\Filter\IriFilter;
  28. #[ApiResource(
  29.     description'Journal scientific council members',
  30.     normalizationContext: ['groups' => [
  31.         'read',
  32.         'read:' self::class,
  33.         'read:' self::class . 'Translation',
  34.     ]],
  35.     denormalizationContext: ['groups' => ['write']],
  36.     security'is_granted("' Journal::class . '")',
  37.     order: ['ord' => 'desc'],
  38.     operations: [
  39.         new GetCollection(),
  40.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  41.         new Get(),
  42.         new Put(),
  43.         new Delete(),
  44.     ],
  45.     extraProperties: ['standard_put' => false],
  46. )]
  47. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  48. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  49. #[ORM\Entity(repositoryClassJournalScientificCouncilMemberRepository::class)]
  50. class JournalScientificCouncilMember implements
  51.     TranslatableInterface,
  52.     OrdStatableInterface,
  53.     LanguageableChildInterface
  54. {
  55.     use IdTrait,
  56.         UuidTrait,
  57.         OrdStatTrait,
  58.         TimestampableTrait,
  59.         TranslatableTrait,
  60.         LanguageableChildTrait;
  61.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  62.     #[Groups(['read''post'])]
  63.     #[Assert\NotNull]
  64.     #[ORM\ManyToOne(targetEntityJournal::class, inversedBy'scientificCouncilMembers')]
  65.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  66.     private Journal $parent;
  67.     #[ApiProperty(description'Name')]
  68.     #[Groups(['read''write'])]
  69.     #[Assert\NotBlank]
  70.     #[ORM\Column(typeTypes::STRINGlength255)]
  71.     private string $name;
  72.     #[ApiProperty(description'Surname')]
  73.     #[Groups(['read''write'])]
  74.     #[Assert\NotBlank]
  75.     #[ORM\Column(typeTypes::STRINGlength255)]
  76.     private string $surname;
  77.     #[ApiProperty(description'Orcid')]
  78.     #[Groups(['read:' self::class, 'write'])]
  79.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  80.     private ?string $orcid null;
  81.     #[ApiProperty(description'Affiliation'writableLinkfalse)]
  82.     #[Groups(['read:' self::class, 'write'])]
  83.     #[Assert\Expression(
  84.         expression'!value || value.getDepth() === 0',
  85.         message'Cannot assign affiliation which is not an institution.'
  86.     )]
  87.     #[ORM\ManyToOne(targetEntityAffiliation::class)]
  88.     #[ORM\JoinColumn(onDelete'set null')]
  89.     private ?Affiliation $affiliation null;
  90.     public function __construct(Journal $parent)
  91.     {
  92.         $this->setUuid();
  93.         $this->parent $parent;
  94.         $this->translations = new ArrayCollection();
  95.         foreach ($this->parent->getLanguages() as $lang) {
  96.             new JournalScientificCouncilMemberTranslation($this$lang);
  97.         }
  98.         $this->createdAt = new \DateTimeImmutable();
  99.         $this->updatedAt = new \DateTimeImmutable();
  100.         $parent->addScientificCouncilMember($this);
  101.     }
  102.     public function getParent(): Journal
  103.     {
  104.         return $this->parent;
  105.     }
  106.     public function getName(): string
  107.     {
  108.         return $this->name;
  109.     }
  110.     public function setName(string $name): self
  111.     {
  112.         $this->name $name;
  113.         return $this;
  114.     }
  115.     public function getSurname(): string
  116.     {
  117.         return $this->surname;
  118.     }
  119.     public function setSurname(string $surname): self
  120.     {
  121.         $this->surname $surname;
  122.         return $this;
  123.     }
  124.     #[Groups(['read'])]
  125.     public function getTitle(): ?string
  126.     {
  127.         return "{$this->name} {$this->surname}";
  128.     }
  129.     public function getOrcid(): ?string
  130.     {
  131.         return $this->orcid;
  132.     }
  133.     public function setOrcid(?string $orcid): self
  134.     {
  135.         $this->orcid $orcid;
  136.         return $this;
  137.     }
  138.     public function getAffiliation(): ?Affiliation
  139.     {
  140.         return $this->affiliation;
  141.     }
  142.     public function setAffiliation(?Affiliation $affiliation): self
  143.     {
  144.         $this->affiliation $affiliation;
  145.         return $this;
  146.     }
  147. }