<?php
namespace Rawafed\ContactFormsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Rawafed\CommonsBundle\DoctrineExtensions\Localizable;
use JMS\Serializer\Annotation as Serializer;
/**
* ContactUsCategory
*
* @ORM\Table(indexes={@ORM\Index(name="idx_name", columns={"name"})})
* @ORM\Entity(repositoryClass="Rawafed\ContactFormsBundle\Entity\Repository\ContactUsCategoryRepository")
*/
class ContactUsCategory extends Localizable
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)
* @Assert\NotBlank()
*/
private $name;
/**
* @var string
*
* @ORM\Column(type="string", length=127, nullable=true)
*/
private $tag;
/**
* @ORM\Column(name="is_enabled", type="boolean", options={"default" = true})
* @Serializer\Exclude
*/
private $enabled = true;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default" = false})
* @Serializer\Exclude
*/
private $is_system = false;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default" = false})
*/
private $has_attachments = false;
/**
* @ORM\Column(type="integer", options={"default" = 65535})
* @Serializer\Exclude
*/
private $view_order = 65535;
/**
* @ORM\OneToMany(targetEntity="ContactUsMessage", mappedBy="category")
* @Serializer\Exclude
**/
protected $messages;
/**
* @ORM\OneToMany(targetEntity="ContactUsEmailRecipient", mappedBy="category", orphanRemoval=true, cascade={"all"})
* @ORM\OrderBy({"type" = "ASC", "email" = "Asc"})
* @Assert\Valid()
* @Assert\NotNull()
* @Assert\Count(min = 1, minMessage = "contactforms.messages.email_recipients_are_mandatory")
* @Serializer\Exclude
**/
protected $emailRecipients;
public function __construct()
{
$this->messages = new ArrayCollection();
$this->emailRecipients = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return ContactUsCategory
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set tag
*
* @param string $tag
* @return ContactUsCategory
*/
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
/**
* Get tag
*
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* Set enabled
*
* @param boolean $enabled
* @return ContactUsCategory
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
return $this;
}
/**
* Get enabled
*
* @return boolean
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* @return bool
*/
public function isSystem()
{
return $this->is_system;
}
/**
* @param bool $is_system
* @return ContactUsCategory
*/
public function setIsSystem($is_system)
{
$this->is_system = $is_system;
return $this;
}
/**
* @return bool
*/
public function hasAttachments()
{
return $this->has_attachments;
}
/**
* @param bool $has_attachments
* @return ContactUsCategory
*/
public function setHasAttachments($has_attachments)
{
$this->has_attachments = $has_attachments;
return $this;
}
/**
* Set view_order
*
* @param integer $viewOrder
* @return ContactUsCategory
*/
public function setViewOrder($viewOrder)
{
$this->view_order = $viewOrder;
return $this;
}
/**
* Get view_order
*
* @return integer
*/
public function getViewOrder()
{
return $this->view_order;
}
public function getMessages()
{
return $this->messages;
}
public function getEmailRecipients()
{
return $this->emailRecipients;
}
public function getEmailRecipientById($id)
{
foreach($this->getEmailRecipients() as $recipient) {
if($recipient->getId() == $id) {
return $recipient;
}
}
return null;
}
public function addEmailRecipient(ContactUsEmailRecipient $emailRecipient)
{
$emailRecipient->setCategory($this);
$this->emailRecipients->add($emailRecipient);
return $this;
}
public function removeEmailRecipient(ContactUsEmailRecipient $emailRecipient)
{
$this->emailRecipients->removeElement($emailRecipient);
return $this;
}
public function __toString()
{
return $this->getName();
}
}