Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AutomaticEmail.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace domain\Communication\AutomaticEmail;
  3. use common\components\ActiveRecordCommon;
  4. use common\components\Date;
  5. use domain\_\StatusInterface;
  6. use domain\Producer\Producer\Producer;
  7. use yii\db\ActiveQuery;
  8. class AutomaticEmail extends ActiveRecordCommon
  9. {
  10. public static function tableName()
  11. {
  12. return 'automatic_email';
  13. }
  14. public function rules()
  15. {
  16. return [
  17. [['id_producer', 'day', 'subject', 'message', 'status'], 'required'],
  18. [['subject', 'message'], 'string'],
  19. [['id_producer', 'day', 'delay_before_distribution', 'status'], 'integer'],
  20. [['integrate_product_list'], 'boolean']
  21. ];
  22. }
  23. public function attributeLabels()
  24. {
  25. return [
  26. 'id_producer' => 'Producteur',
  27. 'day' => 'Jour de distribution',
  28. 'delay_before_distribution' => 'Envoi du message',
  29. 'subject' => 'Sujet',
  30. 'message' => 'Message',
  31. 'integrate_product_list' => 'Intégrer la liste des produits au message',
  32. 'status' => 'Statut'
  33. ];
  34. }
  35. /* Méthodes */
  36. public function isEnabled(): bool
  37. {
  38. return (bool) $this->getStatus() == StatusInterface::STATUS_ONLINE;
  39. }
  40. public function getDayAsString(): string
  41. {
  42. return Date::getDayOfWeekStringByNumber($this->getDay());
  43. }
  44. public function getDelayBeforeDistributionAsString(): string
  45. {
  46. return $this->getDelayBeforeDistribution().' jour(s) avant';
  47. }
  48. public function getStatusAsHtml(): string
  49. {
  50. if($this->getStatus()) {
  51. return '<span class="label label-success">Activé</span>';
  52. }
  53. else {
  54. return '<span class="label label-danger">Désactivé</span>';
  55. }
  56. }
  57. /* Getters / Setters */
  58. public function getId(): ?int
  59. {
  60. return $this->id;
  61. }
  62. public function getProducer(): Producer
  63. {
  64. return $this->producerRelation;
  65. }
  66. public function setProducer(Producer $producer): self
  67. {
  68. $this->populateFieldObject('id_producer', 'producerRelation', $producer);
  69. return $this;
  70. }
  71. public function getDay(): int
  72. {
  73. return $this->day;
  74. }
  75. public function setDay(int $day): self
  76. {
  77. $this->day = $day;
  78. return $this;
  79. }
  80. public function getDelayBeforeDistribution(): int
  81. {
  82. return $this->delay_before_distribution;
  83. }
  84. public function setDelayBeforeDistribution(int $delayBeforeDistribution): self
  85. {
  86. $this->delay_before_distribution = $delayBeforeDistribution;
  87. return $this;
  88. }
  89. public function getSubject(): string
  90. {
  91. return $this->subject;
  92. }
  93. public function setSubject(string $subject): self
  94. {
  95. $this->subject = $subject;
  96. return $this;
  97. }
  98. public function getMessage(): string
  99. {
  100. return $this->message;
  101. }
  102. public function setMessage(string $message): self
  103. {
  104. $this->message = $message;
  105. return $this;
  106. }
  107. public function getIntegrateProductList(): ?bool
  108. {
  109. return $this->integrate_product_list;
  110. }
  111. public function setIntegrateProductList(?bool $integrateProductList): self
  112. {
  113. $this->integrate_product_list = $integrateProductList;
  114. return $this;
  115. }
  116. public function getStatus(): int
  117. {
  118. return $this->status;
  119. }
  120. public function setStatus(int $status): self
  121. {
  122. $this->status = $status;
  123. return $this;
  124. }
  125. /* Relations */
  126. public function getProducerRelation(): ActiveQuery
  127. {
  128. return $this->hasOne(Producer::class, ['id' => 'id_producer']);
  129. }
  130. }