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'][] = 'Результат пошуку'; + +?> +