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