src/Entity/JournalScientificCouncilMember.php line 57

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM,
  5.     Doctrine\DBAL\Types\Types,
  6.     Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Serializer\Annotation\Groups,
  8.     Symfony\Component\Validator\Constraints as Assert;
  9. use ApiPlatform\Metadata\ApiResource,
  10.     ApiPlatform\Metadata\ApiProperty,
  11.     ApiPlatform\Metadata\Get,
  12.     ApiPlatform\Metadata\GetCollection,
  13.     ApiPlatform\Metadata\Post,
  14.     ApiPlatform\Metadata\Put,
  15.     ApiPlatform\Metadata\Delete,
  16.     ApiPlatform\Metadata\ApiFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  18. use App\Entity\Trait\IdTrait,
  19.     App\Entity\Trait\UuidTrait,
  20.     App\Entity\Trait\OrdStatTrait,
  21.     App\Entity\Trait\TimestampableTrait,
  22.     App\Entity\Trait\TranslatableTrait,
  23.     App\Entity\Trait\Languages\LanguageableChildTrait,
  24.     App\Entity\Interface\TranslatableInterface,
  25.     App\Entity\Interface\OrdStatableInterface,
  26.     App\Entity\Interface\LanguageableChildInterface,
  27.     App\Repository\JournalScientificCouncilMemberRepository;
  28. use App\Filter\IriFilter;
  29. #[ApiResource(
  30.     description'Journal scientific council members',
  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. #[ORM\Entity(repositoryClassJournalScientificCouncilMemberRepository::class)]
  51. class JournalScientificCouncilMember implements
  52.     TranslatableInterface,
  53.     OrdStatableInterface,
  54.     LanguageableChildInterface
  55. {
  56.     use IdTrait,
  57.         UuidTrait,
  58.         OrdStatTrait,
  59.         TimestampableTrait,
  60.         TranslatableTrait,
  61.         LanguageableChildTrait;
  62.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  63.     #[Groups(['read''post'])]
  64.     #[Assert\NotNull]
  65.     #[ORM\ManyToOne(targetEntityJournal::class, inversedBy'scientificCouncilMembers')]
  66.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  67.     private Journal $parent;
  68.     #[ApiProperty(description'Name')]
  69.     #[Groups(['read''write'])]
  70.     #[Assert\NotBlank]
  71.     #[ORM\Column(typeTypes::STRINGlength255)]
  72.     private string $name;
  73.     #[ApiProperty(description'Surname')]
  74.     #[Groups(['read''write'])]
  75.     #[Assert\NotBlank]
  76.     #[ORM\Column(typeTypes::STRINGlength255)]
  77.     private string $surname;
  78.     #[ApiProperty(description'Orcid')]
  79.     #[Groups(['read:' self::class, 'write'])]
  80.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  81.     private ?string $orcid null;
  82.     #[ApiProperty(description'Affiliation'writableLinkfalse)]
  83.     #[Groups(['read:' self::class, 'write'])]
  84.     #[Assert\Expression(
  85.         expression'!value || value.getDepth() === 0',
  86.         message'Cannot assign affiliation which is not an institution.'
  87.     )]
  88.     #[ORM\ManyToOne(targetEntityAffiliation::class)]
  89.     #[ORM\JoinColumn(onDelete'set null')]
  90.     private ?Affiliation $affiliation null;
  91.     #[ApiProperty(description'Affilations'writableLinkfalse )]
  92.     #[Groups(['read:' self::class ])]
  93.     #[Assert\NotBlank(allowNull:true)]
  94.     #[ORM\OneToMany(targetEntityJournalScientificCouncilMemberAffilation::class, mappedBy'parent'cascade: ['persist','remove'])]
  95.     #[ORM\OrderBy(['ord' => 'desc'])]
  96.     private Collection $scientificCouncilMemberAffilations;
  97.     public function __construct(Journal $parent)
  98.     {
  99.         $this->setUuid();
  100.         $this->parent $parent;
  101.         $this->translations = new ArrayCollection();
  102.         foreach ($this->parent->getLanguages() as $lang) {
  103.             new JournalScientificCouncilMemberTranslation($this$lang);
  104.         }
  105.         $this->createdAt = new \DateTimeImmutable();
  106.         $this->updatedAt = new \DateTimeImmutable();
  107.         $parent->addScientificCouncilMember($this);
  108.         $this->scientificCouncilMemberAffilations = new ArrayCollection();
  109.     }
  110.     public function getParent(): Journal
  111.     {
  112.         return $this->parent;
  113.     }
  114.     public function getName(): string
  115.     {
  116.         return $this->name;
  117.     }
  118.     public function setName(string $name): self
  119.     {
  120.         $this->name $name;
  121.         return $this;
  122.     }
  123.     public function getSurname(): string
  124.     {
  125.         return $this->surname;
  126.     }
  127.     public function setSurname(string $surname): self
  128.     {
  129.         $this->surname $surname;
  130.         return $this;
  131.     }
  132.     #[Groups(['read'])]
  133.     public function getTitle(): ?string
  134.     {
  135.         return "{$this->name} {$this->surname}";
  136.     }
  137.     public function getOrcid(): ?string
  138.     {
  139.         return $this->orcid;
  140.     }
  141.     public function setOrcid(?string $orcid): self
  142.     {
  143.         $this->orcid $orcid;
  144.         return $this;
  145.     }
  146.     public function getAffiliation(): ?Affiliation
  147.     {
  148.         return $this->affiliation;
  149.     }
  150.     public function setAffiliation(?Affiliation $affiliation): self
  151.     {
  152.         $this->affiliation $affiliation;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return Collection<int, JournalScientificCouncilMemberAffilation>
  157.      */
  158.     public function getScientificCouncilMemberAffilations(): Collection
  159.     {
  160.         return $this->scientificCouncilMemberAffilations ?? new ArrayCollection();
  161.     }
  162.     public function addScientificCouncilMemberAffilation(JournalScientificCouncilMemberAffilation $scientificCouncilMemberAffilation): static
  163.     {
  164.         if (!$this->scientificCouncilMemberAffilations->contains($scientificCouncilMemberAffilation)) {
  165.             $this->scientificCouncilMemberAffilations->add($scientificCouncilMemberAffilation);
  166.             $scientificCouncilMemberAffilation->setParent($this);
  167.         }
  168.         return $this;
  169.     }
  170.     public function removeScientificCouncilMemberAffilation(JournalScientificCouncilMemberAffilation $scientificCouncilMemberAffilation): static
  171.     {
  172.         if ($this->scientificCouncilMemberAffilations->removeElement($scientificCouncilMemberAffilation)) {
  173.             // set the owning side to null (unless already changed)
  174.             if ($scientificCouncilMemberAffilation->getParent() === $this) {
  175.                 $scientificCouncilMemberAffilation->setParent(null);
  176.             }
  177.         }
  178.         return $this;
  179.     }
  180. }