123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace manager\controllers;
- use Yii;
- use \app\models\Design;
- class DesignController extends BaseController
- {
- // ** Статьи (новости) **
- public function actions()
- {
- return [
- 'error' => [
- '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', []);
- }
- }
|