RequestController.php 2.76 KB
<?php
    
    namespace backend\controllers;
    
    use artbox\core\admin\interfaces\ControllerInterface;
    use backend\actions\Index;
    use common\models\Customer;
    use yii\web\Controller;
    use yii\web\NotFoundHttpException;
    
    class RequestController extends Controller implements ControllerInterface
    {
        public function actions()
        {
            return [
                'index' => [
                    'class'            => Index::class,
                    'columns'          => [
	                    'id' => [
		                    'type' => Index::NUMBER_COL,

	                    ],
                    	'name'         => [
                            'type'         => Index::ACTION_COL,
                            'columnConfig' => [
                                #'buttonsTemplate' => '{edit}{delete}',
                                'buttonsTemplate' => '{edit}',
                            ],
                        ],

                        'organization' => [
                            'type' => Index::STRING_COL,
                        ],
                    ],
                    'model'            => Customer::class,
                    'hasLanguage'      => false,
                    'enableMassDelete' => true,
                    'modelPrimaryKey'  => 'id',
                    'create'           => false,
	                'defaultSort'      => ['id' => SORT_DESC]
                ],
            ];
        }
        
        public function actionUpdate($id)
        {
            $model = $this->findModel($id);
            
            return $this->render(
                'update',
                [
                    'model' => $model,
                ]
            );
        }
        
        /**
         * @param $id
         *
         * @return \common\models\Customer|mixed|null
         * @throws \yii\web\NotFoundHttpException
         */
        public function findModel($id)
        {
            $model = Customer::findOne($id);
            if ($model) {
                return $model;
            } else {
                throw new NotFoundHttpException();
            }
        }
        /**
         * Create new model
         *
         * @return mixed
         */
        public function newModel()
        {
            return new Customer();
        }
        /**
         * @param $id
         *
         * @return bool|mixed
         * @throws \Throwable
         * @throws \yii\db\StaleObjectException
         * @throws \yii\web\NotFoundHttpException
         */
        public function deleteModel($id)
        {
            $model = $this->findModel($id);
            
            if ($model->delete()) {
                return true;
            } else {
                return false;
            }
        }
    }