Commit fab1487f4f11aa0c1df62e65761d27a4b987460d
1 parent
9a97f5a5
- comments
Showing
4 changed files
with
153 additions
and
2 deletions
Show diff stats
frontend/controllers/SiteController.php
| ... | ... | @@ -252,4 +252,36 @@ |
| 252 | 252 | 'service_id' => $service_id |
| 253 | 253 | ]); |
| 254 | 254 | } |
| 255 | + | |
| 256 | + public function actionComments($service_id = null){ | |
| 257 | + | |
| 258 | + if (\Yii::$app->request->isAjax){ | |
| 259 | + Yii::$app->response->format = Response::FORMAT_JSON; | |
| 260 | + $model = new Comment(); | |
| 261 | + if ($model->load(\Yii::$app->request->post()) and $model->save()){ | |
| 262 | + return [ | |
| 263 | + 'status' => true, | |
| 264 | + 'message' => 'Спасибо за Ваш отзыв. После проверки модератором он появиться на сайте' | |
| 265 | + ]; | |
| 266 | + }else{ | |
| 267 | + return [ | |
| 268 | + 'status' => false, | |
| 269 | + 'message' => 'Ошибка' | |
| 270 | + ]; | |
| 271 | + } | |
| 272 | + } | |
| 273 | + $dataProvider = new ActiveDataProvider([ | |
| 274 | + 'query' => Comment::find()->where(['status' => true])->andFilterWhere(['service_id' => $service_id]), | |
| 275 | + 'pagination' => [ | |
| 276 | + 'pageSize' => 10, | |
| 277 | + ], | |
| 278 | + ]); | |
| 279 | + $services = Service::find()->where(['status' => true])->andWhere(['parent_id' => null])->all(); | |
| 280 | + | |
| 281 | + return $this->render('comments', [ | |
| 282 | + 'dataProvider' => $dataProvider, | |
| 283 | + 'services' => $services, | |
| 284 | + 'service_id' => $service_id | |
| 285 | + ]); | |
| 286 | + } | |
| 255 | 287 | } | ... | ... |
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * @var \common\models\Comment $model; | |
| 4 | + */ | |
| 5 | + ?> | |
| 6 | +<div class="service-comments style"> | |
| 7 | + <div class="style comments-h-autor"><?=$model->name?></div> | |
| 8 | + <div class="style comments-h-text"><?=$model->comment?></div> | |
| 9 | + <div class="style comments-h-date"><?=date('d.m.Y', $model->created_at)?></div> | |
| 10 | +</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\Comment; | |
| 11 | + use common\models\Question; | |
| 12 | + use yii\helpers\ArrayHelper; | |
| 13 | + use yii\helpers\Html; | |
| 14 | + use yii\widgets\ActiveForm; | |
| 15 | + use yii\widgets\ListView; | |
| 16 | + | |
| 17 | + $this->params[ 'breadcrumbs'][] = \Yii::t('app', 'Вопрос-ответ'); | |
| 18 | + | |
| 19 | + $model = new Comment(['service_id' => $service_id]); | |
| 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_comment_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, 'comment')->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' => '_comment' | |
| 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
| ... | ... | @@ -430,13 +430,14 @@ $(document).ready(function() { |
| 430 | 430 | |
| 431 | 431 | |
| 432 | 432 | |
| 433 | - $(document).on('submit', '#total_question_form', function(e) { | |
| 433 | + $(document).on('submit', '#total_question_form, #total_comment_form', function(e) { | |
| 434 | 434 | e.preventDefault(); |
| 435 | 435 | var form = $(this); |
| 436 | + var id = form.attr('id'); | |
| 436 | 437 | var url = form.attr('action'); |
| 437 | 438 | $.post( |
| 438 | 439 | $(this).attr("action"), $(this).serialize(), function(data) { |
| 439 | - document.getElementById("total_question-form").reset(); | |
| 440 | + document.getElementById(id).reset(); | |
| 440 | 441 | form.find('.submit-close-c-a').click(); |
| 441 | 442 | $(".add-answer-forms").after("<p class='success-message'>"+data.message+"</p>"); |
| 442 | 443 | var dat = form.data('yiiActiveForm'); |
| ... | ... | @@ -447,6 +448,7 @@ $(document).ready(function() { |
| 447 | 448 | }); |
| 448 | 449 | |
| 449 | 450 | |
| 451 | + | |
| 450 | 452 | }); |
| 451 | 453 | |
| 452 | 454 | window.onload = function () { | ... | ... |