Commit 9afd152fa7be8ca629a1a8d7e0428eaceeb2ba20

Authored by Anastasia
1 parent 6a07bb2b

- support from main

- bug fix in mobile
frontend/config/main.php
@@ -253,6 +253,18 @@ @@ -253,6 +253,18 @@
253 ], 253 ],
254 ], 254 ],
255 'components' => [ 255 'components' => [
  256 + 'assetManager' => [
  257 + 'bundles' => [
  258 + // new version gentenella
  259 +// 'kartik\select2\Select2Asset' => [
  260 +// 'css' => [],
  261 +// ],
  262 +// 'kartik\select2\ThemeKrajeeAsset' => [
  263 +// 'css' => []
  264 +// ]
  265 + ],
  266 + 'appendTimestamp' => true,
  267 + ],
256 'user' => [ 268 'user' => [
257 'identityClass' => 'common\models\Author', 269 'identityClass' => 'common\models\Author',
258 'enableAutoLogin' => true, 270 'enableAutoLogin' => true,
frontend/controllers/BookController.php
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 use common\models\Support; 12 use common\models\Support;
13 use yii\data\ActiveDataProvider; 13 use yii\data\ActiveDataProvider;
14 use yii\web\Controller; 14 use yii\web\Controller;
  15 + use yii\web\Response;
15 use yii\web\UploadedFile; 16 use yii\web\UploadedFile;
16 17
17 class BookController extends Controller 18 class BookController extends Controller
@@ -130,4 +131,41 @@ @@ -130,4 +131,41 @@
130 public function actionSuccess(){ 131 public function actionSuccess(){
131 return $this->render('success'); 132 return $this->render('success');
132 } 133 }
  134 +
  135 + public function actionList($q = null){
  136 + \Yii::$app->response->format = Response::FORMAT_JSON;
  137 + $out = [
  138 + 'results' => [
  139 + [
  140 + 'id' => '',
  141 + 'text' => '',
  142 + ],
  143 + ],
  144 + ];
  145 + if (!is_null($q)) {
  146 + $books = Book::find()
  147 + ->select(
  148 + [
  149 + 'id' => 'book.id',
  150 + 'text' => 'book.title',
  151 + ]
  152 + )
  153 + ->andFilterWhere(
  154 + [
  155 + 'ilike',
  156 + 'title',
  157 + $q,
  158 + ]
  159 + )
  160 + ->limit(20)
  161 + ->asArray()
  162 + ->all();
  163 +
  164 + if (!empty($books)) {
  165 + $out[ 'results' ] = $books;
  166 + }
  167 + }
  168 +
  169 + return $out;
  170 + }
133 } 171 }
134 \ No newline at end of file 172 \ No newline at end of file
frontend/controllers/SupportController.php
@@ -10,6 +10,9 @@ @@ -10,6 +10,9 @@
10 10
11 use common\models\Book; 11 use common\models\Book;
12 use common\models\Support; 12 use common\models\Support;
  13 + use frontend\helpers\Url;
  14 + use frontend\models\SearchModel;
  15 + use yii\data\ActiveDataProvider;
13 use yii\web\Controller; 16 use yii\web\Controller;
14 17
15 class SupportController extends Controller 18 class SupportController extends Controller
@@ -29,9 +32,40 @@ @@ -29,9 +32,40 @@
29 'book' => $book 32 'book' => $book
30 ]); 33 ]);
31 } 34 }
32 -  
33 - public function actionSearch()  
34 - { 35 + public function actionSearch(){
35 return $this->render('search'); 36 return $this->render('search');
36 } 37 }
  38 +
  39 + public function actionSearchResult()
  40 + {
  41 + $model = new SearchModel();
  42 + if ($model->load(\Yii::$app->request->post())){
  43 + $booksIds = $model->search();
  44 + if (count($booksIds) == 1){
  45 + return $this->redirect(Url::to(['support/index', 'book_id' => $booksIds[0]['id']]));
  46 + }else{
  47 + $dataProvider = new ActiveDataProvider(
  48 + [
  49 + 'query' => Book::find()
  50 + ->with(
  51 + [
  52 + 'author',
  53 + 'alias',
  54 + ]
  55 + )
  56 + ->where([ 'status' => Book::STATUS_ACTIVE ])->andWhere(['book.id' => $booksIds]),
  57 + 'pagination' => [
  58 + 'pageSize' => 10,
  59 + ],
  60 + ]
  61 + );
  62 + return $this->render(
  63 + 'search-result',
  64 + [
  65 + 'dataProvider' => $dataProvider,
  66 + ]
  67 + );
  68 + }
  69 + }
  70 + }
