Blame view

frontend/controllers/AccountsController.php 32.5 KB
6310a439   Administrator   firs page
1
  <?php
5f49082a   Yarik   test
2
3
      namespace frontend\controllers;
  
84ebac3d   Yarik   test
4
      use common\models\Blog;
989c83b0   Yarik   test
5
      use common\models\BlogSearch;
5f49082a   Yarik   test
6
      use common\models\CompanyInfo;
02524a34   Yarik   test
7
8
      use common\models\Country;
      use common\models\Department;
ea09d15d   Yarik   test
9
      use common\models\Employment;
5f49082a   Yarik   test
10
      use common\models\Fields;
ea09d15d   Yarik   test
11
      use common\models\Gallery;
989c83b0   Yarik   test
12
      use common\models\GallerySearch;
5f49082a   Yarik   test
13
14
15
      use common\models\Job;
      use common\models\Language;
      use common\models\Payment;
7eb29439   Yarik   test
16
      use common\models\Portfolio;
989c83b0   Yarik   test
17
      use common\models\PortfolioSearch;
7eb29439   Yarik   test
18
      use common\models\PortfolioSpecialization;
84ebac3d   Yarik   test
19
      use common\models\Project;
989c83b0   Yarik   test
20
      use common\models\ProjectSearch;
5f49082a   Yarik   test
21
      use common\models\Specialization;
02524a34   Yarik   test
22
      use common\models\Team;
b95371cf   Yarik   test
23
      use common\models\TeamSearch;
5f49082a   Yarik   test
24
25
      use common\models\UserPayment;
      use common\models\UserSpecialization;
ea09d15d   Yarik   test
26
      use common\models\Vacancy;
588209fc   Yarik   test
27
      use common\models\VacancySearch;
5f49082a   Yarik   test
28
29
30
31
32
      use Yii;
      use common\models\User;
      use common\models\UserInfo;
  
      use yii\filters\AccessControl;
588209fc   Yarik   test
33
      use yii\filters\VerbFilter;
5f49082a   Yarik   test
34
35
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
6310a439   Administrator   firs page
36
  
