/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = ContentMenu::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionUpdateStatus() { $model_on = ContentMenu::findOne(['status' => 'on']); // var_dump($model_on->date_update); // var_dump(date('Y-m-d H:i:s')); // $interval = date('d', strtotime(date('Y-m-d H:i:s'))) - date('d', strtotime($model_on->date_update)-(2*24*60*60)); $interval = date('d', strtotime(date('Y-m-d H:i:s'))) - date('d', strtotime($model_on->date_update)); // var_dump($interval); if ($interval == 2) { $model_on->status = 'off'; $model = ContentMenu::find()->where(['>', 'id', $model_on->id])->orderBy(['id' => SORT_ASC])->one(); if (!$model) { // $model = $this->findModelContent('1'); $model = ContentMenu::find()->orderBy(['id' => SORT_ASC])->one(); } $model->status = 'on'; $model->date_update = date('Y-m-d H:i:s'); if ($model->save() && $model_on->save()) { return true; } } else { echo 'Разница в днях ' . $interval; } }
public function actionSwichStatus($id) { // $remove_model = ContentMenu::findOne(['status' => 'on']); $remove_model = ContentMenu::find()->where(['status' => 'on'])->all(); if ($remove_model) { foreach ($remove_model as $rem_model) { $rem_model->status = 'off'; } } $model = $this->findModel($id); if ($model->status == 'on') { $model->status = 'off'; } else { $model->status = 'on'; $model->date_update = date('Y-m-d H:i:s'); } // var_dump($remove_model); // var_dump($model); // die; if ($model->save()) { if ($remove_model) { foreach ($remove_model as $rem_model) { $rem_model->save(); } } return $model->status; } else { return 'Error'; } }
<?php use app\models\ContentMenu; $model_on = ContentMenu::findOne(['status' => 'on']); $model_on->status = 'off'; $id_off = $model_on->id + 1; $count_content = ContentMenu::find()->count(); if ($id_off > $count_content) { $id_off = 1; } $model = ContentMenu::findOne(['id' => $id_off]); $model->status = 'on'; if ($model->save() && $model_on->save()) { return true; }