Blame view

frontend/controllers/AccountsController.php 52.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
      use common\models\Country;
9cc08528   Yarik   test
8
      use common\models\Currency;
02524a34   Yarik   test
9
      use common\models\Department;
ea09d15d   Yarik   test
10
      use common\models\Employment;
5f49082a   Yarik   test
11
      use common\models\Fields;
83b0052c   Yarik   test
12
      use common\models\File;
ea09d15d   Yarik   test
13
      use common\models\Gallery;
989c83b0   Yarik   test
14
      use common\models\GallerySearch;
5f49082a   Yarik   test
15
16
17
      use common\models\Job;
      use common\models\Language;
      use common\models\Payment;
7eb29439   Yarik   test
18
      use common\models\Portfolio;
989c83b0   Yarik   test
19
      use common\models\PortfolioSearch;
7eb29439   Yarik   test
20
      use common\models\PortfolioSpecialization;
fdc1c9de   Yarik   test
21
      use common\models\PortfolioUser;
2f324895   Yarik   test
22
      use common\models\PortfolioUserSearch;
84ebac3d   Yarik   test
23
      use common\models\Project;
989c83b0   Yarik   test
24
      use common\models\ProjectSearch;
5f49082a   Yarik   test
25
      use common\models\Specialization;
02524a34   Yarik   test
26
      use common\models\Team;
b95371cf   Yarik   test
27
      use common\models\TeamSearch;
5f49082a   Yarik   test
28
29
      use common\models\UserPayment;
      use common\models\UserSpecialization;
ea09d15d   Yarik   test
30
      use common\models\Vacancy;
588209fc   Yarik   test
31
      use common\models\VacancySearch;
5f49082a   Yarik   test
32
33
34
35
      use Yii;
      use common\models\User;
      use common\models\UserInfo;
  
a02e2fdb   Yarik   test
36
      use yii\base\ErrorException;
2f324895   Yarik   test
37
      use yii\data\Sort;
a02e2fdb   Yarik   test
38
      use yii\db\ActiveRecord;
5f49082a   Yarik   test
39
      use yii\filters\AccessControl;
588209fc   Yarik   test
40
      use yii\filters\VerbFilter;
5f49082a   Yarik   test
41
42
      use yii\web\Controller;
      use yii\web\NotFoundHttpException;
83b0052c   Yarik   test
43
      use yii\web\UploadedFile;
6310a439   Administrator   firs page
44
  
5f49082a   Yarik   test
45
46
47
48
49
      /**
       * Site controller
       */
      class AccountsController extends Controller
      {
6e1510b2   Administrator   firs page
50
  
5f49082a   Yarik   test
51
          public $layout = 'admin';
6e1510b2   Administrator   firs page
52
  
a02e2fdb   Yarik   test
53
54
          public $defaultAction = 'general';
  
5f49082a   Yarik   test
55
56
57
58
59
60
61
62
63
64
65
          public function behaviors()
          {
              return [
                  'access' => [
                      'class' => AccessControl::className(),
                      'rules' => [
                          [
                              //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'],
                              'allow' => true,
                              'roles' => [ '@' ],
                          ],
6310a439   Administrator   firs page
66
67
                      ],
                  ],
588209fc   Yarik   test
68
69
70
                  'verbs'  => [
                      'class'   => VerbFilter::className(),
                      'actions' => [
989c83b0   Yarik   test
71
72
73
74
75
                          'team-delete'      => [ 'POST' ],
                          'vacancy-delete'   => [ 'POST' ],
                          'portfolio-delete' => [ 'POST' ],
                          'projects-delete'  => [ 'POST' ],
                          'blog-delete'      => [ 'POST' ],
ce4a4468   Yarik   test
76
                          'gallery-cover'    => [ 'POST' ],
588209fc   Yarik   test
77
78
                      ],
                  ],
5f49082a   Yarik   test
79
80
              ];
          }
6310a439   Administrator   firs page
81
  
2f324895   Yarik   test
82
83
84
85
86
87
88
89
90
91
92
93
          public function beforeAction($action)
          {
              $portfolio_user_count = PortfolioUser::find()
                                                   ->where([
                                                       'user_id' => \Yii::$app->user->id,
                                                       'status'  => 2,
                                                   ])
                                                   ->count();
              $this->view->params[ 'portfolio_user_count' ] = $portfolio_user_count;
              return parent::beforeAction($action); // TODO: Change the autogenerated stub
          }
  
a02e2fdb   Yarik   test
94
95
          /**
           * Page of additional skills, consist:
a02e2fdb   Yarik   test
96
97
98
99
           * * working with programs;
           * * education;
           * * own developments and patents;
           * * courses and trainings;
a02e2fdb   Yarik   test
100
101
           * @return string
           */
588209fc   Yarik   test
102
103
104
105
106
107
108
109
110
          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 ]);
          }
  
a02e2fdb   Yarik   test
111
112
          /**
           * Page of blog grid view
a02e2fdb   Yarik   test
113
114
           * @return string
           */