37 } 71 }
38 \ No newline at end of file 72 \ No newline at end of file
frontend/models/SearchModel.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * Created by PhpStorm.
  4 + * User: stes
  5 + * Date: 22.06.18
  6 + * Time: 12:40
  7 + */
  8 +
  9 + namespace frontend\models;
  10 +
  11 + use yii\base\Model;
  12 + use yii\db\Expression;
  13 + use yii\db\Query;
  14 + use yii\web\JsExpression;
  15 +
  16 + class SearchModel extends Model
  17 + {
  18 + public $text;
  19 +
  20 + public $author;
  21 +
  22 + public $bookTitle;
  23 +
  24 + public function rules()
  25 + {
  26 + return [
  27 + [
  28 + 'text',
  29 + 'required',
  30 + 'whenClient' => new JsExpression('function (attribute, value) {
  31 + return $("#next").data("id") == "";
  32 + }'),
  33 + ],
  34 + [
  35 + ['author', 'bookTitle'],
  36 + 'boolean'
  37 + ],
  38 + [
  39 + 'text', 'string'
  40 + ]
  41 + ];
  42 + }
  43 +
  44 + public function search(){
  45 + $query = (new Query())->select('book.id')->from('book')->join('INNER JOIN', 'author', 'book.author_id = author.id');
  46 + if ($this->author){
  47 + $query->where(['ilike', 'book.title', $this->text]);
  48 + }
  49 + if ($this->bookTitle){
  50 + $query->orWhere(['ilike', 'secondname', $this->text])->orWhere(['ilike', new Expression('concat(name,\' \',secondname)'), $this->text]);
  51 + }
  52 + return $query->column();
  53 + }
  54 + }
