From 9a26e63d27f59914b2ecf08cba2f06534fc86f42 Mon Sep 17 00:00:00 2001 From: yarik Date: Wed, 29 Jun 2016 19:20:35 +0300 Subject: [PATCH] Commit --- common/models/Specialization.php | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------- frontend/controllers/SearchController.php | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- frontend/models/SearchPerformerForm.php | 12 +++++++++++- frontend/views/search/_performer_list_view.php | 55 ++++++++++++++++++++++++++++++------------------------- 4 files changed, 241 insertions(+), 161 deletions(-) diff --git a/common/models/Specialization.php b/common/models/Specialization.php index 3468f88..11097a4 100755 --- a/common/models/Specialization.php +++ b/common/models/Specialization.php @@ -1,114 +1,165 @@ '0',], - [['specialization_name'], 'required'], - [['specialization_name','image','background'], 'string', 'max' => 255], - ]; - } + use Yii; + use yii\db\ActiveQuery; + use yii\helpers\ArrayHelper; /** - * @inheritdoc + * This is the model class for table "specialization". + * @property integer $specialization_id + * @property integer $specialization_pid + * @property string $specialization_name + * @property string $image + * @property string $background */ - public function attributeLabels() + class Specialization extends \yii\db\ActiveRecord { - return [ - 'specialization_id' => Yii::t('app', 'specialization_id'), - 'specialization_pid' => Yii::t('app', 'specialization_pid'), - 'specialization_name' => Yii::t('app', 'specialization_name'), - 'specialization_parent_name' => Yii::t('app', 'specialization_parent_name'), - 'image' => Yii::t('app', 'image'), - 'background' => Yii::t('app', 'background'), - 'status' => Yii::t('app', 'status'), - ]; - } - public static function specializationsList(){ - - - $specializationArray = []; + /** + * @inheritdoc + */ + public static function tableName() + { + return 'specialization'; + } - $specialization = Specialization::find()->where(['specialization_id'=> Specialization::find()->select('specialization_id') - ->andWhere('specialization_pid != 0') - ->column()]) - ->all(); + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'specialization_pid', + 'status', + ], + 'integer', + ], + [ + [ 'specialization_pid' ], + 'default', + 'value' => '0', + ], + [ + [ 'specialization_name' ], + 'required', + ], + [ + [ + 'specialization_name', + 'image', + 'background', + ], + 'string', + 'max' => 255, + ], + ]; + } - foreach(ArrayHelper::index($specialization,'specialization_id') as $spec){ - $array = $spec->hasChildrenInArray($specialization); - if($array){ - $specializationArray[$spec->specialization_name] = $array; - } + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'specialization_id' => Yii::t('app', 'specialization_id'), + 'specialization_pid' => Yii::t('app', 'specialization_pid'), + 'specialization_name' => Yii::t('app', 'specialization_name'), + 'specialization_parent_name' => Yii::t('app', 'specialization_parent_name'), + 'image' => Yii::t('app', 'image'), + 'background' => Yii::t('app', 'background'), + 'status' => Yii::t('app', 'status'), + ]; } - return $specializationArray; + public static function specializationsList() + { + $specializationArray = [ ]; - } + $specialization = Specialization::find() + ->where([ + 'specialization_id' => Specialization::find() + ->select('specialization_id') + ->andWhere('specialization_pid != 0') + ->column(), + ]) + ->all(); + foreach(ArrayHelper::index($specialization, 'specialization_id') as $spec) { + $array = $spec->hasChildrenInArray($specialization); + if($array) { + $specializationArray[ $spec->specialization_name ] = $array; + } + } - public function getParent() - { - return $this->hasOne(self::className(), ['specialization_id' => 'specialization_pid']); - } + return $specializationArray; - public function getChildren() - { - return $this->hasMany(self::className(), ['specialization_pid' => 'specialization_id']); - } + } - public function hasChildrenInArray($array){ - $array = ArrayHelper::map($array,'specialization_id', 'specialization_name','specialization_pid'); + public function getParent() + { + return $this->hasOne(self::className(), [ 'specialization_id' => 'specialization_pid' ]); + } - if(isset($array[$this->specialization_id])){ - return $array[$this->specialization_id]; - } else { - return false; + public function getChildren() + { + return $this->hasMany(self::className(), [ 'specialization_pid' => 'specialization_id' ]); } - } + public function hasChildrenInArray($array) + { + $array = ArrayHelper::map($array, 'specialization_id', 'specialization_name', 'specialization_pid'); - public function getStack() - { - $stack[] = $this->specialization_id; - if(!empty($this->children)) { - foreach($this->children as $child) { - $stack[] = $child->specialization_id; - if(!empty($child->children)) { - $stack = array_merge($stack, ArrayHelper::getColumn($child->children, 'specialization_id', false)); + if(isset( $array[ $this->specialization_id ] )) { + return $array[ $this->specialization_id ]; + } else { + return false; + } + + } + + public function getStack() + { + $stack[] = $this->specialization_id; + if(!empty( $this->children )) { + foreach($this->children as $child) { + $stack[] = $child->specialization_id; + if(!empty( $child->children )) { + $stack = array_merge($stack, ArrayHelper::getColumn($child->children, 'specialization_id', false)); + } } } + return $stack; + } + + /** + * @return ActiveQuery + */ + public static function getSorted() + { + return self::find() + ->with([ + 'children' => function($query) { + /** + * @var ActiveQuery $query + */ + $query->orderBy('specialization_name'); + }, + ]) + ->with([ + 'children.children' => function($query) { + /** + * @var ActiveQuery $query + */ + $query->orderBy('specialization_name'); + }, + ]) + ->where([ 'specialization_pid' => 0 ]) + ->orderBy('specialization_name'); } - return $stack; - } -} + } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index b9b1773..0b7000d 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -1,23 +1,24 @@ 'project', 2 => 'performer', - 3 => 'customer' + 3 => 'customer', ]; if(!array_key_exists($action, $actions)) { - return $this->redirect(['/', 'query' => $query]); + return $this->redirect([ + '/', + 'query' => $query, + ]); } else { switch($action) { case 1: - return $this->redirect(['search/'.$actions[$action], 'TenderSearch[info]' => $query]); - break; + return $this->redirect([ + 'search/' . $actions[ $action ], + 'TenderSearch[info]' => $query, + ]); + break; case 2: - return $this->redirect(['search/'.$actions[$action], 'SearchPerformerForm[search]' => $query]); + return $this->redirect([ + 'search/' . $actions[ $action ], + 'SearchPerformerForm[search]' => $query, + ]); break; case 3: - return $this->redirect(['search/'.$actions[$action], 'CustomerSearch[info]' => $query]); + return $this->redirect([ + 'search/' . $actions[ $action ], + 'CustomerSearch[info]' => $query, + ]); break; } } @@ -73,19 +86,26 @@ use frontend\models\Option; { $model = new TenderSearch(); $dataProvider = $model->search(Yii::$app->request->queryParams); - $dataProvider->query->andWhere(['hidden' => 0]); + $dataProvider->query->andWhere([ 'hidden' => 0 ]); $dataProvider->setPagination([ 'pageSize' => 10, ]); $specialization = Specialization::specializationsList(); $currencies = Currency::getCurrencyDropdown(); - $payments = Payment::find()->select(['name', 'payment_id'])->asArray()->indexBy('payment_id')->column(); + $payments = Payment::find() + ->select([ + 'name', + 'payment_id', + ]) + ->asArray() + ->indexBy('payment_id') + ->column(); return $this->render('project', [ - 'model' => $model, - 'dataProvider' => $dataProvider, + 'model' => $model, + 'dataProvider' => $dataProvider, 'specialization' => $specialization, - 'currencies' => $currencies, - 'payments' => $payments, + 'currencies' => $currencies, + 'payments' => $payments, ]); } @@ -103,25 +123,19 @@ use frontend\models\Option; ]); } - - public function actionPerformer() { $specialization = Specialization::specializationsList(); - $specializations = Specialization::find() - ->with('children') - ->where([ 'specialization_pid' => 0 ]) - ->orderBy('specialization_id') - ->all(); + $specializations = Specialization::getSorted()->all(); $searchModel = new SearchPerformerForm(); - return $this->render('performer',[ - 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), - 'specialization' => $specialization, + return $this->render('performer', [ + 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), + 'specialization' => $specialization, 'specializations' => $specializations, - 'model'=> $searchModel + 'model' => $searchModel, ]); } @@ -141,7 +155,7 @@ use frontend\models\Option; ]); $vacancy = $query->offset($pagination->offset) - ->limit($pagination->limit); + ->limit($pagination->limit); $dataProvider = new ActiveDataProvider([ 'query' => $vacancy, @@ -154,11 +168,11 @@ use frontend\models\Option; ], ]); - return $this->render('vacancy',[ - 'dataProvider' => $dataProvider, + return $this->render('vacancy', [ + 'dataProvider' => $dataProvider, 'specialization' => $specialization, - 'model'=> $searchModel, - 'pagination'=> $pagination + 'model' => $searchModel, + 'pagination' => $pagination, ]); } diff --git a/frontend/models/SearchPerformerForm.php b/frontend/models/SearchPerformerForm.php index 7b4cf55..514b739 100755 --- a/frontend/models/SearchPerformerForm.php +++ b/frontend/models/SearchPerformerForm.php @@ -177,9 +177,19 @@ // Clear array from empty strings //$this->specialization = array_filter($this->specialization, 'strlen'); + if($this->portfolio) { + $query->innerJoin('portfolio_specialization', '"portfolio"."portfolio_id" = "portfolio_specialization"."portfolio_id"'); + $query->andFilterWhere([ + 'portfolio_specialization.specialization_id' => $this->specialization, + ]); + } else { + $query->andFilterWhere([ + 'specialization.specialization_id' => $this->specialization, + ]); + } + $query->andFilterWhere([ 'user_info.city' => $this->city, - 'specialization.specialization_id' => $this->specialization, 'user.type' => $this->type, 'user.id' => $query2, ]); diff --git a/frontend/views/search/_performer_list_view.php b/frontend/views/search/_performer_list_view.php index 87c4f2d..53881bb 100755 --- a/frontend/views/search/_performer_list_view.php +++ b/frontend/views/search/_performer_list_view.php @@ -19,34 +19,29 @@ if(!empty( $portfolios )) { for($i = 0; $i < count($portfolios); $i++) { if($i) { - echo Html::a(Html::img($portfolios[ $i ]), '#', [ 'class' => 'small-img-search gallery-box-min' ]); + echo Html::a(Html::img($portfolios[ $i ]), [ + 'performer/portfolio', + 'performer_id' => $model->id, + ], [ 'class' => 'small-img-search' ]); } else { - echo Html::a(Html::img($model->minImg($portfolios[ $i ], '318', '228')), '#', [ 'class' => 'big-img-search gallery-box-min' ]); + echo Html::a(Html::img($model->minImg($portfolios[ $i ], '318', '228')), [ + 'performer/portfolio', + 'performer_id' => $model->id, + ], [ 'class' => 'big-img-search' ]); } } } else { echo 'Работы в порфолио отсутствуют'; } ?> - - -
- minImg($model->userInfo->image, '48', '48')) ?> + minImg($model->userInfo->image, '48', '48')), [ + 'performer/portfolio', + 'performer_id' => $model->id, + ]) ?>
userInfo->member): ?> @@ -55,7 +50,10 @@
NEW
-
name ?>
+
name, [ + 'performer/portfolio', + 'performer_id' => $model->id, + ]) ?>
@@ -73,7 +71,7 @@ ]); ?>
-
comments)?> мнений, userInfo->city ?>
+
comments) ?> мнений, userInfo->city ?>
@@ -82,18 +80,25 @@ свободен -
- - География работ: portfolios, 'city'))) ?>
- specializations as $specialization): ?> - specialization_name ?>, - + specializations); + if($count > 20) { + $count = 20; + } + for($i = 0; $i < $count; $i++) { + echo Html::a($model->specializations[ $i ]->specialization_name, [ + 'search/performer', + 'SearchPerformerForm[specialization][' . $model->specializations[ $i ]->specialization_id . ']' => $model->specializations[ $i ]->specialization_id, + 'SearchPerformerForm[portfolio]' => 0, + ]) . ', '; + } + ?>
Последний визит: userInfo->lastVisit ?>
-- libgit2 0.21.4