588209fc   Yarik   test
115
116
          public function actionBlog()
          {
989c83b0   Yarik   test
117
118
119
120
121
122
123
              $searchModel = new BlogSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('blog', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
588209fc   Yarik   test
124
125
          }
  
a02e2fdb   Yarik   test
126
127
          /**
           * Page of creating one record of blog.
a02e2fdb   Yarik   test
128
129
           * @return string|\yii\web\Response Page html / Redirect
           */
588209fc   Yarik   test
130
131
132
133
134
135
          public function actionBlogCreate()
          {
              $blog = new Blog();
              $post = \Yii::$app->request->post();
              if($blog->load($post) && $blog->save()) {
                  return $this->redirect([
4c9663e0   Yarik   test
136
                      'blog',
588209fc   Yarik   test
137
138
139
140
141
142
                  ]);
              } else {
                  return $this->render('_blog_form', [ 'blog' => $blog ]);
              }
          }
  
a02e2fdb   Yarik   test
143
144
145
146
147
148
149
150
          /**
           * Page of editting one User's record of blog.
           *
           * @param integer $id ID of User's record
           *
           * @return string|\yii\web\Response Page html / Redirect
           * @throws NotFoundHttpException if not found or someone else's post
           */
588209fc   Yarik   test
151
152
          public function actionBlogUpdate($id)
          {
a02e2fdb   Yarik   test
153
154
155
156
157
158
159
              $user = \Yii::$app->user->identity;
              $blog = $user->getBlog()
                           ->where([ 'blog_id' => $id ])
                           ->one();
              if(!$blog instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
588209fc   Yarik   test
160
161
162
163
164
165
166
167
              $post = \Yii::$app->request->post();
              if($blog->load($post) && $blog->save()) {
                  return $this->redirect('blog');
              } else {
                  return $this->render('_blog_form', [ 'blog' => $blog ]);
              }
          }
  
a02e2fdb   Yarik   test
168
169
170
171
172
173
174
175
          /**
           * Delete User's blog record
           *
           * @param $id ID of User's record
           *
           * @return \yii\web\Response Redirect
           * @throws NotFoundHttpException
           */
989c83b0   Yarik   test
176
177
          public function actionBlogDelete($id)
          {
a02e2fdb   Yarik   test
178
179
180
181
182
183
              $user = \Yii::$app->user->identity;
              $blog = $user->getBlog()
                           ->where([ 'blog_id' => $id ])
                           ->one();
              if(!$blog instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
5f49082a   Yarik   test
184
              }
a02e2fdb   Yarik   test
185
186
              $blog->delete();
              return $this->redirect('blog');
70abf3e7   Administrator   add field v.1
187
          }
6310a439   Administrator   firs page
188
  
a02e2fdb   Yarik   test
189
190
          /**
           * Page of contacts. Consist:
a02e2fdb   Yarik   test
191
192
193
           * * phones;
           * * social pages;
           * * sites;
a02e2fdb   Yarik   test
194
195
           * @return string page html
           */
588209fc   Yarik   test
196
          public function actionContacts()
5f49082a   Yarik   test
197
          {
a02e2fdb   Yarik   test
198
199
              $user = \Yii::$app->user->identity;
              $user_info = $user->userInfo;
588209fc   Yarik   test
200
201
202
203
              if(empty( $user_info )) {
                  $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
              }
              if(!empty( \Yii::$app->request->post() )) {
e4a014b8   Yarik   test
204
                  if(!empty( Yii::$app->request->post('Fields') )) {
2cee8b86   Yarik   test
205
  
5346fcf9   Yarik   test
206
207
                      Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru');
                  }
588209fc   Yarik   test
208
209
210
211
212
213
                  $user_info->load(\Yii::$app->request->post());
                  $user_info->save();
              }
              return $this->render('contacts', [ 'user_info' => $user_info ]);
          }
  
a02e2fdb   Yarik   test
214
215
          /**
           * Page of description. Consist of information about User.
a02e2fdb   Yarik   test
216
217
           * @return string page html
           */
588209fc   Yarik   test
218
219
          public function actionDescription()
          {
a02e2fdb   Yarik   test
220
221
              $user = \Yii::$app->user->identity;
              $user_info = $user->userInfo;
588209fc   Yarik   test
222
223
224
225
226
227
228
229
230
231
232
              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 ]);
          }
  
a02e2fdb   Yarik   test
233
234
          /**
           * Page of seniority. Consist:
a02e2fdb   Yarik   test
235
236
237
           * * current job;
           * * year of the beginning of designing
           * * previous jobs
a02e2fdb   Yarik   test
238
239
           * @return string page html
           */
588209fc   Yarik   test
240
241
          public function actionEmployment()
          {
a02e2fdb   Yarik   test
242
243
              $user = \Yii::$app->user->identity;
              $user_info = $user->userInfo;
3e842416   Yarik   test
244
245
246
              if(empty( $user_info )) {
                  $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
              }
588209fc   Yarik   test
247
248
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
3e842416   Yarik   test
249
250
                  $user_info->load($post);
                  $user_info->save();
588209fc   Yarik   test
251
                  $job = [ ];
fdc1c9de   Yarik   test
252
253
                  foreach($post[ 'Job' ] as $index => $value) {
                      $job[ $index ] = new Job([
588209fc   Yarik   test
254
255
256
257
258
259
260
261
262
263
264
265
266
267
                          '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 {
a02e2fdb   Yarik   test
268
269
270
                  $job = $user->getJobs()
                              ->orderBy([ 'current' => SORT_DESC ])
                              ->all();
588209fc   Yarik   test
271
272
273
274
275
276
277
278
279
280
281
282
283
                  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,
                      ]));
                  }
              }
a02e2fdb   Yarik   test
284
285
286
              return $this->render('employment', [
                  'job'       => $job,
                  'user_info' => $user_info,
3e842416   Yarik   test
287
              ]);
588209fc   Yarik   test
288
289
          }
  
e8236f44   Yarik   test
290
291
          /**
           * Page of User's image galleries
e8236f44   Yarik   test
292
293
           * @return string
           */
