TemplateSystem.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace AppBundle\Entity\Message;
  3. use AppBundle\Annotation\DefaultField;
  4. use AppBundle\Entity\Core\File;
  5. use AppBundle\Entity\Organization\Organization;
  6. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  7. use AppBundle\Entity\Traits\TimestampableEntity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13. * Template system
  14. */
  15. #[ORM\Entity(repositoryClass: 'AppBundle\Entity\Message\Repository\TemplateSystemRepository')]
  16. #[ORM\Table(name: 'TemplateSystem')]
  17. #[ORM\UniqueConstraint(name: 'template_organization_idx', columns: ['template', 'organization_id'])]
  18. class TemplateSystem
  19. {
  20. use TimestampableEntity;
  21. use CreatorUpdaterEntity;
  22. /**
  23. * @var int
  24. */
  25. #[ORM\Column(type: 'integer')]
  26. #[ORM\Id]
  27. #[ORM\GeneratedValue(strategy: 'AUTO')]
  28. #[Groups(['templatesystem'])]
  29. private $id;
  30. /**
  31. * @var Organization
  32. *
  33. * @DefaultField
  34. */
  35. #[ORM\ManyToOne(targetEntity: 'AppBundle\Entity\Organization\Organization')]
  36. #[Groups(['templatesystem'])]
  37. private $organization;
  38. /**
  39. * @var string
  40. */
  41. #[ORM\Column(type: 'string', nullable: true)]
  42. #[Assert\Type(type: 'string')]
  43. #[Groups(['templatesystem'])]
  44. private $subject;
  45. /**
  46. * @var string
  47. */
  48. #[ORM\Column(type: 'string')]
  49. #[Assert\Type(type: 'string')]
  50. #[Assert\Choice(callback: ['AppBundle\Enum\Message\TemplateSystemEnum', 'toArray'])]
  51. #[Groups(['templatesystem'])]
  52. private $template;
  53. /**
  54. * @var string
  55. */
  56. #[ORM\Column(type: 'text', nullable: true)]
  57. #[Assert\Type(type: 'string')]
  58. #[Groups(['templatesystem'])]
  59. private $text;
  60. /**
  61. * @var ArrayCollection<File>
  62. */
  63. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Core\File', mappedBy: 'templateSystem', orphanRemoval: true)]
  64. #[Groups(['templatesystem'])]
  65. private $files;
  66. public function __construct()
  67. {
  68. $this->files = new ArrayCollection();
  69. }
  70. /**
  71. * Sets id.
  72. *
  73. * @param int $id
  74. *
  75. * @return $this
  76. */
  77. public function setId($id)
  78. {
  79. $this->id = $id;
  80. return $this;
  81. }
  82. /**
  83. * Gets id.
  84. *
  85. * @return int
  86. */
  87. public function getId()
  88. {
  89. return $this->id;
  90. }
  91. /**
  92. * Set organization
  93. *
  94. * @param Organization $organization
  95. *
  96. * @return TemplateSystem
  97. */
  98. public function setOrganization(Organization $organization = null)
  99. {
  100. $this->organization = $organization;
  101. return $this;
  102. }
  103. /**
  104. * Get organization
  105. *
  106. * @return Organization
  107. */
  108. public function getOrganization()
  109. {
  110. return $this->organization;
  111. }
  112. /**
  113. * Sets subject.
  114. *
  115. * @param string $subject
  116. *
  117. * @return $this
  118. */
  119. public function setSubject($subject)
  120. {
  121. $this->subject = $subject;
  122. return $this;
  123. }
  124. /**
  125. * Gets subject.
  126. *
  127. * @return string
  128. */
  129. public function getSubject()
  130. {
  131. return $this->subject;
  132. }
  133. /**
  134. * Sets template.
  135. *
  136. * @param string $template
  137. *
  138. * @return $this
  139. */
  140. public function setTemplate($template)
  141. {
  142. $this->template = $template;
  143. return $this;
  144. }
  145. /**
  146. * Gets template.
  147. *
  148. * @return string
  149. */
  150. public function getTemplate()
  151. {
  152. return $this->template;
  153. }
  154. /**
  155. * Set text
  156. *
  157. * @param string $text
  158. *
  159. * @return Message
  160. */
  161. public function setText($text)
  162. {
  163. $this->text = $text;
  164. return $this;
  165. }
  166. /**
  167. * Get text
  168. *
  169. * @return string
  170. */
  171. public function getText()
  172. {
  173. return html_entity_decode($this->text);
  174. }
  175. /**
  176. * Adds file.
  177. *
  178. * @param File $file
  179. *
  180. * @return $this
  181. */
  182. public function addFile(File $file)
  183. {
  184. $file->setTemplateSystem($this);
  185. $this->files->add($file);
  186. return $this;
  187. }
  188. /**
  189. * Removes file.
  190. *
  191. * @param File $file
  192. *
  193. * @return $this
  194. */
  195. public function removeFile(File $file)
  196. {
  197. $this->files->removeElement($file);
  198. return $this;
  199. }
  200. /**
  201. * Gets files.
  202. *
  203. * @return ArrayCollection<File>
  204. */
  205. public function getFiles()
  206. {
  207. return $this->files;
  208. }
  209. }