5f49082a   Yarik   test
37
38
39
40
41
      /**
       * Site controller
       */
      class AccountsController extends Controller
      {
6e1510b2   Administrator   firs page
42
  
5f49082a   Yarik   test
43
          public $layout = 'admin';
6e1510b2   Administrator   firs page
44
  
5f49082a   Yarik   test
45
46
47
48
49
50
51
52
53
54
55
          public function behaviors()
          {
              return [
                  'access' => [
                      'class' => AccessControl::className(),
                      'rules' => [
                          [
                              //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'],
                              'allow' => true,
                              'roles' => [ '@' ],
                          ],
6310a439   Administrator   firs page
56
57
                      ],
                  ],
588209fc   Yarik   test
58
59
60
                  'verbs'  => [
                      'class'   => VerbFilter::className(),
                      'actions' => [
989c83b0   Yarik   test
61
62
63
64
65
                          'team-delete'      => [ 'POST' ],
                          'vacancy-delete'   => [ 'POST' ],
                          'portfolio-delete' => [ 'POST' ],
                          'projects-delete'  => [ 'POST' ],
                          'blog-delete'      => [ 'POST' ],
588209fc   Yarik   test
66
67
                      ],
                  ],
5f49082a   Yarik   test
68
69
              ];
          }
6310a439   Administrator   firs page
70
  
588209fc   Yarik   test
71
72
73
74
75
76
77
78
79
80
81
          public function actionAddSkills()
          {
              $user = \Yii::$app->user->identity;
              if(!empty( \Yii::$app->request->post() )) {
                  Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
              }
              return $this->render('add-skills', [ 'user' => $user ]);
          }
  
          public function actionBlog()
          {
989c83b0   Yarik   test
82
83
84
85
86
87
88
              $searchModel = new BlogSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('blog', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
588209fc   Yarik   test
89
90
91
92
93
94
95
96
97
          }
  
          public function actionBlogCreate()
          {
              $blog = new Blog();
              $post = \Yii::$app->request->post();
              if($blog->load($post) && $blog->save()) {
                  return $this->redirect([
                      'blog-update',
989c83b0   Yarik   test
98
                      'id' => $blog->blog_id,
588209fc   Yarik   test
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                  ]);
              } else {
                  return $this->render('_blog_form', [ 'blog' => $blog ]);
              }
          }
  
          public function actionBlogUpdate($id)
          {
              $blog = Blog::findOne($id);
              $post = \Yii::$app->request->post();
              if($blog->load($post) && $blog->save()) {
                  return $this->redirect('blog');
              } else {
                  return $this->render('_blog_form', [ 'blog' => $blog ]);
              }
          }
  
989c83b0   Yarik   test
116
117
118
119
120
121
122
          public function actionBlogDelete($id)
          {
              Blog::findOne($id)
                  ->delete();
              $this->redirect('blog');
          }
  
588209fc   Yarik   test
123
124
125
126
127
          public function actionBookmarks()
          {
              return $this->render('bookmarks');
          }
  
5f49082a   Yarik   test
128
129
          public function actionCabinet()
          {
6310a439   Administrator   firs page
130
  
5f49082a   Yarik   test
131
              $user = $this->findUser(Yii::$app->user->identity->id);
6310a439   Administrator   firs page
132
  
5f49082a   Yarik   test
133
              $langs = Language::getActiveLanguages();
6310a439   Administrator   firs page
134
  
5f49082a   Yarik   test
135
136
137
138
139
140
141
142
143
              if($user->load(Yii::$app->request->post()) && $user->save()) {
                  $user->userInfo->load(Yii::$app->request->post());
                  $user->userInfo->save();
                  Fields::saveFieldData(Yii::$app->request->post('Fields'), $user->id, $user::className(), 'ru');
                  return $this->render('cabinet', [
                      'user'      => $user,
                      'user_info' => $user->userInfo,
                      'langs'     => $langs,
                  ]);
2ff00662   Administrator   firs page
144
  
5f49082a   Yarik   test
145
              } else {
70abf3e7   Administrator   add field v.1
146
  
5f49082a   Yarik   test
147
148
149
150
151
                  return $this->render('cabinet', [
                      'user'      => $user,
                      'user_info' => $user->userInfo,
                      'langs'     => $langs,
                  ]);
6310a439   Administrator   firs page
152
  
5f49082a   Yarik   test
153
              }
6310a439   Administrator   firs page
154
  
70abf3e7   Administrator   add field v.1
155
          }
6310a439   Administrator   firs page
156
  
588209fc   Yarik   test
157
          public function actionContacts()
5f49082a   Yarik   test
158
          {
588209fc   Yarik   test
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
              $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() ]);
              }
              if(!empty( \Yii::$app->request->post() )) {
                  Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
                  $user_info->load(\Yii::$app->request->post());
                  $user_info->save();
              }
              return $this->render('contacts', [ 'user_info' => $user_info ]);
          }
  
          public function actionDescription()
          {
              $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() ]);
              }
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
                  $user_info->load($post);
                  $user_info->save();
              }
              return $this->render('description', [ 'user_info' => $user_info ]);
          }
  
          public function actionEmployment()
          {
3e842416   Yarik   test
191
192
193
194
195
196
              $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() ]);
              }
588209fc   Yarik   test
197
198
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
3e842416   Yarik   test
199
200
                  $user_info->load($post);
                  $user_info->save();
588209fc   Yarik   test
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
                  $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,
                      ]));
                  }
              }
3e842416   Yarik   test
235
236
237
              return $this->render('employment', [ 'job'       => $job,
                                                   'user_info' => $user_info,
              ]);
