Blame view

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