|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
-
- namespace domain\Communication\AutomaticEmail;
-
- use common\components\ActiveRecordCommon;
- use common\components\Date;
- use domain\_\StatusInterface;
- use domain\Producer\Producer\Producer;
- use yii\db\ActiveQuery;
-
- class AutomaticEmail extends ActiveRecordCommon
- {
- public static function tableName()
- {
- return 'automatic_email';
- }
-
- public function rules()
- {
- return [
- [['id_producer', 'day', 'subject', 'message', 'status'], 'required'],
- [['subject', 'message'], 'string'],
- [['id_producer', 'day', 'delay_before_distribution', 'status'], 'integer'],
- [['integrate_product_list'], 'boolean']
- ];
- }
-
- public function attributeLabels()
- {
- return [
- 'id_producer' => 'Producteur',
- 'day' => 'Jour de distribution',
- 'delay_before_distribution' => 'Envoi du message',
- 'subject' => 'Sujet',
- 'message' => 'Message',
- 'integrate_product_list' => 'Intégrer la liste des produits au message',
- 'status' => 'Statut'
- ];
- }
-
- /* Méthodes */
-
- public function isEnabled(): bool
- {
- return (bool) $this->getStatus() == StatusInterface::STATUS_ONLINE;
- }
-
- public function getDayAsString(): string
- {
- return Date::getDayOfWeekStringByNumber($this->getDay());
- }
-
- public function getDelayBeforeDistributionAsString(): string
- {
- return $this->getDelayBeforeDistribution().' jour(s) avant';
- }
-
- public function getStatusAsHtml(): string
- {
- if($this->getStatus()) {
- return '<span class="label label-success">Activé</span>';
- }
- else {
- return '<span class="label label-danger">Désactivé</span>';
- }
- }
-
- /* Getters / Setters */
-
- public function getId(): ?int
- {
- return $this->id;
- }
-
- public function getProducer(): Producer
- {
- return $this->producerRelation;
- }
-
- public function setProducer(Producer $producer): self
- {
- $this->populateFieldObject('id_producer', 'producerRelation', $producer);
- return $this;
- }
-
- public function getDay(): int
- {
- return $this->day;
- }
-
- public function setDay(int $day): self
- {
- $this->day = $day;
- return $this;
- }
-
- public function getDelayBeforeDistribution(): int
- {
- return $this->delay_before_distribution;
- }
-
- public function setDelayBeforeDistribution(int $delayBeforeDistribution): self
- {
- $this->delay_before_distribution = $delayBeforeDistribution;
- return $this;
- }
-
- public function getSubject(): string
- {
- return $this->subject;
- }
-
- public function setSubject(string $subject): self
- {
- $this->subject = $subject;
- return $this;
- }
-
- public function getMessage(): string
- {
- return $this->message;
- }
-
- public function setMessage(string $message): self
- {
- $this->message = $message;
- return $this;
- }
-
- public function getIntegrateProductList(): ?bool
- {
- return $this->integrate_product_list;
- }
-
- public function setIntegrateProductList(?bool $integrateProductList): self
- {
- $this->integrate_product_list = $integrateProductList;
- return $this;
- }
-
- public function getStatus(): int
- {
- return $this->status;
- }
-
- public function setStatus(int $status): self
- {
- $this->status = $status;
- return $this;
- }
-
- /* Relations */
-
- public function getProducerRelation(): ActiveQuery
- {
- return $this->hasOne(Producer::class, ['id' => 'id_producer']);
- }
- }
|