src/Entity/Message/Message.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Message;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. /**
  6.  * Message
  7.  *
  8.  * @ORM\Table(name="tam_messages")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Message\MessageRepository")
  10.  */
  11. class Message
  12. {
  13.     /**
  14.      * @var int
  15.      *
  16.      * @ORM\Column(name="id", type="integer")
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue(strategy="IDENTITY")
  19.      */
  20.     private $id;
  21.     
  22.     /**
  23.      * @var \App\Entity\User
  24.      *
  25.      * @ORM\ManyToOne(targetEntity="\App\Entity\User", fetch="EAGER", inversedBy="sendedMessages")
  26.      * @ORM\JoinColumns({
  27.      *   @ORM\JoinColumn(name="sender", referencedColumnName="id", onDelete="SET NULL")
  28.      * })
  29.      */
  30.     private $sender;
  31.     
  32.     /**
  33.      * @var \App\Entity\User
  34.      *
  35.      * @ORM\ManyToOne(targetEntity="\App\Entity\User", fetch="EAGER", inversedBy="receivedMessages")
  36.      * @ORM\JoinColumns({
  37.      *   @ORM\JoinColumn(name="recipient", referencedColumnName="id", onDelete="SET NULL")
  38.      * })
  39.      */
  40.     private $recipient;
  41.     
  42.     /**
  43.      * @var string
  44.      *
  45.      * @ORM\Column(name="message", type="text", nullable=true)
  46.      */
  47.     private $message;
  48.         
  49.     /**
  50.      * @var \DateTime
  51.      *
  52.      * @ORM\Column(name="date_message", type="datetime", nullable=false)
  53.      */
  54.     private $dateMessage;
  55.     
  56.     /**
  57.      * @var boolean
  58.      *
  59.      * @ORM\Column(name="read", type="boolean", options={"default": FALSE})
  60.      */
  61.     private $read;
  62.     
  63.     /**
  64.      * @var \DateTime
  65.      *
  66.      * @ORM\Column(name="date_read", type="datetime", nullable=true)
  67.      */
  68.     private $dateRead;
  69.     
  70.     
  71.     public function __construct()
  72.     {
  73.         $this->dateMessage = new \DateTime();
  74.         $this->read false;
  75.     }
  76.     /**
  77.      * Get id
  78.      *
  79.      * @return int
  80.      */
  81.     public function getId()
  82.     {
  83.         return $this->id;
  84.     }
  85.     
  86.     /**
  87.      * Set sender
  88.      *
  89.      * @param User $sender
  90.      *
  91.      * @return Message
  92.      */
  93.     public function setSender($sender)
  94.     {
  95.         $this->sender $sender;
  96.         return $this;
  97.     }
  98.     /**
  99.      * Get sender
  100.      *
  101.      * @return User
  102.      */
  103.     public function getSender()
  104.     {
  105.         return $this->sender;
  106.     }
  107.     
  108.     /**
  109.      * Set recipient
  110.      *
  111.      * @param User $recipient
  112.      *
  113.      * @return Message
  114.      */
  115.     public function setRecipient($recipient)
  116.     {
  117.         $this->recipient $recipient;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Get recipient
  122.      *
  123.      * @return User
  124.      */
  125.     public function getRecipient()
  126.     {
  127.         return $this->recipient;
  128.     }
  129.     
  130.     /**
  131.      * Set message
  132.      *
  133.      * @param string $message
  134.      *
  135.      * @return Message
  136.      */
  137.     public function setMessage($message)
  138.     {
  139.         $this->message $message;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get message
  144.      *
  145.      * @return string
  146.      */
  147.     public function getMessage()
  148.     {
  149.         return $this->message;
  150.     }
  151.     
  152.     /**
  153.      * Set dateMessage
  154.      *
  155.      * @param \DateTime $dateMessage
  156.      *
  157.      * @return Message
  158.      */
  159.     public function setDateMessage($dateMessage)
  160.     {
  161.         $this->dateMessage $dateMessage;
  162.         return $this;
  163.     }
  164.     /**
  165.      * Get dateMessage
  166.      *
  167.      * @return \DateTime
  168.      */
  169.     public function getDateMessage()
  170.     {
  171.         return $this->dateMessage;
  172.     }
  173.     
  174.     /**
  175.      * Set read
  176.      *
  177.      * @param boolean $read
  178.      *
  179.      * @return Message
  180.      */
  181.     public function setRead($read)
  182.     {
  183.         $this->read $read;
  184.         return $this;
  185.     }
  186.     /**
  187.      * Get read
  188.      *
  189.      * @return boolean
  190.      */
  191.     public function getRead()
  192.     {
  193.         return $this->read;
  194.     }
  195.     
  196.     /**
  197.      * Set dateRead
  198.      *
  199.      * @param \DateTime $dateRead
  200.      *
  201.      * @return Message
  202.      */
  203.     public function setDateRead($dateRead)
  204.     {
  205.         $this->dateRead $dateRead;
  206.         return $this;
  207.     }
  208.     /**
  209.      * Get dateRead
  210.      *
  211.      * @return \DateTime
  212.      */
  213.     public function getDateRead()
  214.     {
  215.         return $this->dateRead;
  216.     }
  217.     
  218.     
  219.     /***********************
  220.      * OTHER FUNCTION
  221.      ***********************/
  222.      
  223.      
  224.     public function getArrayForJson($schemeAndBaseURL){
  225.         $array = array();
  226.         $array['id'] = $this->getId();
  227.         $array['sender'] = $this->getSender()->getSimpleArrayForJson($schemeAndBaseURL);
  228.         $array['recipient'] = $this->getRecipient()->getSimpleArrayForJson($schemeAndBaseURL);
  229.         $array['message'] = $this->getMessage();
  230.         if($this->getDateMessage()){
  231.             $array['dateMessage'] = $this->getDateMessage()->format("Y-m-d\TH:i:sP");
  232.         }
  233.         if($this->getDateRead()){
  234.             $array['dateRead'] = $this->getDateRead()->format("Y-m-d\TH:i:sP");
  235.         }
  236.         $array['read'] = $this->getRead();
  237.         
  238.         return $array;
  239.         
  240.     }
  241.     
  242.     
  243. }