Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

266 lines
7.2KB

  1. <?php
  2. /**
  3. Copyright Guillaume Bourgeois (2018)
  4. contact@souke.fr
  5. Ce logiciel est un programme informatique servant à aider les producteurs
  6. à distribuer leur production en circuits courts.
  7. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  8. respectant les principes de diffusion des logiciels libres. Vous pouvez
  9. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  10. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  11. sur le site "http://www.cecill.info".
  12. En contrepartie de l'accessibilité au code source et des droits de copie,
  13. de modification et de redistribution accordés par cette licence, il n'est
  14. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  15. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  16. titulaire des droits patrimoniaux et les concédants successifs.
  17. A cet égard l'attention de l'utilisateur est attirée sur les risques
  18. associés au chargement, à l'utilisation, à la modification et/ou au
  19. développement et à la reproduction du logiciel par l'utilisateur étant
  20. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  21. manipuler et qui le réserve donc à des développeurs et des professionnels
  22. avertis possédant des connaissances informatiques approfondies. Les
  23. utilisateurs sont donc invités à charger et tester l'adéquation du
  24. logiciel à leurs besoins dans des conditions permettant d'assurer la
  25. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  26. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  27. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  28. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  29. termes.
  30. */
  31. namespace domain\Communication\AutomaticEmail;
  32. use common\components\ActiveRecordCommon;
  33. use common\components\Date;
  34. use domain\_\StatusInterface;
  35. use domain\PointSale\PointSale\PointSale;
  36. use domain\Producer\Producer\Producer;
  37. use yii\db\ActiveQuery;
  38. class AutomaticEmail extends ActiveRecordCommon
  39. {
  40. public static function tableName()
  41. {
  42. return 'automatic_email';
  43. }
  44. public function rules()
  45. {
  46. return [
  47. [['id_producer', 'subject', 'message', 'status', 'sending_hour'], 'required'],
  48. ['sending_day', 'required', 'when' => function($model) {
  49. return !$model->getDay();
  50. }],
  51. ['delay_before_distribution', 'required', 'when' => function($model) {
  52. return $model->getDay();
  53. }],
  54. [['subject', 'message'], 'string'],
  55. [['id_producer', 'day', 'delay_before_distribution', 'status', 'id_point_sale', 'sending_day', 'sending_hour'], 'integer'],
  56. [['integrate_product_list'], 'boolean']
  57. ];
  58. }
  59. public function attributeLabels()
  60. {
  61. return [
  62. 'id_producer' => 'Producteur',
  63. 'day' => 'Distribution',
  64. 'delay_before_distribution' => 'Envoi du message',
  65. 'subject' => 'Sujet',
  66. 'message' => 'Message',
  67. 'integrate_product_list' => 'Intégrer la liste des produits au message',
  68. 'status' => 'Statut',
  69. 'id_point_sale' => 'Point de vente',
  70. 'sending_day' => "Jour d'envoi",
  71. 'sending_hour' => "Heure d'envoi",
  72. ];
  73. }
  74. /* Méthodes */
  75. public function isEnabled(): bool
  76. {
  77. return (bool) $this->getStatus() == StatusInterface::STATUS_ONLINE;
  78. }
  79. public function getDayAsString(): string
  80. {
  81. if(!$this->getDay()) {
  82. return '';
  83. }
  84. return Date::getDayOfWeekStringByNumber($this->getDay());
  85. }
  86. public function getSendingDayAsString(): string
  87. {
  88. if(!$this->getSendingDay()) {
  89. return '';
  90. }
  91. return Date::getDayOfWeekStringByNumber($this->getSendingDay());
  92. }
  93. public function getDelayBeforeDistributionAsString(): string
  94. {
  95. if(!$this->getDelayBeforeDistribution()) {
  96. return '';
  97. }
  98. return $this->getDelayBeforeDistribution().' jour(s) avant';
  99. }
  100. public function getStatusAsHtml(): string
  101. {
  102. if($this->getStatus()) {
  103. return '<span class="label label-success">Activé</span>';
  104. }
  105. else {
  106. return '<span class="label label-danger">Désactivé</span>';
  107. }
  108. }
  109. /* Getters / Setters */
  110. public function getId(): ?int
  111. {
  112. return $this->id;
  113. }
  114. public function getProducer(): Producer
  115. {
  116. return $this->producerRelation;
  117. }
  118. public function setProducer(Producer $producer): self
  119. {
  120. $this->populateFieldObject('id_producer', 'producerRelation', $producer);
  121. return $this;
  122. }
  123. public function getDay(): ?int
  124. {
  125. if(!$this->day) {
  126. return null;
  127. }
  128. return $this->day;
  129. }
  130. public function setDay(?int $day): self
  131. {
  132. $this->day = $day;
  133. return $this;
  134. }
  135. public function getDelayBeforeDistribution(): ?int
  136. {
  137. if(!$this->delay_before_distribution) {
  138. return 0;
  139. }
  140. return $this->delay_before_distribution;
  141. }
  142. public function setDelayBeforeDistribution(?int $delayBeforeDistribution): self
  143. {
  144. $this->delay_before_distribution = $delayBeforeDistribution;
  145. return $this;
  146. }
  147. public function getSubject(): string
  148. {
  149. return $this->subject;
  150. }
  151. public function setSubject(string $subject): self
  152. {
  153. $this->subject = $subject;
  154. return $this;
  155. }
  156. public function getMessage(): string
  157. {
  158. return $this->message;
  159. }
  160. public function setMessage(string $message): self
  161. {
  162. $this->message = $message;
  163. return $this;
  164. }
  165. public function getIntegrateProductList(): ?bool
  166. {
  167. return $this->integrate_product_list;
  168. }
  169. public function setIntegrateProductList(?bool $integrateProductList): self
  170. {
  171. $this->integrate_product_list = $integrateProductList;
  172. return $this;
  173. }
  174. public function getStatus(): int
  175. {
  176. return $this->status;
  177. }
  178. public function setStatus(int $status): self
  179. {
  180. $this->status = $status;
  181. return $this;
  182. }
  183. public function getPointSale(): ?PointSale
  184. {
  185. return $this->pointSaleRelation;
  186. }
  187. public function setPointSale(PointSale $pointSale): self
  188. {
  189. $this->populateFieldObject('id_point_sale', 'pointSaleRelation', $pointSale);
  190. return $this;
  191. }
  192. public function getSendingDay(): ?int
  193. {
  194. return $this->sending_day;
  195. }
  196. public function setSendingDay(?int $sendingDay): self
  197. {
  198. $this->sending_day = $sendingDay;
  199. return $this;
  200. }
  201. public function getSendingHour(): ?int
  202. {
  203. return $this->sending_hour;
  204. }
  205. public function setSendingHour(?int $sendingHour): self
  206. {
  207. $this->sending_hour = $sendingHour;
  208. return $this;
  209. }
  210. /* Relations */
  211. public function getProducerRelation(): ActiveQuery
  212. {
  213. return $this->hasOne(Producer::class, ['id' => 'id_producer']);
  214. }
  215. public function getPointSaleRelation(): ActiveQuery
  216. {
  217. return $this->hasOne(PointSale::class, ['id' => 'id_point_sale']);
  218. }
  219. }