Commit fa284ab0c278fc25e6d09f9abb5dfb974a3513f1

Authored by Yarik
1 parent e11dfa18

test

common/models/Vacancy.php
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 use yii\behaviors\TimestampBehavior; 7 use yii\behaviors\TimestampBehavior;
8 use yii\db\ActiveQuery; 8 use yii\db\ActiveQuery;
9 use yii\db\Expression; 9 use yii\db\Expression;
  10 + use yii\helpers\ArrayHelper;
10 11
11 /** 12 /**
12 * This is the model class for table "vacancy". 13 * This is the model class for table "vacancy".
@@ -31,6 +32,7 @@ @@ -31,6 +32,7 @@
31 32
32 const STATUS_ACTIVE = 1; 33 const STATUS_ACTIVE = 1;
33 const STATUS_CLOSED = 3; 34 const STATUS_CLOSED = 3;
  35 +
34 /** 36 /**
35 * @inheritdoc 37 * @inheritdoc
36 */ 38 */
@@ -57,11 +59,11 @@ @@ -57,11 +59,11 @@
57 'value' => new Expression('NOW()'), 59 'value' => new Expression('NOW()'),
58 ], 60 ],
59 'slug' => [ 61 'slug' => [
60 - 'class' => 'common\behaviors\Slug',  
61 - 'in_attribute' => 'name', 62 + 'class' => 'common\behaviors\Slug',
  63 + 'in_attribute' => 'name',
62 'out_attribute' => 'link', 64 'out_attribute' => 'link',
63 - 'translit' => true  
64 - ] 65 + 'translit' => true,
  66 + ],