0 \ No newline at end of file 55 \ No newline at end of file
frontend/views/layouts/main.php
@@ -15,18 +15,11 @@ @@ -15,18 +15,11 @@
15 use artbox\core\models\PageCategory; 15 use artbox\core\models\PageCategory;
16 use artbox\core\models\User; 16 use artbox\core\models\User;
17 use artbox\core\seo\widgets\SeoBreadcrumbs; 17 use artbox\core\seo\widgets\SeoBreadcrumbs;
18 - use common\models\page\Category;  
19 use common\models\Settings; 18 use common\models\Settings;
20 use frontend\assets\AppAsset; 19 use frontend\assets\AppAsset;
21 - use artbox\core\components\imagemanager\models\ImageManager;  
22 - use frontend\widgets\ArtboxModalWidget;  
23 - use frontend\widgets\LanguageWidget;  
24 - use yii\bootstrap\Nav;  
25 use yii\bootstrap\Html; 20 use yii\bootstrap\Html;
26 - use yii\db\ActiveQuery;  
27 use artbox\core\helpers\Url; 21 use artbox\core\helpers\Url;
28 use yii\web\View; 22 use yii\web\View;
29 - use yii\widgets\Breadcrumbs;  
30 23
31 24
32 AppAsset::register($this); 25 AppAsset::register($this);
@@ -102,7 +95,7 @@ JS; @@ -102,7 +95,7 @@ JS;
102 95
103 <div class="col-xs-12 hidden-xs hidden-sm col-sm-4 col-md-5 col-lg-4 btns_header"> 96 <div class="col-xs-12 hidden-xs hidden-sm col-sm-4 col-md-5 col-lg-4 btns_header">
104 <a href="<?=\Yii::$app->user->isGuest ? Url::to(['site/register']) : Url::to(['book/add'])?>" class="btn_ add-book"><span>Додати книгу</span></a> 97 <a href="<?=\Yii::$app->user->isGuest ? Url::to(['site/register']) : Url::to(['book/add'])?>" class="btn_ add-book"><span>Додати книгу</span></a>
105 - <a href="#" class="btn_ to-support">Підтримати</a> 98 + <a href="<?=Url::to(['support/search'])?>" class="btn_ to-support">Підтримати</a>
106 </div> 99 </div>
107 <?php if (\Yii::$app->user->isGuest){?> 100 <?php if (\Yii::$app->user->isGuest){?>
108 <div class="col-xs-12 hidden-xs hidden-sm col-sm-2 col-md-2"> 101 <div class="col-xs-12 hidden-xs hidden-sm col-sm-2 col-md-2">
@@ -161,7 +154,7 @@ JS; @@ -161,7 +154,7 @@ JS;
161 </ul> 154 </ul>
162 </nav> 155 </nav>
163 <div class="footer-btn"> 156 <div class="footer-btn">
164 - <a href="#" class="btn_">Підтримати</a> 157 + <a href="<?=Url::to(['support/search'])?>" class="btn_">Підтримати</a>
165 </div> 158 </div>
166 </div> 159 </div>
167 </div> 160 </div>
@@ -175,7 +168,7 @@ JS; @@ -175,7 +168,7 @@ JS;
175 <div class="style mob-list"> 168 <div class="style mob-list">
176 <ul> 169 <ul>
177 <li><a href="<?=Url::to(['site/about'])?>">Про проект</a></li> 170 <li><a href="<?=Url::to(['site/about'])?>">Про проект</a></li>
178 - <li><a href="<?=Url::to(['books/all'])?>">Книги</a></li> 171 + <li><a href="<?=Url::to(['book/index'])?>">Книги</a></li>
179 <li><a href="#">Партнери</a></li> 172 <li><a href="#">Партнери</a></li>
180 <li><a href="<?=Url::to(['site/contacts'])?>">Контакти</a></li> 173 <li><a href="<?=Url::to(['site/contacts'])?>">Контакти</a></li>
181 <li><a href="<?=Url::to(['blog/index'])?>">Блог</a></li> 174 <li><a href="<?=Url::to(['blog/index'])?>">Блог</a></li>
@@ -183,8 +176,8 @@ JS; @@ -183,8 +176,8 @@ JS;
183 </ul> 176 </ul>
184 </div> 177 </div>
185 <div class="style btns-menu-mob"> 178 <div class="style btns-menu-mob">
186 - <div class="style"><a href="#" class="btn_ add-book"><span>Додати книгу</span></a></div>  
187 - <div class="style"><a href="#" class="btn_ to-support">Підтримати</a></div> 179 + <div class="style"><a href="<?=Url::to(['book/add'])?>" class="btn_ add-book"><span>Додати книгу</span></a></div>
  180 + <div class="style"><a href="<?=Url::to(['support/search'])?>" class="btn_ to-support">Підтримати</a></div>
188 </div> 181 </div>
189 </div> 182 </div>
190 183
frontend/views/support/search-result.php 0 → 100644
  1 +<?php
  2 + /**
  3 + * @var \yii\data\ActiveDataProvider $dataProvider
  4 + * @var \yii\web\View $this;
  5 + */
  6 + use yii\widgets\ListView;
  7 + $this->params['breadcrumbs'][] = 'Результат пошуку';
  8 +
  9 +?>
  10 +<section class="section-books-catalog">
  11 + <div class="container">
  12 + <div class="row">
  13 + <div class="col-xs-12">
  14 + <div class="title-blocks">Книги</div>
  15 + </div>
  16 + </div>
  17 + <?= ListView::widget(
  18 + [
  19 + 'dataProvider' => $dataProvider,
  20 + 'itemView' => '@frontend/views/book/_book',
  21 + 'options' => [
  22 + 'class' => 'row',
  23 +
  24 + ],
  25 + 'itemOptions' => [
  26 + 'class' => 'col-xs-12 col-sm-12 col-md-6 books-wrapp',
  27 + ],
  28 + 'layout' => '{items}',
  29 + ]
  30 + ); ?>
  31 +
  32 + <div class="col-xs-12 col-sm-12">
  33 + <?php echo \frontend\widgets\FrontendPager::widget(
  34 + [
  35 + 'pagination' => $dataProvider->pagination,
  36 + 'maxButtonCount' => 5,
  37 + ]
  38 + ); ?>
  39 + </div>
  40 + </div>
  41 +</section>
frontend/views/support/search.php
1 -<section class="section-breadcrumb">  
2 - <div class="container">  
3 - <div class="row">  
4 - <div class="col-xs-12 col-sm-12 breadcrumb-wrapp">  
5 - <ul class="breadcrumb" itemscope="" itemtype=" http://schema.org/BreadcrumbList"><li itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem"><a href="/" itemprop="item"><span itemprop="name">Головна</span></a><meta itemprop="position" content="1"></li>  
6 - <li class="active" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/ListItem"><span itemprop="name">Підтримати</span><link itemprop="item" content="#"><meta itemprop="position" content="2"></li></ul>  
7 - </div>  
8 - </div>  
9 - </div>  
10 -</section>  
11 -  
12 - 1 +<?php
  2 + use frontend\models\SearchModel;
  3 + use kartik\select2\Select2;
  4 + use yii\helpers\Url;
  5 + use yii\web\JsExpression;
  6 + use yii\widgets\ActiveForm;
  7 +
  8 + \artbox\core\admin\assets\Select2::register($this);
  9 + $model = new SearchModel([
  10 + 'author' => true,
  11 + 'bookTitle' => true
  12 + ]);
  13 + $this->params['breadcrumbs'][] = 'Підтримати'
  14 +?>
13 <section class="section-books-support"> 15 <section class="section-books-support">
14 <div class="container"> 16 <div class="container">
15 <div class="row"> 17 <div class="row">
@@ -21,34 +23,91 @@ @@ -21,34 +23,91 @@
21 <div class="hidden-xs col-sm-4"></div> 23 <div class="hidden-xs col-sm-4"></div>
22 <div class="col-xs-12 col-sm-4 support-form-col"> 24 <div class="col-xs-12 col-sm-4 support-form-col">
23 <div class="style support-form-wr"> 25 <div class="style support-form-wr">
24 - <form action="#">  
25 - <div class="style title-support-form">Нова українська артилерія</div>  
26 - <div class="style autor-support-form"> Автор: Генадій Харченко</div> 26 + <?php $form = ActiveForm::begin(['id' => 'search-form', 'action' => '/support/search-result'])?>
27 <div class="input-wr select-support"> 27 <div class="input-wr select-support">
28 <label for="q1">Вибрати</label> 28 <label for="q1">Вибрати</label>
29 - <select name="" id="">  
30 - <option value="" selected disabled></option>  
31 - <option value="">селект1</option>  
32 - <option value="">селект2</option>  
33 - <option value="">селект3</option>  
34 - <option value="">селект4</option>  
35 - <option value="">селект5</option>  
36 - </select> 29 + <?php echo Select2::widget(
  30 + [
  31 + 'name' => 'bookId',
  32 + 'options' => [
  33 + 'placeholder' => \Yii::t('app', 'Почніть вводити назву книги'),
  34 + 'multiple' => false,
  35 +
  36 + ],
  37 + 'toggleAllSettings' => [
  38 + 'selectLabel' => false,
  39 + ],
  40 + 'pluginOptions' => [
  41 + 'allowClear' => true,
  42 + 'minimumInputLength' => 3,
  43 + 'language' => [
  44 + 'errorLoading' => new JsExpression(
  45 + "function () { return 'Зачекайте...'; }"
  46 + ),
  47 + ],
  48 + 'ajax' => [
  49 + 'url' => Url::to([ '/book/list' ]),
  50 + 'dataType' => 'json',
  51 + 'data' => new JsExpression(
  52 + 'function(params) {
  53 + return {
  54 + q:params.term
  55 + };
  56 + }'
  57 + ),
  58 + ],
  59 + 'escapeMarkup' => new JsExpression(
  60 + 'function (markup) {
  61 + return markup;
  62 + }'
  63 + ),
  64 + 'templateResult' => new JsExpression(
  65 + 'function (book) {
  66 + return book.text;
  67 + }'
  68 + ),
  69 + 'templateSelection' => new JsExpression(
  70 + 'function (book) {
  71 + console.log(book.id);
  72 + $("#next").attr("data-id", book.id)
  73 + return book.text;
  74 + }'
  75 + ),
  76 + ],
  77 + ]
  78 + ); ?>
