Blame view

backend/controllers/RequestController.php 2.65 KB
7df05890   Alexey Boroda   -Requests backend...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  <?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'          => [
                          'name'         => [
                              'type' => Index::ACTION_COL,
                              'columnConfig' => [
                                  'buttonsTemplate' => '{edit}{delete}'
                              ]
                          ],
                          'secondname'   => [
                              'type' => Index::STRING_COL,
                          ],
                          'organization' => [
                              'type' => Index::STRING_COL,
                          ],
                      ],
                      'model'            => Customer::class,
                      'hasLanguage'      => false,
                      'enableMassDelete' => true,
                      'modelPrimaryKey'  => 'id',
                      'create'           => false,
                  ],
              ];
          }
          
          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;
              }
          }
      }