diff --git a/frontend/config/main.php b/frontend/config/main.php index 8c45fd0..37b7c1a 100755 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -253,6 +253,18 @@ ], ], 'components' => [ + 'assetManager' => [ + 'bundles' => [ + // new version gentenella +// 'kartik\select2\Select2Asset' => [ +// 'css' => [], +// ], +// 'kartik\select2\ThemeKrajeeAsset' => [ +// 'css' => [] +// ] + ], + 'appendTimestamp' => true, + ], 'user' => [ 'identityClass' => 'common\models\Author', 'enableAutoLogin' => true, diff --git a/frontend/controllers/BookController.php b/frontend/controllers/BookController.php index 5da3842..425d094 100644 --- a/frontend/controllers/BookController.php +++ b/frontend/controllers/BookController.php @@ -12,6 +12,7 @@ use common\models\Support; use yii\data\ActiveDataProvider; use yii\web\Controller; + use yii\web\Response; use yii\web\UploadedFile; class BookController extends Controller @@ -130,4 +131,41 @@ public function actionSuccess(){ return $this->render('success'); } + + public function actionList($q = null){ + \Yii::$app->response->format = Response::FORMAT_JSON; + $out = [ + 'results' => [ + [ + 'id' => '', + 'text' => '', + ], + ], + ]; + if (!is_null($q)) { + $books = Book::find() + ->select( + [ + 'id' => 'book.id', + 'text' => 'book.title', + ] + ) + ->andFilterWhere( + [ + 'ilike', + 'title', + $q, + ] + ) + ->limit(20) + ->asArray() + ->all(); + + if (!empty($books)) { + $out[ 'results' ] = $books; + } + } + + return $out; + } } \ No newline at end of file diff --git a/frontend/controllers/SupportController.php b/frontend/controllers/SupportController.php index 87c58cd..c58c01c 100644 --- a/frontend/controllers/SupportController.php +++ b/frontend/controllers/SupportController.php @@ -10,6 +10,9 @@ use common\models\Book; use common\models\Support; + use frontend\helpers\Url; + use frontend\models\SearchModel; + use yii\data\ActiveDataProvider; use yii\web\Controller; class SupportController extends Controller @@ -29,9 +32,40 @@ 'book' => $book ]); } - - public function actionSearch() - { + public function actionSearch(){ return $this->render('search'); } + + public function actionSearchResult() + { + $model = new SearchModel(); + if ($model->load(\Yii::$app->request->post())){ + $booksIds = $model->search(); + if (count($booksIds) == 1){ + return $this->redirect(Url::to(['support/index', 'book_id' => $booksIds[0]['id']])); + }else{ + $dataProvider = new ActiveDataProvider( + [ + 'query' => Book::find() + ->with( + [ + 'author', + 'alias', + ] + ) + ->where([ 'status' => Book::STATUS_ACTIVE ])->andWhere(['book.id' => $booksIds]), + 'pagination' => [ + 'pageSize' => 10, + ], + ] + ); + return $this->render( + 'search-result', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + } + } } \ No newline at end of file diff --git a/frontend/models/SearchModel.php b/frontend/models/SearchModel.php new file mode 100644 index 0000000..4c7c4da --- /dev/null +++ b/frontend/models/SearchModel.php @@ -0,0 +1,54 @@ + new JsExpression('function (attribute, value) { + return $("#next").data("id") == ""; + }'), + ], + [ + ['author', 'bookTitle'], + 'boolean' + ], + [ + 'text', 'string' + ] + ]; + } + + public function search(){ + $query = (new Query())->select('book.id')->from('book')->join('INNER JOIN', 'author', 'book.author_id = author.id'); + if ($this->author){ + $query->where(['ilike', 'book.title', $this->text]); + } + if ($this->bookTitle){ + $query->orWhere(['ilike', 'secondname', $this->text])->orWhere(['ilike', new Expression('concat(name,\' \',secondname)'), $this->text]); + } + return $query->column(); + } + } \ No newline at end of file diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index f3b0a8b..f9b952a 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -15,18 +15,11 @@ use artbox\core\models\PageCategory; use artbox\core\models\User; use artbox\core\seo\widgets\SeoBreadcrumbs; - use common\models\page\Category; use common\models\Settings; use frontend\assets\AppAsset; - use artbox\core\components\imagemanager\models\ImageManager; - use frontend\widgets\ArtboxModalWidget; - use frontend\widgets\LanguageWidget; - use yii\bootstrap\Nav; use yii\bootstrap\Html; - use yii\db\ActiveQuery; use artbox\core\helpers\Url; use yii\web\View; - use yii\widgets\Breadcrumbs; AppAsset::register($this); @@ -102,7 +95,7 @@ JS; user->isGuest){?> @@ -175,7 +168,7 @@ JS;
-
Додати книгу
-
Підтримати
+
Додати книгу
+
Підтримати
diff --git a/frontend/views/support/search-result.php b/frontend/views/support/search-result.php new file mode 100644 index 0000000..718685f --- /dev/null +++ b/frontend/views/support/search-result.php @@ -0,0 +1,41 @@ +params['breadcrumbs'][] = 'Результат пошуку'; + +?> +
+
+
+
+
Книги
+
+
+ $dataProvider, + 'itemView' => '@frontend/views/book/_book', + 'options' => [ + 'class' => 'row', + + ], + 'itemOptions' => [ + 'class' => 'col-xs-12 col-sm-12 col-md-6 books-wrapp', + ], + 'layout' => '{items}', + ] + ); ?> + +
+ $dataProvider->pagination, + 'maxButtonCount' => 5, + ] + ); ?> +
+
+
diff --git a/frontend/views/support/search.php b/frontend/views/support/search.php index e35a6dd..02c71da 100644 --- a/frontend/views/support/search.php +++ b/frontend/views/support/search.php @@ -1,15 +1,17 @@ -
-
-
- -
-
-
- - + true, + 'bookTitle' => true + ]); + $this->params['breadcrumbs'][] = 'Підтримати' +?>
@@ -21,34 +23,91 @@
-
-
Нова українська артилерія
-
Автор: Генадій Харченко
+ 'search-form', 'action' => '/support/search-result'])?>
- + 'bookId', + 'options' => [ + 'placeholder' => \Yii::t('app', 'Почніть вводити назву книги'), + 'multiple' => false, + + ], + 'toggleAllSettings' => [ + 'selectLabel' => false, + ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'language' => [ + 'errorLoading' => new JsExpression( + "function () { return 'Зачекайте...'; }" + ), + ], + 'ajax' => [ + 'url' => Url::to([ '/book/list' ]), + 'dataType' => 'json', + 'data' => new JsExpression( + 'function(params) { + return { + q:params.term + }; + }' + ), + ], + 'escapeMarkup' => new JsExpression( + 'function (markup) { + return markup; + }' + ), + 'templateResult' => new JsExpression( + 'function (book) { + return book.text; + }' + ), + 'templateSelection' => new JsExpression( + 'function (book) { + console.log(book.id); + $("#next").attr("data-id", book.id) + return book.text; + }' + ), + ], + ] + ); ?>
- - + field($model, 'text')->textInput()->label('Пошук')?>
@@ -57,13 +116,13 @@
- +
- +
diff --git a/frontend/web/js/script.js b/frontend/web/js/script.js index 27eb0e4..5dccd2c 100644 --- a/frontend/web/js/script.js +++ b/frontend/web/js/script.js @@ -148,36 +148,6 @@ $(document).ready(function() { } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(window).resize(function () { // heightSliderCol(); footerBottom(); @@ -264,7 +234,13 @@ $(document).ready(function() { // },400) // } - + $(document).on('beforeSubmit', '#search-form', function(e) { + if ($("#next").data('id') != ''){ + console.log('ololo'); + window.location.replace('/support/index?book_id='+$("#next").data('id')); + return false; + } + }); }); function success(message) { -- libgit2 0.21.4