Commit f53044e7d36193fa2216df9e07edcfe3f30fe121
1 parent
d73fd852
123
Showing
5 changed files
with
51 additions
and
6 deletions
Show diff stats
common/models/Question.php
common/models/Service.php
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace common\models; | 3 | namespace common\models; |
4 | 4 | ||
5 | +use artbox\core\models\Alias; | ||
5 | use artbox\core\models\Image; | 6 | use artbox\core\models\Image; |
6 | use artbox\core\models\traits\AliasableTrait; | 7 | use artbox\core\models\traits\AliasableTrait; |
7 | use backend\behaviors\LevelBehavior; | 8 | use backend\behaviors\LevelBehavior; |
@@ -161,4 +162,6 @@ class Service extends ActiveRecord | @@ -161,4 +162,6 @@ class Service extends ActiveRecord | ||
161 | public function getQuestions(){ | 162 | public function getQuestions(){ |
162 | return $this->hasMany(Question::className(), ['service_id' => 'id']); | 163 | return $this->hasMany(Question::className(), ['service_id' => 'id']); |
163 | } | 164 | } |
165 | + | ||
166 | + | ||
164 | } | 167 | } |
common/models/ServiceLang.php
@@ -5,7 +5,8 @@ | @@ -5,7 +5,8 @@ | ||
5 | use artbox\core\models\Alias; | 5 | use artbox\core\models\Alias; |
6 | use artbox\core\models\Language; | 6 | use artbox\core\models\Language; |
7 | use Yii; | 7 | use Yii; |
8 | - | 8 | + use yii\helpers\Json; |
9 | + | ||
9 | /** | 10 | /** |
10 | * This is the model class for table "service_lang". | 11 | * This is the model class for table "service_lang". |
11 | * | 12 | * |
@@ -132,4 +133,10 @@ | @@ -132,4 +133,10 @@ | ||
132 | { | 133 | { |
133 | return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]); | 134 | return $this->hasOne(Service::className(), [ 'id' => 'service_id' ]); |
134 | } | 135 | } |
136 | + | ||
137 | + public function getQuestionAlias(){ | ||
138 | + return $this->hasOne(Alias::className(), []) | ||
139 | + ->where(['route' => Json::encode(['site\questions', 'service_id' => $this->service_id])]) | ||
140 | + ->andWhere(['language_id' => $this->language_id]); | ||
141 | + } | ||
135 | } | 142 | } |
frontend/controllers/SiteController.php
1 | <?php | 1 | <?php |
2 | namespace frontend\controllers; | 2 | namespace frontend\controllers; |
3 | 3 | ||
4 | + use artbox\core\models\Alias; | ||
4 | use artbox\core\models\Feedback; | 5 | use artbox\core\models\Feedback; |
6 | + use artbox\core\models\Language; | ||
5 | use common\models\Comment; | 7 | use common\models\Comment; |
6 | use common\models\Package; | 8 | use common\models\Package; |
7 | use common\models\Question; | 9 | use common\models\Question; |
@@ -17,6 +19,7 @@ | @@ -17,6 +19,7 @@ | ||
17 | use yii\web\BadRequestHttpException; | 19 | use yii\web\BadRequestHttpException; |
18 | use yii\web\Controller; | 20 | use yii\web\Controller; |
19 | use yii\web\Response; | 21 | use yii\web\Response; |
22 | + use yii\helpers\VarDumper as d; | ||
20 | 23 | ||
21 | /** | 24 | /** |
22 | * Site controller | 25 | * Site controller |
@@ -224,6 +227,7 @@ | @@ -224,6 +227,7 @@ | ||
224 | } | 227 | } |
225 | 228 | ||
226 | public function actionQuestions($service_id = null){ | 229 | public function actionQuestions($service_id = null){ |
230 | + Language::getCurrent(); | ||
227 | 231 | ||
228 | if (\Yii::$app->request->isAjax){ | 232 | if (\Yii::$app->request->isAjax){ |
229 | Yii::$app->response->format = Response::FORMAT_JSON; | 233 | Yii::$app->response->format = Response::FORMAT_JSON; |
@@ -247,12 +251,17 @@ | @@ -247,12 +251,17 @@ | ||
247 | 'pageSize' => 10, | 251 | 'pageSize' => 10, |
248 | ], | 252 | ], |
249 | ]); | 253 | ]); |
250 | - $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); | ||
251 | - | 254 | + $services = Service::find()->with('language.questionAlias')->where(['status' => true])->andWhere(['parent_id' => null])->all(); |
255 | + # d::dump($services[3]->id,10,1); | ||
256 | + #d::dump($dataTest,10,1); | ||
257 | + #die; | ||
258 | + | ||
259 | + | ||
252 | return $this->render('questions', [ | 260 | return $this->render('questions', [ |
253 | 'dataProvider' => $dataProvider, | 261 | 'dataProvider' => $dataProvider, |
254 | 'services' => $services, | 262 | 'services' => $services, |
255 | - 'service_id' => $service_id | 263 | + 'service_id' => $service_id, |
264 | + | ||
256 | ]); | 265 | ]); |
257 | } | 266 | } |
258 | 267 |
frontend/views/site/questions.php
@@ -12,7 +12,10 @@ | @@ -12,7 +12,10 @@ | ||
12 | use yii\helpers\Html; | 12 | use yii\helpers\Html; |
13 | use yii\widgets\ActiveForm; | 13 | use yii\widgets\ActiveForm; |
14 | use yii\widgets\ListView; | 14 | use yii\widgets\ListView; |
15 | - | 15 | + use yii\helpers\VarDumper as d; |
16 | + use artbox\core\models\Alias; | ||
17 | + | ||
18 | + | ||
16 | $this->params[ 'breadcrumbs'][] = \Yii::t('app', 'Quest/Answer'); | 19 | $this->params[ 'breadcrumbs'][] = \Yii::t('app', 'Quest/Answer'); |
17 | 20 | ||
18 | $model = new Question(['service_id' => $service_id]); | 21 | $model = new Question(['service_id' => $service_id]); |
@@ -78,8 +81,30 @@ | @@ -78,8 +81,30 @@ | ||
78 | <span><?=\Yii::t('app','General issues');?></span></a></li> | 81 | <span><?=\Yii::t('app','General issues');?></span></a></li> |
79 | <?php foreach ($services as $service){?> | 82 | <?php foreach ($services as $service){?> |
80 | <li <?=($service_id == $service->id ? 'class="active"' : '')?>> | 83 | <li <?=($service_id == $service->id ? 'class="active"' : '')?>> |
81 | - <a href="<?=Url::current(['service_id' => $service->id])?>"><span><?=$service->title?></span></a></li> | 84 | + <?php |
85 | + $test=Alias::find() | ||
86 | + #->where(['route' => \yii\helpers\Json::encode(['site\questions', 'service_id' => $service->id])]) | ||
87 | + # ->andWhere(['language_id' => $service->language->language_id])->all(); | ||
88 | + #->where(['language_id' => $service->language->language_id]) | ||
89 | + ->where(['LIKE','route','"site/questions","service_id":'.$service->id ]) | ||
90 | + #->where(['LIKE','route','service_id:'.$service->id ]) | ||
91 | + ->andWhere(['language_id' => $service->language->language_id]) | ||
92 | + ->all(); | ||
93 | + | ||
94 | + d::dump($service,10,1); | ||
95 | + # d::dump($test,10,1); | ||
96 | + die; | ||
97 | + | ||
98 | + ?> | ||
99 | + <a href="<?=($service->language->questionAlias !== null) ?Url::to(['alias' => $service->language->questionAlias]): Url::current(['service_id' => $service->id])?>"><span><?=$service->title?></span></a></li> | ||
82 | <?php } ?> | 100 | <?php } ?> |
101 | + | ||
102 | + | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + | ||
83 | </ul> | 108 | </ul> |
84 | </div> | 109 | </div> |
85 | <div class="col-xs-12 col-sm-12"> | 110 | <div class="col-xs-12 col-sm-12"> |