Blame view

frontend/controllers/CabinetController.php 4.09 KB
3bc9af21   Yarik   Layout
1
2
3
  <?php
      namespace frontend\controllers;
      
8195fc24   Yarik   Models
4
      use common\models\User;
dcfb3d5c   Alexey Boroda   -Form ajax ready
5
      use frontend\models\IntellectualProperty;
8195fc24   Yarik   Models
6
7
      use frontend\models\UserData;
      use frontend\models\UserPassport;
30e3d244   Yarik   Forms
8
      use yii\filters\VerbFilter;
3bc9af21   Yarik   Layout
9
10
11
12
13
14
15
      use yii\web\Controller;
      
      /**
       * Cabinet controller
       */
      class CabinetController extends Controller
      {
7f0970a7   Yarik   Layout
16
17
18
          
          public $layout = 'cabinet';
          
3bc9af21   Yarik   Layout
19
20
21
22
23
24
          /**
           * @inheritdoc
           */
          public function behaviors()
          {
              return [
30e3d244   Yarik   Forms
25
26
27
28
                  'verbs' => [
                      'class' => VerbFilter::className(),
                      'actions' => [
                          'personal' => ['post'],
4ff64177   Yarik   Verb
29
                          'passport' => ['post'],
30e3d244   Yarik   Forms
30
31
                      ],
                  ],
3bc9af21   Yarik   Layout
32
33
34
35
36
37
38
39
40
41
              ];
          }
          
          /**
           * Displays index page.
           *
           * @return mixed
           */
          public function actionIndex()
          {
8195fc24   Yarik   Models
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
              \Yii::$app->user->login(User::findOne(1));
              /**
               * @var User $user
               */
              $user = \Yii::$app->user->identity;
              if(!$userData = $user->userData) {
                  $userData = new UserData();
              }
              if(!$userPassport = $user->userPassport) {
                  $userPassport = new UserPassport();
              }
              return $this->render('index', [
                  'userData' => $userData,
                  'userPassport' => $userPassport,
              ]);
3bc9af21   Yarik   Layout
57
58
          }
          
f1b535e4   Yarik   Datepicker
59
60
61
62
63
          public function actionSales()
          {
              
          }
          
30e3d244   Yarik   Forms
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
          public function actionPersonal()
          {
              $request = \Yii::$app->request;
              $response = \Yii::$app->response;
              $response->format = $response::FORMAT_JSON;
              /**
               * @var User $user
               */
              $user = \Yii::$app->user->identity;
              if(!$userData = $user->userData) {
                  $userData = new UserData();
                  $userData->user_id = $user->id;
              }
              if($userData->load($request->post()) && $userData->save()) {
                  return [
                      'success' => true,
                      'message' => 'Данные успешно сохранены',
                  ];
              } else {
                  return [
                      'error' => true,
                      'message' => 'Ошибка сохранения данных',
                  ];
              }
          }
      
          public function actionPassport()
          {
              $request = \Yii::$app->request;
              $response = \Yii::$app->response;
              $response->format = $response::FORMAT_JSON;
              /**
               * @var User $user
               */
              $user = \Yii::$app->user->identity;
              if(!$userPassport = $user->userPassport) {
                  $userPassport = new UserPassport();
                  $userPassport->user_id = $user->id;
              }
              if($userPassport->load($request->post()) && $userPassport->save()) {
                  return [
                      'success' => true,
                      'message' => 'Данные успешно сохранены',
                  ];
              } else {
                  return [
                      'error' => true,
                      'message' => 'Ошибка сохранения данных',
                  ];
              }
          }
dcfb3d5c   Alexey Boroda   -Form ajax ready
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
      
          public function actionAddIntProp()
          {
              $request = \Yii::$app->request;
              $response = \Yii::$app->response;
              $response->format = $response::FORMAT_JSON;
              
              $intProperty = new IntellectualProperty();
              
              if($intProperty->load($request->post()) && $intProperty->save()) {
                  return [
                      'success' => true,
                      'message' => 'Данные успешно сохранены',
                  ];
              } else {
                  return [
                      'error' => true,
                      'message' => 'Ошибка сохранения данных',
                  ];
              }
          }
3bc9af21   Yarik   Layout
136
      }