37 </div> 79 </div>
38 <div class="input-wr search-support"> 80 <div class="input-wr search-support">
39 - <label for="q2">Пошук</label>  
40 - <input id="q2" type="text"> 81 + <?=$form->field($model, 'text')->textInput()->label('Пошук')?>
41 </div> 82 </div>
42 83
43 84
44 <div class="input-wr sidebar_checks support-shecks" style="text-align: center;"> 85 <div class="input-wr sidebar_checks support-shecks" style="text-align: center;">
45 <div style="display: inline-block"> 86 <div style="display: inline-block">
46 - <input type="checkbox" id="q6" name="" value="" checked="">  
47 - <label class="control-label" for="q6">Автор</label> 87 + <?= $form->field(
  88 + $model,
  89 + 'author',
  90 + [
  91 + 'template' => '{input}{label}',
  92 + ]
  93 + )
  94 + ->checkbox([], false)
  95 + ->label(\Yii::t('app', \Yii::t('app', 'Автор'))); ?>
  96 +<!-- <input type="checkbox" id="q6" name="" value="" checked="">-->
  97 +<!-- <label class="control-label" for="q6">Автор</label>-->
48 </div> 98 </div>
49 <div style="display: inline-block; padding-left: 24px;"> 99 <div style="display: inline-block; padding-left: 24px;">
50 - <input type="checkbox" id="q7" name="" value="" checked="">  
51 - <label class="control-label" for="q7">Назва</label> 100 + <?= $form->field(
  101 + $model,
  102 + 'bookTitle',
  103 + [
  104 + 'template' => '{input}{label}',
  105 + ]
  106 + )
  107 + ->checkbox([], false)
  108 + ->label(\Yii::t('app', \Yii::t('app', 'Назва'))); ?>
  109 +<!-- <input type="checkbox" id="q7" name="" value="" checked="">-->
  110 +<!-- <label class="control-label" for="q7">Назва</label>-->