588209fc   Yarik   test
238
239
240
241
          }
  
          public function actionGallery()
          {
989c83b0   Yarik   test
242
243
              $searchModel = new GallerySearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
588209fc   Yarik   test
244
  
989c83b0   Yarik   test
245
246
247
248
              return $this->render('gallery', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
588209fc   Yarik   test
249
250
          }
  
9217ef8e   Administrator   09.02.16
251
252
253
254
255
256
257
258
259
260
          public function actionGalleryVideo()
          {
  
              $user = \Yii::$app->user->identity;
  
              $video = Fields::getData($user->id,Gallery::className(),'youtube');
  
  
  
              if(!empty(Yii::$app->request->post('Fields'))) {
3d0e6093   Administrator   15.02.16
261
                  Fields::saveFieldVideoData(Yii::$app->request->post('Fields'), $user->id, Gallery::className(), 'ru');
9217ef8e   Administrator   09.02.16
262
263
264
265
266
267
268
269
270
              }
  
              return $this->render('gallery-video', [
                  'video'  => $video,
                  'user'  => $user,
              ]);
          }
  
  
588209fc   Yarik   test
271
272
273
274
275
276
          public function actionGalleryCreate()
          {
              $gallery = new Gallery();
              $user = \Yii::$app->user->identity;
              $post = \Yii::$app->request->post();
              if($gallery->load($post) && $gallery->save()) {
9217ef8e   Administrator   09.02.16
277
  
588209fc   Yarik   test
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
                  return $this->redirect([
                      'gallery-update',
                      'id' => $gallery->gallery_id,
                  ]);
              } else {
                  return $this->render('_gallery_form', [
                      'gallery' => $gallery,
                      'user'    => $user,
                  ]);
              }
          }
  
          public function actionGalleryUpdate($id)
          {
              $gallery = Gallery::findOne($id);
              $user = \Yii::$app->user->identity;
              $post = \Yii::$app->request->post();
              if($gallery->load($post) && $gallery->save()) {
                  Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
                  return $this->redirect([
                      'gallery-update',
                      'id' => $gallery->gallery_id,
                  ]);
              } else {
                  return $this->render('_gallery_form', [
                      'gallery' => $gallery,
                      'user'    => $user,
                  ]);
              }
5f49082a   Yarik   test
307
          }
6310a439   Administrator   firs page
308
  
f59447a7   Yarik   test
309
310
311
312
313
314
315
          public function actionGalleryDelete($id)
          {
              Gallery::findOne($id)
                     ->delete();
              $this->redirect('gallery');
          }
  
5f49082a   Yarik   test
316
          public function actionGeneral()
51e0a262   Yarik   test
317
          {
5f49082a   Yarik   test
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
              $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,
              ]);
51e0a262   Yarik   test
347
          }
5f49082a   Yarik   test
348
  
588209fc   Yarik   test
349
          public function actionGetForm($lastindex)
84ebac3d   Yarik   test
350
          {
588209fc   Yarik   test
351
              return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]);
84ebac3d   Yarik   test
352
353
          }
  
5f49082a   Yarik   test
354
          public function actionPortfolio()
