Blame view

frontend/controllers/AccountsController.php 6.85 KB
6310a439   Administrator   firs page
1
2
3
  <?php
  namespace frontend\controllers;
  
51e0a262   Yarik   test
4
  use common\models\CompanyInfo;
70abf3e7   Administrator   add field v.1
5
  use common\models\Fields;
e9013fc3   Yarik   test
6
  use common\models\Job;
2ff00662   Administrator   firs page
7
  use common\models\Language;
6310a439   Administrator   firs page
8
  use Yii;
0ae6f109   Administrator   firs page
9
  use common\models\User;
8e7a541c   Administrator   firs page
10
11
  use common\models\UserInfo;
  
6310a439   Administrator   firs page
12
13
14
15
16
17
18
19
20
21
22
  use yii\filters\AccessControl;
  use yii\web\Controller;
  use yii\web\NotFoundHttpException;
  
  
  /**
   * Site controller
   */
  class AccountsController extends Controller
  {
  
6e1510b2   Administrator   firs page
23
24
25
  
      public $layout = 'admin';
  
6310a439   Administrator   firs page
26
27
28
29
30
31
32
      public function behaviors()
      {
          return [
              'access' => [
                  'class' => AccessControl::className(),
                  'rules' => [
                      [
51e0a262   Yarik   test
33
                          //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'],
6310a439   Administrator   firs page
34
35
36
37
38
39
40
41
42
43
44
45
46
                          'allow' => true,
                          'roles' => ['@'],
                      ],
                  ],
              ],
          ];
      }
  
  
      public function actionCabinet()
      {
  
  
8e7a541c   Administrator   firs page
47
          $user =  $this->findUser(Yii::$app->user->identity->id);
6310a439   Administrator   firs page
48
  
2ff00662   Administrator   firs page
49
50
          $langs = Language::getActiveLanguages();
  
70abf3e7   Administrator   add field v.1
51
52
53
          if ($user->load(Yii::$app->request->post()) && $user->save()) {
              $user->userInfo->load(Yii::$app->request->post());
              $user->userInfo->save();
ea8c5991   Administrator   add Vitaliy's wid...
54
              Fields::saveFieldData( Yii::$app->request->post('Fields'), $user->id, $user::className(),'ru');
70abf3e7   Administrator   add field v.1
55
56
57
58
59
60
61
              return $this->render('cabinet', [
                  'user' => $user,
                  'user_info' => $user->userInfo,
                  'langs' => $langs,
              ]);
  
          } else {
6310a439   Administrator   firs page
62
  
70abf3e7   Administrator   add field v.1
63
64
65
66
67
              return $this->render('cabinet', [
                  'user' => $user,
                  'user_info' => $user->userInfo,
                  'langs' => $langs,
              ]);
6310a439   Administrator   firs page
68
  
70abf3e7   Administrator   add field v.1
69
          }
6310a439   Administrator   firs page
70
71
72
73
  
  
      }
  
fbdb1f1c   Yarik   test
74
75
76
77
78
      public function actionBookmarks()
      {
          return $this->render('bookmarks');
      }
  
51e0a262   Yarik   test
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
      public function actionGeneral()
      {
          $user_info = UserInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one();
          $company_info = CompanyInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one();
          $user = \Yii::$app->user->identity;
          if(empty($user_info))
          {
              $user_info = new UserInfo(['user_id' => \Yii::$app->user->getId()]);
          }
          if(empty($company_info))
          {
              $company_info = new CompanyInfo(['user_id' => \Yii::$app->user->getId()]);
          }
          $post = \Yii::$app->request->post();
          if(!empty($post))
          {
              $user_info->load($post);
              $company_info->load($post);
              $user->load($post);
              if($user_info->save() && $user->save() && $company_info->save())
              {
                  \Yii::$app->session->setFlash('userinfoupdate', 'Информация успешно обновлена');
              } else {
                  \Yii::$app->session->setFlash('userinfoupdate', 'Ошибка обновления. Проверьте форму');
              }
          }
          return $this->render('general', ['user_info' => $user_info, 'user' => $user, 'company_info' => $company_info]);
      }
  
      public function actionPortfolio()
      {
  
      }
  
      /**
       * $user User
       */
      public function actionSetting()
      {
          $user = \Yii::$app->user->identity;
          $post = \Yii::$app->request->post('User');
          if(!empty($post)) {
              if(empty($post['new_password'])) {
                  $user->addError('new_password', 'Введите новый пароль');
              } else {
                  $user->new_password = $post['new_password'];
              }
              if(empty($post['old_password'])) {
                  $user->addError('old_password', 'Введите новый пароль');
              } else {
                  $user->old_password = $post['old_password'];
              }
              if(empty($post['password_reply']) || $post['password_reply'] !== $post['new_password']) {
                  $user->addError('password_reply', 'Неправильный повтор пароля');
              } else {
                  $user->password_reply = $post['password_reply'];
              }
              if(!$user->hasErrors()) {
                  if($user->validatePassword($user->old_password)) {
                      $user->setPassword($user->new_password);
                      $user->generateAuthKey();
                      if($user->save()) {
                          \Yii::$app->session->setFlash('passwordupdate', 'Пароль успешно обновлен');
                      }
                  } else {
                      $user->addError('old_password', 'Неправильный старый пароль');
                  }
              }
          }
          return $this->render('setting', ['user' => $user]);
      }
  
      public function actionContacts()
      {
f819c230   Yarik   test
153
          var_dump(\Yii::$app->request->post());
51e0a262   Yarik   test
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
          $user_info = UserInfo::find()->where(['user_id' => \Yii::$app->user->getId()])->one();
          if(empty($user_info)) {
              $user_info = new UserInfo(['user_id' => \Yii::$app->user->getId()]);
          }
          return $this->render('contacts', ['user_info' => $user_info]);
      }
  
      public function actionService()
      {
          return $this->render('service');
      }
  
      public function actionAddSkills()
      {
  
      }
  
      public function actionEmployment()
      {
eacb83cc   Yarik   test
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
          $post = \Yii::$app->request->post();
          if(!empty($post)) {
              $job = [];
              for($i = 0; $i < count($post['Job']); $i++) {
                  $job[$i] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]);
              }
              if(Job::loadMultiple($job, $post)) {
                  $job[0]->current = 1;
                  if(Job::validateMultiple($job)) {
                      Job::deleteAll(['user_id' => \Yii::$app->user->getId()]);
                      foreach($job as $onejob) {
                          $onejob->save(false);
                      }
                  }
              }
          } else {
              $job = Job::find()->where(['user_id' => \Yii::$app->user->getId()])->orderBy(['current' => SORT_DESC])->all();
              if(empty($job)) {
                  $job[] = new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 0]);
              }
              if(!$job[0]->current) {
                  array_unshift($job, new Job(['user_id' => \Yii::$app->user->getId(), 'current' => 1]));
              }
e9013fc3   Yarik   test
196
197
          }
          return $this->render('employment', ['job' => $job]);
51e0a262   Yarik   test
198
199
200
201
202
203
204
205
206
207
208
      }
  
      public function actionProjects()
      {
          return $this->render('projects');
      }
  
      public function actionGallery()
      {
  
      }
6310a439   Administrator   firs page
209
  
e9013fc3   Yarik   test
210
211
212
213
214
      public function actionGetForm($lastindex)
      {
          return $this->renderAjax('_job_form', ['index' => $lastindex+1]);
      }
  
70abf3e7   Administrator   add field v.1
215
216
217
218
219
      /**
       * @param $id
       * @return User
       * @throws NotFoundHttpException
       */
8e7a541c   Administrator   firs page
220
      protected function findUser($id)
6310a439   Administrator   firs page
221
222
      {
  
70abf3e7   Administrator   add field v.1
223
          if ($model = User::findOne(["id"=>$id])) {
6310a439   Administrator   firs page
224
225
226
227
228
229
230
              return $model;
          } else {
              throw new NotFoundHttpException('The requested page does not exist.');
          }
      }
  
  
6310a439   Administrator   firs page
231
  
6310a439   Administrator   firs page
232
  }