vendor/rawafed/contact-forms-bundle/Entity/ContactUsMessage.php line 19

Open in your IDE?
  1. <?php
  2. namespace Rawafed\ContactFormsBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Rawafed\CommonsBundle\Entity\Country;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Rawafed\EnhancedUploaderBundle\Mapping\Annotation as Uploader;
  10. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  11. use JMS\Serializer\Annotation as Serializer;
  12. /**
  13.  * @ORM\Entity(repositoryClass="Rawafed\ContactFormsBundle\Entity\Repository\ContactUsMessageRepository")
  14.  * @Uploader\Uploadable
  15.  */
  16. class ContactUsMessage
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\Column(type="integer")
  21.      * @ORM\GeneratedValue(strategy="AUTO")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      * @Assert\NotBlank()
  27.      * @Serializer\Groups({"post"})
  28.      */
  29.     private $name;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      * @Assert\NotBlank()
  33.      * @Assert\Email(message="contactforms.messages.bad_email", checkMX=true)
  34.      * @Serializer\Groups({"post"})
  35.      */
  36.     private $email;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      * @Serializer\Groups({"post"})
  40.      */
  41.     private $mobile;
  42.     /**
  43.      * @ORM\Column(type="string", length=255)
  44.      * @Assert\NotBlank()
  45.      * @Serializer\Groups({"post"})
  46.      */
  47.     private $title;
  48.     /**
  49.      * @ORM\Column(type="text")
  50.      * @Assert\NotBlank()
  51.      * @Serializer\Groups({"post"})
  52.      */
  53.     private $message;
  54.     /**
  55.      * @ORM\Column(name="date_time", type="datetime")
  56.      * @Gedmo\Timestampable(on="create")
  57.      */
  58.     private $dateTime;
  59.     /**
  60.      * @ORM\Column(type="EnumMessageStatus", nullable=true, options={"default" : "new"})
  61.      */
  62.     protected $status MessageStatus::NEW;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="ContactUsMessageReply", mappedBy="message", cascade={"persist", "remove"})
  65.      */
  66.     protected $replies;
  67.     /**
  68.      * @var ContactUsCategory
  69.      *
  70.      * @ORM\ManyToOne(targetEntity="ContactUsCategory", inversedBy="messages")
  71.      * @ORM\JoinColumns({
  72.      *   @ORM\JoinColumn(name="category_id", referencedColumnName="id")
  73.      * })
  74.      * @Assert\NotBlank()
  75.      */
  76.     private $category;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity="Rawafed\CommonsBundle\Entity\Country")
  79.      */
  80.     private $country;
  81.     /**
  82.      * @Uploader\UploadableField(mapping="rawafed_upload", fileNameProperty="attachment", uploadsDirName="contactforms")
  83.      *
  84.      * @var File $attachmentFile
  85.      */
  86.     protected $attachmentFile;
  87.     /**
  88.      * @var string
  89.      *
  90.      * @ORM\Column(name="attachment", type="string", nullable=true)
  91.      */
  92.     private $attachment;
  93.     public function __construct()
  94.     {
  95.         $this->replies = new ArrayCollection();
  96.     }
  97.     /**
  98.      * Get id
  99.      *
  100.      * @return integer 
  101.      */
  102.     public function getId()
  103.     {
  104.         return $this->id;
  105.     }
  106.     /**
  107.      * Set name
  108.      *
  109.      * @param string $name
  110.      * @return ContactUsMessage
  111.      */
  112.     public function setName($name)
  113.     {
  114.         $this->name $name;
  115.         return $this;
  116.     }
  117.     /**
  118.      * Get name
  119.      *
  120.      * @return string 
  121.      */
  122.     public function getName()
  123.     {
  124.         return $this->name;
  125.     }
  126.     /**
  127.      * Set email
  128.      *
  129.      * @param string $email
  130.      * @return ContactUsMessage
  131.      */
  132.     public function setEmail($email)
  133.     {
  134.         $this->email $email;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Get email
  139.      *
  140.      * @return string 
  141.      */
  142.     public function getEmail()
  143.     {
  144.         return $this->email;
  145.     }
  146.     /**
  147.      * Set mobile
  148.      *
  149.      * @param string $mobile
  150.      * @return ContactUsMessage
  151.      */
  152.     public function setMobile($mobile)
  153.     {
  154.         $this->mobile $mobile;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Get mobile
  159.      *
  160.      * @return string 
  161.      */
  162.     public function getMobile()
  163.     {
  164.         return $this->mobile;
  165.     }
  166.     /**
  167.      * Set title
  168.      *
  169.      * @param string $title
  170.      * @return ContactUsMessage
  171.      */
  172.     public function setTitle($title)
  173.     {
  174.         $this->title $title;
  175.         return $this;
  176.     }
  177.     /**
  178.      * Get title
  179.      *
  180.      * @return string 
  181.      */
  182.     public function getTitle()
  183.     {
  184.         return $this->title;
  185.     }
  186.     /**
  187.      * Set message
  188.      *
  189.      * @param string $message
  190.      * @return ContactUsMessage
  191.      */
  192.     public function setMessage($message)
  193.     {
  194.         $this->message $message;
  195.         return $this;
  196.     }
  197.     /**
  198.      * Get message
  199.      *
  200.      * @return string 
  201.      */
  202.     public function getMessage()
  203.     {
  204.         return $this->message;
  205.     }
  206.     /**
  207.      * Set dateTime
  208.      *
  209.      * @param \DateTime $dateTime
  210.      * @return ContactUsMessage
  211.      */
  212.     public function setDateTime($dateTime)
  213.     {
  214.         $this->dateTime $dateTime;
  215.         return $this;
  216.     }
  217.     /**
  218.      * Get dateTime
  219.      *
  220.      * @return \DateTime 
  221.      */
  222.     public function getDateTime()
  223.     {
  224.         return $this->dateTime;
  225.     }
  226.     /**
  227.      * Set status
  228.      *
  229.      * @param string $status
  230.      * @return Account
  231.      */
  232.     public function setStatus($status)
  233.     {
  234.         $this->status $status;
  235.         return $this;
  236.     }
  237.     /**
  238.      * Get status
  239.      *
  240.      * @return string
  241.      */
  242.     public function getStatus()
  243.     {
  244.         return $this->status;
  245.     }
  246.     /**
  247.      * Set category
  248.      *
  249.      * @param ContactUsCategory $category
  250.      * @return ContactUsMessage
  251.      */
  252.     public function setCategory(ContactUsCategory $category null)
  253.     {
  254.         $this->category $category;
  255.         return $this;
  256.     }
  257.     /**
  258.      * Get category
  259.      *
  260.      * @return ContactUsCategory 
  261.      */
  262.     public function getCategory()
  263.     {
  264.         return $this->category;
  265.     }
  266.     /**
  267.      * Set country
  268.      *
  269.      * @param Country $country
  270.      * @return ContactUsMessage
  271.      */
  272.     public function setCountry(Country $country null)
  273.     {
  274.         $this->country $country;
  275.         return $this;
  276.     }
  277.     /**
  278.      * Get country
  279.      *
  280.      * @return Country
  281.      */
  282.     public function getCountry()
  283.     {
  284.         return $this->country;
  285.     }
  286.     /**
  287.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $attachmentFile
  288.      * @return ContactUsMessage
  289.      */
  290.     public function setAttachmentFile(File $attachmentFile null)
  291.     {
  292.         $this->attachmentFile $attachmentFile;
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return \Symfony\Component\HttpFoundation\File\File
  297.      */
  298.     public function getAttachmentFile()
  299.     {
  300.         return $this->attachmentFile;
  301.     }
  302.     /**
  303.      * @param string $attachment
  304.      * @return ContactUsMessage
  305.      */
  306.     public function setAttachment($attachment)
  307.     {
  308.         $this->attachment $attachment;
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return string
  313.      */
  314.     public function getAttachment()
  315.     {
  316.         return $this->attachment;
  317.     }
  318.     public function __toString()
  319.     {
  320.         return $this->getTitle();
  321.     }
  322.     /**
  323.      * @return \Doctrine\Common\Collections\Collection
  324.      */
  325.     public function getReplies()
  326.     {
  327.         return $this->replies;
  328.     }
  329.     /**
  330.      * Add reply
  331.      *
  332.      * @param ContactUsMessageReply $contactUsMessageReply
  333.      * @return ContactUsMessage
  334.      */
  335.     public function addReply($messageReply)
  336.     {
  337.         $contactUsMessageReply = new ContactUsMessageReply();
  338.         $contactUsMessageReply->setReplyMessage($messageReply);
  339.         $contactUsMessageReply->setMessage($this);
  340.         if (!$this->replies->contains($contactUsMessageReply)) {
  341.             $this->replies->add($contactUsMessageReply);
  342.             // dd('dd');
  343.         }
  344.         return $this;
  345.     }
  346.     /**
  347.      * @Assert\Callback
  348.      */
  349.     public function validate(ExecutionContextInterface $context)
  350.     {
  351.         if($this->getAttachmentFile() && !$this->getCategory()->hasAttachments()) {
  352.             $context->buildViolation('This category does not allow attachments')
  353.                 ->atPath('attachment')
  354.                 ->addViolation();
  355.         }
  356.     }
  357. }