|
- <?php
-
- namespace domain\Communication\AutomaticEmail;
-
- use common\components\ActiveRecordCommon;
- use common\components\Date;
- use domain\_\StatusInterface;
- use domain\PointSale\PointSale\PointSale;
- 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', 'subject', 'message', 'status', 'sending_hour'], 'required'],
- ['sending_day', 'required', 'when' => function($model) {
- return !$model->getDay();
- }],
- ['delay_before_distribution', 'required', 'when' => function($model) {
- return $model->getDay();
- }],
- [['subject', 'message'], 'string'],
- [['id_producer', 'day', 'delay_before_distribution', 'status', 'id_point_sale', 'sending_day', 'sending_hour'], 'integer'],
- [['integrate_product_list'], 'boolean']
- ];
- }
-
- public function attributeLabels()
- {
- return [
- 'id_producer' => 'Producteur',
- 'day' => 'Distribution',
- 'delay_before_distribution' => 'Envoi du message',
- 'subject' => 'Sujet',
- 'message' => 'Message',
- 'integrate_product_list' => 'Intégrer la liste des produits au message',
- 'status' => 'Statut',
- 'id_point_sale' => 'Point de vente',
- 'sending_day' => "Jour d'envoi",
- 'sending_hour' => "Heure d'envoi",
- ];
- }
-
- /* Méthodes */
-
- public function isEnabled(): bool
- {
- return (bool) $this->getStatus() == StatusInterface::STATUS_ONLINE;
- }
-
- public function getDayAsString(): string
- {
- if(!$this->getDay()) {
- return '';
- }
-
- return Date::getDayOfWeekStringByNumber($this->getDay());
- }
-
- public function getSendingDayAsString(): string
- {
- if(!$this->getSendingDay()) {
- return '';
- }
-
- return Date::getDayOfWeekStringByNumber($this->getSendingDay());
- }
-
- public function getDelayBeforeDistributionAsString(): string
- {
- if(!$this->getDelayBeforeDistribution()) {
- return '';
- }
-
- 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
- {
- if(!$this->day) {
- return null;
- }
-
- return $this->day;
- }
-
- public function setDay(?int $day): self
- {
- $this->day = $day;
- return $this;
- }
-
- public function getDelayBeforeDistribution(): ?int
- {
- if(!$this->delay_before_distribution) {
- return 0;
- }
-
- 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;
- }
-
- public function getPointSale(): ?PointSale
- {
- return $this->pointSaleRelation;
- }
-
- public function setPointSale(PointSale $pointSale): self
- {
- $this->populateFieldObject('id_point_sale', 'pointSaleRelation', $pointSale);
- return $this;
- }
-
- public function getSendingDay(): ?int
- {
- return $this->sending_day;
- }
-
- public function setSendingDay(?int $sendingDay): self
- {
- $this->sending_day = $sendingDay;
- return $this;
- }
-
- public function getSendingHour(): ?int
- {
- return $this->sending_hour;
- }
-
- public function setSendingHour(?int $sendingHour): self
- {
- $this->sending_hour = $sendingHour;
- return $this;
- }
-
- /* Relations */
-
- public function getProducerRelation(): ActiveQuery
- {
- return $this->hasOne(Producer::class, ['id' => 'id_producer']);
- }
-
- public function getPointSaleRelation(): ActiveQuery
- {
- return $this->hasOne(PointSale::class, ['id' => 'id_point_sale']);
- }
- }
|