<?php
namespace App\Entity;
use App\Filter\UserFilter;
use App\Annotation\EsUploadable;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Repository\CommonCommentRepository;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\Interfaces\OwnerMappedInterface;
use App\Entity\Interfaces\UploadMappedInterface;
use Doctrine\Common\Collections\ArrayCollection;
use App\Entity\Interfaces\ContainerMappedInterface;
use App\Entity\Interfaces\TotalLikeMappedInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
/**
* @ApiResource(
* attributes={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* normalizationContext={"groups"={"CommonComment:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"CommonComment:Write"}},
* collectionOperations={
* "get",
* "post"
* },
* itemOperations={
* "get",
* "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)"},
* "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)"},
* "patch_like_toggle"={
* "route_name"="api_common_comments_like_toggle_collection",
* "method"="PATCH",
* "denormalization_context"={"groups"={"CommonComment:Like-Toggle"}}
* },
* "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)"}
* }
* )
* @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"})
* @ApiFilter(BooleanFilter::class, properties={"isReplyed"})
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ApiFilter(OrderFilter::class, properties={"id": "DESC"})
* @ApiFilter(UserFilter::class, properties={"search": "partial"})
* @ORM\Entity(repositoryClass=CommonCommentRepository::class)
*/
class CommonComment implements ContainerMappedInterface, OwnerMappedInterface, TotalLikeMappedInterface, UploadMappedInterface
{
/**
* @var \DateTime
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
protected $createdAt;
/**
* @var \DateTime
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
protected $updatedAt;
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"CommonComment:Read"})
*/
private $id;
/**
* @ORM\Column(type="etext", nullable=true)
* @Assert\Regex(
* pattern="/(\b)(on\S+)(\s*)=|javascript|(<\s*)(\/*)script/mi",
* match=false,
* message="validation.commonComment:message.invalidContent"
* )
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $message;
/**
* @ORM\Column(type="string", length=32)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "enum"={self::STATUS_NEW, self::STATUS_ACCEPTED, self::STATUS_REJECTED}
* }
* }
* )
*
* @Assert\NotBlank(message="validation.commonComment:status.notBlank")
* @Assert\Choice({self::STATUS_NEW, self::STATUS_ACCEPTED, self::STATUS_REJECTED})
*/
private $status = self::STATUS_NEW;
public const STATUS_NEW = "NEW";
public const STATUS_ACCEPTED = "ACCEPTED";
public const STATUS_REJECTED = "REJECTED";
/**
* @ORM\Column(type="boolean", nullable=true)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $isReplyed;
/**
* @ORM\ManyToOne(targetEntity=CommonComment::class, inversedBy="children")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Write"})
* @ApiProperty(readableLink=false, writableLink=false)
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=CommonComment::class, mappedBy="parent")
*
* @Groups({"CommonComment:Read"})
* @ORM\OrderBy({"id" = "ASC"})
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read"})
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*
* @Groups({"CommonComment:Write"})
*/
private $container;
/**
* @ORM\Column(type="string", length=32)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "enum"={self::SOURCE_SESSION, self::SOURCE_ELTASK, self::SOURCE_ELEXAM, self::SOURCE_NEWSFEED, self::SOURCE_DOCFILEBLOCK, self::SOURCE_VIDEOGALLERY, self::SOURCE_INFOPAGE}
* }
* }
* )
*
* @Assert\NotBlank(message="validation.commonComment:source.notBlank")
* @Assert\Choice({self::SOURCE_SESSION, self::SOURCE_ELTASK, self::SOURCE_ELEXAM, self::SOURCE_NEWSFEED, self::SOURCE_DOCFILEBLOCK, self::SOURCE_VIDEOGALLERY, self::SOURCE_INFOPAGE})
*/
private $source;
public const SOURCE_SESSION = "SESSION";
public const SOURCE_ELTASK = "ELTASK";
public const SOURCE_ELEXAM = "ELEXAM";
public const SOURCE_NEWSFEED = "NEWSFEED";
public const SOURCE_DOCFILEBLOCK = "DOCFILEBLOCK";
public const SOURCE_VIDEOGALLERY = "VIDEOGALLERY";
public const SOURCE_INFOPAGE = "INFOPAGE";
/**
* @ORM\ManyToOne(targetEntity=Session::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $session;
/**
* @ORM\ManyToOne(targetEntity=ElTask::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $elTask;
/**
* @ORM\ManyToOne(targetEntity=Newsfeed::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $newsfeed;
/**
* @ORM\ManyToOne(targetEntity=ElExam::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $elExam;
/**
* @ORM\ManyToOne(targetEntity=DocFileBlock::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $docFileBlock;
/**
* @ORM\ManyToOne(targetEntity=DocFile::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $docFile;
/**
* @ORM\ManyToOne(targetEntity=VideoGallery::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $videoGallery;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"CommonComment:Read"})
*/
private $totalLikes;
/**
* @ORM\Column(type="array", nullable=true)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
* @EsUploadable()
*/
protected $mediaFileNames = [];
/**
* @ORM\Column(type="array", nullable=true)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $assignUsers = [];
/**
* @ORM\Column(type="string", length=32, nullable=true)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $mediaFileType;
/**
* @ORM\ManyToOne(targetEntity=InfoPage::class, inversedBy="commonComments")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $infoPage;
/**
* @ORM\Column(type="string", length=32, nullable=true)
* @Groups({"CommonComment:Read", "CommonComment:Write"})
*/
private $timelinePosition;
public const MEDIAFILETYPE_IMAGE = "IMAGE";
public const MEDIAFILETYPE_VIDEO = "VIDEO";
public const MEDIAFILETYPE_DOCUMENT = "DOCUMENT";
public function __construct()
{
$this->children = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getIsReplyed(): ?bool
{
return $this->isReplyed;
}
public function setIsReplyed(?bool $isReplyed): self
{
$this->isReplyed = $isReplyed;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getSource(): ?string
{
return $this->source;
}
public function setSource(string $source): self
{
$this->source = $source;
return $this;
}
public function getSession(): ?Session
{
return $this->session;
}
public function setSession(?Session $session): self
{
$this->session = $session;
return $this;
}
public function getElTask(): ?ElTask
{
return $this->elTask;
}
public function setElTask(?ElTask $elTask): self
{
$this->elTask = $elTask;
return $this;
}
public function getNewsfeed(): ?Newsfeed
{
return $this->newsfeed;
}
public function setNewsfeed(?Newsfeed $newsfeed): self
{
$this->newsfeed = $newsfeed;
return $this;
}
/**
* @Groups({"CommonComment:Read"})
*/
public function getSourceElement()
{
if ($this->source === self::SOURCE_SESSION) {
return $this->session;
} elseif ($this->source === self::SOURCE_ELTASK) {
return $this->elTask;
} elseif ($this->source === self::SOURCE_ELEXAM) {
return $this->elExam;
} elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
return $this->docFile;
} elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
return $this->videoGallery;
} elseif ($this->source === self::SOURCE_INFOPAGE) {
return $this->infoPage;
} else {
return $this->newsfeed;
}
}
public function setSourceElement($obj)
{
if ($this->source === self::SOURCE_SESSION) {
$this->session = $obj;
} elseif ($this->source === self::SOURCE_ELTASK) {
$this->elTask = $obj;
} elseif ($this->source === self::SOURCE_ELEXAM) {
$this->elExam = $obj;
} elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
$this->docFile = $obj;
} elseif ($this->source === self::SOURCE_NEWSFEED) {
$this->newsfeed = $obj;
} elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
$this->videoGallery = $obj;
} elseif ($this->source === self::SOURCE_INFOPAGE) {
$this->infoPage = $obj;
}
return $this;
}
public function getSourceElementUsers()
{
if ($this->source === self::SOURCE_SESSION) {
return [
'speakers' => $this->session->getSpeakers(),
'moderators' => $this->session->getModerators(),
];
} elseif ($this->source === self::SOURCE_ELTASK) {
return [
'speakers' => $this->elTask->getSpeakers(),
'experts' => $this->elTask->getExperts(),
];
} elseif ($this->source === self::SOURCE_DOCFILEBLOCK) {
return [
'authors' => $this->docFile->getAuthors(),
];
} elseif ($this->source === self::SOURCE_NEWSFEED) {
return [
'user' => [$this->newsfeed->getUser()],
];
} elseif ($this->source === self::SOURCE_VIDEOGALLERY) {
return [
'speakers' => $this->videoGallery->getSpeakers(),
'moderators' => $this->videoGallery->getModerators(),
];
}
}
public function getElExam(): ?ElExam
{
return $this->elExam;
}
public function setElExam(?ElExam $elExam): self
{
$this->elExam = $elExam;
return $this;
}
public function getDocFileBlock(): ?DocFileBlock
{
return $this->docFileBlock;
}
public function setDocFileBlock(?DocFileBlock $docFileBlock): self
{
$this->docFileBlock = $docFileBlock;
return $this;
}
public function getDocFile(): ?DocFile
{
return $this->docFile;
}
public function setDocFile(?DocFile $docFile): self
{
$this->docFile = $docFile;
return $this;
}
public function getTotalLikes(): ?int
{
return $this->totalLikes;
}
public function setTotalLikes(?int $totalLikes)
{
$this->totalLikes = $totalLikes;
return $this;
}
public function getMediaFileNames(): ?array
{
return $this->mediaFileNames;
}
public function setMediaFileNames(?array $mediaFileNames): self
{
$this->mediaFileNames = $mediaFileNames;
return $this;
}
public function getAssignUsers(): ?array
{
return $this->assignUsers;
}
public function setAssignUsers(?array $assignUsers): self
{
$this->assignUsers = $assignUsers;
return $this;
}
public function getMediaFileType(): ?string
{
return $this->mediaFileType;
}
public function setMediaFileType(?string $mediaFileType): self
{
$this->mediaFileType = $mediaFileType;
return $this;
}
public function getVideoGallery(): ?VideoGallery
{
return $this->videoGallery;
}
public function setVideoGallery(?VideoGallery $videoGallery): self
{
$this->videoGallery = $videoGallery;
return $this;
}
public function getInfoPage(): ?InfoPage
{
return $this->infoPage;
}
public function setInfoPage(?InfoPage $infoPage): self
{
$this->infoPage = $infoPage;
return $this;
}
public function getTimelinePosition(): ?string
{
return $this->timelinePosition;
}
public function setTimelinePosition(?string $timelinePosition): self
{
$this->timelinePosition = $timelinePosition;
return $this;
}
}