<?php
namespace App\Entity\Message;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Message
*
* @ORM\Table(name="tam_messages")
* @ORM\Entity(repositoryClass="App\Repository\Message\MessageRepository")
*/
class Message
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var \App\Entity\User
*
* @ORM\ManyToOne(targetEntity="\App\Entity\User", fetch="EAGER", inversedBy="sendedMessages")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="sender", referencedColumnName="id", onDelete="SET NULL")
* })
*/
private $sender;
/**
* @var \App\Entity\User
*
* @ORM\ManyToOne(targetEntity="\App\Entity\User", fetch="EAGER", inversedBy="receivedMessages")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="recipient", referencedColumnName="id", onDelete="SET NULL")
* })
*/
private $recipient;
/**
* @var string
*
* @ORM\Column(name="message", type="text", nullable=true)
*/
private $message;
/**
* @var \DateTime
*
* @ORM\Column(name="date_message", type="datetime", nullable=false)
*/
private $dateMessage;
/**
* @var boolean
*
* @ORM\Column(name="read", type="boolean", options={"default": FALSE})
*/
private $read;
/**
* @var \DateTime
*
* @ORM\Column(name="date_read", type="datetime", nullable=true)
*/
private $dateRead;
public function __construct()
{
$this->dateMessage = new \DateTime();
$this->read = false;
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set sender
*
* @param User $sender
*
* @return Message
*/
public function setSender($sender)
{
$this->sender = $sender;
return $this;
}
/**
* Get sender
*
* @return User
*/
public function getSender()
{
return $this->sender;
}
/**
* Set recipient
*
* @param User $recipient
*
* @return Message
*/
public function setRecipient($recipient)
{
$this->recipient = $recipient;
return $this;
}
/**
* Get recipient
*
* @return User
*/
public function getRecipient()
{
return $this->recipient;
}
/**
* Set message
*
* @param string $message
*
* @return Message
*/
public function setMessage($message)
{
$this->message = $message;
return $this;
}
/**
* Get message
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* Set dateMessage
*
* @param \DateTime $dateMessage
*
* @return Message
*/
public function setDateMessage($dateMessage)
{
$this->dateMessage = $dateMessage;
return $this;
}
/**
* Get dateMessage
*
* @return \DateTime
*/
public function getDateMessage()
{
return $this->dateMessage;
}
/**
* Set read
*
* @param boolean $read
*
* @return Message
*/
public function setRead($read)
{
$this->read = $read;
return $this;
}
/**
* Get read
*
* @return boolean
*/
public function getRead()
{
return $this->read;
}
/**
* Set dateRead
*
* @param \DateTime $dateRead
*
* @return Message
*/
public function setDateRead($dateRead)
{
$this->dateRead = $dateRead;
return $this;
}
/**
* Get dateRead
*
* @return \DateTime
*/
public function getDateRead()
{
return $this->dateRead;
}
/***********************
* OTHER FUNCTION
***********************/
public function getArrayForJson($schemeAndBaseURL){
$array = array();
$array['id'] = $this->getId();
$array['sender'] = $this->getSender()->getSimpleArrayForJson($schemeAndBaseURL);
$array['recipient'] = $this->getRecipient()->getSimpleArrayForJson($schemeAndBaseURL);
$array['message'] = $this->getMessage();
if($this->getDateMessage()){
$array['dateMessage'] = $this->getDateMessage()->format("Y-m-d\TH:i:sP");
}
if($this->getDateRead()){
$array['dateRead'] = $this->getDateRead()->format("Y-m-d\TH:i:sP");
}
$array['read'] = $this->getRead();
return $array;
}
}