src/Entity/SortingInstruction.php line 20

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. /**
  7. * SortingInstruction
  8. *
  9. * @ORM\Table(name="SortingInstruction")
  10. *
  11. * @ORM\Entity
  12. *
  13. * @Audit\Auditable
  14. *
  15. * @Audit\Security(view={"ROLE_ALLOWED_TO_AUDIT"})
  16. */
  17. class SortingInstruction
  18. {
  19. // Type constants
  20. public const TYPE_SILVER = 1;
  21. public const TYPE_GOLD = 2;
  22. /**
  23. * @var int
  24. *
  25. * @ORM\Column(name="id", type="integer")
  26. *
  27. * @ORM\Id
  28. *
  29. * @ORM\GeneratedValue(strategy="IDENTITY")
  30. */
  31. private $id;
  32. /**
  33. * @var \DateTime
  34. *
  35. * @ORM\Column(name="created", type="datetime")
  36. *
  37. * @Gedmo\Timestampable(on="create")
  38. */
  39. private $created;
  40. /**
  41. * @var \DateTime
  42. *
  43. * @ORM\Column(name="updated", type="datetime")
  44. *
  45. * @Gedmo\Timestampable(on="update")
  46. */
  47. private $updated;
  48. /**
  49. * @var int|null
  50. *
  51. * @ORM\Column(name="type", type="integer", nullable=true)
  52. */
  53. private $type;
  54. /**
  55. * @var string|null
  56. *
  57. * @ORM\Column(name="description", type="text", nullable=true)
  58. */
  59. private $description;
  60. /**
  61. * @var Account
  62. *
  63. * @ORM\OneToOne(targetEntity="MedBrief\MSR\Entity\Account", mappedBy="defaultSortingInstruction")
  64. */
  65. private $account;
  66. /**
  67. * __toString
  68. *
  69. * @return string
  70. */
  71. public function __toString()
  72. {
  73. return sprintf('%1$s Sorting Instruction', $this->getAccount() ? $this->getAccount()->getName() : '');
  74. }
  75. /**
  76. * Get id.
  77. *
  78. * @return int
  79. */
  80. public function getId()
  81. {
  82. return $this->id;
  83. }
  84. /**
  85. * Set created.
  86. *
  87. * @param \DateTime $created
  88. *
  89. * @return SortingInstruction
  90. */
  91. public function setCreated($created)
  92. {
  93. $this->created = $created;
  94. return $this;
  95. }
  96. /**
  97. * Get created.
  98. *
  99. * @return \DateTime
  100. */
  101. public function getCreated()
  102. {
  103. return $this->created;
  104. }
  105. /**
  106. * Set updated.
  107. *
  108. * @param \DateTime $updated
  109. *
  110. * @return SortingInstruction
  111. */
  112. public function setUpdated($updated)
  113. {
  114. $this->updated = $updated;
  115. return $this;
  116. }
  117. /**
  118. * Get updated.
  119. *
  120. * @return \DateTime
  121. */
  122. public function getUpdated()
  123. {
  124. return $this->updated;
  125. }
  126. /**
  127. * Set type.
  128. *
  129. * @param int|null $type
  130. *
  131. * @return SortingInstruction
  132. */
  133. public function setType($type = null)
  134. {
  135. $this->type = $type;
  136. return $this;
  137. }
  138. /**
  139. * Get type.
  140. *
  141. * @return int|null
  142. */
  143. public function getType()
  144. {
  145. return $this->type;
  146. }
  147. /**
  148. * Get typeOptions
  149. *
  150. * @return array
  151. */
  152. public static function getTypeOptions()
  153. {
  154. return [
  155. self::TYPE_SILVER => 'Silver Sort',
  156. self::TYPE_GOLD => 'Gold Sort',
  157. ];
  158. }
  159. /**
  160. * Get typeLabel
  161. *
  162. * @return string
  163. */
  164. public function getTypeLabel()
  165. {
  166. $options = self::getTypeOptions();
  167. return $options[$this->getType()] ?? '';
  168. }
  169. /**
  170. * Set description.
  171. *
  172. * @param string|null $description
  173. *
  174. * @return SortingInstruction
  175. */
  176. public function setDescription($description = null)
  177. {
  178. $this->description = $description;
  179. return $this;
  180. }
  181. /**
  182. * Get description.
  183. *
  184. * @return string|null
  185. */
  186. public function getDescription()
  187. {
  188. return $this->description;
  189. }
  190. /**
  191. * Set account.
  192. *
  193. * @param Account|null $account
  194. *
  195. * @return SortingInstruction
  196. */
  197. public function setAccount(?Account $account = null)
  198. {
  199. if ($this->account && !$account) {
  200. $this->account->setDefaultSortingInstruction(null);
  201. } elseif ($account) {
  202. $account->setDefaultSortingInstruction($this);
  203. }
  204. $this->account = $account;
  205. return $this;
  206. }
  207. /**
  208. * Get account.
  209. *
  210. * @return Account|null
  211. */
  212. public function getAccount()
  213. {
  214. return $this->account;
  215. }
  216. }