|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?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",
- ];
- }
-
-
-
- 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>';
- }
- }
-
-
-
- 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;
- }
-
-
-
- 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']);
- }
- }
|