Commit 77af80be authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавлены методы, для полноценной работы подписок на кейсы

parent 66d011d4
......@@ -2,7 +2,10 @@
namespace common\modules\cases\models;
use common\components\ActiveRecordModel;
use common\modules\triggers\models\CasesSchedule;
use Yii;
use common\modules\users\models\User;
/**
* This is the model class for table "cases_bids".
......@@ -11,7 +14,7 @@ use Yii;
* @property string $email
* @property string $date
*/
class CasesBids extends \yii\db\ActiveRecord
class CasesBids extends ActiveRecordModel
{
/**
* @inheritdoc
......@@ -21,6 +24,13 @@ class CasesBids extends \yii\db\ActiveRecord
return 'cases_bids';
}
/**
* @inheritdoc
*/
public function name() {
return 'Подписка на кейсы';
}
/**
* @inheritdoc
*/
......@@ -28,11 +38,49 @@ class CasesBids extends \yii\db\ActiveRecord
{
return [
[['email', 'date'], 'required'],
[['email'], 'unique', 'message' => 'Вы уже подписаны на новости блога'],
[['date'], 'safe'],
[['email'], 'string', 'max' => 255],
];
}
/**
* @param bool $insert
* @param array $changedAttributes
* @return bool
*/
public function afterSave($insert, $changedAttributes)
{
parent::afterSave($insert, $changedAttributes);
if (!is_null($this->email)) {
/** @var User $user */
$user = User::find()->where(['email' => $this->email])->one();
if (!is_null($user)) {
$user->afterSubscribe(['email' => $this->email], true);
}
Yii::$app->cache->set('user_email', $this->email);
}
}
/**
* @return bool
*/
public function beforeDelete(){
if (!parent::beforeDelete())
return false;
CasesSchedule::deleteAll(['email' => $this->email]);
return true;
}
/**
* @return array
*/
public function behaviors(){
return [];
}
/**
* @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