Blame view

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

      namespace frontend\controllers;

  

      use common\models\Blog;

      use common\models\Fields;

      use common\models\Gallery;

      use common\models\Portfolio;

      use common\models\PortfolioSpecialization;

      use Yii;

b4142e17   Yarik   test
10
      use yii\data\ActiveDataProvider;

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

      use yii\data\Pagination;

42931736   Yarik   test
13
      use yii\data\Sort;

eb7e82fb   Administrator   29.02.16
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
      use yii\helpers\ArrayHelper;

      use yii\web\BadRequestHttpException;

      use yii\web\Controller;

      use common\models\User;

  

      /**

       * 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 )) {

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

                  }

              }

              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
59
          public function actionCommon($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
60
          {

38a6e1dd   Yarik   test
61
62
63
              $user = User::find()

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

                          ->with('jobs')

32ed90fd   Yarik   test
64
65
                          ->with('comments')

                          ->with('comments.rating')

38a6e1dd   Yarik   test
66
                          ->one();

eb7e82fb   Administrator   29.02.16
67
68
69
70
71
72
  

              if(!$user instanceof User) {

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

              }

  

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

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

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

eb7e82fb   Administrator   29.02.16
75
76
77
              $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
78
79
80
81
82
83
84
85
86
              $geography = $user->getPortfolios()

                                ->select([

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

                                    'city'  => 'city',

                                ])

                                ->groupBy('city')

                                ->asArray()

                                ->indexBy('city')

                                ->column();

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

225c5168   Yarik   test
88
89
90
91
92
93
94
                  'user'         => $user,

                  'educations'   => $educations,

                  'developments' => $developments,

                  'courses'      => $courses,

                  'phones'       => $phones,

                  'sites'        => $sites,

                  'soft'         => $soft,

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

eb7e82fb   Administrator   29.02.16
96
97
98
99
              ]);

  

          }

  

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

eb7e82fb   Administrator   29.02.16
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
          {

              $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
119
120
121
                  'allModels'  => $user->getPortfolios()

                                       ->orderBy('portfolio_id')

                                       ->all(),

eb7e82fb   Administrator   29.02.16
122
123
124
125
126
127
128
129
130
131
132
133
134
135
                  'pagination' => [

                      'pageSize' => 9,

                  ],

              ]);

  

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

                  'user'      => $user,

                  'filters'   => $filters,

                  'portfolio' => $portfolio,

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

              ]);

  

          }

  

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

eb7e82fb   Administrator   29.02.16
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
          {

              $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),

              ]);

          }

  

5014e10b   Yarik   test
179
          public function actionPortfolioView($performer_id, $portfolio_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
180
181
182
183
184
185
186
187
188
189
190
191
          {

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

              $portfolio = $user->getPortfolios()

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

                                ->one();

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

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

                  'user'      => $user,

                  'portfolio' => $portfolio,

              ]);

          }

  

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

b4142e17   Yarik   test
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
          {

              $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
213
          public function actionBlogList($performer_id, $type = 'implementer')

eb7e82fb   Administrator   29.02.16
214
215
216
217
218
219
220
          {

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

  

              if(!$user instanceof User) {

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

              }

  

42931736   Yarik   test
221
222
223
              $blog = new ActiveDataProvider([

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

                  'pagination' => new Pagination([

f0a961be   Yarik   test
224
                      'pageSize' => 1,

42931736   Yarik   test
225
226
227
228
229
230
231
                  ]),

                  'sort' => new Sort([

                      'defaultOrder' => [

                          'date_add' => SORT_DESC,

                          'name' => SORT_ASC,

                      ],

                  ]),

eb7e82fb   Administrator   29.02.16
232
233
234
235
236
              ]);

  

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

                  'user'       => $user,

                  'blog'       => $blog,

eb7e82fb   Administrator   29.02.16
237
238
239
              ]);

          }

  

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

eb7e82fb   Administrator   29.02.16
241
242
243
244
245
246
247
          {

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

  

              if(!$user instanceof User) {

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

              }

  

4ff3ca88   Yarik   test
248
249
250
251
252
              $article = Blog::find()

                             ->where([

                                 'link'    => $link,

                                 'user_id' => $performer_id,

                             ])

38a6e1dd   Yarik   test
253
254
                             ->with('comments')

                             ->one();

eb7e82fb   Administrator   29.02.16
255
256
257
258
259
              $article->updateCounters([ 'view_count' => 1 ]);

  

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

                  'user'    => $user,

                  'article' => $article,

eb7e82fb   Administrator   29.02.16
260
261
262
              ]);

          }

  

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

eb7e82fb   Administrator   29.02.16
264
265
266
267
268
269
270
271
272
273
274
275
          {

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

  

              if(!$user instanceof User) {

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

              }

  

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

                  'user' => $user,

              ]);

          }

  

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

eb7e82fb   Administrator   29.02.16
277
          {

b4142e17   Yarik   test
278
279
280
281
              $user = User::find()

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

                          ->with('jobs')

                          ->one();

eb7e82fb   Administrator   29.02.16
282
283
284
285
286
287
288
289
290
              if(!$user instanceof User) {

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

              }

  

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

                  'user' => $user,

              ]);

          }

  

5014e10b   Yarik   test
291
          public function actionGallery($performer_id, $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('Пользователь не найден');

              }

  

f0a961be   Yarik   test
299
300
301
302
303
              $gallery = new ActiveDataProvider([

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

                  'pagination' => [

                      'pageSize' => 5,

                  ],

eb7e82fb   Administrator   29.02.16
304
305
306
307
308
309
310
311
312
              ]);

  

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

  

              $this->layout = 'gallery';

  

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

                  'user'       => $user,

                  'gallery'    => $gallery,

eb7e82fb   Administrator   29.02.16
313
314
315
                  'videos'     => $videos,

              ]);

          }

5014e10b   Yarik   test
316
317
318
  

          public function beforeAction($action)

          {

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

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

5014e10b   Yarik   test
321
              }

f7b97c9e   Yarik   test
322
323
324
325
326
327
328
329
330
              if(!empty(\Yii::$app->request->get('performer_id'))) {

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

                  if(!empty($user) && $user->type == 2) {

                      $queryParams = \Yii::$app->request->queryParams;

                      unset($queryParams['performer_id']);

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

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

                  }

              }

5014e10b   Yarik   test
331
332
              return parent::beforeAction($action);

          }

eb7e82fb   Administrator   29.02.16
333
      }