fbdb1f1c
Yarik
test
|
1
|
<?php
|
fa284ab0
Yarik
test
|
2
3
4
5
6
7
8
|
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
10
|
use common\models\PortfolioUser;
use common\models\Specialization;
|
fa284ab0
Yarik
test
|
11
12
13
14
15
16
17
|
use common\models\Team;
use common\models\Vacancy;
use common\models\VacancySpecialization;
use Yii;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
use yii\data\Pagination;
|
225c5168
Yarik
test
|
18
|
use yii\data\Sort;
|
239b3249
Yarik
test
|
19
|
use yii\db\ActiveQuery;
|
fa284ab0
Yarik
test
|
20
21
22
23
|
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use common\models\User;
|
225c5168
Yarik
test
|
24
|
use yii\web\NotFoundHttpException;
|
fbdb1f1c
Yarik
test
|
25
26
|
/**
|
fa284ab0
Yarik
test
|
27
|
* Site controller
|
fbdb1f1c
Yarik
test
|
28
|
*/
|
fa284ab0
Yarik
test
|
29
|
class CompanyController extends Controller
|
fbdb1f1c
Yarik
test
|
30
|
{
|
fbdb1f1c
Yarik
test
|
31
|
|
fa284ab0
Yarik
test
|
32
33
34
35
|
public $layout = 'company';
public $defaultAction = 'common';
|
90930c7c
Yarik
test
|
36
37
38
39
40
41
42
43
44
45
46
47
|
public function afterAction($action, $result)
{
if(!empty( $action->controller->actionParams[ 'company_id' ] )) {
$company_id = $action->controller->actionParams[ 'company_id' ];
$user = User::findOne($company_id);
if(!empty( $user->userInfo )) {
$user->userInfo->updateCounters([ 'view_count' => 1 ]);
}
}
return parent::afterAction($action, $result);
}
|
fa284ab0
Yarik
test
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
],
];
|
d36bdac6
Administrator
17.02.16
|
62
|
}
|
d36bdac6
Administrator
17.02.16
|
63
|
|
5014e10b
Yarik
test
|
64
|
public function actionCommon($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
65
|
{
|
225c5168
Yarik
test
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/**
* @var User $company
*/
if(!$company = User::find()
->where([ 'id' => $company_id ])
->with('teams')
->with('teams.department')
->with('userInfo')
->with('companyInfo')
->one()
) {
throw new NotFoundHttpException('Компания не найдена');
}
$projectProvider = new ActiveDataProvider([
|
004b2298
Yarik
test
|
81
|
'query' => $company->getPortfolios(),
|
225c5168
Yarik
test
|
82
|
]);
|
fa284ab0
Yarik
test
|
83
|
|
225c5168
Yarik
test
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
$blogProvider = new ActiveDataProvider([
'query' => $company->getBlog()
->with('comments'),
'sort' => new Sort([
'defaultOrder' => [
'date_add' => SORT_DESC,
'name' => SORT_ASC,
],
]),
'pagination' => new Pagination([
'pageSize' => 2,
'pageParam' => '',
]),
]);
$commentProvider = new ActiveDataProvider([
|
110087c2
Yarik
test
|
100
101
|
'query' => $company->getComments()
->with('rating')
|
b9a54f61
Yarik
test
|
102
|
->with('user'),
|
225c5168
Yarik
test
|
103
104
105
106
107
108
109
110
111
112
|
'sort' => new Sort([
'defaultOrder' => [
'date_add' => SORT_DESC,
],
]),
'pagination' => new Pagination([
'pageSize' => 4,
'pageParam' => '',
]),
]);
|
fa284ab0
Yarik
test
|
113
114
|
return $this->render('common', [
|
225c5168
Yarik
test
|
115
116
117
118
|
'company' => $company,
'projectProvider' => $projectProvider,
'blogProvider' => $blogProvider,
'commentProvider' => $commentProvider,
|
fa284ab0
Yarik
test
|
119
120
|
]);
}
|
d36bdac6
Administrator
17.02.16
|
121
|
|
76f36646
Yarik
test
|
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
public function actionProjects($company_id, $type = 'implementer')
{
$company = User::findOne($company_id);
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
$dataProvider = new ActiveDataProvider([
'query' => $company->getProjects(),
'pagination' => [
'pageSize' => 10,
],
]);
return $this->render('project-list', [
|
f0a961be
Yarik
test
|
138
|
'company' => $company,
|
76f36646
Yarik
test
|
139
140
141
142
|
'dataProvider' => $dataProvider,
]);
}
|
5014e10b
Yarik
test
|
143
|
public function actionPortfolio($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
144
|
{
|
38ffb9db
Yarik
test
|
145
146
147
148
149
150
151
152
153
154
155
|
$company = User::find()
->where([
'id' => $company_id,
])
->joinWith([
'portfolios' => function($query) {
$query->indexBy('portfolio_id');
},
'portfolios.specializations',
])
->one();
|
fa284ab0
Yarik
test
|
156
157
158
159
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
38ffb9db
Yarik
test
|
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
$filters = Specialization::find()
->select([
'count' => 'COUNT(portfolio_specialization.specialization_id)',
'portfolio_specialization.specialization_id',
'specialization.specialization_name',
])
->join('INNER JOIN', 'portfolio_specialization', 'specialization.specialization_id = portfolio_specialization.specialization_id')
->where([ 'portfolio_specialization.portfolio_id' => array_keys($company->portfolios) ])
->groupBy([
'portfolio_specialization.specialization_id',
'specialization.specialization_name',
])
->indexBy('specialization_id')
->asArray()
->all();
$portfolio = new ActiveDataProvider([
'query' => $company->getPortfolios(),
|
fa284ab0
Yarik
test
|
179
180
181
|
'pagination' => [
'pageSize' => 9,
],
|
239b3249
Yarik
test
|
182
|
'sort' => new Sort([
|
38ffb9db
Yarik
test
|
183
184
185
186
|
'defaultOrder' => [
'portfolio_id' => SORT_DESC,
],
]),
|
fa284ab0
Yarik
test
|
187
188
189
190
191
192
|
]);
return $this->render('portfolio', [
'company' => $company,
'filters' => $filters,
'portfolio' => $portfolio,
|
fa284ab0
Yarik
test
|
193
|
]);
|
d36bdac6
Administrator
17.02.16
|
194
195
|
}
|
f0a961be
Yarik
test
|
196
|
public function actionPortfolioFilter($company_id, $filter, $type = 'implementer')
|
fa284ab0
Yarik
test
|
197
|
{
|
38ffb9db
Yarik
test
|
198
199
200
201
202
203
204
205
206
207
208
|
$company = User::find()
->where([
'id' => $company_id,
])
->joinWith([
'portfolios' => function($query) {
$query->indexBy('portfolio_id');
},
'portfolios.specializations',
])
->one();
|
fa284ab0
Yarik
test
|
209
210
211
212
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
38ffb9db
Yarik
test
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
$filters = Specialization::find()
->select([
'count' => 'COUNT(portfolio_specialization.specialization_id)',
'portfolio_specialization.specialization_id',
'specialization.specialization_name',
])
->join('INNER JOIN', 'portfolio_specialization', 'specialization.specialization_id = portfolio_specialization.specialization_id')
->where([ 'portfolio_specialization.portfolio_id' => array_keys($company->portfolios) ])
->groupBy([
'portfolio_specialization.specialization_id',
'specialization.specialization_name',
])
->indexBy('specialization_id')
->asArray()
->all();
$portfolio = new ActiveDataProvider([
'query' => $company->getPortfolios()
->joinWith('specializations')
->where([ 'portfolio_specialization.specialization_id' => $filter ]),
|
fa284ab0
Yarik
test
|
234
235
236
237
238
239
240
241
242
243
|
'pagination' => [
'pageSize' => 9,
],
]);
return $this->render('portfolio', [
'company' => $company,
'filters' => $filters,
'portfolio' => $portfolio,
'filter_id' => $filter,
|
fa284ab0
Yarik
test
|
244
245
|
]);
}
|
d36bdac6
Administrator
17.02.16
|
246
|
|
38ffb9db
Yarik
test
|
247
|
public function actionPortfolioView($company_id, $portfolio_id, $portfolio_user = NULL, $type = 'implementer')
|
fa284ab0
Yarik
test
|
248
249
250
251
|
{
$user = User::findOne($company_id);
$portfolio = $user->getPortfolios()
->where([ 'portfolio_id' => $portfolio_id ])
|
239b3249
Yarik
test
|
252
253
254
255
256
257
258
259
|
->with([
'portfolioUsers' => function($query) {
/**
* @var ActiveQuery $query
*/
$query->andWhere([ 'status' => 1 ]);
},
])
|
38ffb9db
Yarik
test
|
260
|
->with('portfolioUsers.gallery')
|
fa284ab0
Yarik
test
|
261
|
->one();
|
38ffb9db
Yarik
test
|
262
263
|
if(!empty( $portfolio_user )) {
$portfolio_user = PortfolioUser::find()
|
239b3249
Yarik
test
|
264
265
266
267
|
->where([
'portfolio_user_id' => $portfolio_user,
'status' => 1,
])
|
38ffb9db
Yarik
test
|
268
269
270
|
->with('gallery')
->with('user')
->one();
|
239b3249
Yarik
test
|
271
272
273
274
275
276
277
278
|
if(empty( $portfolio_user )) {
$this->redirect([
'portfolio-view',
'performer_id' => $company_id,
'portfolio_id' => $portfolio_id,
'type' => $type,
]);
}
|
38ffb9db
Yarik
test
|
279
280
281
|
} else {
$portfolio->updateCounters([ 'view_count' => 1 ]);
}
|
fa284ab0
Yarik
test
|
282
|
return $this->render('portfolio-view', [
|
38ffb9db
Yarik
test
|
283
284
285
|
'user' => $user,
'portfolio' => $portfolio,
'portfolio_user' => $portfolio_user,
|
fa284ab0
Yarik
test
|
286
287
|
]);
}
|
d36bdac6
Administrator
17.02.16
|
288
|
|
5014e10b
Yarik
test
|
289
|
public function actionTeam($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
290
291
|
{
$company = User::findOne($company_id);
|
fa284ab0
Yarik
test
|
292
293
294
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
a020aad3
Yarik
test
|
295
|
$comments = new ActiveDataProvider([
|
225c5168
Yarik
test
|
296
|
'query' => $company->getComments(),
|
a020aad3
Yarik
test
|
297
|
'pagination' => [
|
225c5168
Yarik
test
|
298
|
'pageSize' => 4,
|
a020aad3
Yarik
test
|
299
300
|
],
]);
|
fa284ab0
Yarik
test
|
301
302
|
$query = Team::find()
->where([ 'user_id' => $company_id ]);
|
a020aad3
Yarik
test
|
303
304
305
306
307
|
$team = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 9,
],
|
fa284ab0
Yarik
test
|
308
|
]);
|
fa284ab0
Yarik
test
|
309
|
return $this->render('team', [
|
a020aad3
Yarik
test
|
310
311
312
|
'company' => $company,
'team' => $team,
'comments' => $comments,
|
fa284ab0
Yarik
test
|
313
|
]);
|
d36bdac6
Administrator
17.02.16
|
314
315
|
}
|
5014e10b
Yarik
test
|
316
|
public function actionBlogList($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
317
318
|
{
$company = User::findOne($company_id);
|
d36bdac6
Administrator
17.02.16
|
319
|
|
fa284ab0
Yarik
test
|
320
321
322
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
d36bdac6
Administrator
17.02.16
|
323
|
|
42931736
Yarik
test
|
324
|
$blog = new ActiveDataProvider([
|
f0a961be
Yarik
test
|
325
|
'query' => $company->getBlog(),
|
42931736
Yarik
test
|
326
327
328
|
'pagination' => new Pagination([
'pageSize' => 5,
]),
|
f0a961be
Yarik
test
|
329
|
'sort' => new Sort([
|
42931736
Yarik
test
|
330
331
|
'defaultOrder' => [
'date_add' => SORT_DESC,
|
f0a961be
Yarik
test
|
332
|
'name' => SORT_ASC,
|
42931736
Yarik
test
|
333
334
|
],
]),
|
fa284ab0
Yarik
test
|
335
|
]);
|
f6ea8941
Administrator
09.02.16
|
336
|
|
fa284ab0
Yarik
test
|
337
|
return $this->render('blog-list', [
|
f0a961be
Yarik
test
|
338
339
|
'company' => $company,
'blog' => $blog,
|
fa284ab0
Yarik
test
|
340
|
]);
|
d36bdac6
Administrator
17.02.16
|
341
342
|
}
|
5014e10b
Yarik
test
|
343
|
public function actionBlogView($company_id, $link, $type = 'implementer')
|
fa284ab0
Yarik
test
|
344
345
|
{
$company = User::findOne($company_id);
|
d36bdac6
Administrator
17.02.16
|
346
|
|
fa284ab0
Yarik
test
|
347
348
349
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
d36bdac6
Administrator
17.02.16
|
350
|
|
4ff3ca88
Yarik
test
|
351
352
353
354
355
356
357
358
|
$article = Blog::find()
->where([
'link' => $link,
'user_id' => $company_id,
])
->with('comments')
->one();
$article->updateCounters([ 'view_count' => 1 ]);
|
d36bdac6
Administrator
17.02.16
|
359
|
|
fa284ab0
Yarik
test
|
360
361
362
|
return $this->render('blog-view', [
'company' => $company,
'article' => $article,
|
d36bdac6
Administrator
17.02.16
|
363
|
|
fa284ab0
Yarik
test
|
364
365
|
]);
}
|
eb7e82fb
Administrator
29.02.16
|
366
|
|
5014e10b
Yarik
test
|
367
|
public function actionReview($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
368
369
|
{
$company = User::findOne($company_id);
|
eb7e82fb
Administrator
29.02.16
|
370
|
|
ad9c004b
Yarik
test
|
371
372
373
374
|
if(empty($company)) {
throw new NotFoundHttpException('Company not found');
}
|
fa284ab0
Yarik
test
|
375
376
377
|
return $this->render('review', [
'company' => $company,
]);
|
eb7e82fb
Administrator
29.02.16
|
378
379
|
}
|
5014e10b
Yarik
test
|
380
|
public function actionVacancyList($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
381
|
{
|
eb7e82fb
Administrator
29.02.16
|
382
|
|
fa284ab0
Yarik
test
|
383
|
$company = User::findOne($company_id);
|
eb7e82fb
Administrator
29.02.16
|
384
|
|
fa284ab0
Yarik
test
|
385
386
387
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
eb7e82fb
Administrator
29.02.16
|
388
|
|
fa284ab0
Yarik
test
|
389
|
$query = $company->getVacancies();
|
eb7e82fb
Administrator
29.02.16
|
390
|
|
fa284ab0
Yarik
test
|
391
|
$provider = new ActiveDataProvider([
|
a020aad3
Yarik
test
|
392
393
394
395
|
'query' => $query,
'pagination' => [
'pageSize' => 5,
],
|
fa284ab0
Yarik
test
|
396
397
398
399
400
401
402
|
'sort' => [
'defaultOrder' => [
'date_add' => SORT_DESC,
'name' => SORT_ASC,
],
],
]);
|
eb7e82fb
Administrator
29.02.16
|
403
|
|
fa284ab0
Yarik
test
|
404
|
return $this->render('vacancy-list', [
|
a020aad3
Yarik
test
|
405
406
|
'company' => $company,
'provider' => $provider,
|
fa284ab0
Yarik
test
|
407
|
]);
|
eb7e82fb
Administrator
29.02.16
|
408
|
|
fa284ab0
Yarik
test
|
409
|
}
|
eb7e82fb
Administrator
29.02.16
|
410
|
|
5014e10b
Yarik
test
|
411
|
public function actionVacancyView($company_id, $link, $type = 'implementer')
|
fa284ab0
Yarik
test
|
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
{
$company = User::findOne($company_id);
$vacancy = $company->getVacancies()
->where([ 'link' => $link ])
->with([
'employments',
'specializations',
])
->one();
$specialization_id = $vacancy->getSpecializations()
->select('specialization_id')
->column();
$vacancy_id = VacancySpecialization::find()
->where([ 'specialization_id' => $specialization_id ])
->select('vacancy_id')
->column();
$similar_vacancies = Vacancy::find()
->where([
'city' => $vacancy->city,
'vacancy_id' => $vacancy_id,
])
->andFilterWhere([
'<>',
'vacancy_id',
$vacancy->vacancy_id,
])
->orderBy([ 'vacancy_id' => SORT_DESC ])
->limit(3)
->all();
return $this->render('vacancy-view', [
'company' => $company,
'vacancy' => $vacancy,
'similar_vacancies' => $similar_vacancies,
]);
}
|
fbdb1f1c
Yarik
test
|
451
|
|
5014e10b
Yarik
test
|
452
|
public function actionGallery($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
453
454
|
{
$company = User::findOne($company_id);
|
f6ea8941
Administrator
09.02.16
|
455
|
|
fa284ab0
Yarik
test
|
456
457
458
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
cda2c1c9
Administrator
add yii jquery
|
459
|
|
f0a961be
Yarik
test
|
460
461
462
463
464
|
$gallery = new ActiveDataProvider([
'query' => $company->getGalleries(),
'pagination' => [
'pageSize' => 5,
],
|
fa284ab0
Yarik
test
|
465
|
]);
|
fbdb1f1c
Yarik
test
|
466
|
|
fa284ab0
Yarik
test
|
467
|
$videos = Fields::getData($company->id, Gallery::className(), 'youtube');
|
d36bdac6
Administrator
17.02.16
|
468
|
|
fa284ab0
Yarik
test
|
469
|
$this->layout = 'gallery-company';
|
f6ea8941
Administrator
09.02.16
|
470
|
|
fa284ab0
Yarik
test
|
471
|
return $this->render('gallery', [
|
38ffb9db
Yarik
test
|
472
473
474
|
'company' => $company,
'gallery' => $gallery,
'videos' => $videos,
|
fa284ab0
Yarik
test
|
475
|
]);
|
d36bdac6
Administrator
17.02.16
|
476
|
}
|
76f36646
Yarik
test
|
477
478
479
|
public function beforeAction($action)
{
|
f0a961be
Yarik
test
|
480
481
|
if(!empty( \Yii::$app->request->get('type') )) {
$action->controller->view->params[ 'type' ] = \Yii::$app->request->get('type');
|
76f36646
Yarik
test
|
482
|
}
|
f0a961be
Yarik
test
|
483
|
if(!empty( \Yii::$app->request->get('company_id') )) {
|
f7b97c9e
Yarik
test
|
484
|
$user = User::findOne(\Yii::$app->request->get('company_id'));
|
f0a961be
Yarik
test
|
485
|
if(!empty( $user ) && $user->type == 1) {
|
f7b97c9e
Yarik
test
|
486
|
$queryParams = \Yii::$app->request->queryParams;
|
f0a961be
Yarik
test
|
487
488
489
|
unset( $queryParams[ 'company_id' ] );
$queryParams[ 'performer_id' ] = $user->id;
return $this->redirect(array_merge([ 'performer/' . $action->id ], $queryParams));
|
f7b97c9e
Yarik
test
|
490
491
|
}
}
|
76f36646
Yarik
test
|
492
493
|
return parent::beforeAction($action);
}
|
fbdb1f1c
Yarik
test
|
494
|
}
|