588209fc   Yarik   test
294
295
          public function actionGallery()
          {
989c83b0   Yarik   test
296
297
              $searchModel = new GallerySearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
588209fc   Yarik   test
298
  
989c83b0   Yarik   test
299
300
301
302
              return $this->render('gallery', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
588209fc   Yarik   test
303
304
          }
  
e8236f44   Yarik   test
305
306
          /**
           * Page of User's videos
e8236f44   Yarik   test
307
308
           * @return string
           */
9217ef8e   Administrator   09.02.16
309
310
311
312
313
          public function actionGalleryVideo()
          {
  
              $user = \Yii::$app->user->identity;
  
1b56164e   Yarik   test
314
              $video = Fields::getData($user->id, Gallery::className(), 'youtube');
9217ef8e   Administrator   09.02.16
315
  
1b56164e   Yarik   test
316
              if(!empty( Yii::$app->request->post('Fields') )) {
3d0e6093   Administrator   15.02.16
317
                  Fields::saveFieldVideoData(Yii::$app->request->post('Fields'), $user->id, Gallery::className(), 'ru');
9217ef8e   Administrator   09.02.16
318
319
320
              }
  
              return $this->render('gallery-video', [
1b56164e   Yarik   test
321
                  'video' => $video,
9217ef8e   Administrator   09.02.16
322
323
324
325
                  'user'  => $user,
              ]);
          }
  
e8236f44   Yarik   test
326
327
          /**
           * Page of creating a photo gallery
e8236f44   Yarik   test
328
329
           * @return string|\yii\web\Response
           */
588209fc   Yarik   test
330
331
332
333
334
335
          public function actionGalleryCreate()
          {
              $gallery = new Gallery();
              $user = \Yii::$app->user->identity;
              $post = \Yii::$app->request->post();
              if($gallery->load($post) && $gallery->save()) {
588209fc   Yarik   test
336
                  return $this->redirect([
bbc81528   Yarik   test
337
                      'gallery',
588209fc   Yarik   test
338
339
340
341
342
343
344
345
346
                  ]);
              } else {
                  return $this->render('_gallery_form', [
                      'gallery' => $gallery,
                      'user'    => $user,
                  ]);
              }
          }
  
e8236f44   Yarik   test
347
348
349
350
351
352
353
          /**
           * Page of updating existing photo gallery
           *
           * @param $id ID of Gallery
           *
           * @return string|\yii\web\Response
           */
588209fc   Yarik   test
354
355
          public function actionGalleryUpdate($id)
          {
588209fc   Yarik   test
356
              $user = \Yii::$app->user->identity;
2e35d6bd   Yarik   test
357
358
359
              $gallery = $user->getGalleries()
                              ->where([ 'gallery_id' => $id ])
                              ->one();
588209fc   Yarik   test
360
361
              $post = \Yii::$app->request->post();
              if($gallery->load($post) && $gallery->save()) {
588209fc   Yarik   test
362
                  return $this->redirect([
bbc81528   Yarik   test
363
                      'gallery',
588209fc   Yarik   test
364
365
366
367
368
369
370
                  ]);
              } else {
                  return $this->render('_gallery_form', [
                      'gallery' => $gallery,
                      'user'    => $user,
                  ]);
              }
5f49082a   Yarik   test
371
          }
6310a439   Administrator   firs page
372
  
e8236f44   Yarik   test
373
374
375
376
377
378
379
          /**
           * Page of deleting existing photo gallery
           *
           * @param $id ID of Gallery
           *
           * @throws \Exception
           */
f59447a7   Yarik   test
380
381
382
383
384
385
386
          public function actionGalleryDelete($id)
          {
              Gallery::findOne($id)
                     ->delete();
              $this->redirect('gallery');
          }
  
a02e2fdb   Yarik   test
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
          /**
           * Page of credentials. Consist:
           * <ul>
           *      <li>
           *          Company info:
           *          <ul>
           *              <li>Company name</li>
           *              <li>Employees count</li>
           *              <li>Street</li>
           *              <li>House</li>
           *          </ul>
           *      </li>
           *      <li>
           *          User info:
           *          <ul>
           *              <li>User name</li>
           *              <li>User surname</li>
           *              <li>Email</li>
           *          </ul>
           *      </li>
           *      <li>
           *          Common info:
           *          <ul>
           *              <li>Status (free/busy)</li>
           *              <li>City</li>
           *              <li>Avatar</li>
           *              <li>Cover</li>
           *              <li>Membership</li>
           *          </ul>
           *      </li>
           * </ul>
a02e2fdb   Yarik   test
418
419
           * @return string page html
           */
5f49082a   Yarik   test
420
          public function actionGeneral()
51e0a262   Yarik   test
421
          {
b4142e17   Yarik   test
422
423
424
              /**
               * @var User $user
               */
a02e2fdb   Yarik   test
425
426
427
              $user = \Yii::$app->user->identity;
              $user_info = $user->userInfo;
              $company_info = $user->companyInfo;
5f49082a   Yarik   test
428
429
              $user = \Yii::$app->user->identity;
              if(empty( $user_info )) {
76f36646   Yarik   test
430
                  //$user_info = new UserInfo([ 'user_id' => $user->id ]);
5f49082a   Yarik   test
431
              }
54d398c7   Administrator   24.02.16
432
  
5f49082a   Yarik   test
433
              if(empty( $company_info )) {
a02e2fdb   Yarik   test
434
                  $company_info = new CompanyInfo([ 'user_id' => $user->id ]);
5f49082a   Yarik   test
435
              }
54d398c7   Administrator   24.02.16
436
  
5f49082a   Yarik   test
437
438
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
54d398c7   Administrator   24.02.16
439
  
a41edafc   Yarik   test
440
                  if($user_info->load($post)) {
54d398c7   Administrator   24.02.16
441
442
443
                      $user_info->save();
                  }
  
a41edafc   Yarik   test
444
                  if($company_info->load($post)) {
54d398c7   Administrator   24.02.16
445
446
447
                      $company_info->save();
                  }
  
a41edafc   Yarik   test
448
                  if($user->load($post) && $user->save()) {
5f49082a   Yarik   test
449
450
451
452
453
454
455
456
457
458
                      \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
459
          }
5f49082a   Yarik   test
460
  
e8236f44   Yarik   test
461
462
463
464
465
466
467
          /**
           * Renders form via ajax, using lastindex.
           *
           * @param integer $lastindex Last index of form input of current type
           *
           * @return string
           */
588209fc   Yarik   test
468
          public function actionGetForm($lastindex)
84ebac3d   Yarik   test
469
          {
588209fc   Yarik   test
470
              return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]);
84ebac3d   Yarik   test
471
472
          }
  
2f324895   Yarik   test
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
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
534
535
536
537
538
539
540
541
542
543
544
545
546
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
          public function actionParticipant()
          {
              $searchModel = new PortfolioUserSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
              $dataProvider->query->joinWith('portfolio');
              $dataProvider->sort = new Sort([
                  'defaultOrder' => [
                      'portfolio_user_id' => SORT_ASC,
                  ],
                  'attributes'   => [
                      'project' => [
                          'asc'  => [
                              'portfolio.name' => SORT_ASC,
                          ],
                          'desc' => [
                              'portfolio.name' => SORT_DESC,
                          ],
                      ],
                      'portfolio_user_id',
                      'position',
                      'time',
                      'status',
                  ],
              ]);
              $dataProvider->pagination->pageSize = 5;
              return $this->render('participant', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
          }
  
          public function actionParticipantConfirm($id)
          {
              $portfolioUser = PortfolioUser::find()
                                            ->where([
                                                'portfolio_user_id' => $id,
                                                'user_id'           => \Yii::$app->user->id,
                                                'status'            => 2,
                                            ])
                                            ->one();
              if(empty( $portfolioUser )) {
                  throw new NotFoundHttpException('Приглашение не найдено');
              }
              $portfolioUser->status = 1;
              if($portfolioUser->save(false)) {
                  return $this->redirect([ 'accounts/participant' ]);
              } else {
                  throw new \Exception('Неизвестная ошибка');
              }
          }
  
          public function actionParticipantDelete($id)
          {
              $portfolioUser = PortfolioUser::find()
                                            ->where([
                                                'portfolio_user_id' => $id,
                                                'user_id'           => \Yii::$app->user->id,
                                            ])
                                            ->one();
              if(empty( $portfolioUser )) {
                  throw new NotFoundHttpException('Приглашение не найдено');
              }
              if($portfolioUser->delete()) {
                  return $this->redirect([ 'accounts/participant' ]);
              } else {
                  throw new \Exception('Неизвестная ошибка');
              }
          }
  
          public function actionParticipantEdit($id)
          {
              $portfolioUser = PortfolioUser::find()
                                            ->where([
                                                'portfolio_user_id' => $id,
                                                'user_id'           => \Yii::$app->user->id,
                                            ])
                                            ->with('gallery')
                                            ->one();
              if(empty( $portfolioUser )) {
                  throw new NotFoundHttpException('Приглашение не найдено');
              }
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
                  if($portfolioUser->load($post)) {
                      $portfolioUser->status = 1;
                      if($portfolioUser->save()) {
                          if(!empty($portfolioUser->gallery)) {
                              $portfolioUser->gallery->load($post);
                              $portfolioUser->portfolioGallery->load($post);
                              if($portfolioUser->gallery->save() && $portfolioUser->portfolioGallery->save()) {
                                  return $this->redirect(['accounts/participant']);
                              }
                          } else {
                              return $this->redirect(['accounts/participant-edit', 'id' => $portfolioUser->portfolio_user_id]);
                          }
                      }
                  }
              }
              return $this->render('participant-edit', [ 'model' => $portfolioUser ]);
          }
  
