Commit bf722066 authored by Shakarim Sapa's avatar Shakarim Sapa

- Добавили новый атрибут в модель расписания

parent 8445a069
...@@ -14,6 +14,7 @@ use common\modules\users\models\User; ...@@ -14,6 +14,7 @@ use common\modules\users\models\User;
* @property integer $id * @property integer $id
* @property string $email * @property string $email
* @property integer $post_id * @property integer $post_id
* @property integer $sent
* @property string $date * @property string $date
* *
* @property Post $post * @property Post $post
...@@ -43,7 +44,7 @@ class BlogSchedule extends ActiveRecordModel ...@@ -43,7 +44,7 @@ class BlogSchedule extends ActiveRecordModel
{ {
return [ return [
[['email', 'post_id', 'date'], 'required'], [['email', 'post_id', 'date'], 'required'],
[['post_id'], 'integer'], [['post_id', 'sent'], 'integer'],
[['date'], 'safe'], [['date'], 'safe'],
[['email'], 'string', 'max' => 255], [['email'], 'string', 'max' => 255],
[['post_id'], 'exist', 'skipOnError' => true, 'targetClass' => Post::className(), 'targetAttribute' => ['post_id' => 'id']], [['post_id'], 'exist', 'skipOnError' => true, 'targetClass' => Post::className(), 'targetAttribute' => ['post_id' => 'id']],
...@@ -58,8 +59,9 @@ class BlogSchedule extends ActiveRecordModel ...@@ -58,8 +59,9 @@ class BlogSchedule extends ActiveRecordModel
return [ return [
'id' => 'ID', 'id' => 'ID',
'email' => 'Email', 'email' => 'Email',
'post_id' => 'Post ID', 'post_id' => 'Пост',
'date' => 'Date', 'sent' => 'Отправлено',
'date' => 'Дата отправки',
]; ];
} }
...@@ -100,11 +102,15 @@ class BlogSchedule extends ActiveRecordModel ...@@ -100,11 +102,15 @@ class BlogSchedule extends ActiveRecordModel
} }
// Далее мы уже имеем в распоряжении сформированный массив // Далее мы уже имеем в распоряжении сформированный массив
foreach($result_posts as $post_id) { foreach($result_posts as $post_id) {
// Сдвигаем дату на 7 дней вперед
$date->modify('+7 days'); $date->modify('+7 days');
// Создали новый экземпляр модели
$model = new BlogSchedule(); $model = new BlogSchedule();
// Переопределили свойства
$model->email = $email; $model->email = $email;
$model->post_id = $post_id; $model->post_id = $post_id;
$model->date = $date->format('Y-m-d'); $model->date = $date->format('Y-m-d');
// Сохраняем запись в расписании
if (!$model->save()) if (!$model->save())
echo current(current($model->getErrors())).'<br>'; echo current(current($model->getErrors())).'<br>';
} }
......
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