src/Entity/CommonComment.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Filter\UserFilter;
  4. use App\Annotation\EsUploadable;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use ApiPlatform\Core\Annotation\ApiFilter;
  8. use App\Repository\CommonCommentRepository;
  9. use Doctrine\Common\Collections\Collection;
  10. use ApiPlatform\Core\Annotation\ApiProperty;
  11. use ApiPlatform\Core\Annotation\ApiResource;
  12. use App\Entity\Interfaces\OwnerMappedInterface;
  13. use App\Entity\Interfaces\UploadMappedInterface;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use App\Entity\Interfaces\ContainerMappedInterface;
  16. use App\Entity\Interfaces\TotalLikeMappedInterface;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  20. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  21. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  22. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  23. /**
  24.  * @ApiResource(
  25.  *      attributes={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  26.  *      normalizationContext={"groups"={"CommonComment:Read"}, "skip_null_values"=false},
  27.  *      denormalizationContext={"groups"={"CommonComment:Write"}},
  28.  *      collectionOperations={
  29.  *          "get",
  30.  *          "post"
  31.  *     },
  32.  *      itemOperations={
  33.  *          "get",
  34.  *          "put"={"security"="is_granted('IS_CO_ANY_SPE', object) || is_granted('IS_CO_OPR', object) || is_granted('IS_CO_SESSCO_SPE_MODERATOR', object) || is_granted('IS_CO_SESSCO_SPE_SPEAKER', object)"},
  35.  *          "patch"={"security"="is_granted('IS_CO_ANY_SPE', object) || is_granted('IS_CO_OPR', object) || is_granted('IS_CO_SESSCO_SPE_MODERATOR', object) || is_granted('IS_CO_SESSCO_SPE_SPEAKER', object)"},
  36.  *          "patch_like_toggle"={
  37.  *              "route_name"="api_common_comments_like_toggle_collection",
  38.  *              "method"="PATCH",
  39.  *              "denormalization_context"={"groups"={"CommonComment:Like-Toggle"}}
  40.  *          },
  41.  *          "delete"={"security"="is_granted('IS_CO_ANY_SPE', object) || is_granted('IS_CO_OPR', object) || is_granted('IS_CO_SESSCO_SPE_MODERATOR', object) || is_granted('IS_CO_SESSCO_SPE_SPEAKER', object)"}
  42.  *     }
  43.  * )
  44.  * @ApiFilter(SearchFilter::class, properties={"message": "partial", "status": "exact", "container.id": "exact", "parent.id": "exact", "user.id": "exact", "source": "exact", "session.id": "exact", "elTask.id": "exact", "newsfeed.id": "exact", "elExam.id": "exact", "docFileBlock.id": "exact", "docFile.id": "exact", "videoGallery.id": "exact"})
  45.  * @ApiFilter(BooleanFilter::class, properties={"isReplyed"})
  46.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  47.  * @ApiFilter(OrderFilter::class, properties={"id": "DESC"})
  48.  * @ApiFilter(UserFilter::class, properties={"search": "partial"})
  49.  * @ORM\Entity(repositoryClass=CommonCommentRepository::class)
  50.  */
  51. class CommonComment implements ContainerMappedInterfaceOwnerMappedInterfaceTotalLikeMappedInterfaceUploadMappedInterface
  52. {
  53.     /**
  54.      * @var \DateTime
  55.      * @Gedmo\Timestampable(on="create")
  56.      * @ORM\Column(type="datetime")
  57.      *
  58.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  59.      */
  60.     protected $createdAt;
  61.     /**
  62.      * @var \DateTime
  63.      * @Gedmo\Timestampable(on="update")
  64.      * @ORM\Column(type="datetime")
  65.      *
  66.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  67.      */
  68.     protected $updatedAt;
  69.     public function setCreatedAt(\DateTime $createdAt)
  70.     {
  71.         $this->createdAt $createdAt;
  72.         return $this;
  73.     }
  74.     public function getCreatedAt()
  75.     {
  76.         return $this->createdAt;
  77.     }
  78.     public function setUpdatedAt(\DateTime $updatedAt)
  79.     {
  80.         $this->updatedAt $updatedAt;
  81.         return $this;
  82.     }
  83.     public function getUpdatedAt()
  84.     {
  85.         return $this->updatedAt;
  86.     }
  87.     /**
  88.      * @ORM\Id
  89.      * @ORM\GeneratedValue
  90.      * @ORM\Column(type="integer")
  91.      * @Groups({"CommonComment:Read"})
  92.      */
  93.     private $id;
  94.     /**
  95.      * @ORM\Column(type="etext", nullable=true)
  96.      * @Assert\Regex(
  97.      *     pattern="/(\b)(on\S+)(\s*)=|javascript|(<\s*)(\/*)script/mi",
  98.      *     match=false,
  99.      *     message="validation.commonComment:message.invalidContent"
  100.      * )
  101.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  102.      */
  103.     private $message;
  104.     /**
  105.      * @ORM\Column(type="string", length=32)
  106.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  107.      * @ApiProperty(
  108.      *     attributes={
  109.      *         "openapi_context"={
  110.      *             "type"="string",
  111.      *             "enum"={self::STATUS_NEW, self::STATUS_ACCEPTED, self::STATUS_REJECTED}
  112.      *         }
  113.      *     }
  114.      * )
  115.      *
  116.      * @Assert\NotBlank(message="validation.commonComment:status.notBlank")
  117.      * @Assert\Choice({self::STATUS_NEW, self::STATUS_ACCEPTED, self::STATUS_REJECTED})
  118.      */
  119.     private $status self::STATUS_NEW;
  120.     public const STATUS_NEW "NEW";
  121.     public const STATUS_ACCEPTED "ACCEPTED";
  122.     public const STATUS_REJECTED "REJECTED";
  123.     /**
  124.      * @ORM\Column(type="boolean", nullable=true)
  125.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  126.      */
  127.     private $isReplyed;
  128.     /**
  129.      * @ORM\ManyToOne(targetEntity=CommonComment::class, inversedBy="children")
  130.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  131.      *
  132.      * @Groups({"CommonComment:Write"})
  133.      * @ApiProperty(readableLink=false, writableLink=false)
  134.      */
  135.     private $parent;
  136.     /**
  137.      * @ORM\OneToMany(targetEntity=CommonComment::class, mappedBy="parent")
  138.      *
  139.      * @Groups({"CommonComment:Read"})
  140.      * @ORM\OrderBy({"id" = "ASC"})
  141.      */
  142.     private $children;
  143.     /**
  144.      * @ORM\ManyToOne(targetEntity=User::class)
  145.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  146.      *
  147.      * @Groups({"CommonComment:Read"})
  148.      */
  149.     private $user;
  150.     /**
  151.      * @ORM\ManyToOne(targetEntity=Container::class)
  152.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  153.      *
  154.      * @Groups({"CommonComment:Write"})
  155.      */
  156.     private $container;
  157.     /**
  158.      * @ORM\Column(type="string", length=32)
  159.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  160.      *
  161.      * @ApiProperty(
  162.      *     attributes={
  163.      *         "openapi_context"={
  164.      *             "type"="string",
  165.      *             "enum"={self::SOURCE_SESSION, self::SOURCE_ELTASK, self::SOURCE_ELEXAM, self::SOURCE_NEWSFEED, self::SOURCE_DOCFILEBLOCK, self::SOURCE_VIDEOGALLERY, self::SOURCE_INFOPAGE}
  166.      *         }
  167.      *     }
  168.      * )
  169.      *
  170.      * @Assert\NotBlank(message="validation.commonComment:source.notBlank")
  171.      * @Assert\Choice({self::SOURCE_SESSION, self::SOURCE_ELTASK, self::SOURCE_ELEXAM, self::SOURCE_NEWSFEED, self::SOURCE_DOCFILEBLOCK, self::SOURCE_VIDEOGALLERY, self::SOURCE_INFOPAGE})
  172.      */
  173.     private $source;
  174.     public const SOURCE_SESSION "SESSION";
  175.     public const SOURCE_ELTASK "ELTASK";
  176.     public const SOURCE_ELEXAM "ELEXAM";
  177.     public const SOURCE_NEWSFEED "NEWSFEED";
  178.     public const SOURCE_DOCFILEBLOCK "DOCFILEBLOCK";
  179.     public const SOURCE_VIDEOGALLERY "VIDEOGALLERY";
  180.     public const SOURCE_INFOPAGE "INFOPAGE";
  181.     /**
  182.      * @ORM\ManyToOne(targetEntity=Session::class, inversedBy="commonComments")
  183.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  184.      *
  185.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  186.      */
  187.     private $session;
  188.     /**
  189.      * @ORM\ManyToOne(targetEntity=ElTask::class, inversedBy="commonComments")
  190.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  191.      *
  192.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  193.      */
  194.     private $elTask;
  195.     /**
  196.      * @ORM\ManyToOne(targetEntity=Newsfeed::class, inversedBy="commonComments")
  197.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  198.      *
  199.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  200.      */
  201.     private $newsfeed;
  202.     /**
  203.      * @ORM\ManyToOne(targetEntity=ElExam::class, inversedBy="commonComments")
  204.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  205.      *
  206.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  207.      */
  208.     private $elExam;
  209.     /**
  210.      * @ORM\ManyToOne(targetEntity=DocFileBlock::class, inversedBy="commonComments")
  211.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  212.      *
  213.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  214.      */
  215.     private $docFileBlock;
  216.     /**
  217.      * @ORM\ManyToOne(targetEntity=DocFile::class, inversedBy="commonComments")
  218.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  219.      *
  220.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  221.      */
  222.     private $docFile;
  223.     /**
  224.      * @ORM\ManyToOne(targetEntity=VideoGallery::class, inversedBy="commonComments")
  225.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  226.      *
  227.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  228.      */
  229.     private $videoGallery;
  230.     /**
  231.      * @ORM\Column(type="integer", nullable=true)
  232.      * @Groups({"CommonComment:Read"})
  233.      */
  234.     private $totalLikes;
  235.     /**
  236.      * @ORM\Column(type="array", nullable=true)
  237.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  238.      * @EsUploadable()
  239.      */
  240.     protected $mediaFileNames = [];
  241.     /**
  242.      * @ORM\Column(type="array", nullable=true)
  243.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  244.      */
  245.     private $assignUsers = [];
  246.     /**
  247.      * @ORM\Column(type="string", length=32, nullable=true)
  248.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  249.      */
  250.     private $mediaFileType;
  251.     /**
  252.      * @ORM\ManyToOne(targetEntity=InfoPage::class, inversedBy="commonComments")
  253.      * @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
  254.      *
  255.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  256.      */
  257.     private $infoPage;
  258.     /**
  259.      * @ORM\Column(type="string", length=32, nullable=true)
  260.      * @Groups({"CommonComment:Read", "CommonComment:Write"})
  261.      */
  262.     private $timelinePosition;
  263.     public const MEDIAFILETYPE_IMAGE "IMAGE";
  264.     public const MEDIAFILETYPE_VIDEO "VIDEO";
  265.     public const MEDIAFILETYPE_DOCUMENT "DOCUMENT";
  266.     public function __construct()
  267.     {
  268.         $this->children = new ArrayCollection();
  269.     }
  270.     public function getId(): ?int
  271.     {
  272.         return $this->id;
  273.     }
  274.     public function getMessage(): ?string
  275.     {
  276.         return $this->message;
  277.     }
  278.     public function setMessage(string $message): self
  279.     {
  280.         $this->message $message;
  281.         return $this;
  282.     }
  283.     public function getStatus(): ?string
  284.     {
  285.         return $this->status;
  286.     }
  287.     public function setStatus(string $status): self
  288.     {
  289.         $this->status $status;
  290.         return $this;
  291.     }
  292.     public function getIsReplyed(): ?bool
  293.     {
  294.         return $this->isReplyed;
  295.     }
  296.     public function setIsReplyed(?bool $isReplyed): self
  297.     {
  298.         $this->isReplyed $isReplyed;
  299.         return $this;
  300.     }
  301.     public function getParent(): ?self
  302.     {
  303.         return $this->parent;
  304.     }
  305.     public function setParent(?self $parent): self
  306.     {
  307.         $this->parent $parent;
  308.         return $this;
  309.     }
  310.     /**
  311.      * @return Collection|self[]
  312.      */
  313.     public function getChildren(): Collection
  314.     {
  315.         return $this->children;
  316.     }
  317.     public function addChild(self $child): self
  318.     {
  319.         if (!$this->children->contains($child)) {
  320.             $this->children[] = $child;
  321.             $child->setParent($this);
  322.         }
  323.         return $this;
  324.     }
  325.     public function removeChild(self $child): self
  326.     {
  327.         if ($this->children->removeElement($child)) {
  328.             // set the owning side to null (unless already changed)
  329.             if ($child->getParent() === $this) {
  330.                 $child->setParent(null);
  331.             }
  332.         }
  333.         return $this;
  334.     }
  335.     public function getUser(): ?User
  336.     {
  337.         return $this->user;
  338.     }
  339.     public function setUser(?User $user): self
  340.     {
  341.         $this->user $user;
  342.         return $this;
  343.     }
  344.     public function getContainer(): ?Container
  345.     {
  346.         return $this->container;
  347.     }
  348.     public function setContainer(?Container $container): self
  349.     {
  350.         $this->container $container;
  351.         return $this;
  352.     }
  353.     public function getSource(): ?string
  354.     {
  355.         return $this->source;
  356.     }
  357.     public function setSource(string $source): self
  358.     {
  359.         $this->source $source;
  360.         return $this;
  361.     }
  362.     public function getSession(): ?Session
  363.     {
  364.         return $this->session;
  365.     }
  366.     public function setSession(?Session $session): self
  367.     {
  368.         $this->session $session;
  369.         return $this;
  370.     }
  371.     public function getElTask(): ?ElTask
  372.     {
  373.         return $this->elTask;
  374.     }
  375.     public function setElTask(?ElTask $elTask): self
  376.     {
  377.         $this->elTask $elTask;
  378.         return $this;
  379.     }
  380.     public function getNewsfeed(): ?Newsfeed
  381.     {
  382.         return $this->newsfeed;
  383.     }
  384.     public function setNewsfeed(?Newsfeed $newsfeed): self
  385.     {
  386.         $this->newsfeed $newsfeed;
  387.         return $this;
  388.     }
  389.     /**
  390.      * @Groups({"CommonComment:Read"})
  391.      */
  392.     public function getSourceElement()
  393.     {
  394.         if ($this->source === self::SOURCE_SESSION) {
  395.             return $this->session;
  396.         } elseif ($this->source === self::SOURCE_ELTASK) {
  397.             return $this->elTask;
  398.         } elseif ($this->source === self::SOURCE_ELEXAM) {
  399.             return $this->elExam;
  400.         } elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
  401.             return $this->docFile;
  402.         } elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
  403.             return $this->videoGallery;
  404.         } elseif ($this->source === self::SOURCE_INFOPAGE) {
  405.             return $this->infoPage;
  406.         } else {
  407.             return $this->newsfeed;
  408.         }
  409.     }
  410.     public function setSourceElement($obj)
  411.     {
  412.         if ($this->source === self::SOURCE_SESSION) {
  413.             $this->session $obj;
  414.         } elseif ($this->source === self::SOURCE_ELTASK) {
  415.             $this->elTask $obj;
  416.         } elseif ($this->source === self::SOURCE_ELEXAM) {
  417.             $this->elExam $obj;
  418.         } elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
  419.             $this->docFile $obj;
  420.         } elseif ($this->source === self::SOURCE_NEWSFEED) {
  421.             $this->newsfeed $obj;
  422.         } elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
  423.             $this->videoGallery $obj;
  424.         } elseif ($this->source === self::SOURCE_INFOPAGE) {
  425.             $this->infoPage $obj;
  426.         }
  427.         return $this;
  428.     }
  429.     public function getSourceElementUsers()
  430.     {
  431.         if ($this->source === self::SOURCE_SESSION) {
  432.             return [
  433.                 'speakers' => $this->session->getSpeakers(),
  434.                 'moderators' => $this->session->getModerators(),
  435.             ];
  436.         } elseif ($this->source === self::SOURCE_ELTASK) {
  437.             return [
  438.                 'speakers' => $this->elTask->getSpeakers(),
  439.                 'experts' => $this->elTask->getExperts(),
  440.             ];
  441.         } elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
  442.             return [
  443.                 'authors' => $this->docFile->getAuthors(),
  444.             ];
  445.         } elseif ($this->source === self::SOURCE_NEWSFEED) {
  446.             return [
  447.                 'user' => [$this->newsfeed->getUser()],
  448.             ];
  449.         } elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
  450.             return [
  451.                 'speakers' => $this->videoGallery->getSpeakers(),
  452.                 'moderators' => $this->videoGallery->getModerators(),
  453.             ];
  454.         }
  455.     }
  456.     public function getElExam(): ?ElExam
  457.     {
  458.         return $this->elExam;
  459.     }
  460.     public function setElExam(?ElExam $elExam): self
  461.     {
  462.         $this->elExam $elExam;
  463.         return $this;
  464.     }
  465.     public function getDocFileBlock(): ?DocFileBlock
  466.     {
  467.         return $this->docFileBlock;
  468.     }
  469.     public function setDocFileBlock(?DocFileBlock $docFileBlock): self
  470.     {
  471.         $this->docFileBlock $docFileBlock;
  472.         return $this;
  473.     }
  474.     public function getDocFile(): ?DocFile
  475.     {
  476.         return $this->docFile;
  477.     }
  478.     public function setDocFile(?DocFile $docFile): self
  479.     {
  480.         $this->docFile $docFile;
  481.         return $this;
  482.     }
  483.     public function getTotalLikes(): ?int
  484.     {
  485.         return $this->totalLikes;
  486.     }
  487.     public function setTotalLikes(?int $totalLikes)
  488.     {
  489.         $this->totalLikes $totalLikes;
  490.         return $this;
  491.     }
  492.     public function getMediaFileNames(): ?array
  493.     {
  494.         return $this->mediaFileNames;
  495.     }
  496.     public function setMediaFileNames(?array $mediaFileNames): self
  497.     {
  498.         $this->mediaFileNames $mediaFileNames;
  499.         return $this;
  500.     }
  501.     public function getAssignUsers(): ?array
  502.     {
  503.         return $this->assignUsers;
  504.     }
  505.     public function setAssignUsers(?array $assignUsers): self
  506.     {
  507.         $this->assignUsers $assignUsers;
  508.         return $this;
  509.     }
  510.     public function getMediaFileType(): ?string
  511.     {
  512.         return $this->mediaFileType;
  513.     }
  514.     public function setMediaFileType(?string $mediaFileType): self
  515.     {
  516.         $this->mediaFileType $mediaFileType;
  517.         return $this;
  518.     }
  519.     public function getVideoGallery(): ?VideoGallery
  520.     {
  521.         return $this->videoGallery;
  522.     }
  523.     public function setVideoGallery(?VideoGallery $videoGallery): self
  524.     {
  525.         $this->videoGallery $videoGallery;
  526.         return $this;
  527.     }
  528.     public function getInfoPage(): ?InfoPage
  529.     {
  530.         return $this->infoPage;
  531.     }
  532.     public function setInfoPage(?InfoPage $infoPage): self
  533.     {
  534.         $this->infoPage $infoPage;
  535.         return $this;
  536.     }
  537.     public function getTimelinePosition(): ?string
  538.     {
  539.         return $this->timelinePosition;
  540.     }
  541.     public function setTimelinePosition(?string $timelinePosition): self
  542.     {
  543.         $this->timelinePosition $timelinePosition;
  544.         return $this;
  545.     }
  546. }