Commit cc2da9cc6c86f3e71f3c05dfbcdf1824754bb5b7
1 parent
2a888c42
- question page
Showing
7 changed files
with
333 additions
and
3 deletions
Show diff stats
frontend/config/main.php
@@ -180,7 +180,7 @@ | @@ -180,7 +180,7 @@ | ||
180 | 'formId' => 'question-form', | 180 | 'formId' => 'question-form', |
181 | 'scenario' => 'question', | 181 | 'scenario' => 'question', |
182 | 'successCallback' => 'function (data) { | 182 | 'successCallback' => 'function (data) { |
183 | - document.getElementById("comment-form").reset(); | 183 | + document.getElementById("question-form").reset(); |
184 | var data = $("#question-form").data(\'yiiActiveForm\'); | 184 | var data = $("#question-form").data(\'yiiActiveForm\'); |
185 | $("#question-form").find(".submit-close-c-a span").click(); | 185 | $("#question-form").find(".submit-close-c-a span").click(); |
186 | $("#question-form").parent().parent().parent().find(".service-c-a-btns").after("<p>Спасибо за Вваш вопрос. Мы обязательно на него ответим</p>") | 186 | $("#question-form").parent().parent().parent().find(".service-c-a-btns").after("<p>Спасибо за Вваш вопрос. Мы обязательно на него ответим</p>") |
frontend/controllers/SiteController.php
@@ -4,10 +4,12 @@ | @@ -4,10 +4,12 @@ | ||
4 | use artbox\core\models\Feedback; | 4 | use artbox\core\models\Feedback; |
5 | use common\models\Comment; | 5 | use common\models\Comment; |
6 | use common\models\Package; | 6 | use common\models\Package; |
7 | + use common\models\Question; | ||
7 | use common\models\Service; | 8 | use common\models\Service; |
8 | use common\models\Settings; | 9 | use common\models\Settings; |
9 | use common\models\slider\Slide; | 10 | use common\models\slider\Slide; |
10 | use Yii; | 11 | use Yii; |
12 | + use yii\data\ActiveDataProvider; | ||
11 | use yii\db\ActiveQuery; | 13 | use yii\db\ActiveQuery; |
12 | use yii\db\Expression; | 14 | use yii\db\Expression; |
13 | use yii\filters\VerbFilter; | 15 | use yii\filters\VerbFilter; |
@@ -217,4 +219,37 @@ | @@ -217,4 +219,37 @@ | ||
217 | public function actionPage6(){ | 219 | public function actionPage6(){ |
218 | return $this->render('page6'); | 220 | return $this->render('page6'); |
219 | } | 221 | } |
222 | + | ||
223 | + public function actionQuestions($service_id = null){ | ||
224 | + | ||
225 | + if (\Yii::$app->request->isAjax){ | ||
226 | + Yii::$app->response->format = Response::FORMAT_JSON; | ||
227 | + $model = new Question(); | ||
228 | + $model->scenario = Question::SCENARIO_QUESTION; | ||
229 | + if ($model->load(\Yii::$app->request->post()) and $model->save()){ | ||
230 | + return [ | ||
231 | + 'status' => true, | ||
232 | + 'message' => 'Спасибо за Ваш вопрос' | ||
233 | + ]; | ||
234 | + }else{ | ||
235 | + return [ | ||
236 | + 'status' => false, | ||
237 | + 'message' => 'Ошибка' | ||
238 | + ]; | ||
239 | + } | ||
240 | + } | ||
241 | + $dataProvider = new ActiveDataProvider([ | ||
242 | + 'query' => Question::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id]), | ||
243 | + 'pagination' => [ | ||
244 | + 'pageSize' => 10, | ||
245 | + ], | ||
246 | + ]); | ||
247 | + $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); | ||
248 | + | ||
249 | + return $this->render('questions', [ | ||
250 | + 'dataProvider' => $dataProvider, | ||
251 | + 'services' => $services, | ||
252 | + 'service_id' => $service_id | ||
253 | + ]); | ||
254 | + } | ||
220 | } | 255 | } |
frontend/views/service/_prices.php
1 | +<?php | ||
2 | + /** | ||
3 | + * @var \common\models\Question $model; | ||
4 | + */ | ||
5 | + use artbox\core\helpers\Url; | ||
6 | +?> | ||
7 | +<div class="service-comments style service-ansvers"> | ||
8 | + <div class="style comments-h-autor"><?=$model->name?></div> | ||
9 | + <div class="style comments-h-text"><?=$model->question?> </div> | ||
10 | + <div class="style answers-date-wr"> | ||
11 | + <span><?=date('d.m.Y', $model->created_at)?></span><p> отделение: | ||
12 | + <?php if ($model->service_id != null) {?> | ||
13 | + <a href="<?=Url::to(['alias' => $model->service->alias])?>"><?=$model->service->title?></a></p> | ||
14 | + <?php }?> | ||
15 | + </div> | ||
16 | + <div class="service-ansvers-text-wr style"> | ||
17 | + <div class="service-ansvers-title">врач-гинеколог <span>Алексей нестеренко</span></div> | ||
18 | + <div class="service-ansvers-txt"> | ||
19 | + <?=$model->answer?> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | +</div> |
1 | +<?php | ||
2 | + /** | ||
3 | + * @var \yii\data\ActiveDataProvider $dataProvider | ||
4 | + * @var \common\models\Service[] $services | ||
5 | + * @var \yii\web\View $this | ||
6 | + * @var int $service_id | ||
7 | + */ | ||
8 | + | ||
9 | + use artbox\core\helpers\Url; | ||
10 | + use common\models\Question; | ||
11 | + use yii\helpers\ArrayHelper; | ||
12 | + use yii\helpers\Html; | ||
13 | + use yii\widgets\ActiveForm; | ||
14 | + use yii\widgets\ListView; | ||
15 | + | ||
16 | + $this->params[ 'breadcrumbs'][] = \Yii::t('app', 'Вопрос-ответ'); | ||
17 | + | ||
18 | + $model = new Question(['service_id' => $service_id]); | ||
19 | + $model->scenario = Question::SCENARIO_QUESTION; | ||
20 | + | ||
21 | + $data = ['' => 'Общие вопросы'] + ArrayHelper::map($services, 'id', 'title'); | ||
22 | + ?> | ||
23 | + | ||
24 | + | ||
25 | +<section class="section-service-page section-answer-page"> | ||
26 | + <div class="container"> | ||
27 | + <div class="row"> | ||
28 | + <div class="col-xs-12 col-sm-12"> | ||
29 | + <h1 class="title-pages">Вопрос-Ответ</h1> | ||
30 | + </div> | ||
31 | + </div> | ||
32 | + <div class="row"> | ||
33 | + <div class="col-xs-12 col-sm-12"> | ||
34 | + <div class="style add-answer-forms"> | ||
35 | + <span class="btn_">Задать вопрос</span> | ||
36 | + </div> | ||
37 | + <div class="style hidden-answer-comment-form hidden"> | ||
38 | + <div class="hidden-answer-comment-form-title">Задать вопрос</div> | ||
39 | + <?php $form = ActiveForm::begin(['id' => 'total_question_form'])?> | ||
40 | + <div class="col-xs-12 col-sm-6"> | ||
41 | + <div class="input-wr"> | ||
42 | + <?=$form->field($model, 'service_id')->dropDownList($data)->label('Выбор отделения')?> | ||
43 | + </div> | ||
44 | + | ||
45 | + <div class="input-wr required"> | ||
46 | + <?=$form->field($model, 'name')->label('ФИО')?> | ||
47 | + </div> | ||
48 | + <div class="input-wr required"> | ||
49 | + <?=$form->field($model, 'email')->label('Email')?> | ||
50 | + </div> | ||
51 | + </div> | ||
52 | + <div class="col-xs-12 col-sm-6"> | ||
53 | + <div class="input-wr"> | ||
54 | + <?=$form->field($model, 'question')->textarea(['cols' => 30, 'rows' => 10])->label('Ваш вопрос')?> | ||
55 | +<!-- <label class="control-label" for="feedback-name">Ваш вопрос</label>--> | ||
56 | +<!-- <textarea name="" id="" cols="30" rows="10"></textarea>--> | ||
57 | + </div> | ||
58 | + </div> | ||
59 | + <div class="col-xs-12 col-sm-12"> | ||
60 | + <div class="button-wr submit-close-wr-c-a"> | ||
61 | + <?=Html::submitButton('Отправить вопрос')?> | ||
62 | +<!-- <button type="submit">Отправить вопрос</button>--> | ||
63 | + <div class="submit-close-c-a submit-close-c-a-page"><span>Свернуть окно</span></div> | ||
64 | + </div> | ||
65 | + </div> | ||
66 | + <?php $form::end();?> | ||
67 | + </div> | ||
68 | + </div> | ||
69 | + <div class="col-xs-12 col-sm-12"> | ||
70 | + <ul class="answers-category-list"> | ||
71 | + <li <?=($service_id == null ? 'class="active"' : '')?>><a href="<?=Url::current(['service_id' => null])?>"><span>Общие вопросы</span></a></li> | ||
72 | + <?php foreach ($services as $service){?> | ||
73 | + <li <?=($service_id == $service->id ? 'class="active"' : '')?>><a href="<?=Url::current(['service_id' => $service->id])?>"><span><?=$service->title?></span></a></li> | ||
74 | + <?php } ?> | ||
75 | + </ul> | ||
76 | + </div> | ||
77 | + <div class="col-xs-12 col-sm-12"> | ||
78 | + <div class="service-comments-wr style"> | ||
79 | + <?php echo ListView::widget( | ||
80 | + [ | ||
81 | + 'itemOptions' => [ | ||
82 | + ], | ||
83 | + 'layout' => '{items}', | ||
84 | + 'dataProvider' => $dataProvider, | ||
85 | + 'itemView' => '_question' | ||
86 | + ] | ||
87 | + );?> | ||
88 | + | ||
89 | + | ||
90 | + <div class="style navi-c-a"> | ||
91 | + <?php echo \frontend\widgets\FrontendPager::widget( | ||
92 | + [ | ||
93 | + 'pagination' => $dataProvider->pagination, | ||
94 | + 'prevPageLabel' => 'previous', | ||
95 | + 'nextPageLabel' => 'next', | ||
96 | + 'maxButtonCount' => 3, | ||
97 | + 'lastPageLabel' => 'last_number', | ||
98 | + ] | ||
99 | + );?> | ||
100 | + </div> | ||
101 | + | ||
102 | + | ||
103 | + </div> | ||
104 | + </div> | ||
105 | + </div> | ||
106 | + </div> | ||
107 | +</section> |
frontend/web/js/script.js
@@ -425,12 +425,26 @@ $(document).ready(function() { | @@ -425,12 +425,26 @@ $(document).ready(function() { | ||
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
428 | - $('nav').addClass('hide_') | ||
429 | - $('body').addClass('start-preloader') | 428 | + $('nav').addClass('hide_'); |
429 | + $('body').addClass('start-preloader'); | ||
430 | 430 | ||
431 | 431 | ||
432 | 432 | ||
433 | + $(document).on('submit', '#total_question_form', function(e) { | ||
434 | + e.preventDefault(); | ||
435 | + var form = $(this); | ||
436 | + var url = form.attr('action'); | ||
437 | + $.post( | ||
438 | + $(this).attr("action"), $(this).serialize(), function(data) { | ||
439 | + document.getElementById("total_question-form").reset(); | ||
440 | + form.find('.submit-close-c-a').click(); | ||
441 | + $(".add-answer-forms").after("<p class='success-message'>"+data.message+"</p>"); | ||
442 | + var dat = form.data('yiiActiveForm'); | ||
443 | + dat.validate = false; | ||
444 | + }).fail(function(){ | ||
433 | 445 | ||
446 | + }); | ||
447 | + }); | ||
434 | 448 | ||
435 | 449 | ||
436 | }); | 450 | }); |
1 | +<?php | ||
2 | + | ||
3 | + namespace frontend\widgets; | ||
4 | + | ||
5 | + use function key_exists; | ||
6 | + use yii\helpers\ArrayHelper; | ||
7 | + use yii\helpers\Html; | ||
8 | + | ||
9 | + /** | ||
10 | + * Class FrontendPager | ||
11 | + * | ||
12 | + * @package frontend\widgets | ||
13 | + */ | ||
14 | + class FrontendPager extends \yii\widgets\LinkPager | ||
15 | + { | ||
16 | + public $dots = false; | ||
17 | + public $dotsClass = null; | ||
18 | + | ||
19 | + public $params = null; | ||
20 | + | ||
21 | + public $pageParam = 'page'; | ||
22 | + | ||
23 | + public $defaultPageSize = 20; | ||
24 | + | ||
25 | + public $pageSizeParam = 'per-page'; | ||
26 | + | ||
27 | + public $route; | ||
28 | + | ||
29 | + public $urlManager; | ||
30 | + | ||
31 | + protected function renderPageButtons() | ||
32 | + { | ||
33 | + $pageCount = $this->pagination->getPageCount(); | ||
34 | + if ($pageCount < 2 && $this->hideOnSinglePage) { | ||
35 | + return ''; | ||
36 | + } | ||
37 | + | ||
38 | + $buttons = []; | ||
39 | + $currentPage = $this->pagination->getPage(); | ||
40 | + | ||
41 | + // first page | ||
42 | + | ||
43 | + // prev page | ||
44 | + if ($this->prevPageLabel !== false) { | ||
45 | + if (( $page = $currentPage - 1 ) < 0) { | ||
46 | + $page = 0; | ||
47 | + } | ||
48 | + $buttons[] = $this->renderPageButton( | ||
49 | + $this->prevPageLabel, | ||
50 | + $page, | ||
51 | + $this->prevPageCssClass, | ||
52 | + $currentPage <= 0, | ||
53 | + false | ||
54 | + ); | ||
55 | + } | ||
56 | + $firstPageLabel = '1'; | ||
57 | + list($beginPage, $endPage) = $this->getPageRange(); | ||
58 | + if ($beginPage !== 0) { | ||
59 | + $buttons[] = $this->renderPageButton( | ||
60 | + $firstPageLabel, | ||
61 | + 0, | ||
62 | + $this->firstPageCssClass, | ||
63 | + $currentPage <= 0, | ||
64 | + false | ||
65 | + ); | ||
66 | + } | ||
67 | + | ||
68 | + // internal pages | ||
69 | + | ||
70 | + for ($i = $beginPage; $i <= $endPage; ++$i) { | ||
71 | + $buttons[] = $this->renderPageButton( | ||
72 | + $i + 1, | ||
73 | + $i, | ||
74 | + null, | ||
75 | + $this->disableCurrentPageButton && $i == $currentPage, | ||
76 | + $i == $currentPage | ||
77 | + ); | ||
78 | + } | ||
79 | + // last page | ||
80 | + $lastPageLabel = $this->lastPageLabel === true ? $pageCount : $this->lastPageLabel; | ||
81 | + if ($lastPageLabel !== false and $endPage !== $pageCount - 1) { | ||
82 | + if ($endPage + 1 < $pageCount - 1 and $this->dots) { | ||
83 | + $buttons[] = $this->renderPageButton('...', $endPage + 1, $this->dotsClass, true, false); | ||
84 | + } | ||
85 | + if ($lastPageLabel == 'last_number') { | ||
86 | + $lastPageLabel = $pageCount; | ||
87 | + } | ||
88 | + $buttons[] = $this->renderPageButton( | ||
89 | + $lastPageLabel, | ||
90 | + $pageCount - 1, | ||
91 | + $this->lastPageCssClass, | ||
92 | + $currentPage >= $pageCount - 1, | ||
93 | + false | ||
94 | + ); | ||
95 | + } | ||
96 | + // next page | ||
97 | + if ($this->nextPageLabel !== false) { | ||
98 | + if (( $page = $currentPage + 1 ) >= $pageCount - 1) { | ||
99 | + $page = $pageCount - 1; | ||
100 | + } | ||
101 | + $buttons[] = $this->renderPageButton( | ||
102 | + $this->nextPageLabel, | ||
103 | + $page, | ||
104 | + $this->nextPageCssClass, | ||
105 | + $currentPage >= $pageCount - 1, | ||
106 | + false | ||
107 | + ); | ||
108 | + } | ||
109 | + return Html::tag('ul', implode("\n", $buttons), $this->options); | ||
110 | + } | ||
111 | + | ||
112 | + protected function renderPageButton($label, $page, $class, $disabled, $active) | ||
113 | + { | ||
114 | + $options = [ 'class' => empty($class) ? $this->pageCssClass : $class ]; | ||
115 | + if ($active) { | ||
116 | + Html::addCssClass($options, $this->activePageCssClass); | ||
117 | + } | ||
118 | + if ($disabled) { | ||
119 | + Html::addCssClass($options, $this->disabledPageCssClass); | ||
120 | + $tag = ArrayHelper::remove($this->disabledListItemSubTagOptions, 'tag', 'span'); | ||
121 | + | ||
122 | + return Html::tag('li', Html::tag($tag, $label, $this->disabledListItemSubTagOptions), $options); | ||
123 | + } | ||
124 | + $linkOptions = $this->linkOptions; | ||
125 | + $linkOptions[ 'data-page' ] = $page; | ||
126 | + if ($page == 0 and !$active) { | ||
127 | + $link = stristr($this->pagination->createUrl(0), '?', true); | ||
128 | + /** | ||
129 | + * @var \artbox\catalog\models\Filter $filter | ||
130 | + */ | ||
131 | + $filter = \Yii::$app->get('filter')->filterObj; | ||
132 | + if (key_exists($link, $filter->getReplacedFilters())) { | ||
133 | + $link = $filter->getReplacedFilters()[ $link ]; | ||
134 | + } | ||
135 | + return Html::tag( | ||
136 | + 'li', | ||
137 | + Html::a($label, $link, $linkOptions), | ||
138 | + $options | ||
139 | + ); | ||
140 | + } | ||
141 | + if ($active) { | ||
142 | + return Html::tag('li', Html::a($label, null, $linkOptions), $options); | ||
143 | + } else { | ||
144 | + return Html::tag('li', Html::a($label, $this->pagination->createUrl($page), $linkOptions), $options); | ||
145 | + } | ||
146 | + | ||
147 | + } | ||
148 | + | ||
149 | + } | ||
0 | \ No newline at end of file | 150 | \ No newline at end of file |