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();
|
e82beebc
Yarik
test
|
262
263
264
|
if(empty($portfolio)) {
throw new NotFoundHttpException('Портфолио не найдено');
}
|
38ffb9db
Yarik
test
|
265
266
|
if(!empty( $portfolio_user )) {
$portfolio_user = PortfolioUser::find()
|
239b3249
Yarik
test
|
267
268
269
270
|
->where([
'portfolio_user_id' => $portfolio_user,
'status' => 1,
])
|
38ffb9db
Yarik
test
|
271
272
273
|
->with('gallery')
->with('user')
->one();
|
239b3249
Yarik
test
|
274
275
276
277
278
279
280
281
|
if(empty( $portfolio_user )) {
$this->redirect([
'portfolio-view',
'performer_id' => $company_id,
'portfolio_id' => $portfolio_id,
'type' => $type,
]);
}
|
38ffb9db
Yarik
test
|
282
283
284
|
} else {
$portfolio->updateCounters([ 'view_count' => 1 ]);
}
|
fa284ab0
Yarik
test
|
285
|
return $this->render('portfolio-view', [
|
38ffb9db
Yarik
test
|
286
287
288
|
'user' => $user,
'portfolio' => $portfolio,
'portfolio_user' => $portfolio_user,
|
fa284ab0
Yarik
test
|
289
290
|
]);
}
|
d36bdac6
Administrator
17.02.16
|
291
|
|
5014e10b
Yarik
test
|
292
|
public function actionTeam($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
293
294
|
{
$company = User::findOne($company_id);
|
fa284ab0
Yarik
test
|
295
296
297
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
a020aad3
Yarik
test
|
298
|
$comments = new ActiveDataProvider([
|
225c5168
Yarik
test
|
299
|
'query' => $company->getComments(),
|
a020aad3
Yarik
test
|
300
|
'pagination' => [
|
225c5168
Yarik
test
|
301
|
'pageSize' => 4,
|
a020aad3
Yarik
test
|
302
303
|
],
]);
|
fa284ab0
Yarik
test
|
304
305
|
$query = Team::find()
->where([ 'user_id' => $company_id ]);
|
a020aad3
Yarik
test
|
306
307
308
309
310
|
$team = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 9,
],
|
fa284ab0
Yarik
test
|
311
|
]);
|
fa284ab0
Yarik
test
|
312
|
return $this->render('team', [
|
a020aad3
Yarik
test
|
313
314
315
|
'company' => $company,
'team' => $team,
'comments' => $comments,
|
fa284ab0
Yarik
test
|
316
|
]);
|
d36bdac6
Administrator
17.02.16
|
317
318
|
}
|
5014e10b
Yarik
test
|
319
|
public function actionBlogList($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
320
321
|
{
$company = User::findOne($company_id);
|
d36bdac6
Administrator
17.02.16
|
322
|
|
fa284ab0
Yarik
test
|
323
324
325
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
d36bdac6
Administrator
17.02.16
|
326
|
|
42931736
Yarik
test
|
327
|
$blog = new ActiveDataProvider([
|
f0a961be
Yarik
test
|
328
|
'query' => $company->getBlog(),
|
42931736
Yarik
test
|
329
330
331
|
'pagination' => new Pagination([
'pageSize' => 5,
]),
|
f0a961be
Yarik
test
|
332
|
'sort' => new Sort([
|
42931736
Yarik
test
|
333
334
|
'defaultOrder' => [
'date_add' => SORT_DESC,
|
f0a961be
Yarik
test
|
335
|
'name' => SORT_ASC,
|
42931736
Yarik
test
|
336
337
|
],
]),
|
fa284ab0
Yarik
test
|
338
|
]);
|
f6ea8941
Administrator
09.02.16
|
339
|
|
fa284ab0
Yarik
test
|
340
|
return $this->render('blog-list', [
|
f0a961be
Yarik
test
|
341
342
|
'company' => $company,
'blog' => $blog,
|
fa284ab0
Yarik
test
|
343
|
]);
|
d36bdac6
Administrator
17.02.16
|
344
345
|
}
|
5014e10b
Yarik
test
|
346
|
public function actionBlogView($company_id, $link, $type = 'implementer')
|
fa284ab0
Yarik
test
|
347
348
|
{
$company = User::findOne($company_id);
|
d36bdac6
Administrator
17.02.16
|
349
|
|
fa284ab0
Yarik
test
|
350
351
352
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
4ff3ca88
Yarik
test
|
353
354
355
356
357
358
359
|
$article = Blog::find()
->where([
'link' => $link,
'user_id' => $company_id,
])
->with('comments')
->one();
|
e82beebc
Yarik
test
|
360
361
362
|
if(empty($article)) {
throw new NotFoundHttpException('Запись не найдена');
}
|
4ff3ca88
Yarik
test
|
363
|
$article->updateCounters([ 'view_count' => 1 ]);
|
d36bdac6
Administrator
17.02.16
|
364
|
|
fa284ab0
Yarik
test
|
365
366
367
|
return $this->render('blog-view', [
'company' => $company,
'article' => $article,
|
d36bdac6
Administrator
17.02.16
|
368
|
|
fa284ab0
Yarik
test
|
369
370
|
]);
}
|
eb7e82fb
Administrator
29.02.16
|
371
|
|
5014e10b
Yarik
test
|
372
|
public function actionReview($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
373
374
|
{
$company = User::findOne($company_id);
|
eb7e82fb
Administrator
29.02.16
|
375
|
|
ad9c004b
Yarik
test
|
376
377
378
379
|
if(empty($company)) {
throw new NotFoundHttpException('Company not found');
}
|
fa284ab0
Yarik
test
|
380
381
382
|
return $this->render('review', [
'company' => $company,
]);
|
eb7e82fb
Administrator
29.02.16
|
383
384
|
}
|
5014e10b
Yarik
test
|
385
|
public function actionVacancyList($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
386
|
{
|
eb7e82fb
Administrator
29.02.16
|
387
|
|
fa284ab0
Yarik
test
|
388
|
$company = User::findOne($company_id);
|
eb7e82fb
Administrator
29.02.16
|
389
|
|
fa284ab0
Yarik
test
|
390
391
392
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
eb7e82fb
Administrator
29.02.16
|
393
|
|
fa284ab0
Yarik
test
|
394
|
$query = $company->getVacancies();
|
eb7e82fb
Administrator
29.02.16
|
395
|
|
fa284ab0
Yarik
test
|
396
|
$provider = new ActiveDataProvider([
|
a020aad3
Yarik
test
|
397
398
399
400
|
'query' => $query,
'pagination' => [
'pageSize' => 5,
],
|
fa284ab0
Yarik
test
|
401
402
403
404
405
406
407
|
'sort' => [
'defaultOrder' => [
'date_add' => SORT_DESC,
'name' => SORT_ASC,
],
],
]);
|
eb7e82fb
Administrator
29.02.16
|
408
|
|
fa284ab0
Yarik
test
|
409
|
return $this->render('vacancy-list', [
|
a020aad3
Yarik
test
|
410
411
|
'company' => $company,
'provider' => $provider,
|
fa284ab0
Yarik
test
|
412
|
]);
|
eb7e82fb
Administrator
29.02.16
|
413
|
|
fa284ab0
Yarik
test
|
414
|
}
|
eb7e82fb
Administrator
29.02.16
|
415
|
|
5014e10b
Yarik
test
|
416
|
public function actionVacancyView($company_id, $link, $type = 'implementer')
|
fa284ab0
Yarik
test
|
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
451
452
453
454
455
|
{
$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
|
456
|
|
5014e10b
Yarik
test
|
457
|
public function actionGallery($company_id, $type = 'implementer')
|
fa284ab0
Yarik
test
|
458
459
|
{
$company = User::findOne($company_id);
|
f6ea8941
Administrator
09.02.16
|
460
|
|
fa284ab0
Yarik
test
|
461
462
463
|
if(!$company instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
cda2c1c9
Administrator
add yii jquery
|
464
|
|
f0a961be
Yarik
test
|
465
466
467
468
469
|
$gallery = new ActiveDataProvider([
'query' => $company->getGalleries(),
'pagination' => [
'pageSize' => 5,
],
|
fa284ab0
Yarik
test
|
470
|
]);
|
fbdb1f1c
Yarik
test
|
471
|
|
fa284ab0
Yarik
test
|
472
|
$videos = Fields::getData($company->id, Gallery::className(), 'youtube');
|
d36bdac6
Administrator
17.02.16
|
473
|
|
fa284ab0
Yarik
test
|
474
|
$this->layout = 'gallery-company';
|
f6ea8941
Administrator
09.02.16
|
475
|
|
fa284ab0
Yarik
test
|
476
|
return $this->render('gallery', [
|
38ffb9db
Yarik
test
|
477
478
479
|
'company' => $company,
'gallery' => $gallery,
'videos' => $videos,
|
fa284ab0
Yarik
test
|
480
|
]);
|
d36bdac6
Administrator
17.02.16
|
481
|
}
|
76f36646
Yarik
test
|
482
483
484
|
public function beforeAction($action)
{
|
f0a961be
Yarik
test
|
485
486
|
if(!empty( \Yii::$app->request->get('type') )) {
$action->controller->view->params[ 'type' ] = \Yii::$app->request->get('type');
|
76f36646
Yarik
test
|
487
|
}
|
f0a961be
Yarik
test
|
488
|
if(!empty( \Yii::$app->request->get('company_id') )) {
|
f7b97c9e
Yarik
test
|
489
|
$user = User::findOne(\Yii::$app->request->get('company_id'));
|
f0a961be
Yarik
test
|
490
|
if(!empty( $user ) && $user->type == 1) {
|
f7b97c9e
Yarik
test
|
491
|
$queryParams = \Yii::$app->request->queryParams;
|
f0a961be
Yarik
test
|
492
493
494
|
unset( $queryParams[ 'company_id' ] );
$queryParams[ 'performer_id' ] = $user->id;
return $this->redirect(array_merge([ 'performer/' . $action->id ], $queryParams));
|
f7b97c9e
Yarik
test
|
495
496
|
}
}
|
76f36646
Yarik
test
|
497
498
|
return parent::beforeAction($action);
}
|
fbdb1f1c
Yarik
test
|
499
|
}
|