65 ]; 67 ];
66 } 68 }
67 69
@@ -72,7 +74,12 @@ @@ -72,7 +74,12 @@
72 { 74 {
73 return [ 75 return [
74 [ 76 [
75 - [ 'name', 'description', 'city', 'link' ], 77 + [
  78 + 'name',
  79 + 'description',
  80 + 'city',
  81 + 'link',
  82 + ],
76 'required', 83 'required',
77 ], 84 ],
78 [ 85 [
@@ -80,22 +87,31 @@ @@ -80,22 +87,31 @@
80 'string', 87 'string',
81 ], 88 ],
82 [ 89 [
83 - [ 'employmentInput', 'specializationInput', ], 90 + [
  91 + 'employmentInput',
  92 + 'specializationInput',
  93 + ],
84 'safe', 94 'safe',
85 ], 95 ],
86 [ 96 [
87 - ['salary_currency', 'status',],  
88 - 'integer' 97 + [
  98 + 'salary_currency',
  99 + 'status',
  100 + ],
  101 + 'integer',
89 ], 102 ],
90 [ 103 [
91 - ['salary'], 104 + [ 'salary' ],
92 'integer', 105 'integer',
93 'min' => 0, 106 'min' => 0,
94 ], 107 ],
95 [ 108 [
96 - [ 'employmentInput', 'specializationInput' ], 109 + [
  110 + 'employmentInput',
  111 + 'specializationInput',
  112 + ],
97 'default', 113 'default',
98 - 'value' => [], 114 + 'value' => [ ],
99 ], 115 ],
100 [ 116 [
101 [ 'view_count' ], 117 [ 'view_count' ],
@@ -118,7 +134,7 @@ @@ -118,7 +134,7 @@
118 'max' => 255, 134 'max' => 255,
119 ], 135 ],
120 [ 136 [
121 - ['phone'], 137 + [ 'phone' ],
122 'match', 138 'match',
123 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/', 139 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/',
124 ], 140 ],
@@ -179,22 +195,25 @@ @@ -179,22 +195,25 @@
179 return Fields::getData($this->vacancy_id, Vacancy::className(), 'requirements'); 195 return Fields::getData($this->vacancy_id, Vacancy::className(), 'requirements');
180 } 196 }
181 197
  198 + public function getVacancySpecializations()
  199 + {
  200 + return $this->hasMany(VacancySpecialization::className(), [ 'specialization_id' => 'specialization_id' ]);
  201 + }
  202 +
182 /** 203 /**
183 * @return ActiveQuery 204 * @return ActiveQuery
184 */ 205 */
185 public function getSpecializations() 206 public function getSpecializations()
186 { 207 {
187 return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ]) 208 return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ])
188 - ->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]); 209 + ->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]);
189 } 210 }
190 211
191 -  
192 public function getSalaryCurrency() 212 public function getSalaryCurrency()
193 { 213 {
194 return $this->hasOne(Currency::className(), [ 'currency_id' => 'salary_currency' ]); 214 return $this->hasOne(Currency::className(), [ 'currency_id' => 'salary_currency' ]);
195 } 215 }
196 216
197 -  
198 /** 217 /**
199 * Return array of Vacancy's specialization IDs 218 * Return array of Vacancy's specialization IDs
200 * @return integer[] 219 * @return integer[]
frontend/controllers/CompanyController.php
1 <?php 1 <?php
2 -namespace frontend\controllers;  
3 -  
4 -  
5 -use common\models\Blog;  
6 -use common\models\Fields;  
7 -use common\models\Gallery;  
8 -use common\models\Portfolio;  
9 -use common\models\PortfolioSpecialization;  
10 -use common\models\Team;  
11 -use common\models\Vacancy;  
12 -use common\models\VacancySpecialization;  
13 -use Yii;  
14 -use yii\data\ActiveDataProvider;  
15 -use yii\data\ArrayDataProvider;  
16 -use yii\data\Pagination;  
17 -use yii\helpers\ArrayHelper;  
18 -use yii\web\BadRequestHttpException;  
19 -use yii\web\Controller;  
20 -use common\models\User;  
21 -/**  
22 - * Site controller  
23 - */  
24 -class CompanyController extends Controller  
25 -{  
26 - public $layout = 'company';  
27 -  
28 - public $defaultAction = 'common'; 2 + namespace frontend\controllers;
  3 +
  4 + use common\models\Blog;
  5 + use common\models\Fields;
  6 + use common\models\Gallery;
  7 + use common\models\Portfolio;
  8 + use common\models\PortfolioSpecialization;
  9 + use common\models\Team;
  10 + use common\models\Vacancy;
  11 + use common\models\VacancySpecialization;
  12 + use Yii;
  13 + use yii\data\ActiveDataProvider;
  14 + use yii\data\ArrayDataProvider;
  15 + use yii\data\Pagination;
  16 + use yii\helpers\ArrayHelper;
  17 + use yii\web\BadRequestHttpException;
  18 + use yii\web\Controller;
  19 + use common\models\User;
29 20
30 /** 21 /**
31 - * @inheritdoc 22 + * Site controller
32 */ 23 */
33 - public function actions() 24 + class CompanyController extends Controller
34 { 25 {
35 - return [  
36 - 'error' => [  
37 - 'class' => 'yii\web\ErrorAction',  
38 - ],  
39 - 'captcha' => [  
40 - 'class' => 'yii\captcha\CaptchaAction',  
41 - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,  
42 - ],  
43 - ];  
44 - }  
45 -  
46 - public function actionIndex()  
47 - {  
48 - $this->redirect('site/index');  
49 - }  
50 26
51 - public function actionCommon($company_id)  
52 - {  
53 - $company = User::findOne($company_id);  
54 -  
55 - $educations = Fields::getData($company->id,$company->className(),'education');  
56 - $phones = Fields::getData($company->id,$company->className(),'phone');  
57 - $sites = Fields::getData($company->id,$company->className(),'site');  
58 - $soft = implode(', ',ArrayHelper::getColumn(Fields::getData($company->id,$company->className(),'soft'), 'soft'));  
59 -  
60 - return $this->render('common',[  
61 - 'company' => $company,  
62 - 'educations' => $educations,  
63 - 'phones' => $phones,  
64 - 'sites' => $sites,  
65 - 'soft' => $soft  
66 - ]);  
67 - }  
68 -  
69 - public function actionPortfolio($company_id)  
70 - {  
71 - $company = User::findOne($company_id);  
72 -  
73 - if(!$company instanceof User){  
74 - throw new BadRequestHttpException('Пользователь не найден'); 27 + public $layout = 'company';
  28 +
  29 + public $defaultAction = 'common';
  30 +
  31 + /**
  32 + * @inheritdoc
  33 + */
  34 + public function actions()
  35 + {
  36 + return [
  37 + 'error' => [
  38 + 'class' => 'yii\web\ErrorAction',
  39 + ],
  40 + 'captcha' => [
  41 + 'class' => 'yii\captcha\CaptchaAction',
  42 + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL,
  43 + ],
  44 + ];
75 } 45 }
76 - $projects = ArrayHelper::getColumn($company->portfolios,'portfolio_id');  
77 -  
78 -  
79 - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"])  
80 - ->where(["portfolio_id"=>$projects ])->groupBy("specialization_id")->all();  
81 -  
82 - $portfolio = new ArrayDataProvider([  
83 - 'allModels' => $company->getPortfolios()->orderBy('portfolio_id')->all(),  
84 - 'pagination' => [  
85 - 'pageSize' => 9,  
86 - ],  
87 - ]);  
88 -  
89 - return $this->render('portfolio',[  
90 - 'company' => $company,  
91 - 'filters' => $filters,  
92 - 'portfolio' => $portfolio,  
93 - 'count' => count($company->portfolios)  
94 - ]);  
95 - }  
96 -  
97 - public function actionPortfolioFilter($performer_id, $filter){  
98 - $company = User::findOne($performer_id);  
99 46
100 - if(!$company instanceof User){  
101 - throw new BadRequestHttpException('Пользователь не найден'); 47 + public function actionIndex()
  48 + {
  49 + $this->redirect('site/index');
102 } 50 }
103 - $portfolios = ArrayHelper::getColumn($company->portfolios,'portfolio_id');  
104 51
  52 + public function actionCommon($company_id)
  53 + {
  54 + $company = User::findOne($company_id);
  55 +
  56 + $educations = Fields::getData($company->id, $company->className(), 'education');
  57 + $phones = Fields::getData($company->id, $company->className(), 'phone');
  58 + $sites = Fields::getData($company->id, $company->className(), 'site');
  59 + $soft = implode(', ', ArrayHelper::getColumn(Fields::getData($company->id, $company->className(), 'soft'), 'soft'));
  60 +
  61 + return $this->render('common', [
  62 + 'company' => $company,
  63 + 'educations' => $educations,
  64 + 'phones' => $phones,
  65 + 'sites' => $sites,
  66 + 'soft' => $soft,
  67 + ]);
  68 + }
105 69
106 - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"])  
107 - ->where(["portfolio_id"=>$portfolios ])->groupBy("specialization_id")->all();  
108 -  
109 -  
110 - $filter_result = PortfolioSpecialization::find()  
111 - ->where(['specialization_id'=>$filter,  
112 - 'portfolio_id'=>$portfolios  
113 - ])->all();  
114 -  
115 -  
116 - $portfolio = new ArrayDataProvider([  
117 - 'allModels' => Portfolio::find()->where(['portfolio_id'=>ArrayHelper::getColumn($filter_result,'portfolio_id')])->all(),  
118 - 'pagination' => [  
119 - 'pageSize' => 9,  
120 - ],  
121 - ]);  
122 -  
123 - return $this->render('portfolio',[  
124 - 'company' => $company,  
125 - 'filters' => $filters,  
126 - 'portfolio' => $portfolio,  
127 - 'filter_id' => $filter,  
128 - 'count' => count($company->portfolios)  
129 - ]);  
130 - }  
131 -  
132 - public function actionPortfolioView($company_id , $portfolio_id)  
133 - {  
134 - $user = User::findOne($company_id);  
135 - $portfolio = $user->getPortfolios()  
136 - ->where([ 'portfolio_id' => $portfolio_id ])  
137 - ->one();  
138 - $portfolio->updateCounters([ 'view_count' => 1 ]);  
139 - return $this->render('portfolio-view', [  
140 - 'user' => $user,  
141 - 'portfolio' => $portfolio,  
142 - ]);  
143 - }  
144 -  
145 - public function actionTeam($company_id)  
146 - {  
147 - $company = User::findOne($company_id);  
148 -  
149 - if(!$company instanceof User){  
150 - throw new BadRequestHttpException('Пользователь не найден'); 70 + public function actionPortfolio($company_id)
  71 + {
  72 + $company = User::findOne($company_id);
  73 +
  74 + if(!$company instanceof User) {
  75 + throw new BadRequestHttpException('Пользователь не найден');
  76 + }
  77 + $projects = ArrayHelper::getColumn($company->portfolios, 'portfolio_id');
  78 +
  79 + $filters = PortfolioSpecialization::find()
  80 + ->select([
  81 + "specialization_id",
  82 + "COUNT('specialization_id') AS count",
  83 + ])
  84 + ->where([ "portfolio_id" => $projects ])
  85 + ->groupBy("specialization_id")
  86 + ->all();
  87 +
  88 + $portfolio = new ArrayDataProvider([
  89 + 'allModels' => $company->getPortfolios()
  90 + ->orderBy('portfolio_id')
  91 + ->all(),
  92 + 'pagination' => [
  93 + 'pageSize' => 9,
  94 + ],
  95 + ]);
  96 +
  97 + return $this->render('portfolio', [
  98 + 'company' => $company,
  99 + 'filters' => $filters,
  100 + 'portfolio' => $portfolio,
  101 + 'count' => count($company->portfolios),
  102 + ]);
151 } 103 }
152 104
  105 + public function actionPortfolioFilter($performer_id, $filter)
  106 + {
  107 + $company = User::findOne($performer_id);
  108 +
  109 + if(!$company instanceof User) {
  110 + throw new BadRequestHttpException('Пользователь не найден');
  111 + }
  112 + $portfolios = ArrayHelper::getColumn($company->portfolios, 'portfolio_id');
  113 +
  114 + $filters = PortfolioSpecialization::find()
  115 + ->select([
  116 + "specialization_id",
  117 + "COUNT('specialization_id') AS count",
  118 + ])
  119 + ->where([ "portfolio_id" => $portfolios ])
  120 + ->groupBy("specialization_id")
  121 + ->all();
  122 +
  123 + $filter_result = PortfolioSpecialization::find()
  124 + ->where([
  125 + 'specialization_id' => $filter,
  126 + 'portfolio_id' => $portfolios,
  127 + ])
  128 + ->all();
  129 +
  130 + $portfolio = new ArrayDataProvider([
  131 + 'allModels' => Portfolio::find()
  132 + ->where([ 'portfolio_id' => ArrayHelper::getColumn($filter_result, 'portfolio_id') ])
  133 + ->all(),
  134 + 'pagination' => [
  135 + 'pageSize' => 9,
  136 + ],
  137 + ]);
  138 +
  139 + return $this->render('portfolio', [
  140 + 'company' => $company,
  141 + 'filters' => $filters,
  142 + 'portfolio' => $portfolio,
  143 + 'filter_id' => $filter,
  144 + 'count' => count($company->portfolios),
  145 + ]);
  146 + }
153 147
154 - $query = Team::find()->where(['user_id'=>$company_id]); 148 + public function actionPortfolioView($company_id, $portfolio_id)
  149 + {
  150 + $user = User::findOne($company_id);
  151 + $portfolio = $user->getPortfolios()
  152 + ->where([ 'portfolio_id' => $portfolio_id ])
  153 + ->one();
  154 + $portfolio->updateCounters([ 'view_count' => 1 ]);
  155 + return $this->render('portfolio-view', [
  156 + 'user' => $user,
  157 + 'portfolio' => $portfolio,
  158 + ]);
  159 + }
155 160
156 - $countQuery = clone $query; 161 + public function actionTeam($company_id)
  162 + {
  163 + $company = User::findOne($company_id);
157 164
158 - $pagination = new Pagination(['totalCount' => $countQuery->count(),  
159 - 'pageSize' => 9,  
160 - ]); 165 + if(!$company instanceof User) {
  166 + throw new BadRequestHttpException('Пользователь не найден');
  167 + }
161 168
162 - $team = $query->offset($pagination->offset)  
163 - ->limit($pagination->limit)  
164 - ->all(); 169 + $query = Team::find()
  170 + ->where([ 'user_id' => $company_id ]);
165 171
166 - $team = new ArrayDataProvider([  
167 - 'allModels' => $team,  
168 - ]); 172 + $countQuery = clone $query;
169 173
  174 + $pagination = new Pagination([
  175 + 'totalCount' => $countQuery->count(),
  176 + 'pageSize' => 9,
  177 + ]);
170 178
171 - return $this->render('team',[  
172 - 'company' => $company,  
173 - 'team' => $team,  
174 - 'pagination' => $pagination  
175 - ]);  
176 - } 179 + $team = $query->offset($pagination->offset)
  180 + ->limit($pagination->limit)
  181 + ->all();
177 182
178 - public function actionBlogList($company_id)  
179 - {  
180 - $company = User::findOne($company_id); 183 + $team = new ArrayDataProvider([
  184 + 'allModels' => $team,
  185 + ]);
181 186
182 - if(!$company instanceof User){  
183 - throw new BadRequestHttpException('Пользователь не найден'); 187 + return $this->render('team', [
  188 + 'company' => $company,
  189 + 'team' => $team,
  190 + 'pagination' => $pagination,
  191 + ]);
184 } 192 }
185 193
  194 + public function actionBlogList($company_id)
  195 + {
  196 + $company = User::findOne($company_id);
186 197
187 - $query = Blog::find()->where(['user_id'=>$company_id]);  
188 -  
189 - $countQuery = clone $query;  
190 -  
191 - $pagination = new Pagination(['totalCount' => $countQuery->count(),  
192 - 'pageSize' => 5,  
193 - ]); 198 + if(!$company instanceof User) {
  199 + throw new BadRequestHttpException('Пользователь не найден');
  200 + }
194 201
195 - $article = $query->offset($pagination->offset)  
196 - ->limit($pagination->limit)  
197 - ->all(); 202 + $query = Blog::find()
  203 + ->where([ 'user_id' => $company_id ]);
198 204
199 - $blog = new ArrayDataProvider([  
200 - 'allModels' => $article,  
201 - ]); 205 + $countQuery = clone $query;
202 206
  207 + $pagination = new Pagination([
  208 + 'totalCount' => $countQuery->count(),
  209 + 'pageSize' => 5,
  210 + ]);
203 211
204 - return $this->render('blog-list',[  
205 - 'company' => $company,  
206 - 'blog' => $blog,  
207 - 'pagination' => $pagination  
208 - ]);  
209 - }  
210 - 212 + $article = $query->offset($pagination->offset)
  213 + ->limit($pagination->limit)
  214 + ->all();
211 215
212 - public function actionBlogView($company_id, $link)  
213 - {  
214 - $company = User::findOne($company_id); 216 + $blog = new ArrayDataProvider([
  217 + 'allModels' => $article,
  218 + ]);
215 219
216 - if(!$company instanceof User){  
217 - throw new BadRequestHttpException('Пользователь не найден'); 220 + return $this->render('blog-list', [
  221 + 'company' => $company,
  222 + 'blog' => $blog,
  223 + 'pagination' => $pagination,
  224 + ]);
218 } 225 }
219 226
  227 + public function actionBlogView($company_id, $link)
  228 + {
  229 + $company = User::findOne($company_id);
220 230
221 - $article = Blog::findOne(['link'=>$link,'user_id'=>$company_id]);  
222 - $article->view_count ++;  
223 - $article->save(); 231 + if(!$company instanceof User) {
  232 + throw new BadRequestHttpException('Пользователь не найден');
  233 + }
224 234
  235 + $article = Blog::findOne([
  236 + 'link' => $link,
  237 + 'user_id' => $company_id,
  238 + ]);
  239 + $article->view_count++;
  240 + $article->save();
225 241
226 - return $this->render('blog-view',[  
227 - 'company' => $company,  
228 - 'article' =>$article, 242 + return $this->render('blog-view', [
  243 + 'company' => $company,
  244 + 'article' => $article,
229 245
230 - ]);  
231 - }  
232 -  
233 - public function actionReview($company_id)  
234 - {  
235 - $company = User::findOne($company_id);  
236 -  
237 - return $this->render('review',[  
238 - 'company' => $company  
239 - ]);  
240 - }  
241 -  
242 - public function actionVacancyList($company_id)  
243 - { 246 + ]);
  247 + }
244 248
245 - $company = User::findOne($company_id); 249 + public function actionReview($company_id)
  250 + {
  251 + $company = User::findOne($company_id);
246 252
247 - if(!$company instanceof User){  
248 - throw new BadRequestHttpException('Пользователь не найден'); 253 + return $this->render('review', [
  254 + 'company' => $company,
  255 + ]);
249 } 256 }
250 257
  258 + public function actionVacancyList($company_id)
  259 + {
251 260
252 - $query = $company->getVacancies(); 261 + $company = User::findOne($company_id);
253 262
254 - $countQuery = clone $query; 263 + if(!$company instanceof User) {
  264 + throw new BadRequestHttpException('Пользователь не найден');
  265 + }
255 266
256 - $pagination = new Pagination(['totalCount' => $countQuery->count(),  
257 - 'pageSize' => 5,  
258 - ]); 267 + $query = $company->getVacancies();
259 268
260 - $vacancy = $query->offset($pagination->offset)  
261 - ->limit($pagination->limit); 269 + $countQuery = clone $query;
262 270
  271 + $pagination = new Pagination([
  272 + 'totalCount' => $countQuery->count(),
  273 + 'pageSize' => 5,
  274 + ]);
263 275
264 - $provider = new ActiveDataProvider([  
265 - 'query' => $vacancy,  
266 - 'pagination' => false,  
267 - 'sort' => [  
268 - 'defaultOrder' => [  
269 - 'date_add' => SORT_DESC,  
270 - 'name' => SORT_ASC,  
271 - ]  
272 - ],  
273 - ]); 276 + $vacancy = $query->offset($pagination->offset)
  277 + ->limit($pagination->limit);
274 278
  279 + $provider = new ActiveDataProvider([
  280 + 'query' => $vacancy,
  281 + 'pagination' => false,
  282 + 'sort' => [
  283 + 'defaultOrder' => [
  284 + 'date_add' => SORT_DESC,
  285 + 'name' => SORT_ASC,
  286 + ],
  287 + ],
  288 + ]);
275 289
  290 + return $this->render('vacancy-list', [
  291 + 'company' => $company,
  292 + 'provider' => $provider,
  293 + 'pagination' => $pagination,
  294 + ]);
276 295
277 - return $this->render('vacancy-list',[  
278 - 'company' => $company,  
279 - 'provider' => $provider,  
280 - 'pagination' => $pagination  
281 - ]); 296 + }
282 297
283 - } 298 + public function actionVacancyView($company_id, $link)
  299 + {
  300 + $company = User::findOne($company_id);
  301 + $vacancy = $company->getVacancies()
  302 + ->where([ 'link' => $link ])
  303 + ->with([
  304 + 'employments',
  305 + 'specializations',
  306 + ])
  307 + ->one();
  308 +
  309 + $specialization_id = $vacancy->getSpecializations()
  310 + ->select('specialization_id')
  311 + ->column();
  312 +
  313 + $vacancy_id = VacancySpecialization::find()
  314 + ->where([ 'specialization_id' => $specialization_id ])
  315 + ->select('vacancy_id')
  316 + ->column();
  317 +
  318 + $similar_vacancies = Vacancy::find()
  319 + ->where([
  320 + 'city' => $vacancy->city,
  321 + 'vacancy_id' => $vacancy_id,
  322 + ])
  323 + ->andFilterWhere([
  324 + '<>',
  325 + 'vacancy_id',
  326 + $vacancy->vacancy_id,
  327 + ])
  328 + ->orderBy([ 'vacancy_id' => SORT_DESC ])
  329 + ->limit(3)
  330 + ->all();
  331 +
  332 + return $this->render('vacancy-view', [
  333 + 'company' => $company,
  334 + 'vacancy' => $vacancy,
  335 + 'similar_vacancies' => $similar_vacancies,
  336 + ]);
  337 + }
284 338
285 - public function actionVacancyView($company_id, $link)  
286 - {  
287 - $company = User::findOne($company_id);  
288 - $vacancy = $company->getVacancies()->where(['link' => $link])->with(['employments'])->one(); 339 + public function actionGallery($company_id)
  340 + {
  341 + $company = User::findOne($company_id);
289 342
  343 + if(!$company instanceof User) {
  344 + throw new BadRequestHttpException('Пользователь не найден');
  345 + }
290 346
291 - $specialization_id = $vacancy->getSpecializations()->select('specialization_id')->column(); 347 + $query = Gallery::find()
  348 + ->where([ 'user_id' => $company_id ]);
292 349
293 - $vacancy_id = VacancySpecialization::find()->where(['specialization_id'=>$specialization_id])->select('vacancy_id')->column(); 350 + $countQuery = clone $query;
294 351
  352 + $pagination = new Pagination([
  353 + 'totalCount' => $countQuery->count(),
  354 + 'pageSize' => 5,
  355 + ]);
295 356
296 - $similar_vacancies = Vacancy::find()  
297 - ->where([  
298 - 'city' => $vacancy->city,  
299 - 'vacancy_id' => $vacancy_id  
300 - ])  
301 - ->andFilterWhere([  
302 - '<>',  
303 - 'vacancy_id',  
304 - $vacancy->vacancy_id  
305 - ])->limit(3)  
306 - ->all(); 357 + $gallery = $query->offset($pagination->offset)
  358 + ->limit($pagination->limit)
  359 + ->all();
307 360
308 - return $this->render('vacancy-view',[  
309 - 'company' => $company,  
310 - 'vacancy' => $vacancy,  
311 - 'similar_vacancies' => $similar_vacancies  
312 - ]);  
313 - } 361 + $gallery = new ArrayDataProvider([
  362 + 'allModels' => $gallery,
  363 + ]);
314 364
  365 + $videos = Fields::getData($company->id, Gallery::className(), 'youtube');
315 366
316 - public function actionGallery($company_id)  
317 - {  
318 - $company = User::findOne($company_id); 367 + $this->layout = 'gallery-company';
319 368
320 - if(!$company instanceof User){  
321 - throw new BadRequestHttpException('Пользователь не найден'); 369 + return $this->render('gallery', [
  370 + 'company' => $company,
  371 + 'gallery' => $gallery,
  372 + 'pagination' => $pagination,
  373 + 'videos' => $videos,
  374 + ]);
322 } 375 }
323 -  
324 -  
325 - $query = Gallery::find()->where(['user_id'=>$company_id]);  
326 -  
327 - $countQuery = clone $query;  
328 -  
329 - $pagination = new Pagination(['totalCount' => $countQuery->count(),  
330 - 'pageSize' => 5,  
331 - ]);  
332 -  
333 - $gallery = $query->offset($pagination->offset)  
334 - ->limit($pagination->limit)  
335 - ->all();  
336 -  
337 - $gallery = new ArrayDataProvider([  
338 - 'allModels' => $gallery,  
339 - ]);  
340 -  
341 - $videos = Fields::getData($company->id,Gallery::className(),'youtube');  
342 -  
343 - $this->layout = 'gallery-company';  
344 -  
345 - return $this->render('gallery',[  
346 - 'company' => $company,  
347 - 'gallery' =>$gallery,  
348 - 'pagination' => $pagination,  
349 - 'videos' => $videos  
350 - ]);  
351 } 376 }
352 -}  
frontend/views/company/_vacancy_list_view.php
1 <?php 1 <?php
  2 + /**
  3 + * @var Vacancy $model
  4 + */
  5 + use common\models\Vacancy;
