src/Entity/HistorySend.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\HistorySendRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8. * @ORM\Entity(repositoryClass="App\Repository\HistorySendRepository", repositoryClass=HistorySendRepository::class)
  9. * @ORM\HasLifecycleCallbacks
  10. */
  11. class HistorySend
  12. {
  13. public const STATUSES = [
  14. 'Ошибка' => self::STATUS_ERROR,
  15. 'Успешно' => self::STATUS_SUCCESS,
  16. ];
  17. public const STATUS_ERROR = 0;
  18. public const STATUS_SUCCESS = 1;
  19. public const STATUS_SENT_FROM_SERVICE = 2; // Успешно отправлено сервисом
  20. public const CERTIFICATE_TYPE = 'certificate'; //Отправка сертификата получателю
  21. public const CERT_REPORT_TYPE = 'cert_report'; //Отправка уведомления - Сертификат доставлен
  22. public const ORDER_CREATE_TYPE = 'order_create'; //Отправка уведомления - Заказ оформлен
  23. public const SEND_TYPE_SMS = 'sms';
  24. public const SEND_TYPE_EMAIL = 'email';
  25. /**
  26. * @ORM\Id
  27. * @ORM\GeneratedValue
  28. * @ORM\Column(type="integer")
  29. */
  30. private $id;
  31. /**
  32. * @ORM\Column(type="datetime_immutable")
  33. */
  34. private $timestamp;
  35. /**
  36. * @ORM\Column(type="integer")
  37. * @Assert\Choice(callback="getStatuses", message="Choose a valid status.")
  38. */
  39. private $status;
  40. /**
  41. * @ORM\ManyToOne(targetEntity=Order::class, inversedBy="historySends")
  42. * @ORM\JoinColumn(nullable=false)
  43. */
  44. private $order;
  45. /**
  46. * @ORM\ManyToOne(targetEntity=WidgetUser::class, inversedBy="historySends", cascade={"persist"})
  47. * @ORM\JoinColumn(nullable=false)
  48. */
  49. private $Client;
  50. /**
  51. * @ORM\Column(type="string", length=255)
  52. */
  53. private $recipient;
  54. /**
  55. * @ORM\Column(type="string", length=50, nullable=true)
  56. */
  57. private $type;
  58. /**
  59. * @ORM\Column(type="datetime_immutable", nullable=true)
  60. */
  61. private $updatedAt;
  62. /**
  63. * @ORM\Column(type="string", length=50, nullable=true)
  64. */
  65. private $sendType;
  66. /**
  67. * @ORM\ManyToOne(targetEntity=OrderItem::class, inversedBy="historySends", cascade={"persist"})
  68. * @ORM\JoinColumn(nullable=true)
  69. */
  70. private $orderItem;
  71. /**
  72. * @ORM\Column(type="string", length=50, nullable=true)
  73. */
  74. private $externalId;
  75. /**
  76. * @ORM\Column(type="string", length=50, nullable=true)
  77. */
  78. private $serviceStatus;
  79. public function getId(): ?int
  80. {
  81. return $this->id;
  82. }
  83. public function getTimestamp(): ?DateTimeImmutable
  84. {
  85. return $this->timestamp;
  86. }
  87. public function setTimestamp(DateTimeImmutable $timestamp): self
  88. {
  89. $this->timestamp = $timestamp;
  90. return $this;
  91. }
  92. public function getStatus(): ?int
  93. {
  94. return $this->status;
  95. }
  96. public function setStatus(int $status): self
  97. {
  98. $this->status = $status;
  99. return $this;
  100. }
  101. public function getStatusText(): ? string
  102. {
  103. return array_search($this->status, HistorySend::STATUSES)??self::STATUSES['Ошибка'];
  104. }
  105. public function getOrder(): ?Order
  106. {
  107. return $this->order;
  108. }
  109. public function setOrder(?Order $order): self
  110. {
  111. $this->order = $order;
  112. return $this;
  113. }
  114. public function getClient(): ?WidgetUser
  115. {
  116. return $this->Client;
  117. }
  118. public function setClient(?WidgetUser $Client): self
  119. {
  120. $this->Client = $Client;
  121. return $this;
  122. }
  123. public function getRecipient(): ?string
  124. {
  125. return $this->recipient;
  126. }
  127. public function setRecipient(string $recipient): self
  128. {
  129. $this->recipient = $recipient;
  130. return $this;
  131. }
  132. /**
  133. * @return string|null
  134. */
  135. public function getType(): ?string
  136. {
  137. return $this->type;
  138. }
  139. /**
  140. * @param string|null $type
  141. * @return self
  142. */
  143. public function setType(?string $type): self
  144. {
  145. if (in_array($type, [self::CERTIFICATE_TYPE, self::CERT_REPORT_TYPE, self::ORDER_CREATE_TYPE, null])) {
  146. $this->type = $type;
  147. }
  148. return $this;
  149. }
  150. /**
  151. * @return OrderItem|null
  152. */
  153. public function getOrderItem(): ?OrderItem
  154. {
  155. return $this->orderItem;
  156. }
  157. /**
  158. * @param OrderItem|null $orderItem
  159. * @return HistorySend
  160. */
  161. public function setOrderItem(?OrderItem $orderItem): self
  162. {
  163. $this->orderItem = $orderItem;
  164. return $this;
  165. }
  166. /**
  167. * @return string|null
  168. */
  169. public function getExternalId(): string|null
  170. {
  171. return $this->externalId;
  172. }
  173. /**
  174. * @param string|null $externalId
  175. * @return HistorySend
  176. */
  177. public function setExternalId(?string $externalId): self
  178. {
  179. $this->externalId = $externalId;
  180. return $this;
  181. }
  182. /**
  183. * @return string|null
  184. */
  185. public function getServiceStatus(): string|null
  186. {
  187. return $this->serviceStatus;
  188. }
  189. /**
  190. * @param string|null $serviceStatus
  191. * @return HistorySend
  192. */
  193. public function setServiceStatus(?string $serviceStatus): self
  194. {
  195. $this->serviceStatus = $serviceStatus;
  196. return $this;
  197. }
  198. /**
  199. * @return string|null
  200. */
  201. public function getSendType(): ?string
  202. {
  203. return $this->sendType;
  204. }
  205. /**
  206. * @param string|null $sendType
  207. * @return HistorySend
  208. */
  209. public function setSendType(?string $sendType): self
  210. {
  211. $this->sendType = $sendType;
  212. return $this;
  213. }
  214. /**
  215. * @return DateTimeImmutable|null
  216. */
  217. public function getUpdatedAt(): ?DateTimeImmutable
  218. {
  219. return $this->updatedAt;
  220. }
  221. /**
  222. * @param mixed $updatedAt
  223. */
  224. public function setUpdatedAt(DateTimeImmutable $updatedAt): self
  225. {
  226. $this->updatedAt = $updatedAt;
  227. return $this;
  228. }
  229. /**
  230. * @ORM\PrePersist
  231. * @ORM\PreUpdate
  232. */
  233. public function updateTimestamps(): void
  234. {
  235. $this->setUpdatedAt(new DateTimeImmutable());
  236. }
  237. }