Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

231 lines
5.5KB

  1. <?php
  2. namespace domain\Communication\AutomaticEmail;
  3. use common\components\ActiveRecordCommon;
  4. use common\components\Date;
  5. use domain\_\StatusInterface;
  6. use domain\PointSale\PointSale\PointSale;
  7. use domain\Producer\Producer\Producer;
  8. use yii\db\ActiveQuery;
  9. class AutomaticEmail extends ActiveRecordCommon
  10. {
  11. public static function tableName()
  12. {
  13. return 'automatic_email';
  14. }
  15. public function rules()
  16. {
  17. return [
  18. [['id_producer', 'subject', 'message', 'status', 'sending_hour'], 'required'],
  19. ['sending_day', 'required', 'when' => function($model) {
  20. return !$model->getDay();
  21. }],
  22. ['delay_before_distribution', 'required', 'when' => function($model) {
  23. return $model->getDay();
  24. }],
  25. [['subject', 'message'], 'string'],
  26. [['id_producer', 'day', 'delay_before_distribution', 'status', 'id_point_sale', 'sending_day', 'sending_hour'], 'integer'],
  27. [['integrate_product_list'], 'boolean']
  28. ];
  29. }
  30. public function attributeLabels()
  31. {
  32. return [
  33. 'id_producer' => 'Producteur',
  34. 'day' => 'Distribution',
  35. 'delay_before_distribution' => 'Envoi du message',
  36. 'subject' => 'Sujet',
  37. 'message' => 'Message',
  38. 'integrate_product_list' => 'Intégrer la liste des produits au message',
  39. 'status' => 'Statut',
  40. 'id_point_sale' => 'Point de vente',
  41. 'sending_day' => "Jour d'envoi",
  42. 'sending_hour' => "Heure d'envoi",
  43. ];
  44. }
  45. /* Méthodes */
  46. public function isEnabled(): bool
  47. {
  48. return (bool) $this->getStatus() == StatusInterface::STATUS_ONLINE;
  49. }
  50. public function getDayAsString(): string
  51. {
  52. if(!$this->getDay()) {
  53. return '';
  54. }
  55. return Date::getDayOfWeekStringByNumber($this->getDay());
  56. }
  57. public function getSendingDayAsString(): string
  58. {
  59. if(!$this->getSendingDay()) {
  60. return '';
  61. }
  62. return Date::getDayOfWeekStringByNumber($this->getSendingDay());
  63. }
  64. public function getDelayBeforeDistributionAsString(): string
  65. {
  66. if(!$this->getDelayBeforeDistribution()) {
  67. return '';
  68. }
  69. return $this->getDelayBeforeDistribution().' jour(s) avant';
  70. }
  71. public function getStatusAsHtml(): string
  72. {
  73. if($this->getStatus()) {
  74. return '<span class="label label-success">Activé</span>';
  75. }
  76. else {
  77. return '<span class="label label-danger">Désactivé</span>';
  78. }
  79. }
  80. /* Getters / Setters */
  81. public function getId(): ?int
  82. {
  83. return $this->id;
  84. }
  85. public function getProducer(): Producer
  86. {
  87. return $this->producerRelation;
  88. }
  89. public function setProducer(Producer $producer): self
  90. {
  91. $this->populateFieldObject('id_producer', 'producerRelation', $producer);
  92. return $this;
  93. }
  94. public function getDay(): ?int
  95. {
  96. if(!$this->day) {
  97. return null;
  98. }
  99. return $this->day;
  100. }
  101. public function setDay(?int $day): self
  102. {
  103. $this->day = $day;
  104. return $this;
  105. }
  106. public function getDelayBeforeDistribution(): ?int
  107. {
  108. if(!$this->delay_before_distribution) {
  109. return 0;
  110. }
  111. return $this->delay_before_distribution;
  112. }
  113. public function setDelayBeforeDistribution(?int $delayBeforeDistribution): self
  114. {
  115. $this->delay_before_distribution = $delayBeforeDistribution;
  116. return $this;
  117. }
  118. public function getSubject(): string
  119. {
  120. return $this->subject;
  121. }
  122. public function setSubject(string $subject): self
  123. {
  124. $this->subject = $subject;
  125. return $this;
  126. }
  127. public function getMessage(): string
  128. {
  129. return $this->message;
  130. }
  131. public function setMessage(string $message): self
  132. {
  133. $this->message = $message;
  134. return $this;
  135. }
  136. public function getIntegrateProductList(): ?bool
  137. {
  138. return $this->integrate_product_list;
  139. }
  140. public function setIntegrateProductList(?bool $integrateProductList): self
  141. {
  142. $this->integrate_product_list = $integrateProductList;
  143. return $this;
  144. }
  145. public function getStatus(): int
  146. {
  147. return $this->status;
  148. }
  149. public function setStatus(int $status): self
  150. {
  151. $this->status = $status;
  152. return $this;
  153. }
  154. public function getPointSale(): ?PointSale
  155. {
  156. return $this->pointSaleRelation;
  157. }
  158. public function setPointSale(PointSale $pointSale): self
  159. {
  160. $this->populateFieldObject('id_point_sale', 'pointSaleRelation', $pointSale);
  161. return $this;
  162. }
  163. public function getSendingDay(): ?int
  164. {
  165. return $this->sending_day;
  166. }
  167. public function setSendingDay(?int $sendingDay): self
  168. {
  169. $this->sending_day = $sendingDay;
  170. return $this;
  171. }
  172. public function getSendingHour(): ?int
  173. {
  174. return $this->sending_hour;
  175. }
  176. public function setSendingHour(?int $sendingHour): self
  177. {
  178. $this->sending_hour = $sendingHour;
  179. return $this;
  180. }
  181. /* Relations */
  182. public function getProducerRelation(): ActiveQuery
  183. {
  184. return $this->hasOne(Producer::class, ['id' => 'id_producer']);
  185. }
  186. public function getPointSaleRelation(): ActiveQuery
  187. {
  188. return $this->hasOne(PointSale::class, ['id' => 'id_point_sale']);
  189. }
  190. }