52 </div> 111 </div>
53 </div> 112 </div>
54 113
@@ -57,13 +116,13 @@ @@ -57,13 +116,13 @@
57 </div> 116 </div>
58 117
59 <div class="support-link"> 118 <div class="support-link">
60 - <a href="#"><span>вибрати з каталогу</span></a> 119 + <a href="<?=Url::to(['/book/index'])?>"><span>вибрати з каталогу</span></a>
61 </div> 120 </div>
62 121
63 <div class="button-wr"> 122 <div class="button-wr">
64 - <button type="submit">Продовжити</button> 123 + <button id="next" type="submit" data-id="">Продовжити</button>
65 </div> 124 </div>
66 - </form> 125 + <?php ActiveForm::end()?>
67 </div> 126 </div>
68 </div> 127 </div>
69 </div> 128 </div>
frontend/web/js/script.js
@@ -148,36 +148,6 @@ $(document).ready(function() { @@ -148,36 +148,6 @@ $(document).ready(function() {
148 } 148 }
149 } 149 }
150 150
151 -  
152 -  
153 -  
154 -  
155 -  
156 -  
157 -  
158 -  
159 -  
160 -  
161 -  
162 -  
163 -  
164 -  
165 -  
166 -  
167 -  
168 -  
169 -  
170 -  
171 -  
172 -  
173 -  
174 -  
175 -  
176 -  
177 -  
178 -  
179 -  
180 -  
181 $(window).resize(function () { 151 $(window).resize(function () {
182 // heightSliderCol(); 152 // heightSliderCol();
183 footerBottom(); 153 footerBottom();
@@ -264,7 +234,13 @@ $(document).ready(function() { @@ -264,7 +234,13 @@ $(document).ready(function() {
264 // },400) 234 // },400)
265 // } 235 // }
266 236
267 - 237 + $(document).on('beforeSubmit', '#search-form', function(e) {
  238 + if ($("#next").data('id') != ''){
  239 + console.log('ololo');
  240 + window.location.replace('/support/index?book_id='+$("#next").data('id'));
  241 + return false;
  242 + }
  243 + });
268 244
269 }); 245 });
270 function success(message) { 246 function success(message) {