51e0a262   Yarik   test
355
          {
989c83b0   Yarik   test
356
357
              $searchModel = new PortfolioSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
9fdba9c2   Administrator   15.02.16
358
              $dataProvider->pagination->pageSize=5;
989c83b0   Yarik   test
359
360
361
362
              return $this->render('portfolio', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
7eb29439   Yarik   test
363
364
365
366
367
          }
  
          public function actionPortfolioCreate()
          {
              $portfolio = new Portfolio();
9fdba9c2   Administrator   15.02.16
368
              $specializations = Specialization::find()->orderBy('specialization_id')->all();
7eb29439   Yarik   test
369
              $post = \Yii::$app->request->post();
84ebac3d   Yarik   test
370
              if(!empty( $post )) {
7eb29439   Yarik   test
371
372
373
374
375
376
377
378
                  $portfolio->load($post);
                  $portfolio->validate();
                  if(!$portfolio->hasErrors()) {
                      $portfolio->save();
                      $portfolio->unlinkAll('specializations', true);
                      foreach($portfolio->specializationInput as $one_specialization) {
                          $portfolio->link('specializations', Specialization::findOne($one_specialization));
                      }
84ebac3d   Yarik   test
379
                      return $this->redirect('portfolio');
7eb29439   Yarik   test
380
381
                  }
              }
84ebac3d   Yarik   test
382
383
              return $this->render('_portfolio_form', [
                  'portfolio'      => $portfolio,
9fdba9c2   Administrator   15.02.16
384
                  'specializations' => $specializations,
84ebac3d   Yarik   test
385
              ]);
7eb29439   Yarik   test
386
          }
5f49082a   Yarik   test
387
  
7eb29439   Yarik   test
388
389
390
          public function actionPortfolioUpdate($id)
          {
              $portfolio = Portfolio::findOne($id);
9fdba9c2   Administrator   15.02.16
391
              $specializations = Specialization::find()->orderBy('specialization_id')->all();
7eb29439   Yarik   test
392
              $post = \Yii::$app->request->post();
84ebac3d   Yarik   test
393
              if(!empty( $post )) {
7eb29439   Yarik   test
394
395
396
397
398
399
400
401
                  $portfolio->load($post);
                  $portfolio->validate();
                  if(!$portfolio->hasErrors()) {
                      $portfolio->save();
                      $portfolio->unlinkAll('specializations', true);
                      foreach($portfolio->specializationInput as $one_specialization) {
                          $portfolio->link('specializations', Specialization::findOne($one_specialization));
                      }
84ebac3d   Yarik   test
402
                      return $this->redirect('portfolio');
7eb29439   Yarik   test
403
404
                  }
              }
84ebac3d   Yarik   test
405
406
              return $this->render('_portfolio_form', [
                  'portfolio'      => $portfolio,
9fdba9c2   Administrator   15.02.16
407
                  'specializations' => $specializations,
84ebac3d   Yarik   test
408
              ]);
51e0a262   Yarik   test
409
          }
5f49082a   Yarik   test
410
  
989c83b0   Yarik   test
411
412
413
414
415
416
417
          public function actionPortfolioDelete($id)
          {
              Portfolio::findOne($id)
                       ->delete();
              $this->redirect('portfolio');
          }
  
5f49082a   Yarik   test
418
419
          public function actionProjects()
          {
989c83b0   Yarik   test
420
421
422
423
424
425
426
              $searchModel = new ProjectSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('projects', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
5f49082a   Yarik   test
427
          }
6310a439   Administrator   firs page
428
  
84ebac3d   Yarik   test
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
          public function actionProjectsCreate()
          {
              $project = new Project();
              $specialization = Specialization::find()
                                              ->select([
                                                  'specialization_name',
                                                  'specialization_id',
                                              ])
                                              ->indexBy('specialization_id')
                                              ->asArray()
                                              ->column();
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
aa182b5c   Yarik   test
448
449
450
451
452
453
454
455
456
              $projects = Project::find()
                                 ->select([
                                     'name',
                                     'project_id',
                                 ])
                                 ->where([ 'user_id' => \Yii::$app->user->getId() ])
                                 ->indexBy('project_id')
                                 ->asArray()
                                 ->column();
84ebac3d   Yarik   test
457
              $post = \Yii::$app->request->post();
aa182b5c   Yarik   test
458
              if(!empty( $post )) {
84ebac3d   Yarik   test
459
460
461
                  $project->load($post);
                  $project->validate();
                  if(!$project->hasErrors()) {
b95371cf   Yarik   test
462
463
464
465
466
467
468
469
470
471
472
473
                      $date_end = new \DateTime();
                      switch($post[ 'Project' ][ 'date_end' ]) {
                          case 2:
                              $date_end->modify('+14 day');
                              break;
                          case 3:
                              $date_end->modify('+30 day');
                              break;
                          default:
                              $date_end->modify('+7 day');
                      };
                      $project->date_end = \Yii::$app->formatter->asDate($date_end->getTimestamp(), 'short');
84ebac3d   Yarik   test
474
475
476
                      $project->save();
                      $project->unlinkAll('specializations', true);
                      foreach($project->specializationInput as $one_specialization) {
aa182b5c   Yarik   test
477
                          $project->link('specializations', Specialization::findOne($one_specialization));
84ebac3d   Yarik   test
478
479
480
                      }
                      $project->unlinkAll('payments', true);
                      foreach($project->paymentInput as $one_payment) {
aa182b5c   Yarik   test
481
                          $project->link('payments', Payment::findOne($one_payment));
84ebac3d   Yarik   test
482
                      }
ea09d15d   Yarik   test
483
484
485
486
                      return $this->redirect([
                          'projects-update',
                          'id' => $project->project_id,
                      ]);
84ebac3d   Yarik   test
487
488
                  }
              }
aa182b5c   Yarik   test
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
              return $this->render('_projects_form', [
                  'project'        => $project,
                  'specialization' => $specialization,
                  'payment'        => $payment,
                  'projects'       => $projects,
              ]);
          }
  
          public function actionProjectsUpdate($id)
          {
              $project = Project::findOne($id);
              $specialization = Specialization::find()
                                              ->select([
                                                  'specialization_name',
                                                  'specialization_id',
                                              ])
                                              ->indexBy('specialization_id')
                                              ->asArray()
                                              ->column();
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
              $projects = Project::find()
                                 ->select([
                                     'name',
                                     'project_id',
                                 ])
                                 ->where([ 'user_id' => \Yii::$app->user->getId() ])
                                 ->andWhere([
                                     'not',
                                     [ 'project_id' => $project->project_id ],
                                 ])
                                 ->indexBy('project_id')
                                 ->asArray()
                                 ->column();
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
                  $project->load($post);
                  $project->validate();
                  if(!$project->hasErrors()) {
b95371cf   Yarik   test
534
535
536
537
538
539
540
541
542
543
544
545
                      $date_end = new \DateTime();
                      switch($post[ 'Project' ][ 'date_end' ]) {
                          case 2:
                              $date_end->modify('+14 day');
                              break;
                          case 3:
                              $date_end->modify('+30 day');
                              break;
                          default:
                              $date_end->modify('+7 day');
                      };
                      $project->date_end = \Yii::$app->formatter->asDate($date_end->getTimestamp(), 'short');
aa182b5c   Yarik   test
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
                      $project->save();
                      $project->unlinkAll('specializations', true);
                      foreach($project->specializationInput as $one_specialization) {
                          $project->link('specializations', Specialization::findOne($one_specialization));
                      }
                      $project->unlinkAll('payments', true);
                      foreach($project->paymentInput as $one_payment) {
                          $project->link('payments', Payment::findOne($one_payment));
                      }
                      return $this->render('_projects_form', [
                          'project'        => $project,
                          'specialization' => $specialization,
                          'payment'        => $payment,
                          'projects'       => $projects,
                      ]);
                      //return $this->redirect('projects');
                  }
              }
              return $this->render('_projects_form', [
                  'project'        => $project,
                  'specialization' => $specialization,
                  'payment'        => $payment,
                  'projects'       => $projects,
              ]);
84ebac3d   Yarik   test
570
571
          }
  
989c83b0   Yarik   test
572
573
574
575
576
577
578
          public function actionProjectsDelete($id)
          {
              Project::findOne($id)
                     ->delete();
              $this->redirect('projects');
          }
  
588209fc   Yarik   test
579
          public function actionService()
ea09d15d   Yarik   test
580
          {
ea09d15d   Yarik   test
581
              $user = \Yii::$app->user->identity;
588209fc   Yarik   test
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
              $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() ]);
              }
              $specialization = Specialization::find()
                                              ->select([
                                                  'specialization_name',
                                                  'specialization_id',
                                              ])
                                              ->indexBy('specialization_id')
                                              ->asArray()
                                              ->column();
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
ea09d15d   Yarik   test
604
              $post = \Yii::$app->request->post();
