No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

152 líneas
3.5KB

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