Blame view

backend/controllers/RequestController.php 4.51 KB
7df05890   Alexey Boroda   -Requests backend...
1
2
3
4
5
6
7
8
9
10
11
12
  <?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
      {
6f032403   Alexey Boroda   -Confirm mail ready
13
14
15
16
17
18
19
          const LANGUAGES = [
              1 => 'en',
              2 => 'ru',
              3 => 'ua',
              4 => 'fr',
          ];
          
7df05890   Alexey Boroda   -Requests backend...
20
21
22
23
24
25
          public function actions()
          {
              return [
                  'index' => [
                      'class'            => Index::class,
                      'columns'          => [
08d25902   Alexey Boroda   -Send mail ready
26
27
28
29
30
                          'id'   => [
                              'type' => Index::NUMBER_COL,
                          
                          ],
                          'name' => [
b32c8ed8   Alexey Boroda   -Testing email
31
                              'type'         => Index::ACTION_COL,
7df05890   Alexey Boroda   -Requests backend...
32
                              'columnConfig' => [
d74c8480   alex   remove {delete} ...
33
34
                                  #'buttonsTemplate' => '{edit}{delete}',
                                  'buttonsTemplate' => '{edit}',
b32c8ed8   Alexey Boroda   -Testing email
35
                              ],
7df05890   Alexey Boroda   -Requests backend...
36
                          ],
08d25902   Alexey Boroda   -Send mail ready
37
                          
7df05890   Alexey Boroda   -Requests backend...
38
39
40
41
42
43
44
45
46
                          'organization' => [
                              'type' => Index::STRING_COL,
                          ],
                      ],
                      'model'            => Customer::class,
                      'hasLanguage'      => false,
                      'enableMassDelete' => true,
                      'modelPrimaryKey'  => 'id',
                      'create'           => false,
08d25902   Alexey Boroda   -Send mail ready
47
                      'defaultSort'      => [ 'id' => SORT_DESC ],
7df05890   Alexey Boroda   -Requests backend...
48
49
50
51
52
53
54
55
                  ],
              ];
          }
          
          public function actionUpdate($id)
          {
              $model = $this->findModel($id);
              
08d25902   Alexey Boroda   -Send mail ready
56
57
58
59
              $model->scenario = Customer::ADMIN_SCENARIO;
              
              $request = \Yii::$app->request;
              
6f032403   Alexey Boroda   -Confirm mail ready
60
              $wasNew = ( strval($model->status) === '2' );
08d25902   Alexey Boroda   -Send mail ready
61
62
63
64
              
              if ($request->isPost) {
                  if ($model->load($request->post()) && $model->save()) {
                      
6f032403   Alexey Boroda   -Confirm mail ready
65
66
                      if ($wasNew && ( strval($model->status) === '1' )) {
                          $this->mail($model);
08d25902   Alexey Boroda   -Send mail ready
67
68
69
70
71
72
                      }
                      
                      return $this->redirect([ 'index' ]);
                  }
              }
              
7df05890   Alexey Boroda   -Requests backend...
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
116
117
118
119
120
121
122
              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
123
          
6f032403   Alexey Boroda   -Confirm mail ready
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
          public function mail(Customer $model)
          {
              $subject = "CONFIRM__#" . $model->id . ': ' . $model->name;
              
              \Yii::$app->language = self::LANGUAGES[ intval($model->language_id) ];
              
              \Yii::$app->mailer->compose(
                  'thanks_' . $model->language_id,
                  [
                      'phone' => '+380732590821',
                      'email' => 'energyforum@euromediacompany.com',
                      'model' => $model,
                  ]
              )
                                ->setFrom(
                                    [
                                        'artboxcore@gmail.com' => 'NINTH INTERNATIONAL FORUM',
                                    ]
                                )
                                ->setTo(
                                    $model->email
                                )
                                ->setSubject($subject)
                                ->send();
08d25902   Alexey Boroda   -Send mail ready
148
          }
7df05890   Alexey Boroda   -Requests backend...
149
      }