2 use frontend\helpers\TextHelper; 6 use frontend\helpers\TextHelper;
3 use yii\bootstrap\Html; 7 use yii\bootstrap\Html;
4 use yii\helpers\Url; 8 use yii\helpers\Url;
5 - use yii\helpers\StringHelper;  
6 9
7 ?> 10 ?>
8 11
@@ -14,7 +17,7 @@ @@ -14,7 +17,7 @@
14 ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?> 17 ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?>
15 <div class="performer-vacant-reclam-bl-title-two"> 18 <div class="performer-vacant-reclam-bl-title-two">
16 <?= $model->city ?> 19 <?= $model->city ?>
17 - <?= \Yii::$app->formatter->asDatetime($model->date_add, 'Y-MM-dd') ?> 20 + <?= \Yii::$app->formatter->asDatetime($model->date_add, 'dd.MM.Y') ?>
18 <?php 21 <?php
19 if(!empty( $model->salary )) { 22 if(!empty( $model->salary )) {
20 ?> 23 ?>
frontend/views/company/vacancy-view.php
1 <?php 1 <?php
2 /** 2 /**
3 - * @var $this yii\web\View  
4 - * @var User $company  
5 - * @var Vacancy $vacancy 3 + * @var $this yii\web\View
  4 + * @var User $company
  5 + * @var Vacancy $vacancy
  6 + * @var Vacancy[] $similar_vacancies
6 */ 7 */
7 8
8 use common\models\User; 9 use common\models\User;
9 use common\models\Vacancy; 10 use common\models\Vacancy;
10 use yii\helpers\ArrayHelper; 11 use yii\helpers\ArrayHelper;
11 use yii\helpers\Html; 12 use yii\helpers\Html;
12 -use yii\helpers\Url; 13 + use yii\helpers\Url;
13 14
14 -$this->params[ 'company' ] = $company; 15 + $this->params[ 'company' ] = $company;
15 $this->title = 'My Yii Application'; 16 $this->title = 'My Yii Application';
16 ?> 17 ?>
17 -<div class="performer-vacancy-list style">  
18 - <?php  
19 - echo Html::a('к списку вакансий', [  
20 - 'vacancy-list',  
21 - 'company_id' => $company->id,  
22 - ]);  
23 - ?>  
24 -</div>  
25 -<div class="performer-vacancy-blocks-desk-wr style">  
26 - <div class="performer-vacancy-date style"> Вакансия от <?= $vacancy->date_add ?> </div>  
27 - <div class="performance-vacancy-page-title style"><?= $vacancy->name ?></div>  
28 - <div class="performance-vacancy-page-options style">  
29 - <ul>  
30 - <?php  
31 - if(!empty( $vacancy->user_name )) {  
32 - echo "<li><span>Контактное лицо:</span><p>{$vacancy->user_name}</p></li>";  
33 - }  
34 - if(!empty( $vacancy->phone )) {  
35 - echo "<li><span>Телефон:</span><p>{$vacancy->phone}</p></li>";  
36 - }  
37 - ?>  
38 - <?php  
39 - if(!empty( $vacancy->city )) {  
40 - echo "<li><span>Город:</span><p>{$vacancy->city}</p></li>";  
41 - }  
42 - ?>  
43 - <?php  
44 - if(!empty( $vacancy->employments )) {  
45 - echo "<li><span>Вид занятости:</span><p>" . implode(', ', ArrayHelper::getColumn($vacancy->employments, 'name')) . "</p></li>";  
46 - }  
47 - ?>  
48 - <?php  
49 - if(!empty( $vacancy->requirements )) {  
50 - echo "<li><span>Требования:</span><p>" . implode(', ', ArrayHelper::getColumn($vacancy->requirements, 'requirements')) . "</p></li>";  
51 - }  
52 - ?>  
53 - </ul>  
54 - </div>  
55 - <div class="performance-vacancy-description style">Описание вакансии</div>  
56 - <div class="performance-vacancy-desc-txt style"> 18 + <div class="performer-vacancy-list style">
57 <?php 19 <?php
58 - echo $vacancy->description; 20 + echo Html::a('к списку вакансий', [
  21 + 'vacancy-list',
  22 + 'company_id' => $company->id,
  23 + ]);
59 ?> 24 ?>
60 </div> 25 </div>
61 - <div class="performance-vacancy-desc-form style">  
62 - <a href="#">Отправить резюме</a>  
63 - </div>  
64 -</div>  
65 -<div class="performance-vacancy-similar style">  
66 - <div class="performance-vacancy-similar-title style">Похожие вакансии</div>  
67 - <div class="style">  
68 -  
69 - <?php foreach($similar_vacancies as $similar_vacancy):?>  
70 - <div class="performance-vacancy-similar-blocks-wr style">  
71 -  
72 - <?= Html::a($similar_vacancy->name, Url::toRoute([  
73 - 'company/vacancy-view',  
74 - 'company_id' => $similar_vacancy->user_id,  
75 - 'link' => $similar_vacancy->link,  
76 - ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?>  
77 -  
78 - <div class="performer-vacant-reclam-bl-title-two"><?= $similar_vacancy->city ?>. <?= \Yii::$app->formatter->asDatetime($similar_vacancy->date_add, 'Y-MM-dd') ?>. 26 + <div class="performer-vacancy-blocks-desk-wr style">
  27 + <div class="performer-vacancy-date style"> Вакансия от <?= $vacancy->date_add ?> </div>
  28 + <div class="performance-vacancy-page-title style"><?= $vacancy->name ?></div>
  29 + <div class="performance-vacancy-page-options style">
  30 + <ul>
79 <?php 31 <?php
80 - if(!empty( $similar_vacancy->salary )) {  
81 - ?>  
82 - <?= $similar_vacancy->salary ?>  
83 - <?= $similar_vacancy->salaryCurrency->label ?>  
84 - <?php  
85 - }  
86 - ?></div> 32 + if(!empty( $vacancy->user_name )) {
  33 + echo "<li><span>Контактное лицо:</span><p>{$vacancy->user_name}</p></li>";
  34 + }
  35 + if(!empty( $vacancy->phone )) {
  36 + echo "<li><span>Телефон:</span><p>{$vacancy->phone}</p></li>";
  37 + }
  38 + ?>
  39 + <?php
  40 + if(!empty( $vacancy->city )) {
  41 + echo "<li><span>Город:</span><p>{$vacancy->city}</p></li>";
  42 + }
  43 + ?>
  44 + <?php
  45 + if(!empty( $vacancy->employments )) {
  46 + echo "<li><span>Вид занятости:</span><p>" . implode(', ', ArrayHelper::getColumn($vacancy->employments, 'name')) . "</p></li>";
  47 + }
  48 + ?>
  49 + <?php
  50 + if(!empty( $vacancy->requirements )) {
  51 + echo "<li><span>Требования:</span><p>" . implode(', ', ArrayHelper::getColumn($vacancy->requirements, 'requirements')) . "</p></li>";
  52 + }
  53 + ?>
  54 + </ul>
  55 + </div>
  56 + <div class="performance-vacancy-description style">Описание вакансии</div>
  57 + <div class="performance-vacancy-desc-txt style">
  58 + <?php
  59 + echo $vacancy->description;
  60 + ?>
  61 + </div>
  62 + <div class="performance-vacancy-desc-form style">
  63 + <a href="#">Отправить резюме</a>
87 </div> 64 </div>
88 - <?php endforeach;?> 65 + </div>
  66 +<?php
  67 + if(!empty( $similar_vacancies )) {
  68 + ?>
  69 + <div class="performance-vacancy-similar style">
  70 + <div class="performance-vacancy-similar-title style">Похожие вакансии</div>
  71 + <div class="style">
  72 + <?php foreach($similar_vacancies as $similar_vacancy): ?>
  73 + <div class="performance-vacancy-similar-blocks-wr style">
89 74
  75 + <?= Html::a($similar_vacancy->name, Url::toRoute([
  76 + 'company/vacancy-view',
  77 + 'company_id' => $similar_vacancy->user_id,
  78 + 'link' => $similar_vacancy->link,
  79 + ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?>
90 80
91 - </div>  
92 -</div>  
93 \ No newline at end of file 81 \ No newline at end of file
  82 + <div class="performer-vacant-reclam-bl-title-two"><?= $similar_vacancy->city ?>. <?= \Yii::$app->formatter->asDatetime($similar_vacancy->date_add, 'Y-MM-dd') ?>.
  83 + <?php
  84 + if(!empty( $similar_vacancy->salary )) {
  85 + ?>
  86 + <?= $similar_vacancy->salary ?>
  87 + <?= $similar_vacancy->salaryCurrency->label ?>
  88 + <?php
  89 + }
  90 + ?></div>
  91 + </div>
  92 + <?php endforeach; ?>
  93 + </div>
  94 + </div>
  95 + <?php
  96 + }
  97 +?>
94 \ No newline at end of file 98 \ No newline at end of file