e8236f44   Yarik   test
574
575
          /**
           * Page of User's portfolio
e8236f44   Yarik   test
576
577
           * @return string
           */
5f49082a   Yarik   test
578
          public function actionPortfolio()
51e0a262   Yarik   test
579
          {
989c83b0   Yarik   test
580
581
              $searchModel = new PortfolioSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
1b56164e   Yarik   test
582
              $dataProvider->pagination->pageSize = 5;
989c83b0   Yarik   test
583
584
585
586
              return $this->render('portfolio', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
7eb29439   Yarik   test
587
588
          }
  
e8236f44   Yarik   test
589
590
          /**
           * Page of creating User's portfolio records.
e8236f44   Yarik   test
591
592
           * @return string|\yii\web\Response
           */
7eb29439   Yarik   test
593
594
          public function actionPortfolioCreate()
          {
2e35d6bd   Yarik   test
595
              $user = \Yii::$app->user->identity;
7eb29439   Yarik   test
596
              $portfolio = new Portfolio();
fdc1c9de   Yarik   test
597
  
1b56164e   Yarik   test
598
599
600
601
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
2e35d6bd   Yarik   test
602
603
604
605
606
607
608
609
              $galleries = $user->getGalleries()
                                ->select([
                                    'name',
                                    'gallery_id',
                                ])
                                ->asArray()
                                ->indexBy('gallery_id')
                                ->column();
7eb29439   Yarik   test
610
              $post = \Yii::$app->request->post();
fdc1c9de   Yarik   test
611
              $portfolioUsers = $portfolio->portfolioUsers;
84ebac3d   Yarik   test
612
              if(!empty( $post )) {
7eb29439   Yarik   test
613
614
615
616
617
618
                  $portfolio->load($post);
                  $portfolio->validate();
                  if(!$portfolio->hasErrors()) {
                      $portfolio->save();
                      $portfolio->unlinkAll('specializations', true);
                      foreach($portfolio->specializationInput as $one_specialization) {
1b56164e   Yarik   test
619
                          $portfolio->link('specializations', Specialization::findOne($one_specialization));
7eb29439   Yarik   test
620
                      }
fdc1c9de   Yarik   test
621
622
623
624
625
626
627
                      $portfolio->unlinkAll('portfolioUsers', true);
                      $success = true;
                      if(!empty( $post[ 'PortfolioUser' ] )) {
                          $portfolioUsers = [ ];
                          foreach($post[ 'PortfolioUser' ] as $index => $item) {
                              $portfolioUsers[ $index ] = new PortfolioUser([ 'portfolio_id' => $portfolio->portfolio_id ]);
                          }
2f324895   Yarik   test
628
                          $success = ( PortfolioUser::loadMultiple($portfolioUsers, $post) && PortfolioUser::validateMultiple($portfolioUsers) );
fdc1c9de   Yarik   test
629
630
631
632
633
634
635
636
637
                          if($success) {
                              foreach($portfolioUsers as $index => $portfolioUser) {
                                  $portfolioUser->save(false);
                              }
                          }
                      }
                      if($success) {
                          return $this->redirect('portfolio');
                      }
7eb29439   Yarik   test
638
639
                  }
              }
84ebac3d   Yarik   test
640
              return $this->render('_portfolio_form', [
1b56164e   Yarik   test
641
                  'portfolio'       => $portfolio,
9fdba9c2   Administrator   15.02.16
642
                  'specializations' => $specializations,
2e35d6bd   Yarik   test
643
                  'galleries'       => $galleries,
fdc1c9de   Yarik   test
644
                  'portfolioUsers'  => $portfolioUsers,
84ebac3d   Yarik   test
645
              ]);
7eb29439   Yarik   test
646
          }
5f49082a   Yarik   test
647
  
e8236f44   Yarik   test
648
649
650
651
652
653
654
655
          /**
           * Page of updating User's portfolio record.
           *
           * @param integer $id ID of User's portfolio record
           *
           * @return string|\yii\web\Response
           * @throws NotFoundHttpException if record not found
           */
7eb29439   Yarik   test
656
657
          public function actionPortfolioUpdate($id)
          {
a02e2fdb   Yarik   test
658
659
660
              $user = \Yii::$app->user->identity;
              $portfolio = $user->getPortfolios()
                                ->where([ 'portfolio_id' => $id ])
fdc1c9de   Yarik   test
661
                                ->with('portfolioUsers.user')
a02e2fdb   Yarik   test
662
                                ->one();
2e35d6bd   Yarik   test
663
664
665
666
667
668
669
670
              $galleries = $user->getGalleries()
                                ->select([
                                    'name',
                                    'gallery_id',
                                ])
                                ->asArray()
                                ->indexBy('gallery_id')
                                ->column();
a02e2fdb   Yarik   test
671
672
673
              if(!$portfolio instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
1b56164e   Yarik   test
674
675
676
677
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
f7089e23   Administrator   15.02.16
678
  
7eb29439   Yarik   test
679
              $post = \Yii::$app->request->post();
2f324895   Yarik   test
680
681
682
683
684
685
686
              $portfolioUsers = $portfolio->getPortfolioUsers()
                                          ->where([ 'status' => 2 ])
                                          ->all();
              $portfolioUsersConfirmed = $portfolio->getPortfolioUsers()
                                                   ->where([ 'status' => 1 ])
                                                   ->indexBy('user_id')
                                                   ->all();
f7089e23   Administrator   15.02.16
687
  
84ebac3d   Yarik   test
688
              if(!empty( $post )) {
7eb29439   Yarik   test
689
690
691
692
693
                  $portfolio->load($post);
                  $portfolio->validate();
                  if(!$portfolio->hasErrors()) {
                      $portfolio->save();
                      $portfolio->unlinkAll('specializations', true);
7eb29439   Yarik   test
694
                      foreach($portfolio->specializationInput as $one_specialization) {
e4a014b8   Yarik   test
695
                          $portfolio->link('specializations', Specialization::findOne($one_specialization));
7eb29439   Yarik   test
696
                      }
2f324895   Yarik   test
697
698
699
700
                      PortfolioUser::deleteAll([
                          'portfolio_id' => $portfolio->portfolio_id,
                          'status'       => 2,
                      ]);
fdc1c9de   Yarik   test
701
702
703
704
705
706
                      $success = true;
                      if(!empty( $post[ 'PortfolioUser' ] )) {
                          $portfolioUsers = [ ];
                          foreach($post[ 'PortfolioUser' ] as $index => $item) {
                              $portfolioUsers[ $index ] = new PortfolioUser([ 'portfolio_id' => $portfolio->portfolio_id ]);
                          }
2f324895   Yarik   test
707
708
709
710
711
712
713
714
715
                          $success = PortfolioUser::loadMultiple($portfolioUsers, $post);
                          foreach($portfolioUsers as $index => $portfolioUser) {
                              if($portfolioUser->status == 1) {
                                  $portfolioUsersConfirmed[ $portfolioUser->user_id ]->position = $portfolioUser->position;
                                  $portfolioUsersConfirmed[ $portfolioUser->user_id ]->time = $portfolioUser->time;
                                  unset( $portfolioUsers[ $index ] );
                              }
                          }
                          $success = ( $success && PortfolioUser::validateMultiple($portfolioUsers) && PortfolioUser::validateMultiple($portfolioUsersConfirmed) );
fdc1c9de   Yarik   test
716
717
                          if($success) {
                              foreach($portfolioUsers as $index => $portfolioUser) {
2f324895   Yarik   test
718
                                  $portfolioUser->status = 2;
fdc1c9de   Yarik   test
719
720
                                  $portfolioUser->save(false);
                              }
2f324895   Yarik   test
721
722
723
                              foreach($portfolioUsersConfirmed as $index => $portfolioUserConfirmed) {
                                  $portfolioUserConfirmed->save(false);
                              }
fdc1c9de   Yarik   test
724
725
726
727
728
                          }
                      }
                      if($success) {
                          return $this->redirect('portfolio');
                      }
7eb29439   Yarik   test
729
730
                  }
              }
f7089e23   Administrator   15.02.16
731
  
84ebac3d   Yarik   test
732
              return $this->render('_portfolio_form', [
2f324895   Yarik   test
733
734
735
736
737
                  'portfolio'               => $portfolio,
                  'specializations'         => $specializations,
                  'galleries'               => $galleries,
                  'portfolioUsers'          => $portfolioUsers,
                  'portfolioUsersConfirmed' => $portfolioUsersConfirmed,
84ebac3d   Yarik   test
738
              ]);
51e0a262   Yarik   test
739
          }
5f49082a   Yarik   test
740
  
e8236f44   Yarik   test
741
742
743
744
745
746
747
748
          /**
           * Page of deleting User's portfolio record.
           *
           * @param integer $id ID of User's portfolio record
           *
           * @throws NotFoundHttpException
           * @throws \Exception if record not found
           */
989c83b0   Yarik   test
749
750
          public function actionPortfolioDelete($id)
          {
a02e2fdb   Yarik   test
751
752
753
754
755
756
757
758
              $user = \Yii::$app->user->identity;
              $portfolio = $user->getPortfolios()
                                ->where([ 'portfolio_id' => $id ])
                                ->one();
              if(!$portfolio instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
              $portfolio->delete();
989c83b0   Yarik   test
759
760
761
              $this->redirect('portfolio');
          }
  
e8236f44   Yarik   test
762
763
          /**
           * Page of User's projects.
e8236f44   Yarik   test
764
765
           * @return string
           */
5f49082a   Yarik   test
766
767
          public function actionProjects()
          {
989c83b0   Yarik   test
768
769
770
771
772
773
774
              $searchModel = new ProjectSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('projects', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
5f49082a   Yarik   test
775
          }
6310a439   Administrator   firs page
776
  
e8236f44   Yarik   test
777
778
          /**
           * Page of creating User's project.
e8236f44   Yarik   test
779
780
           * @return string|\yii\web\Response
           */
84ebac3d   Yarik   test
781
782
783
          public function actionProjectsCreate()
          {
              $project = new Project();
d36bdac6   Administrator   17.02.16
784
  
1b56164e   Yarik   test
785
786
787
788
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
d36bdac6   Administrator   17.02.16
789
  
84ebac3d   Yarik   test
790
791
792
793
794
795
796
797
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
aa182b5c   Yarik   test
798
799
800
801
802
803
804
805
806
              $projects = Project::find()
                                 ->select([
                                     'name',
                                     'project_id',
                                 ])
                                 ->where([ 'user_id' => \Yii::$app->user->getId() ])
                                 ->indexBy('project_id')
                                 ->asArray()
                                 ->column();
84ebac3d   Yarik   test
807
              $post = \Yii::$app->request->post();
aa182b5c   Yarik   test
808
              if(!empty( $post )) {
84ebac3d   Yarik   test
809
                  $project->load($post);
83b0052c   Yarik   test
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
                  $project->files = UploadedFile::getInstances($project, 'files');
                  if(!empty( $project->files )) {
                      $file_id = [ ];
                      if(is_array($project->files)) {
                          foreach($project->files as $file) {
                              if($file instanceof UploadedFile) {
                                  $file_model = new File();
                                  $file_id[] = $file_model->saveFile($file);
                              }
                          }
                      } else {
                          if($project->files instanceof UploadedFile) {
                              $file_model = new File();
                              $file_id[] = $file_model->saveFile($this->file);
                          }
                      }
                      $project->file = json_encode($file_id);
                  }
84ebac3d   Yarik   test
828
829
                  $project->validate();
                  if(!$project->hasErrors()) {
492ed7f7   Yarik   test
830
                      $project->save(false);
84ebac3d   Yarik   test
831
832
                      $project->unlinkAll('specializations', true);
                      foreach($project->specializationInput as $one_specialization) {
aa182b5c   Yarik   test
833
                          $project->link('specializations', Specialization::findOne($one_specialization));
84ebac3d   Yarik   test
834
835
836
                      }
                      $project->unlinkAll('payments', true);
                      foreach($project->paymentInput as $one_payment) {
aa182b5c   Yarik   test
837
                          $project->link('payments', Payment::findOne($one_payment));
84ebac3d   Yarik   test
838
                      }
ea09d15d   Yarik   test
839
                      return $this->redirect([
420d3dcd   Yarik   test
840
                          'projects',
ea09d15d   Yarik   test
841
                      ]);
84ebac3d   Yarik   test
842
843
                  }
              }
aa182b5c   Yarik   test
844
              return $this->render('_projects_form', [
1b56164e   Yarik   test
845
                  'project'         => $project,
d36bdac6   Administrator   17.02.16
846
                  'specializations' => $specializations,
1b56164e   Yarik   test
847
848
                  'payment'         => $payment,
                  'projects'        => $projects,
aa182b5c   Yarik   test
849
850
851
              ]);
          }
  
e8236f44   Yarik   test
852
853
854
855
856
857
858
859
          /**
           * Page of updating User's project.
           *
           * @param integer $id ID of User's project
           *
           * @return string
           * @throws NotFoundHttpException if record not found
           */
aa182b5c   Yarik   test
860
861
          public function actionProjectsUpdate($id)
          {
a02e2fdb   Yarik   test
862
863
864
865
866
867
868
              $user = \Yii::$app->user->identity;
              $project = $user->getProjects()
                              ->where([ 'project_id' => $id ])
                              ->one();
              if(!$project instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
1b56164e   Yarik   test
869
870
871
872
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
aa182b5c   Yarik   test
873
874
875
876
877
878
879
880
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
a02e2fdb   Yarik   test
881
882
883
884
885
886
887
888
889
890
891
892
              $projects = $user->getProjects()
                               ->select([
                                   'name',
                                   'project_id',
                               ])
                               ->andWhere([
                                   'not',
                                   [ 'project_id' => $project->project_id ],
                               ])
                               ->indexBy('project_id')
                               ->asArray()
                               ->column();
aa182b5c   Yarik   test
893
894
895
              $post = \Yii::$app->request->post();
              if(!empty( $post )) {
                  $project->load($post);
83b0052c   Yarik   test
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
                  $project->files = UploadedFile::getInstances($project, 'files');
                  if(!empty( $project->files )) {
                      $file_id = [ ];
                      if(is_array($project->files)) {
                          foreach($project->files as $file) {
                              if($file instanceof UploadedFile) {
                                  $file_model = new File();
                                  $file_id[] = $file_model->saveFile($file);
                              }
                          }
                      } else {
                          if($project->files instanceof UploadedFile) {
                              $file_model = new File();
                              $file_id[] = $file_model->saveFile($this->file);
                          }
                      }
                      $project->file = json_encode($file_id);
                  }
aa182b5c   Yarik   test
914
915
                  $project->validate();
                  if(!$project->hasErrors()) {
492ed7f7   Yarik   test
916
                      $project->save(false);
aa182b5c   Yarik   test
917
918
919
920
921
922
923
924
                      $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));
                      }
a41edafc   Yarik   test
925
                      return $this->redirect([ 'projects' ]);
aa182b5c   Yarik   test
926
927
928
                  }
              }
              return $this->render('_projects_form', [
1b56164e   Yarik   test
929
                  'project'         => $project,
d02fd466   Yarik   test
930
                  'specializations' => $specializations,
1b56164e   Yarik   test
931
932
                  'payment'         => $payment,
                  'projects'        => $projects,
aa182b5c   Yarik   test
933
              ]);
84ebac3d   Yarik   test
934
935
          }
  
e8236f44   Yarik   test
936
937
938
939
940
941
942
943
          /**
           * Page of deleting User's project
           *
           * @param integer $id ID of User's project
           *
           * @throws NotFoundHttpException
           * @throws \Exception
           */
989c83b0   Yarik   test
944
945
          public function actionProjectsDelete($id)
          {
a02e2fdb   Yarik   test
946
947
              $user = \Yii::$app->user->identity;
              $project = $user->getProjects()
1b56164e   Yarik   test
948
949
                              ->where([ 'project_id' => $id ])
                              ->one();
a02e2fdb   Yarik   test
950
951
952
953
              if(!$project instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
              $project->delete();
989c83b0   Yarik   test
954
955
956
              $this->redirect('projects');
          }
  
e8236f44   Yarik   test
957
958
959
960
961
962
963
964
965
966
967
968
          /**
           * Page of editting User's service info. Consist of:
           * * cost of work;
           * * service specializations;
           * * work geography;
           * * work guarantee;
           * * work on contract;
           * * providing estimates;
           * * purchase of materials;
           * * delivery of materials;
           * * minimal prepayment;
           * * payment types;
e8236f44   Yarik   test
969
970
           * @return string
           */
588209fc   Yarik   test
971
          public function actionService()
ea09d15d   Yarik   test
972
          {
5d627502   Yarik   test
973
974
975
              /**
               * @var User $user
               */
ea09d15d   Yarik   test
976
              $user = \Yii::$app->user->identity;
a02e2fdb   Yarik   test
977
              $user_info = $user->userInfo;
588209fc   Yarik   test
978
979
980
              if(empty( $user_info )) {
                  $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]);
              }
1b56164e   Yarik   test
981
982
983
984
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
588209fc   Yarik   test
985
986
987
988
989
990
991
992
              $payment = Payment::find()
                                ->select([
                                    'name',
                                    'payment_id',
                                ])
                                ->indexBy('payment_id')
                                ->asArray()
                                ->column();
1b56164e   Yarik   test
993
              $currencies = Currency::getCurrencyDropdown();
ea09d15d   Yarik   test
994
              $post = \Yii::$app->request->post();
588209fc   Yarik   test
995
996
997
998
999
1000
1001
              if(!empty( $post )) {
                  $user_info->load($post);
                  $user_info->validate();
                  if(!$user_info->hasErrors()) {
                      $user_info->save();
                      $user->load($post);
                      $user->unlinkAll('specializations', true);
38a6e1dd   Yarik   test
1002
1003
1004
1005
                      if(is_array($user->specializationInput)) {
                          foreach($user->specializationInput as $one_specialization) {
                              $user->link('specializations', Specialization::findOne($one_specialization));
                          }
588209fc   Yarik   test
1006
1007
                      }
                      $user->unlinkAll('payments', true);
38a6e1dd   Yarik   test
1008
1009
1010
1011
                      if(is_array($user->paymentInput)) {
                          foreach($user->paymentInput as $one_payment) {
                              $user->link('payments', Payment::findOne($one_payment));
                          }
588209fc   Yarik   test
1012
1013
                      }
                  }
ea09d15d   Yarik   test
1014
              }
588209fc   Yarik   test
1015
              return $this->render('service', [
1b56164e   Yarik   test
1016
1017
                  'user'            => $user,
                  'user_info'       => $user_info,
e8236f44   Yarik   test
1018
                  'specializations' => $specializations,
1b56164e   Yarik   test
1019
1020
                  'payment'         => $payment,
                  'currencies'      => $currencies,
588209fc   Yarik   test
1021
              ]);
ea09d15d   Yarik   test
1022
1023
          }
  
588209fc   Yarik   test
1024
          /**
e8236f44   Yarik   test
1025
1026
           * Page of account setting. Consist of:
           * * changing password;
e8236f44   Yarik   test
1027
           * @return string
588209fc   Yarik   test
1028
1029
           */
          public function actionSetting()
ea09d15d   Yarik   test
1030
          {
ea09d15d   Yarik   test
1031
              $user = \Yii::$app->user->identity;
588209fc   Yarik   test
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
              $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
1060
              }
588209fc   Yarik   test
1061
              return $this->render('setting', [ 'user' => $user ]);
ea09d15d   Yarik   test
1062
1063
          }
  
