Blame view

frontend/controllers/PerformerController.php 15.4 KB
eb7e82fb   Administrator   29.02.16
1
2
3
4
5
6
7
8
  <?php

      namespace frontend\controllers;

  

      use common\models\Blog;

      use common\models\Fields;

      use common\models\Gallery;

      use common\models\Portfolio;

      use common\models\PortfolioSpecialization;

38ffb9db   Yarik   test
9
      use common\models\PortfolioUser;

eb7e82fb   Administrator   29.02.16
10
      use Yii;

b4142e17   Yarik   test
11
      use yii\data\ActiveDataProvider;

eb7e82fb   Administrator   29.02.16
12
13
      use yii\data\ArrayDataProvider;

      use yii\data\Pagination;

42931736   Yarik   test
14
      use yii\data\Sort;

239b3249   Yarik   test
15
      use yii\db\ActiveQuery;

eb7e82fb   Administrator   29.02.16
16
17
18
19
      use yii\helpers\ArrayHelper;

      use yii\web\BadRequestHttpException;

      use yii\web\Controller;

      use common\models\User;

e82beebc   Yarik   test
20
      use yii\web\NotFoundHttpException;

eb7e82fb   Administrator   29.02.16
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  

      /**

       * Site controller

       */

      class PerformerController extends Controller

      {

  

          public $layout = 'performer';

  

          public $user;

  

          public $defaultAction = 'common';

  

          public function afterAction($action, $result)

          {

              if(!empty( $action->controller->actionParams[ 'performer_id' ] )) {

                  $performer_id = $action->controller->actionParams[ 'performer_id' ];

                  $user = User::findOne($performer_id);

                  if(!empty( $user->userInfo )) {

272ce289   Yarik   test
40
41
42
43
44
45
46
47
48
49
50
51
52
                      if($user->userInfo->is_freelancer xor $user->userInfo->is_customer) {

                          $type = $action->controller->actionParams['type'];

                          $get = \Yii::$app->request->get();

                          if(!empty($type)) {

                              if($user->userInfo->is_freelancer && $type == 'customer') {

                                  $get['type'] = 'implementer';

                                  $this->redirect(array_merge([$action->id], $get));

                              } elseif($user->userInfo->is_customer && $type == 'implementer') {

                                  $get['type'] = 'customer';

                                  $this->redirect(array_merge([$action->id], $get));

                              }

                          }

                      }

9b93120e   Alex Savenko   review fix
53
54
55
56
                      if($user->id != \Yii::$app->user->id) {

                          $user->userInfo->updateCounters([ 'view_count' => 1 ]);

                      }

                      $user->updateRating();

eb7e82fb   Administrator   29.02.16
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
                  }

              }

              return parent::afterAction($action, $result);

          }

  

          /**

           * @inheritdoc

           */

          public function actions()

          {

              return [

                  'error'   => [

                      'class' => 'yii\web\ErrorAction',

                  ],

                  'captcha' => [

                      'class'           => 'yii\captcha\CaptchaAction',

                      'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,

                  ],

              ];

          }

  

5014e10b   Yarik   test
78
          public function actionCommon($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
79
          {

38a6e1dd   Yarik   test
80
81
82
              $user = User::find()

                          ->where([ 'id' => $performer_id ])

                          ->with('jobs')

32ed90fd   Yarik   test
83
84
                          ->with('comments')

                          ->with('comments.rating')

38a6e1dd   Yarik   test
85
                          ->one();

eb7e82fb   Administrator   29.02.16
86
87
  

              if(!$user instanceof User) {

e82beebc   Yarik   test
88
                  throw new NotFoundHttpException('Пользователь не найден');

eb7e82fb   Administrator   29.02.16
89
90
91
              }

  

              $educations = Fields::getData($user->id, $user->className(), 'education');

225c5168   Yarik   test
92
93
              $developments = Fields::getData($user->id, $user->className(), 'development');

              $courses = Fields::getData($user->id, $user->className(), 'courses');

eb7e82fb   Administrator   29.02.16
94
95
96
              $phones = Fields::getData($user->id, $user->className(), 'phone');

              $sites = Fields::getData($user->id, $user->className(), 'site');

              $soft = implode(', ', ArrayHelper::getColumn(Fields::getData($user->id, $user->className(), 'soft'), 'soft'));

5d627502   Yarik   test
97
98
99
100
101
102
103
104
105
              $geography = $user->getPortfolios()

                                ->select([

                                    'count' => 'COUNT(*)',

                                    'city'  => 'city',

                                ])

                                ->groupBy('city')

                                ->asArray()

                                ->indexBy('city')

                                ->column();

eb7e82fb   Administrator   29.02.16
106
              return $this->render('common', [

225c5168   Yarik   test
107
108
109
110
111
112
113
                  'user'         => $user,

                  'educations'   => $educations,

                  'developments' => $developments,

                  'courses'      => $courses,

                  'phones'       => $phones,

                  'sites'        => $sites,

                  'soft'         => $soft,

5d627502   Yarik   test
114
                  'geography'    => $geography,

eb7e82fb   Administrator   29.02.16
115
116
117
118
              ]);

  

          }

  

5014e10b   Yarik   test
119
          public function actionPortfolio($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

              $projects = ArrayHelper::getColumn($user->portfolios, 'portfolio_id');

  

              $filters = PortfolioSpecialization::find()

                                                ->select([

                                                    "specialization_id",

                                                    "COUNT('specialization_id') AS count",

                                                ])

                                                ->where([ "portfolio_id" => $projects ])

                                                ->groupBy("specialization_id")

                                                ->all();

  

              $portfolio = new ArrayDataProvider([

4ff3ca88   Yarik   test
138
139
140
                  'allModels'  => $user->getPortfolios()

                                       ->orderBy('portfolio_id')

                                       ->all(),

eb7e82fb   Administrator   29.02.16
141
142
143
144
145
146
147
148
149
150
151
152
153
154
                  'pagination' => [

                      'pageSize' => 9,

                  ],

              ]);

  

              return $this->render('portfolio', [

                  'user'      => $user,

                  'filters'   => $filters,

                  'portfolio' => $portfolio,

                  'count'     => count($user->portfolios),

              ]);

  

          }

  

5014e10b   Yarik   test
155
          public function actionPortfolioFilter($performer_id, $filter, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

              $portfolios = ArrayHelper::getColumn($user->portfolios, 'portfolio_id');

  

              $filters = PortfolioSpecialization::find()

                                                ->select([

                                                    "specialization_id",

                                                    "COUNT('specialization_id') AS count",

                                                ])

                                                ->where([ "portfolio_id" => $portfolios ])

                                                ->groupBy("specialization_id")

                                                ->all();

  

              $filter_result = PortfolioSpecialization::find()

                                                      ->where([

                                                          'specialization_id' => $filter,

                                                          'portfolio_id'      => $portfolios,

                                                      ])

                                                      ->all();

  

              $portfolio = new ArrayDataProvider([

                  'allModels'  => Portfolio::find()

                                           ->where([ 'portfolio_id' => ArrayHelper::getColumn($filter_result, 'portfolio_id') ])

                                           ->all(),

                  'pagination' => [

                      'pageSize' => 9,

                  ],

              ]);

  

              return $this->render('portfolio', [

                  'user'      => $user,

                  'filters'   => $filters,

                  'portfolio' => $portfolio,

                  'filter_id' => $filter,

                  'count'     => count($user->portfolios),

              ]);

          }

  

38ffb9db   Yarik   test
198
          public function actionPortfolioView($performer_id, $portfolio_id, $portfolio_user = NULL, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
199
200
201
202
          {

              $user = User::findOne($performer_id);

              $portfolio = $user->getPortfolios()

                                ->where([ 'portfolio_id' => $portfolio_id ])

239b3249   Yarik   test
203
204
205
206
207
208
209
210
                                ->with([

                                    'portfolioUsers' => function($query) {

                                        /**

                                         * @var ActiveQuery $query

                                         */

                                        $query->andWhere([ 'status' => 1 ]);

                                    },

                                ])

38ffb9db   Yarik   test
211
                                ->with('portfolioUsers.gallery')

eb7e82fb   Administrator   29.02.16
212
                                ->one();

e82beebc   Yarik   test
213
214
215
              if(empty($portfolio)) {

                  throw new NotFoundHttpException('Портфолио не найдено');

              }

38ffb9db   Yarik   test
216
217
              if(!empty( $portfolio_user )) {

                  $portfolio_user = PortfolioUser::find()

239b3249   Yarik   test
218
219
220
221
                                                 ->where([

                                                     'portfolio_user_id' => $portfolio_user,

                                                     'status'            => 1,

                                                 ])

38ffb9db   Yarik   test
222
223
224
                                                 ->with('gallery')

                                                 ->with('user')

                                                 ->one();

239b3249   Yarik   test
225
226
227
228
229
230
231
232
                  if(empty( $portfolio_user )) {

                      $this->redirect([

                          'portfolio-view',

                          'performer_id' => $performer_id,

                          'portfolio_id' => $portfolio_id,

                          'type'         => $type,

                      ]);

                  }

38ffb9db   Yarik   test
233
234
235
              } else {

                  $portfolio->updateCounters([ 'view_count' => 1 ]);

              }

eb7e82fb   Administrator   29.02.16
236
              return $this->render('portfolio-view', [

38ffb9db   Yarik   test
237
238
239
                  'user'           => $user,

                  'portfolio'      => $portfolio,

                  'portfolio_user' => $portfolio_user,

eb7e82fb   Administrator   29.02.16
240
241
242
              ]);

          }

  

5014e10b   Yarik   test
243
          public function actionProjects($performer_id, $type = 'implementer')

b4142e17   Yarik   test
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

              $dataProvider = new ActiveDataProvider([

                  'query'      => $user->getProjects(),

                  'pagination' => [

                      'pageSize' => 10,

                  ],

              ]);

  

              return $this->render('project-list', [

                  'user'         => $user,

                  'dataProvider' => $dataProvider,

              ]);

          }

  

5014e10b   Yarik   test
264
          public function actionBlogList($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
265
266
267
268
269
270
271
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

42931736   Yarik   test
272
              $blog = new ActiveDataProvider([

38ffb9db   Yarik   test
273
                  'query'      => $user->getBlog(),

42931736   Yarik   test
274
                  'pagination' => new Pagination([

c20d5820   Yarik   test
275
                      'pageSize' => 5,

42931736   Yarik   test
276
                  ]),

38ffb9db   Yarik   test
277
                  'sort'       => new Sort([

42931736   Yarik   test
278
279
                      'defaultOrder' => [

                          'date_add' => SORT_DESC,

38ffb9db   Yarik   test
280
                          'name'     => SORT_ASC,

42931736   Yarik   test
281
282
                      ],

                  ]),

eb7e82fb   Administrator   29.02.16
283
284
285
              ]);

  

              return $this->render('blog-list', [

38ffb9db   Yarik   test
286
287
                  'user' => $user,

                  'blog' => $blog,

eb7e82fb   Administrator   29.02.16
288
289
290
              ]);

          }

  

5014e10b   Yarik   test
291
          public function actionBlogView($performer_id, $link, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
292
293
294
295
296
297
298
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

4ff3ca88   Yarik   test
299
300
301
302
303
              $article = Blog::find()

                             ->where([

                                 'link'    => $link,

                                 'user_id' => $performer_id,

                             ])

38a6e1dd   Yarik   test
304
305
                             ->with('comments')

                             ->one();

e82beebc   Yarik   test
306
307
308
              if(empty($article)) {

                  throw new NotFoundHttpException('Запись не найдена');

              }

eb7e82fb   Administrator   29.02.16
309
310
311
312
313
              $article->updateCounters([ 'view_count' => 1 ]);

  

              return $this->render('blog-view', [

                  'user'    => $user,

                  'article' => $article,

eb7e82fb   Administrator   29.02.16
314
315
316
              ]);

          }

  

5014e10b   Yarik   test
317
          public function actionReview($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
318
319
320
321
322
323
324
325
326
327
328
329
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

              return $this->render('review', [

                  'user' => $user,

              ]);

          }

  

5014e10b   Yarik   test
330
          public function actionWorkplace($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
331
          {

b4142e17   Yarik   test
332
333
334
335
              $user = User::find()

                          ->where([ 'id' => $performer_id ])

                          ->with('jobs')

                          ->one();

eb7e82fb   Administrator   29.02.16
336
337
338
339
340
341
342
343
344
              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

              return $this->render('workplace', [

                  'user' => $user,

              ]);

          }

  

5014e10b   Yarik   test
345
          public function actionGallery($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
346
347
348
349
350
351
352
          {

              $user = User::findOne($performer_id);

  

              if(!$user instanceof User) {

                  throw new BadRequestHttpException('Пользователь не найден');

              }

  

f0a961be   Yarik   test
353
              $gallery = new ActiveDataProvider([

4a3f5562   Yarik   test
354
                  'query'      => $user->getGalleries()->andWhere(['not', ['photo' => '']])->andWhere(['not', ['photo' => NULL]]),

f0a961be   Yarik   test
355
356
357
                  'pagination' => [

                      'pageSize' => 5,

                  ],

eb7e82fb   Administrator   29.02.16
358
359
360
361
362
363
364
              ]);

  

              $videos = Fields::getData($user->id, Gallery::className(), 'youtube');

  

              $this->layout = 'gallery';

  

              return $this->render('gallery', [

38ffb9db   Yarik   test
365
366
367
                  'user'    => $user,

                  'gallery' => $gallery,

                  'videos'  => $videos,

eb7e82fb   Administrator   29.02.16
368
369
              ]);

          }

5014e10b   Yarik   test
370
371
372
  

          public function beforeAction($action)

          {

5d627502   Yarik   test
373
374
              if(!empty( \Yii::$app->request->get('type') )) {

                  $action->controller->view->params[ 'type' ] = \Yii::$app->request->get('type');

5014e10b   Yarik   test
375
              }

38ffb9db   Yarik   test
376
              if(!empty( \Yii::$app->request->get('performer_id') )) {

f7b97c9e   Yarik   test
377
                  $user = User::findOne(\Yii::$app->request->get('performer_id'));

38ffb9db   Yarik   test
378
                  if(!empty( $user ) && $user->type == 2) {

f7b97c9e   Yarik   test
379
                      $queryParams = \Yii::$app->request->queryParams;

38ffb9db   Yarik   test
380
381
382
                      unset( $queryParams[ 'performer_id' ] );

                      $queryParams[ 'company_id' ] = $user->id;

                      return $this->redirect(array_merge([ 'company/' . $action->id ], $queryParams));

f7b97c9e   Yarik   test
383
384
                  }

              }

5014e10b   Yarik   test
385
386
              return parent::beforeAction($action);

          }

eb7e82fb   Administrator   29.02.16
387
      }