Blame view

backend/controllers/RequestController.php 3.47 KB
7df05890   Alexey Boroda   -Requests backend...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  <?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'          => [
08d25902   Alexey Boroda   -Send mail ready
19
20
21
22
23
                          'id'   => [
                              'type' => Index::NUMBER_COL,
                          
                          ],
                          'name' => [
b32c8ed8   Alexey Boroda   -Testing email
24
                              'type'         => Index::ACTION_COL,
7df05890   Alexey Boroda   -Requests backend...
25
                              'columnConfig' => [
d74c8480   alex   remove {delete} ...
26
27
                                  #'buttonsTemplate' => '{edit}{delete}',
                                  'buttonsTemplate' => '{edit}',
b32c8ed8   Alexey Boroda   -Testing email
28
                              ],
7df05890   Alexey Boroda   -Requests backend...
29
                          ],
08d25902   Alexey Boroda   -Send mail ready
30
                          
7df05890   Alexey Boroda   -Requests backend...
31
32
33
34
35
36
37
38
39
                          'organization' => [
                              'type' => Index::STRING_COL,
                          ],
                      ],
                      'model'            => Customer::class,
                      'hasLanguage'      => false,
                      'enableMassDelete' => true,
                      'modelPrimaryKey'  => 'id',
                      'create'           => false,
08d25902   Alexey Boroda   -Send mail ready
40
                      'defaultSort'      => [ 'id' => SORT_DESC ],
7df05890   Alexey Boroda   -Requests backend...
41
42
43
44
45
46
47
48
                  ],
              ];
          }
          
          public function actionUpdate($id)
          {
              $model = $this->findModel($id);
              
08d25902   Alexey Boroda   -Send mail ready
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
              $model->scenario = Customer::ADMIN_SCENARIO;
              
              $request = \Yii::$app->request;
              
              $wasNew = (strval($model->status) === '2');
              
              if ($request->isPost) {
                  if ($model->load($request->post()) && $model->save()) {
                      
                      if ($wasNew && (strval($model->status) === '1' )) {
                          $this->mail($model->email);
                      }
                      
                      return $this->redirect([ 'index' ]);
                  }
              }
              
7df05890   Alexey Boroda   -Requests backend...
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
              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;
              }
          }
08d25902   Alexey Boroda   -Send mail ready
116
117
118
119
          
          public function mail($email) {
          
          }
7df05890   Alexey Boroda   -Requests backend...
120
      }