Commit d94284ff authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавлена логика по отправке письма после добавления новой записи в блог

parent a3beea67
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
namespace common\modules\blog\models; namespace common\modules\blog\models;
use common\modules\bids\models\Bid;
use common\modules\triggers\models\TriggerLogs;
use common\modules\triggers\models\TriggerSchedule;
use Yii; use Yii;
use yii\helpers\Url; use yii\helpers\Url;
...@@ -33,11 +36,29 @@ class Post extends \common\components\ActiveRecordModel ...@@ -33,11 +36,29 @@ class Post extends \common\components\ActiveRecordModel
const PAGE_SIZE = 2; const PAGE_SIZE = 2;
const MESSAGE_TEMPLATE_ID = 1;
public static $active_title = [ public static $active_title = [
self::ACTIVE_FALSE => 'Скрыта', self::ACTIVE_FALSE => 'Скрыта',
self::ACTIVE_TRUE => 'Доступна', self::ACTIVE_TRUE => 'Доступна',
]; ];
/**
* @param bool $insert
* @param array $changedAttributes
*/
public function afterSave($insert, $changedAttributes){
parent::afterSave($insert, $changedAttributes);
$users = User::find()->all();
foreach($users as $user) {
if (Bid::find()->where(['email' => $user->email])->exists()==true && TriggerLogs::find()->where(['user_id' => $user->id, 'action' => TriggerLogs::USER_SUBSCRIBE_TO_BLOG])==true) {
$templateData = [];
TriggerSchedule::sendMessage($this->email, self::MESSAGE_TEMPLATE_ID, $templateData);
}
}
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment