[ 'class' => 'yii\web\ErrorAction', ], ]; } public function actionIndex() { return $this->redirect("blocks"); } public function actionActive($id) { $model = Design::findOne($id); if($model) $model->Active($id); return $this->redirect(['blocks']); } public function actionDelete($id) { Design::findOne($id)->delete(); return $this->redirect(['index']); } public function actionTopicactive($id) { $model = Design::findOne($id); if($model) $model->Active($id); return $this->redirect('blocks'); } public function actionCreate() { $model = new Design(); if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){ // print_a($post);exit; $post['Design'] = $this->formNormalizer($post['Design']); if($model->load($post, 'Design')) { if($model->save()) { return $this->redirect('blocks'); }else{ print_a($model->getErrors()); } }else{ print_a($model->getErrors()); } } return $this->render('/design/form', ['model' => $model]); } public function actionPurge() { Yii::$app->cache->delete("main-page-main-view-glob"); Yii::$app->cache->delete("MainPageBlock_desktop"); Yii::$app->cache->delete("MainPageBlock_mobile"); Yii::$app->cache->delete("main-page-main-view"); Yii::$app->cache->delete("main-page-third-row-l2"); Yii::$app->cache->delete("main-page-third-row-l2-0"); Yii::$app->cache->delete("main-page-third-row-l2-1"); Yii::$app->cache->delete("main-page-third-row-l2-2"); Yii::$app->cache->delete("main-page-topic-widget-0"); Yii::$app->cache->delete("main-page-topic-widget-1"); Yii::$app->cache->delete("main-page-topic-widget-2"); Yii::$app->cache->delete("main-page-wide-widget-0"); Yii::$app->cache->delete("main-page-wide-widget-1"); Yii::$app->cache->delete("main-page-wide-widget-2"); return $this->render('/design/purge'); } public function actionUpdate($id) { $model = Design::findOne($id); if (Yii::$app->request->isPost && $post = Yii::$app->request->post()){ // print_a($post);exit; $post['Design'] = $this->formNormalizer($post['Design']); if($model->load($post, 'Design')) { if($model->save()) { return $this->redirect('blocks'); }else{ print_a($model->getErrors()); } }else{ print_a($model->getErrors()); } } return $this->render('/design/form', ['model' => $model]); } public function actionSort() { if (isset($_POST['item']) && is_array($_POST['item'])) { $i = 0; $a = array(); // beginTransaction(); было бы неплохо обернуть в транзакцию но хз как это сделать foreach ($_POST['item'] as $item) { $model = Design::findOne($item); $model->order = $i; $a[$model->id] = $i; $model->save(true, ['order']); // print_a($model->errors); $i++; } return json_encode(['status'=>'ok','data'=>$a]); } return json_encode(['status'=>'err']); } public function formNormalizer($post) { switch($post['type']){ case 'story': $post['parent_id'] = $post['Story']; break; case 'topic': $post['parent_id'] = $post['Topic']; break; case 'tag': $post['parent_id'] = $post['Tag']; break; case 3: break; } $post['active'] = $this->CheckYN(@$post['active']); return $post; } public function CheckYN($attr) { return (isset($attr) && $attr == 'Y')?'Y':'N'; } public function actionBlocks() { $model = new Design();; return $this->render('/design/list', ['model' => $model]); } public function actionTop() { return $this->render('/design/top', []); } }