Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/src/CoreBundle/Entity/MessageRelUser.php

166 lines
3.7 KiB

<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="message_rel_user", indexes={
* },
* uniqueConstraints={
* @ORM\UniqueConstraint(name="message_receiver", columns={"message_id", "user_id"})
* },
* )
* @ORM\Entity()
*/
#[UniqueEntity(
fields: ['message', 'receiver'],
errorPath: 'message',
message: 'This message-receiver relation is already used.',
)]
// @todo add security checks.
#[ApiResource]
class MessageRelUser
{
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue()
*/
#[Groups(['message:read', 'message:write'])]
protected ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity="Message", inversedBy="receivers", cascade={"persist"})
* @ORM\JoinColumn(name="message_id", referencedColumnName="id", nullable=false)
*/
protected Message $message;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", cascade={"persist"})
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
#[Assert\NotNull]
#[Groups(['message:read', 'message:write'])]
protected User $receiver;
/**
* @ORM\Column(name="msg_read", type="boolean", nullable=false)
*/
#[Groups(['message:read', 'message:write'])]
protected bool $read;
/**
* @ORM\Column(name="starred", type="boolean", nullable=false)
*/
#[Groups(['message:read', 'message:write'])]
protected bool $starred;
/**
* @var Collection|MessageTag[]
*
* @ORM\ManyToMany(targetEntity="MessageTag", inversedBy="messageRelUsers", cascade={"persist"})
* @ORM\JoinTable(name="message_rel_user_rel_tags")
*/
#[Assert\Valid]
#[Groups(['message:read', 'message:write'])]
protected Collection $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
$this->read = false;
$this->starred = false;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @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 isRead(): bool
{
return $this->read;
}
public function setRead(bool $read): self
{
$this->read = $read;
return $this;
}
public function isStarred(): bool
{
return $this->starred;
}
public function setStarred(bool $starred): self
{
$this->starred = $starred;
return $this;
}
public function getMessage(): Message
{
return $this->message;
}
public function setMessage(Message $message): self
{
$this->message = $message;
return $this;
}
public function getReceiver(): User
{
return $this->receiver;
}
public function setReceiver(User $receiver): self
{
$this->receiver = $receiver;
return $this;
}
}