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