src/Entity/AcademicTitle.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use App\Entity\Traits\TimestampableEntity;
  6. use App\Repository\AcademicTitleRepository;
  7. use ApiPlatform\Core\Annotation\ApiResource;
  8. use App\Entity\Interfaces\ClientMappedInterface;
  9. use App\Entity\Interfaces\ElasticUpdateInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  13. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  14. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  15. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  16. /**
  17.  * @ApiResource(
  18.  *      attributes={"security"="is_granted('ROLE_OPERATOR')", "filters"={"translation.groups"}},
  19.  *      normalizationContext={"groups"={"AcademicTitle:Read"}, "skip_null_values"=false},
  20.  *      denormalizationContext={"groups"={"AcademicTitle:Write"}},
  21.  *      collectionOperations={
  22.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  23.  *          "get_for_public_page"={
  24.  *              "route_name"="api_pub_academic_titles_get_for_public_page_collection",
  25.  *              "method"="GET",
  26.  *              "security"="is_granted('PUBLIC_ACCESS')",
  27.  *              "normalization_context"={"groups"={"AcademicTitle:PRead"}, "skip_null_values"=false}
  28.  *          },
  29.  *          "post"
  30.  *      },
  31.  *      itemOperations={
  32.  *          "get"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  33.  *          "put"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  34.  *          "patch"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  35.  *          "delete"={"security"="is_granted('IS_CLIENT_OPR', object)"}
  36.  *     }
  37.  * )
  38.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "client.id": "exact", "translations.name": "partial"})
  39.  * @ApiFilter(OrderFilter::class, properties={"ord": "ASC", "translations.name", "id"})
  40.  * @ORM\Entity(repositoryClass=AcademicTitleRepository::class)
  41.  */
  42. class AcademicTitle extends AbstractTranslatable implements ClientMappedInterfaceElasticUpdateInterface
  43. {
  44.     /**
  45.      * Hook timestampable behavior
  46.      * updates createdAt, updatedAt fields
  47.      */
  48.     use TimestampableEntity;
  49.     /**
  50.      * @ORM\OneToMany(targetEntity="AcademicTitleTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  51.      *
  52.      * @Groups({"AcademicTitle:Write", "AcademicTitleTranslationGroup", "User:EL"})
  53.      * @Assert\Valid()
  54.      */
  55.     protected $translations;
  56.     /**
  57.      * @Groups({"AcademicTitle:Read", "AcademicTitle:PRead", "User:Read", "User:Get-Admin","User:Write","User:Me", "User:Attendee-List", "User:Attendee-List-O", "User:Change-Profile", "User:Get-Limited","Session:Select","VideoGalleryHistory:Read" , "JobQueue:Read", "AccessLog:Read", "EventLog:Read", "WatchTime:Read", "CommonComment:Read", "CommonCommentLike:Read", "SessionQuestionLike:Read", "NewsfeedLike:Read", "SessionReaction:Read", "SessionComment:Read", "Session:Read", "DocFile:Read", "Session:PRead", "Conference:Read", "Conference:PRead", "ElCourse:PRead", "Session:Agenda", "Newsfeed:Read", "NewsfeedComment:Read", "ChatThread:Read", "ChatMessage:Read", "Session:VideoLibrary", "VoteResult:Read", "VoteResult:Exp", "SessionQuestion:Read", "Meeting:Read", "MeetingBooking:Read", "Import:Read", "SessionQuestion:Exp", "VoucherCode:Read", "ElCourse:Read", "ElTask:Read", "VideoLibrary:Read", "ElExamAttempt:Read", "ElExamAnswer:Read", "ElCourseJoin:Read", "ElTaskAttempt:Read", "ElExamAttempt:Read", "VideoGallery:Read", "VideoGallery:Read-Public", "VideoGallery:PRead", "SurveyResult:Read", "User:PRead", "User:PSRead", "Certificate:Read", "ElLession:Detail", "User:Assign-List", "Company:Read", "ElCourseRating:Read", "User:Get-Open"})
  58.      */
  59.     private $name;
  60.     /**
  61.      * @ORM\Id
  62.      * @ORM\GeneratedValue
  63.      * @ORM\Column(type="integer")
  64.      * @Groups({"AcademicTitle:Read", "AcademicTitle:PRead", "User:Read", "User:Get-Admin","User:Write","User:Me", "User:Attendee-List", "User:Attendee-List-O", "User:Change-Profile", "User:Get-Limited","Session:Select","VideoGalleryHistory:Read" , "JobQueue:Read", "AccessLog:Read", "EventLog:Read", "WatchTime:Read", "CommonComment:Read", "CommonCommentLike:Read", "SessionQuestionLike:Read", "NewsfeedLike:Read", "SessionReaction:Read", "SessionComment:Read", "Session:Read", "DocFile:Read", "Session:PRead", "Conference:Read", "Conference:PRead", "ElCourse:PRead", "Session:Agenda", "Newsfeed:Read", "NewsfeedComment:Read", "ChatThread:Read", "ChatMessage:Read", "Session:VideoLibrary", "VoteResult:Read", "VoteResult:Exp", "SessionQuestion:Read", "Meeting:Read", "MeetingBooking:Read", "Import:Read", "SessionQuestion:Exp", "VoucherCode:Read", "ElCourse:Read", "ElTask:Read", "VideoLibrary:Read", "ElExamAttempt:Read", "ElExamAnswer:Read", "ElCourseJoin:Read", "ElTaskAttempt:Read", "ElExamAttempt:Read", "VideoGallery:Read", "VideoGallery:Read-Public", "VideoGallery:PRead", "SurveyResult:Read", "User:PRead", "User:PSRead", "Certificate:Read", "ElLession:Detail", "User:Assign-List", "Company:Read", "ElCourseRating:Read", "User:Get-Open"})
  65.      */
  66.     private $id;
  67.     /**
  68.      * @ORM\ManyToOne(targetEntity=Client::class)
  69.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  70.      * @Groups({"AcademicTitle:Write"})
  71.      */
  72.     private $client;
  73.     protected function createTranslation(): TranslationInterface
  74.     {
  75.         return new AcademicTitleTranslation();
  76.     }
  77.     public function addTranslation(TranslationInterface $translation): void
  78.     {
  79.         $this->setUpdatedAt(new \DateTime());
  80.         parent::addTranslation($translation);
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->getTranslation()->getName();
  85.     }
  86.     public function setName(string $name): self
  87.     {
  88.         $this->getTranslation()->setName($name);
  89.         return $this;
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getClient(): ?Client
  96.     {
  97.         return $this->client;
  98.     }
  99.     public function setClient(?Client $client): self
  100.     {
  101.         $this->client $client;
  102.         return $this;
  103.     }
  104.     public function getQueueInfo(): array
  105.     {
  106.         return [
  107.             'type' => 'AcademicTitle',
  108.             'id' => $this->getId()
  109.         ];
  110.     }
  111. }