src/Entity/EmailChanel.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\EmailChanelRepository;
  7. use ApiPlatform\Core\Annotation\ApiFilter;
  8. use App\Entity\Traits\TimestampableEntity;
  9. use ApiPlatform\Core\Annotation\ApiResource;
  10. use App\Entity\Interfaces\ClientMappedInterface;
  11. use App\Entity\Interfaces\ElasticUpdateInterface;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  15. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  16. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  17. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  18. /**
  19.  * @ApiResource(
  20.  *      attributes={"security"="is_granted('ROLE_OPERATOR')", "filters"={"translation.groups"}},
  21.  *      normalizationContext={"groups"={"EmailChanel:Read"}, "skip_null_values"=false},
  22.  *      denormalizationContext={"groups"={"EmailChanel:Write"}},
  23.  *      collectionOperations={
  24.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  25.  *          "post"
  26.  *      },
  27.  *      itemOperations={
  28.  *          "get"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  29.  *          "put"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  30.  *          "patch"={"security"="is_granted('IS_CLIENT_OPR', object)"},
  31.  *          "delete"={"security"="is_granted('IS_CLIENT_OPR', object)"}
  32.  *     }
  33.  * )
  34.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "client.id": "exact", "translations.name": "partial"})
  35.  * @ApiFilter(OrderFilter::class, properties={"ord": "ASC", "translations.name", "id"})
  36.  * @ORM\Entity(repositoryClass=EmailChanelRepository::class)
  37.  */
  38. class EmailChanel extends AbstractTranslatable implements ClientMappedInterfaceElasticUpdateInterface
  39. {
  40.     /**
  41.      * Hook timestampable behavior
  42.      * updates createdAt, updatedAt fields
  43.      */
  44.     use TimestampableEntity;
  45.     /**
  46.      * @ORM\OneToMany(targetEntity="EmailChanelTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
  47.      *
  48.      * @Groups({"EmailChanel:Write", "EmailChanelTranslationGroup", "User:EL"})
  49.      * @Assert\Valid()
  50.      */
  51.     protected $translations;
  52.     /**
  53.      * @Groups({"EmailChanel:Read", "User:Read", "User:Get-Admin","User:Write","User:Me", "User:Attendee-List", "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", "Certificate:Read", "ElLession:Detail", "User:Assign-List"})
  54.      */
  55.     private $name;
  56.     /**
  57.      * @ORM\Id
  58.      * @ORM\GeneratedValue
  59.      * @ORM\Column(type="integer")
  60.      * @Groups({"EmailChanel:Read", "User:Read", "User:Get-Admin","User:Write","User:Me", "User:Attendee-List", "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", "Certificate:Read", "ElLession:Detail", "User:Assign-List"})
  61.      */
  62.     private $id;
  63.     /**
  64.      * @ORM\ManyToOne(targetEntity=Client::class)
  65.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  66.      * @Groups({"EmailChanel:Write"})
  67.      */
  68.     private $client;
  69.     /**
  70.      * @ORM\ManyToMany(targetEntity=User::class, mappedBy="unsubscribedEmailChanels")
  71.      */
  72.     private $users;
  73.     public function __construct()
  74.     {
  75.         parent::__construct();
  76.         $this->users = new ArrayCollection();
  77.     }
  78.     protected function createTranslation(): TranslationInterface
  79.     {
  80.         return new EmailChanelTranslation();
  81.     }
  82.     public function addTranslation(TranslationInterface $translation): void
  83.     {
  84.         $this->setUpdatedAt(new \DateTime());
  85.         parent::addTranslation($translation);
  86.     }
  87.     public function getName(): ?string
  88.     {
  89.         return $this->getTranslation()->getName();
  90.     }
  91.     public function setName(string $name): self
  92.     {
  93.         $this->getTranslation()->setName($name);
  94.         return $this;
  95.     }
  96.     public function getId(): ?int
  97.     {
  98.         return $this->id;
  99.     }
  100.     public function getClient(): ?Client
  101.     {
  102.         return $this->client;
  103.     }
  104.     public function setClient(?Client $client): self
  105.     {
  106.         $this->client $client;
  107.         return $this;
  108.     }
  109.     public function getQueueInfo(): array
  110.     {
  111.         return [
  112.             'type' => 'EmailChanel',
  113.             'id' => $this->getId()
  114.         ];
  115.     }
  116.     /**
  117.      * @return Collection<int, User>
  118.      */
  119.     public function getUsers(): Collection
  120.     {
  121.         return $this->users;
  122.     }
  123.     public function addUser(User $user): self
  124.     {
  125.         if (!$this->users->contains($user)) {
  126.             $this->users[] = $user;
  127.             $user->addUnsubscribedEmailChanel($this);
  128.         }
  129.         return $this;
  130.     }
  131.     public function removeUser(User $user): self
  132.     {
  133.         if ($this->users->removeElement($user)) {
  134.             $user->removeUnsubscribedEmailChanel($this);
  135.         }
  136.         return $this;
  137.     }
  138. }