[], 'post' => [ 'security' => "is_granted('ROLE_USER')", // 'deserialize' => false, // 'controller' => Create::class, // 'openapi_context' => [ // 'requestBody' => [ // 'content' => [ // 'multipart/form-data' => [ // 'schema' => [ // 'type' => 'object', // 'properties' => [ // 'title' => [ // 'type' => 'string', // ], // 'content' => [ // 'type' => 'string', // ], // ], // ], // ], // ], // ], // ], ], ], itemOperations: [ 'get' => [ 'security' => "is_granted('VIEW', object)", ], 'put' => [ 'security' => "is_granted('EDIT', object)", ], 'delete' => [ 'security' => "is_granted('DELETE', object)", ], ], attributes: [ 'security' => "is_granted('ROLE_USER')", ], denormalizationContext: [ 'groups' => ['message:write'], ], normalizationContext: [ 'groups' => ['message:read'], ], )] #[ApiFilter(OrderFilter::class, properties: ['title', 'sendDate'])] #[ApiFilter(SearchFilter::class, properties: [ 'read' => 'exact', 'msgType' => 'exact', 'userSender' => 'exact', 'userReceiver' => 'exact', ])] class Message { public const MESSAGE_TYPE_INBOX = 1; public const MESSAGE_TYPE_OUTBOX = 2; public const MESSAGE_TYPE_PROMOTED = 3; /** * @ORM\Column(name="id", type="bigint") * @ORM\Id * @ORM\GeneratedValue() */ #[Groups(['message:read'])] protected int $id; /** * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="sentMessages") * @ORM\JoinColumn(name="user_sender_id", referencedColumnName="id", nullable=false) */ #[Assert\NotBlank] #[Groups(['message:read', 'message:write'])] protected User $userSender; /** * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="receivedMessages") * @ORM\JoinColumn(name="user_receiver_id", referencedColumnName="id", nullable=true) */ #[Groups(['message:read', 'message:write'])] protected User $userReceiver; /** * @ORM\Column(name="msg_type", type="smallint", nullable=false) */ #[Assert\NotBlank] #[Assert\Choice([ self::MESSAGE_TYPE_INBOX, self::MESSAGE_TYPE_OUTBOX, self::MESSAGE_TYPE_PROMOTED, ])] #[Groups(['message:read', 'message:write'])] protected int $msgType; /** * @ORM\Column(name="msg_read", type="boolean", nullable=false) */ #[Assert\NotNull] #[Groups(['message:read', 'message:write'])] protected bool $read; /** * @ORM\Column(name="send_date", type="datetime", nullable=false) */ #[Groups(['message:read'])] protected DateTime $sendDate; /** * @ORM\Column(name="title", type="string", length=255, nullable=false) */ #[Assert\NotBlank] #[Groups(['message:read', 'message:write'])] protected string $title; /** * @ORM\Column(name="content", type="text", nullable=false) */ #[Assert\NotBlank] #[Groups(['message:read', 'message:write'])] protected string $content; /** * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroup") * @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true, onDelete="CASCADE") */ protected ?CGroup $group = null; /** * @var Collection|Message[] * @ORM\OneToMany(targetEntity="Message", mappedBy="parent") */ protected Collection $children; /** * @ORM\ManyToOne(targetEntity="Message", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") */ protected ?Message $parent = null; /** * @Gedmo\Timestampable(on="update") * @ORM\Column(name="update_date", type="datetime", nullable=true) */ protected ?DateTime $updateDate; /** * @ORM\Column(name="votes", type="integer", nullable=true) */ protected ?int $votes; /** * @var Collection|MessageAttachment[] * * @ORM\OneToMany(targetEntity="MessageAttachment", mappedBy="message") */ protected Collection $attachments; /** * @var Collection|MessageFeedback[] * * @ORM\OneToMany(targetEntity="MessageFeedback", mappedBy="message", orphanRemoval=true) */ protected Collection $likes; /** * @var Collection|MessageTag[] * * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\MessageTag", inversedBy="messages", cascade={"persist"}) * @ORM\JoinTable(name="message_rel_tags") */ #[Groups(['message:read', 'message:write'])] protected Collection $tags; public function __construct() { $this->sendDate = new DateTime('now'); $this->updateDate = $this->sendDate; $this->content = ''; $this->attachments = new ArrayCollection(); $this->children = new ArrayCollection(); $this->tags = new ArrayCollection(); $this->likes = new ArrayCollection(); $this->votes = 0; $this->read = false; } /** * @return Collection|MessageTag[] */ public function getTags() { return $this->tags; } public function addTag(MessageTag $tag): self { if (!$this->tags->contains($tag)) { $this->tags->add($tag); } return $this; } public function removeTag(MessageTag $tag): self { if ($this->tags->contains($tag)) { $this->tags->removeElement($tag); } return $this; } public function setUserSender(User $userSender): self { $this->userSender = $userSender; return $this; } public function getUserSender(): User { return $this->userSender; } public function setUserReceiver(User $userReceiver): self { $this->userReceiver = $userReceiver; return $this; } /** * Get userReceiver. * * @return User */ public function getUserReceiver() { return $this->userReceiver; } public function setMsgType(int $msgType): self { $this->msgType = $msgType; return $this; } public function getMsgType(): int { return $this->msgType; } public function setSendDate(DateTime $sendDate): self { $this->sendDate = $sendDate; return $this; } /** * Get sendDate. * * @return DateTime */ public function getSendDate() { return $this->sendDate; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getTitle(): string { return $this->title; } public function setContent(string $content): self { $this->content = $content; return $this; } /** * Get content. * * @return string */ public function getContent() { return $this->content; } public function setUpdateDate(DateTime $updateDate): self { $this->updateDate = $updateDate; return $this; } /** * Get updateDate. * * @return DateTime */ public function getUpdateDate() { return $this->updateDate; } /** * Get id. * * @return int */ public function getId() { return $this->id; } public function setVotes(int $votes): self { $this->votes = $votes; return $this; } public function getVotes(): int { return $this->votes; } /** * Get attachments. * * @return Collection|MessageAttachment[] */ public function getAttachments() { return $this->attachments; } public function addAttachment(MessageAttachment $attachment): self { $this->attachments->add($attachment); $attachment->setMessage($this); return $this; } public function getParent(): ?self { return $this->parent; } /** * @return Collection|Message[] */ public function getChildren() { return $this->children; } public function addChild(self $child): self { $this->children[] = $child; $child->setParent($this); return $this; } public function setParent(self $parent = null): self { $this->parent = $parent; return $this; } /** * @return MessageFeedback[]|Collection */ public function getLikes() { return $this->likes; } public function getGroup(): ?CGroup { return $this->group; } public function setGroup(?CGroup $group): self { $this->group = $group; return $this; } public function isRead(): bool { return $this->read; } public function setRead(bool $read): self { $this->read = $read; return $this; } }