e8236f44   Yarik   test
1064
1065
          /**
           * Page of company's team
e8236f44   Yarik   test
1066
1067
           * @return string
           */
02524a34   Yarik   test
1068
1069
          public function actionTeam()
          {
b95371cf   Yarik   test
1070
1071
              $searchModel = new TeamSearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
e4a014b8   Yarik   test
1072
1073
1074
1075
1076
1077
1078
1079
              $departments = Department::find()
                                       ->select([
                                           'name',
                                           'department_id',
                                       ])
                                       ->indexBy('department_id')
                                       ->asArray()
                                       ->column();
b95371cf   Yarik   test
1080
1081
1082
1083
  
              return $this->render('team', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
e4a014b8   Yarik   test
1084
                  'departments'  => $departments,
b95371cf   Yarik   test
1085
              ]);
02524a34   Yarik   test
1086
1087
          }
  
e8236f44   Yarik   test
1088
1089
          /**
           * Page of creating company's team member
e8236f44   Yarik   test
1090
1091
           * @return string|\yii\web\Response
           */
02524a34   Yarik   test
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
          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([
e4a014b8   Yarik   test
1111
                      'team',
02524a34   Yarik   test
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
                  ]);
              } else {
                  return $this->render('_team_form', [
                      'team'       => $team,
                      'department' => $department,
                      'country'    => $country,
                  ]);
              }
          }
  
e8236f44   Yarik   test
1122
1123
1124
1125
1126
1127
1128
1129
          /**
           * Page of updating company's team member info.
           *
           * @param integer $id ID of company's team member
           *
           * @return string|\yii\web\Response
           * @throws NotFoundHttpException
           */
02524a34   Yarik   test
1130
1131
          public function actionTeamUpdate($id)
          {
a02e2fdb   Yarik   test
1132
1133
1134
1135
1136
1137
1138
              $user = \Yii::$app->user->identity;
              $team = $user->getTeams()
                           ->where([ 'team_id' => $id ])
                           ->one();
              if(!$team instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
02524a34   Yarik   test
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
              $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()) {
ce4a4468   Yarik   test
1154
1155
                  return $this->redirect([
                      'team',
02524a34   Yarik   test
1156
                  ]);
02524a34   Yarik   test
1157
1158
1159
1160
1161
1162
1163
1164
1165
              } else {
                  return $this->render('_team_form', [
                      'team'       => $team,
                      'department' => $department,
                      'country'    => $country,
                  ]);
              }
          }
  
e8236f44   Yarik   test
1166
1167
1168
1169
1170
1171
1172
1173
          /**
           * Page of deleting company's team member.
           *
           * @param integer $id ID of company's team member
           *
           * @throws NotFoundHttpException
           * @throws \Exception
           */
588209fc   Yarik   test
1174
1175
          public function actionTeamDelete($id)
          {
a02e2fdb   Yarik   test
1176
1177
1178
1179
1180
1181
1182
1183
1184
              $user = \Yii::$app->user->identity;
              $team = $user->getTeams()
                           ->where([ 'team_id' => $id ])
                           ->one();
              if(!$team instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
  
              }
              $team->delete();
588209fc   Yarik   test
1185
1186
1187
              $this->redirect('team');
          }
  
e8236f44   Yarik   test
1188
1189
          /**
           * Page of company's vacancies
e8236f44   Yarik   test
1190
1191
           * @return string
           */
ea09d15d   Yarik   test
1192
1193
          public function actionVacancy()
          {
588209fc   Yarik   test
1194
1195
1196
1197
1198
1199
1200
              $searchModel = new VacancySearch();
              $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  
              return $this->render('vacancy', [
                  'searchModel'  => $searchModel,
                  'dataProvider' => $dataProvider,
              ]);
ea09d15d   Yarik   test
1201
1202
          }
  
e8236f44   Yarik   test
1203
1204
          /**
           * Page of creating company's vacancies.
e8236f44   Yarik   test
1205
1206
           * @return string|\yii\web\Response
           */
ea09d15d   Yarik   test
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
          public function actionVacancyCreate()
          {
              $vacancy = new Vacancy();
              $employment = Employment::find()
                                      ->select([
                                          'name',
                                          'employment_id',
                                      ])
                                      ->indexBy('employment_id')
                                      ->asArray()
                                      ->column();
1b56164e   Yarik   test
1218
1219
1220
1221
1222
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
              $currencies = Currency::getCurrencyDropdown();
a41edafc   Yarik   test
1223
              $user = \Yii::$app->user->identity;
ea09d15d   Yarik   test
1224
              $post = \Yii::$app->request->post();
02524a34   Yarik   test
1225
              if(!empty( $post )) {
ea09d15d   Yarik   test
1226
1227
                  $vacancy->load($post);
                  $vacancy->validate();
a41edafc   Yarik   test
1228
1229
1230
                  if(empty( $vacancy->specializationInput )) {
                      $vacancy->addError('specializationInput');
                  }
ea09d15d   Yarik   test
1231
1232
1233
1234
1235
1236
1237
                  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));
                      }
