diff --git a/backend/config/main.php b/backend/config/main.php index 0b7fcaf..089ca47 100755 --- a/backend/config/main.php +++ b/backend/config/main.php @@ -24,6 +24,8 @@ 'seo' => 'artbox\core\controllers\SeoController', 'feedback' => 'artbox\core\controllers\FeedbackController', 'blog' => 'artbox\weblog\controllers\ArticleController', + 'blog-category' => 'artbox\weblog\controllers\CategoryController', + 'blog-tag' => 'artbox\weblog\controllers\TagController', ], 'components' => [ 'assetManager' => [ diff --git a/backend/views/layouts/menu_items.php b/backend/views/layouts/menu_items.php index b72690c..7c27fe2 100755 --- a/backend/views/layouts/menu_items.php +++ b/backend/views/layouts/menu_items.php @@ -74,6 +74,28 @@ ], ], [ + 'label' => \Yii::t('core', 'Блог'), + 'url' => ['#'], + 'icon' => 'book', + 'items' => [ + [ + 'label' => \Yii::t('core', 'Статьи'), + 'url' => ['/blog/index'], + 'icon' => 'list-alt', + ], + [ + 'label' => \Yii::t('core', 'Категории'), + 'url' => ['/blog-category/index'], + 'icon' => 'ticket', + ], + [ + 'label' => \Yii::t('core', 'Тэги'), + 'url' => ['/blog-tag/index'], + 'icon' => 'tags', + ] + ], + ], + [ 'label' => \Yii::t('core', 'Image manager'), 'url' => [ '/imagemanager' ], 'icon' => 'image', @@ -81,17 +103,12 @@ [ 'label' => \Yii::t('core', 'Slider'), 'url' => ['/slider/index'], - 'icon' => 'bolt', + 'icon' => 'exchange', ], [ 'label' => \Yii::t('core', 'Наши Объекты'), 'url' => ['/objectkb/index'], - 'icon' => 'bolt', - ], - [ - 'label' => \Yii::t('core', 'Блог'), - 'url' => ['/blog/index'], - 'icon' => 'bolt', + 'icon' => 'sun-o', ], ] ); \ No newline at end of file diff --git a/common/messages/ru/app.php b/common/messages/ru/app.php index a3d9339..c8dd502 100644 --- a/common/messages/ru/app.php +++ b/common/messages/ru/app.php @@ -124,4 +124,5 @@ return [ "Show on home page" => "Показать на главной странице", 'Go to contact page' => 'На страницу контактов', 'Share' => 'Поделиться', + 'All' => "Все", ]; \ No newline at end of file diff --git a/frontend/config/main.php b/frontend/config/main.php index 5756b14..f0b9d8e 100644 --- a/frontend/config/main.php +++ b/frontend/config/main.php @@ -52,8 +52,8 @@ return [ 'processRoutes' => [ 'object/view', 'blog/article', -// 'blog/tag', -// 'blog/category', + 'blog/tag', + 'blog/category', ], ], ], diff --git a/frontend/controllers/BlogController.php b/frontend/controllers/BlogController.php index 937d7d0..c73ba41 100644 --- a/frontend/controllers/BlogController.php +++ b/frontend/controllers/BlogController.php @@ -2,6 +2,8 @@ namespace frontend\controllers; use yii\data\ActiveDataProvider; + use yii\helpers\Html; + use yii\helpers\Url; use yii\web\Controller; use artbox\weblog\models\Article; use yii\web\NotFoundHttpException; @@ -16,16 +18,18 @@ { public function actionIndex() { + + $query = Article::find() + ->where( + [ + 'status' => true, + ] + ) + ->orderBy("sort"); $dataProvider = new ActiveDataProvider( [ - 'query' => Article::find() - ->where( - [ - 'status' => true, - ] - ) - ->orderBy("sort"), + 'query' => $query, 'pagination' => [ 'pageSize' => 5, ], @@ -77,4 +81,80 @@ } } + public function actionSearch(){ + if( \Yii::$app->request->isPost ){ + + $req = \Yii::$app->request; + if (!empty($req->post("title"))){ + $title = Html::encode($req->post("title")); + $query = Article::find() + ->joinWith("lang") + ->where( + [ + 'status' => true, + ] + ) + ->andWhere( + [ + "like", "lower(title)", $title + ] + ) + ->orderBy("sort"); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 5, + ], + ] + ); + + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + } + + return $this->redirect(Url::toRoute(['blog/index'])); + + } + + public function actionCategory($id){ + + $query = Article::find() + ->joinWith("categories.lang") + ->where( + [ + 'blog_article.status' => true, + ] + ) + ->andWhere( + [ + "blog_category.id" => $id, + "blog_category.status" => true, + ] + ) + ->orderBy("sort"); + + $dataProvider = new ActiveDataProvider( + [ + 'query' => $query, + 'pagination' => [ + 'pageSize' => 5, + ], + ] + ); + + return $this->render( + 'index', + [ + 'dataProvider' => $dataProvider, + ] + ); + } + } \ No newline at end of file diff --git a/frontend/views/blog/index.php b/frontend/views/blog/index.php index d346366..da7b6c2 100644 --- a/frontend/views/blog/index.php +++ b/frontend/views/blog/index.php @@ -45,8 +45,14 @@
- + 'blog/search' + ] + )?> + +
diff --git a/frontend/widgets/CategoryWidget.php b/frontend/widgets/CategoryWidget.php index 4129480..3d38697 100644 --- a/frontend/widgets/CategoryWidget.php +++ b/frontend/widgets/CategoryWidget.php @@ -7,13 +7,31 @@ */ use yii\base\Widget; + use artbox\weblog\models\Category; class CategoryWidget extends Widget { + + public $categories; + + public function init() + { + parent::init(); + + $this->categories = Category::find() + ->with("lang.alias") + ->where(["status"=>true]) + ->orderBy("sort") + ->all(); + } + public function run() { return $this->render( - 'category_view' + 'category_view', + [ + 'categories' => $this->categories + ] ); } } diff --git a/frontend/widgets/SearchWidget.php b/frontend/widgets/SearchWidget.php index 9aff8de..fbc10ca 100644 --- a/frontend/widgets/SearchWidget.php +++ b/frontend/widgets/SearchWidget.php @@ -1,4 +1,5 @@ route)) { + // by default route is the same as view in which it was used + $this->route = \Yii::$app->controller->id . "/" . \Yii::$app->controller->action->id; + } + + } + public function run() { return $this->render( - 'search_view' + 'search_view', + [ + 'route' => $this->route, + 'paramForSearch' => $this->paramForSearch, + ] ); } } \ No newline at end of file diff --git a/frontend/widgets/views/category_view.php b/frontend/widgets/views/category_view.php index cc01be3..885c7a6 100644 --- a/frontend/widgets/views/category_view.php +++ b/frontend/widgets/views/category_view.php @@ -3,24 +3,55 @@ * User: timur * Date: 28.01.18 * Time: 12:43 + * + * @var Category[] $categories */ + use artbox\weblog\models\Category; + use yii\helpers\Html; + use yii\helpers\Url; + ?> diff --git a/frontend/widgets/views/search_view.php b/frontend/widgets/views/search_view.php index 93602c8..7c408f9 100644 --- a/frontend/widgets/views/search_view.php +++ b/frontend/widgets/views/search_view.php @@ -3,8 +3,14 @@ * User: timur * Date: 28.01.18 * Time: 12:38 + * + * @var string $route + * @var string $paramForSearch + * */ + use yii\widgets\ActiveForm; + use yii\helpers\Html; ?>
-
-
- - - - -
-
+ + \yii\helpers\Url::toRoute($route), + 'options' => [ + 'role' => "search", + ], + ] + ); + + echo Html::tag( + "div", + Html::input( + "text", + $paramForSearch, + null, + [ + 'class' => "form-control", + 'placeholder' => Yii::t("app", "Search"), + ] + ) . Html::tag( + "span", + Html::button( + "", + [ + 'class' => "btn btn-template-main", + 'type' => "submit", + ] + ), + [ + 'class' => "input-group-btn", + ] + ) + + , + [ + 'class' => "input-group", + ] + ); + + $form::end(); + + ?> +
-- libgit2 0.21.4