src/Entity/MatterCommunication.php line 23

Open in your IDE?
  1. <?php
  2. namespace MedBrief\MSR\Entity;
  3. use DH\Auditor\Provider\Doctrine\Auditing\Annotation as Audit;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use MedBrief\MSR\Traits\FilterableClassConstantsTrait;
  7. /**
  8. * MatterCommunication
  9. *
  10. * @ORM\Table(name="MatterCommunication")
  11. *
  12. * @ORM\Entity
  13. *
  14. * @ORM\HasLifecycleCallbacks
  15. *
  16. * @Audit\Auditable
  17. *
  18. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  19. */
  20. class MatterCommunication
  21. {
  22. use FilterableClassConstantsTrait;
  23. // Label constants
  24. public const LABEL_IMPORTANT = 'important';
  25. public const LABEL_IMPORTANT__LABEL = 'Important';
  26. public const LABEL_INSTRUCTION = 'instruction';
  27. public const LABEL_INSTRUCTION__LABEL = 'Instruction';
  28. public const LABEL_INITIAL_INSTRUCTION = 'initial_instruction';
  29. public const LABEL_INITIAL_INSTRUCTION__LABEL = 'Initial Instruction';
  30. public const LABEL_ISSUE = 'issue';
  31. public const LABEL_ISSUE__LABEL = 'Issue';
  32. public const LABEL_FEEDBACK = 'feedback';
  33. public const LABEL_FEEDBACK__LABEL = 'Feedback';
  34. public const LABEL_COMPLAINT = 'complaint';
  35. public const LABEL_COMPLAINT__LABEL = 'Complaint';
  36. public const LABEL_ACTION_REQUIRED = 'action_required';
  37. public const LABEL_ACTION_REQUIRED__LABEL = 'Action Required';
  38. public const LABEL_COMPLETE = 'complete';
  39. public const LABEL_COMPLETE__LABEL = 'Complete';
  40. public const LABEL_RELEASE = 'release';
  41. public const LABEL_RELEASE__LABEL = 'Release';
  42. public const LABEL_NOTIFICATION = 'notification';
  43. public const LABEL_NOTIFICATION__LABEL = 'Notification';
  44. public const LABEL_EXPERT = 'expert';
  45. public const LABEL_EXPERT__LABEL = 'Expert';
  46. public const LABEL_INTERNAL = 'internal';
  47. public const LABEL_INTERNAL__LABEL = 'Internal';
  48. public const LABEL_REDACTION = 'redaction';
  49. public const LABEL_REDACTION__LABEL = 'Redaction';
  50. public const LABEL_AMENDMENT = 'amendment';
  51. public const LABEL_AMENDMENT__LABEL = 'Amendment';
  52. // Send receive Constants
  53. public const TYPE_SENT = true;
  54. public const TYPE_SENT__LABEL = 'Sent';
  55. public const TYPE_RECEIVED = false;
  56. public const TYPE_RECEIVED__LABEL = 'Received';
  57. /**
  58. * @var int
  59. *
  60. * @ORM\Column(name="id", type="integer")
  61. *
  62. * @ORM\Id
  63. *
  64. * @ORM\GeneratedValue(strategy="IDENTITY")
  65. */
  66. private $id;
  67. /**
  68. * @var array|null
  69. *
  70. * @ORM\Column(name="labels", type="array", nullable=true)
  71. */
  72. private $labels;
  73. /**
  74. * @var string|null
  75. *
  76. * @ORM\Column(name="content", type="text", nullable=true)
  77. */
  78. private $content;
  79. /**
  80. * @var \DateTime
  81. *
  82. * @ORM\Column(name="created", type="datetime")
  83. *
  84. * @Gedmo\Timestampable(on="create")
  85. */
  86. private $created;
  87. /**
  88. * @var \DateTime
  89. *
  90. * @ORM\Column(name="updated", type="datetime")
  91. *
  92. * @Gedmo\Timestampable(on="update")
  93. */
  94. private $updated;
  95. /**
  96. * The search index used for filtering.
  97. *
  98. * @var string|null
  99. *
  100. * @ORM\Column(name="search_index", type="text", nullable=true)
  101. */
  102. private $search_index;
  103. /**
  104. * @var bool|null
  105. *
  106. * @ORM\Column(name="isSentEmail", type="boolean", nullable=true)
  107. */
  108. private $isSentEmail;
  109. /**
  110. * @var Email
  111. *
  112. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Email", cascade={"persist","remove"}, orphanRemoval=true)
  113. *
  114. * @ORM\JoinColumns({
  115. *
  116. * @ORM\JoinColumn(name="email_id", referencedColumnName="id", unique=true, nullable=true)
  117. * })
  118. */
  119. private $email;
  120. /**
  121. * @var Project
  122. *
  123. * @ORM\ManyToOne(targetEntity="MedBrief\MSR\Entity\Project", inversedBy="matterCommunications")
  124. *
  125. * @ORM\JoinColumns({
  126. *
  127. * @ORM\JoinColumn(name="project_id", referencedColumnName="id", nullable=true)
  128. * })
  129. */
  130. private $project;
  131. /**
  132. * Constructor
  133. */
  134. public function __construct()
  135. {
  136. $this->labels = [];
  137. $this->isSentEmail = self::TYPE_RECEIVED;
  138. }
  139. /**
  140. * __toString
  141. *
  142. * @return string
  143. */
  144. public function __toString()
  145. {
  146. return (string) $this->getId() ?: 'Unknown';
  147. }
  148. /**
  149. * Get id.
  150. *
  151. * @return int
  152. */
  153. public function getId()
  154. {
  155. return $this->id;
  156. }
  157. /**
  158. * Set labels.
  159. *
  160. * @param array|null $labels
  161. *
  162. * @return MatterCommunication
  163. */
  164. public function setLabels($labels = null)
  165. {
  166. $this->labels = $labels;
  167. return $this;
  168. }
  169. /**
  170. * Add Label to labels array
  171. *
  172. * @param MatterCommunication $label
  173. *
  174. * @return MatterCommunication
  175. */
  176. public function addLabels(MatterCommunication $label)
  177. {
  178. $this->labels = $label;
  179. return $this;
  180. }
  181. /**
  182. * Remove Label to labels array
  183. *
  184. * @param MatterCommunication $label
  185. *
  186. * @return void
  187. */
  188. public function removeLabels(MatterCommunication $label): void
  189. {
  190. $this->labels = $label;
  191. }
  192. /**
  193. * Get labels.
  194. *
  195. * @return array|null
  196. */
  197. public function getLabels()
  198. {
  199. return $this->labels;
  200. }
  201. /**
  202. * Returns an array of permitted values for the Labels field.
  203. *
  204. * @return array
  205. */
  206. public static function getLabelOptions()
  207. {
  208. $typeOptions = self::getConstantsWithLabelsAsChoices('LABEL');
  209. return $typeOptions;
  210. }
  211. /**
  212. * Returns an array of Labels to be readable by humans.
  213. *
  214. * @return array
  215. */
  216. public function getLabelLabels()
  217. {
  218. $labelOptions = array_flip(self::getLabelOptions());
  219. return array_map(function ($label) use ($labelOptions) {
  220. return $labelOptions[$label] ?: 'Unknown';
  221. }, $this->labels);
  222. }
  223. /**
  224. * Set content.
  225. *
  226. * @param string|null $content
  227. *
  228. * @return MatterCommunication
  229. */
  230. public function setContent($content = null)
  231. {
  232. $this->content = $content;
  233. return $this;
  234. }
  235. /**
  236. * Get content.
  237. *
  238. * @return string|null
  239. */
  240. public function getContent()
  241. {
  242. return $this->content;
  243. }
  244. /**
  245. * Set created.
  246. *
  247. * @param \DateTime $created
  248. *
  249. * @return MatterCommunication
  250. */
  251. public function setCreated($created)
  252. {
  253. $this->created = $created;
  254. return $this;
  255. }
  256. /**
  257. * Get created.
  258. *
  259. * @return \DateTime
  260. */
  261. public function getCreated()
  262. {
  263. return $this->created;
  264. }
  265. /**
  266. * Set updated.
  267. *
  268. * @param \DateTime $updated
  269. *
  270. * @return MatterCommunication
  271. */
  272. public function setUpdated($updated)
  273. {
  274. $this->updated = $updated;
  275. return $this;
  276. }
  277. /**
  278. * Get updated.
  279. *
  280. * @return \DateTime
  281. */
  282. public function getUpdated()
  283. {
  284. return $this->updated;
  285. }
  286. /**
  287. * Set searchIndex
  288. *
  289. * @param string $searchIndex
  290. *
  291. * @return MatterCommunication
  292. */
  293. public function setSearchIndex($searchIndex)
  294. {
  295. $this->search_index = $searchIndex;
  296. return $this;
  297. }
  298. /**
  299. * Get searchIndex
  300. *
  301. * @return string
  302. */
  303. public function getSearchIndex()
  304. {
  305. return $this->search_index;
  306. }
  307. /**
  308. * Updates the Search Index field with internal data. The Search Index Field
  309. * provides an easy way to perform a 'like' query for a generalised search.
  310. *
  311. * @ORM\PrePersist
  312. *
  313. * @ORM\PreUpdate
  314. */
  315. public function updateSearchIndex()
  316. {
  317. $date = $this->getEmail()->getDateSent()->format('d.m.Y');
  318. $searchIndex
  319. = $this->getEmail()->getSender()
  320. . ' '
  321. . $this->getEmail()->getRecipients()
  322. . ' '
  323. . $this->getEmail()->getSubject()
  324. . ' '
  325. . $date;
  326. $this->setSearchIndex($searchIndex);
  327. }
  328. /**
  329. * Set email.
  330. *
  331. * @param Email|null $email
  332. *
  333. * @return MatterCommunication
  334. */
  335. public function setEmail(?Email $email = null)
  336. {
  337. $this->email = $email;
  338. return $this;
  339. }
  340. /**
  341. * Get email.
  342. *
  343. * @return Email|null
  344. */
  345. public function getEmail()
  346. {
  347. return $this->email;
  348. }
  349. /**
  350. * Set project.
  351. *
  352. * @param Project|null $project
  353. *
  354. * @return MatterCommunication
  355. */
  356. public function setProject(?Project $project = null)
  357. {
  358. $this->project = $project;
  359. return $this;
  360. }
  361. /**
  362. * Get project.
  363. *
  364. * @return Project|null
  365. */
  366. public function getProject()
  367. {
  368. return $this->project;
  369. }
  370. /**
  371. * Set isSentEmail.
  372. *
  373. * @param bool|null $isSentEmail
  374. *
  375. * @return MatterCommunication
  376. */
  377. public function setIsSentEmail($isSentEmail = null)
  378. {
  379. $this->isSentEmail = $isSentEmail;
  380. return $this;
  381. }
  382. /**
  383. * Get isSentEmail.
  384. *
  385. * @return bool|null
  386. */
  387. public function getIsSentEmail()
  388. {
  389. return $this->isSentEmail;
  390. }
  391. /**
  392. * Returns an array of permitted values for the isSentEmail field and their
  393. * associated labels.
  394. *
  395. * @return array
  396. */
  397. public static function getIsSentEmailOptions()
  398. {
  399. $typeOptions = self::getConstantsWithLabelsAsChoices('TYPE');
  400. return $typeOptions;
  401. }
  402. /**
  403. * Returns a human readable version of the type isSentEmailLabel
  404. *
  405. * @return string
  406. */
  407. public function getIsSentEmailLabel()
  408. {
  409. $options = array_flip(self::getIsSentEmailOptions());
  410. return $options[$this->getIsSentEmail()] ?? '';
  411. }
  412. }