588209fc   Yarik   test
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
              if(!empty( $post )) {
                  $user_info->load($post);
                  $user_info->validate();
                  if(!$user_info->hasErrors()) {
                      $user_info->save();
                      $user->load($post);
                      $user->unlinkAll('specializations', true);
                      foreach($user->specializationInput as $one_specialization) {
                          $user->link('specializations', Specialization::findOne($one_specialization));
                      }
                      $user->unlinkAll('payments', true);
                      foreach($user->paymentInput as $one_payment) {
                          $user->link('payments', Payment::findOne($one_payment));
                      }
                  }
ea09d15d   Yarik   test
620
              }
588209fc   Yarik   test
621
622
623
624
625
626
              return $this->render('service', [
                  'user'           => $user,
                  'user_info'      => $user_info,
                  'specialization' => $specialization,
                  'payment'        => $payment,
              ]);
ea09d15d   Yarik   test
627
628
          }
  
588209fc   Yarik   test
629
630
631
632
          /**
           * $user User
           */
          public function actionSetting()
ea09d15d   Yarik   test
633
          {
ea09d15d   Yarik   test
634
              $user = \Yii::$app->user->identity;
588209fc   Yarik   test
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
              $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', 'Неправильный старый пароль');
                      }
                  }
ea09d15d   Yarik   test
663
              }
588209fc   Yarik   test
664
              return $this->render('setting', [ 'user' => $user ]);
ea09d15d   Yarik   test
665
666
          }
  