1b56164e   Yarik   test
1238
1239
1240
1241
                      $vacancy->unlinkAll('specializations', true);
                      foreach($vacancy->specializationInput as $one_specialization) {
                          $vacancy->link('specializations', Specialization::findOne($one_specialization));
                      }
02524a34   Yarik   test
1242
                      return $this->redirect([
ec94728d   Yarik   test
1243
                          'vacancy',
02524a34   Yarik   test
1244
                      ]);
ea09d15d   Yarik   test
1245
1246
1247
                  }
              }
              return $this->render('_vacancy_form', [
1b56164e   Yarik   test
1248
1249
1250
1251
                  'vacancy'         => $vacancy,
                  'employment'      => $employment,
                  'currencies'      => $currencies,
                  'specializations' => $specializations,
a41edafc   Yarik   test
1252
                  'user'            => $user,
ea09d15d   Yarik   test
1253
1254
1255
              ]);
          }
  
e8236f44   Yarik   test
1256
1257
1258
1259
1260
1261
1262
1263
          /**
           * Page of updating company's vacancy.
           *
           * @param integer $id ID of company's vacancy.
           *
           * @return string|\yii\web\Response
           * @throws NotFoundHttpException
           */
ea09d15d   Yarik   test
1264
1265
          public function actionVacancyUpdate($id)
          {
a02e2fdb   Yarik   test
1266
1267
              $user = \Yii::$app->user->identity;
              $vacancy = $user->getVacancies()
1b56164e   Yarik   test
1268
1269
                              ->where([ 'vacancy_id' => $id ])
                              ->one();
a02e2fdb   Yarik   test
1270
1271
1272
              if(!$vacancy instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
              }
ea09d15d   Yarik   test
1273
1274
1275
1276
1277
1278
1279
1280
              $employment = Employment::find()
                                      ->select([
                                          'name',
                                          'employment_id',
                                      ])
                                      ->indexBy('employment_id')
                                      ->asArray()
                                      ->column();
1b56164e   Yarik   test
1281
1282
1283
1284
              $specializations = Specialization::find()
                                               ->where([ 'specialization_pid' => 0 ])
                                               ->orderBy('specialization_id')
                                               ->all();
a41edafc   Yarik   test
1285
              $user = \Yii::$app->user->identity;
1b56164e   Yarik   test
1286
              $currencies = Currency::getCurrencyDropdown();
ea09d15d   Yarik   test
1287
              $post = \Yii::$app->request->post();
02524a34   Yarik   test
1288
              if(!empty( $post )) {
9fd076e8   Administrator   01.03.16
1289
  
ea09d15d   Yarik   test
1290
1291
                  $vacancy->load($post);
                  $vacancy->validate();
ea09d15d   Yarik   test
1292
                  if(!$vacancy->hasErrors()) {
9fd076e8   Administrator   01.03.16
1293
  
ea09d15d   Yarik   test
1294
1295
1296
1297
1298
1299
                      $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));
                      }
1b56164e   Yarik   test
1300
1301
1302
1303
                      $vacancy->unlinkAll('specializations', true);
                      foreach($vacancy->specializationInput as $one_specialization) {
                          $vacancy->link('specializations', Specialization::findOne($one_specialization));
                      }
02524a34   Yarik   test
1304
                      return $this->redirect([
ec94728d   Yarik   test
1305
                          'vacancy',
02524a34   Yarik   test
1306
                      ]);
ea09d15d   Yarik   test
1307
1308
1309
                  }
              }
              return $this->render('_vacancy_form', [
1b56164e   Yarik   test
1310
1311
1312
1313
                  'vacancy'         => $vacancy,
                  'employment'      => $employment,
                  'currencies'      => $currencies,
                  'specializations' => $specializations,
a41edafc   Yarik   test
1314
                  'user'            => $user,
ea09d15d   Yarik   test
1315
1316
1317
              ]);
          }
  
e8236f44   Yarik   test
1318
1319
1320
1321
1322
1323
1324
1325
          /**
           * Page of deleting company's vacancy.
           *
           * @param integer $id ID of company's vacancy
           *
           * @throws NotFoundHttpException
           * @throws \Exception
           */
588209fc   Yarik   test
1326
          public function actionVacancyDelete($id)
5f49082a   Yarik   test
1327
          {
a02e2fdb   Yarik   test
1328
1329
              $user = \Yii::$app->user->identity;
              $vacancy = $user->getVacancies()
1b56164e   Yarik   test
1330
1331
                              ->where([ 'vacancy_id' => $id ])
                              ->one();
a02e2fdb   Yarik   test
1332
1333
1334
1335
1336
              if(!$vacancy instanceof ActiveRecord) {
                  throw new NotFoundHttpException('Запись не найдена');
  
              }
              $vacancy->delete();
588209fc   Yarik   test
1337
              $this->redirect('vacancy');
6310a439   Administrator   firs page
1338
          }
6310a439   Administrator   firs page
1339
  
5f49082a   Yarik   test
1340
          /**
e8236f44   Yarik   test
1341
           * Used to find model of User and throws exception if not found.
5f49082a   Yarik   test
1342
           *
e8236f44   Yarik   test
1343
1344
1345
1346
           * @param integer $id ID of User
           *
           * @return User if User with particular ID found
           * @throws NotFoundHttpException if User with particular ID not found
5f49082a   Yarik   test
1347
1348
1349
           */
          protected function findUser($id)
          {
6310a439   Administrator   firs page
1350
  
5f49082a   Yarik   test
1351
1352
1353
1354
1355
1356
              if($model = User::findOne([ "id" => $id ])) {
                  return $model;
              } else {
                  throw new NotFoundHttpException('The requested page does not exist.');
              }
          }
6310a439   Administrator   firs page
1357
  
2293c233   Administrator   16.03.16
1358
1359
1360
1361
          public function actionGalleryCover()
          {
              $gallery_id = Yii::$app->request->post('gallery_id');
  
ce4a4468   Yarik   test
1362
1363
1364
1365
1366
              $cover = Gallery::find()
                              ->select('cover')
                              ->where([ 'gallery_id' => $gallery_id ])
                              ->column();
              die( $cover[ 0 ] );
2293c233   Administrator   16.03.16
1367
1368
1369
  
          }
  
5f49082a   Yarik   test
1370
      }