97fb6489
Yarik
test
|
1
|
<?php
|
e7156033
Yarik
test
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
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;
use yii\data\ArrayDataProvider;
use yii\data\Pagination;
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use common\models\User;
|
e8236f44
Yarik
test
|
16
|
|
97fb6489
Yarik
test
|
17
|
/**
|
e7156033
Yarik
test
|
18
|
* Site controller
|
97fb6489
Yarik
test
|
19
|
*/
|
e7156033
Yarik
test
|
20
|
class PerformerController extends Controller
|
97fb6489
Yarik
test
|
21
|
{
|
97fb6489
Yarik
test
|
22
|
|
e7156033
Yarik
test
|
23
|
public $layout = 'performer';
|
9bb0160d
Administrator
09.02.16
|
24
|
|
e7156033
Yarik
test
|
25
|
public $user;
|
9bb0160d
Administrator
09.02.16
|
26
|
|
e7156033
Yarik
test
|
27
|
public $defaultAction = 'common';
|
4f404e20
Administrator
09.02.16
|
28
|
|
e7156033
Yarik
test
|
29
30
31
32
33
34
35
36
37
38
|
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);
|
9217ef8e
Administrator
09.02.16
|
39
|
}
|
9217ef8e
Administrator
09.02.16
|
40
|
|
e7156033
Yarik
test
|
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/**
* @inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
],
];
}
|
9217ef8e
Administrator
09.02.16
|
56
|
|
e7156033
Yarik
test
|
57
58
|
public function actionCommon($performer_id)
{
|
f7089e23
Administrator
15.02.16
|
59
|
|
e7156033
Yarik
test
|
60
|
$user = User::findOne($performer_id);
|
f7089e23
Administrator
15.02.16
|
61
|
|
e7156033
Yarik
test
|
62
63
64
|
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
4f404e20
Administrator
09.02.16
|
65
|
|
e7156033
Yarik
test
|
66
67
68
69
|
$educations = Fields::getData($user->id, $user->className(), 'education');
$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'));
|
97fb6489
Yarik
test
|
70
|
|
e7156033
Yarik
test
|
71
72
73
74
75
76
77
|
return $this->render('common', [
'user' => $user,
'educations' => $educations,
'phones' => $phones,
'sites' => $sites,
'soft' => $soft,
]);
|
3d620c67
Administrator
15.02.16
|
78
|
|
3d620c67
Administrator
15.02.16
|
79
|
}
|
3d620c67
Administrator
15.02.16
|
80
|
|
e7156033
Yarik
test
|
81
82
83
|
public function actionPortfolio($performer_id)
{
$user = User::findOne($performer_id);
|
3d620c67
Administrator
15.02.16
|
84
|
|
e7156033
Yarik
test
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
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([
'allModels' => $user->portfolios,
'pagination' => [
'pageSize' => 9,
],
]);
return $this->render('portfolio', [
'user' => $user,
'filters' => $filters,
'portfolio' => $portfolio,
'count' => count($user->portfolios),
]);
|
3d620c67
Administrator
15.02.16
|
112
|
|
e7156033
Yarik
test
|
113
|
}
|
1f651082
Yarik
test
|
114
|
|
e7156033
Yarik
test
|
115
116
117
|
public function actionPortfolioFilter($performer_id, $filter)
{
$user = User::findOne($performer_id);
|
376a557b
Administrator
09.02.16
|
118
|
|
e7156033
Yarik
test
|
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
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),
]);
|
9217ef8e
Administrator
09.02.16
|
156
157
|
}
|
e7156033
Yarik
test
|
158
159
160
161
162
163
164
165
166
167
168
169
|
public function actionPortfolioView($performer_id, $portfolio_id)
{
$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,
]);
}
|
9217ef8e
Administrator
09.02.16
|
170
|
|
e7156033
Yarik
test
|
171
172
173
|
public function actionBlogList($performer_id)
{
$user = User::findOne($performer_id);
|
376a557b
Administrator
09.02.16
|
174
|
|
e7156033
Yarik
test
|
175
176
177
|
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
376a557b
Administrator
09.02.16
|
178
|
|
e7156033
Yarik
test
|
179
|
$query = $user->getBlog();
|
376a557b
Administrator
09.02.16
|
180
|
|
e7156033
Yarik
test
|
181
|
$countQuery = clone $query;
|
376a557b
Administrator
09.02.16
|
182
|
|
e7156033
Yarik
test
|
183
184
185
186
|
$pagination = new Pagination([
'totalCount' => $countQuery->count(),
'pageSize' => 5,
]);
|
376a557b
Administrator
09.02.16
|
187
|
|
e7156033
Yarik
test
|
188
189
190
|
$article = $query->offset($pagination->offset)
->limit($pagination->limit)
->all();
|
97fb6489
Yarik
test
|
191
|
|
e7156033
Yarik
test
|
192
193
194
|
$blog = new ArrayDataProvider([
'allModels' => $article,
]);
|
9217ef8e
Administrator
09.02.16
|
195
|
|
e7156033
Yarik
test
|
196
197
198
199
200
|
return $this->render('blog-list', [
'user' => $user,
'blog' => $blog,
'pagination' => $pagination,
]);
|
9217ef8e
Administrator
09.02.16
|
201
202
|
}
|
e7156033
Yarik
test
|
203
204
205
|
public function actionBlogView($performer_id, $link)
{
$user = User::findOne($performer_id);
|
9217ef8e
Administrator
09.02.16
|
206
|
|
e7156033
Yarik
test
|
207
208
209
|
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
376a557b
Administrator
09.02.16
|
210
|
|
e7156033
Yarik
test
|
211
212
213
214
215
|
$article = Blog::findOne([
'link' => $link,
'user_id' => $performer_id,
]);
$article->updateCounters([ 'view_count' => 1 ]);
|
97fb6489
Yarik
test
|
216
|
|
e7156033
Yarik
test
|
217
218
219
|
return $this->render('blog-view', [
'user' => $user,
'article' => $article,
|
9217ef8e
Administrator
09.02.16
|
220
|
|
e7156033
Yarik
test
|
221
|
]);
|
9217ef8e
Administrator
09.02.16
|
222
223
|
}
|
e7156033
Yarik
test
|
224
225
226
|
public function actionReview($performer_id)
{
$user = User::findOne($performer_id);
|
9217ef8e
Administrator
09.02.16
|
227
|
|
e7156033
Yarik
test
|
228
229
230
|
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
fbdb1f1c
Yarik
test
|
231
|
|
e7156033
Yarik
test
|
232
233
234
|
return $this->render('review', [
'user' => $user,
]);
|
9217ef8e
Administrator
09.02.16
|
235
|
}
|
f6ea8941
Administrator
09.02.16
|
236
|
|
e7156033
Yarik
test
|
237
238
239
240
241
242
|
public function actionWorkplace($performer_id)
{
$user = User::findOne($performer_id);
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
|
9217ef8e
Administrator
09.02.16
|
243
|
|
e7156033
Yarik
test
|
244
245
246
|
return $this->render('workplace', [
'user' => $user,
]);
|
9217ef8e
Administrator
09.02.16
|
247
248
|
}
|
e7156033
Yarik
test
|
249
250
251
|
public function actionGallery($performer_id)
{
$user = User::findOne($performer_id);
|
9217ef8e
Administrator
09.02.16
|
252
|
|
e7156033
Yarik
test
|
253
254
255
256
257
|
if(!$user instanceof User) {
throw new BadRequestHttpException('Пользователь не найден');
}
$query = Gallery::find([ 'user_id' => $performer_id ]);
|
9217ef8e
Administrator
09.02.16
|
258
|
|
e7156033
Yarik
test
|
259
|
$countQuery = clone $query;
|
9217ef8e
Administrator
09.02.16
|
260
|
|
e7156033
Yarik
test
|
261
262
263
264
|
$pagination = new Pagination([
'totalCount' => $countQuery->count(),
'pageSize' => 5,
]);
|
9217ef8e
Administrator
09.02.16
|
265
|
|
e7156033
Yarik
test
|
266
267
268
|
$gallery = $query->offset($pagination->offset)
->limit($pagination->limit)
->all();
|
9217ef8e
Administrator
09.02.16
|
269
|
|
e7156033
Yarik
test
|
270
271
272
|
$gallery = new ArrayDataProvider([
'allModels' => $gallery,
]);
|
9217ef8e
Administrator
09.02.16
|
273
|
|
e7156033
Yarik
test
|
274
|
$videos = Fields::getData($user->id, Gallery::className(), 'youtube');
|
3d0e6093
Administrator
15.02.16
|
275
|
|
e7156033
Yarik
test
|
276
|
$this->layout = 'gallery';
|
9217ef8e
Administrator
09.02.16
|
277
|
|
e7156033
Yarik
test
|
278
279
280
281
282
283
284
|
return $this->render('gallery', [
'user' => $user,
'gallery' => $gallery,
'pagination' => $pagination,
'videos' => $videos,
]);
}
|
fbdb1f1c
Yarik
test
|
285
|
}
|