02524a34   Yarik   test
667
668
          public function actionTeam()
          {
b95371cf   Yarik   test
669
670
671
672
673
674
675
              $searchModel = new TeamSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('team', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
02524a34   Yarik   test
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
          }
  
          public function actionTeamCreate()
          {
              $team = new Team();
              $department = Department::find()
                                      ->select([
                                          'name',
                                          'department_id',
                                      ])
                                      ->indexBy('department_id')
                                      ->asArray()
                                      ->column();
              $country = Country::find()
                                ->select([ 'country_name' ])
                                ->indexBy('country_name')
                                ->asArray()
                                ->column();
              $post = \Yii::$app->request->post();
              if($team->load($post) && $team->save()) {
                  return $this->redirect([
                      'team-update',
                      'id' => $team->team_id,
                  ]);
              } else {
                  return $this->render('_team_form', [
                      'team'       => $team,
                      'department' => $department,
                      'country'    => $country,
                  ]);
              }
          }
  
          public function actionTeamUpdate($id)
          {
              $team = Team::findOne($id);
              $department = Department::find()
                                      ->select([
                                          'name',
                                          'department_id',
                                      ])
                                      ->indexBy('department_id')
                                      ->asArray()
                                      ->column();
              $country = Country::find()
                                ->select([ 'country_name' ])
                                ->indexBy('country_name')
                                ->asArray()
                                ->column();
              $post = \Yii::$app->request->post();
              if($team->load($post) && $team->save()) {
                  return $this->redirect([
                      'team-update',
                      'id' => $team->team_id,
                  ]);
              } else {
                  return $this->render('_team_form', [
                      'team'       => $team,
                      'department' => $department,
                      'country'    => $country,
                  ]);
              }
          }
  
588209fc   Yarik   test
740
741
742
743
744
745
746
          public function actionTeamDelete($id)
          {
              Team::findOne($id)
                  ->delete();
              $this->redirect('team');
          }
  
ea09d15d   Yarik   test
747
748
          public function actionVacancy()
          {
588209fc   Yarik   test
749
750
751
752
753
754
755
              $searchModel = new VacancySearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('vacancy', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
ea09d15d   Yarik   test
756
757
758
759
760
761
762
763
764
765
766
767
768
769
          }
  
          public function actionVacancyCreate()
          {
              $vacancy = new Vacancy();
              $employment = Employment::find()
                                      ->select([
                                          'name',
                                          'employment_id',
                                      ])
                                      ->indexBy('employment_id')
                                      ->asArray()
                                      ->column();
              $post = \Yii::$app->request->post();
02524a34   Yarik   test
770
              if(!empty( $post )) {
ea09d15d   Yarik   test
771
772
773
774
775
776
777
778
779
                  $vacancy->load($post);
                  $vacancy->validate();
                  if(!$vacancy->hasErrors()) {
                      $vacancy->save();
                      Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru');
                      $vacancy->unlinkAll('employments', true);
                      foreach($vacancy->employmentInput as $one_employment) {
                          $vacancy->link('employments', Employment::findOne($one_employment));
                      }
02524a34   Yarik   test
780
781
782
783
                      return $this->redirect([
                          'vacancy-update',
                          'id' => $vacancy->vacancy_id,
                      ]);
ea09d15d   Yarik   test
784
785
786
                  }
              }
              return $this->render('_vacancy_form', [
02524a34   Yarik   test
787
                  'vacancy'    => $vacancy,
ea09d15d   Yarik   test
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
                  'employment' => $employment,
              ]);
          }
  
          public function actionVacancyUpdate($id)
          {
              $vacancy = Vacancy::findOne($id);
              $employment = Employment::find()
                                      ->select([
                                          'name',
                                          'employment_id',
                                      ])
                                      ->indexBy('employment_id')
                                      ->asArray()
                                      ->column();
              $post = \Yii::$app->request->post();
02524a34   Yarik   test
804
              if(!empty( $post )) {
ea09d15d   Yarik   test
805
806
807
808
809
810
811
812
813
                  $vacancy->load($post);
                  $vacancy->validate();
                  if(!$vacancy->hasErrors()) {
                      $vacancy->save();
                      Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru');
                      $vacancy->unlinkAll('employments', true);
                      foreach($vacancy->employmentInput as $one_employment) {
                          $vacancy->link('employments', Employment::findOne($one_employment));
                      }
02524a34   Yarik   test
814
815
816
817
                      return $this->redirect([
                          'vacancy-update',
                          'id' => $vacancy->vacancy_id,
                      ]);
ea09d15d   Yarik   test
818
819
820
                  }
              }
              return $this->render('_vacancy_form', [
02524a34   Yarik   test
821
                  'vacancy'    => $vacancy,
ea09d15d   Yarik   test
822
823
824
825
                  'employment' => $employment,
              ]);
          }
  
588209fc   Yarik   test
826
          public function actionVacancyDelete($id)
5f49082a   Yarik   test
827
          {
588209fc   Yarik   test
828
              Vacancy::findOne($id)
989c83b0   Yarik   test
829
                     ->delete();
588209fc   Yarik   test
830
              $this->redirect('vacancy');
6310a439   Administrator   firs page
831
          }
6310a439   Administrator   firs page
832
  
5f49082a   Yarik   test
833
834
835
836
837
838
839
840
          /**
           * @param $id
           *
           * @return User
           * @throws NotFoundHttpException
           */
          protected function findUser($id)
          {
6310a439   Administrator   firs page
841
  
5f49082a   Yarik   test
842
843
844
845
846
847
              if($model = User::findOne([ "id" => $id ])) {
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
          }
6310a439   Administrator   firs page
848
  
5f49082a   Yarik   test
849
      }