Commit bf722066 authored by Shakarim Sapa's avatar Shakarim Sapa

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

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