public function actionIndex($slug) { $this->layout = 'category'; $query = News::find(); $category = Categories::findOne(['slug' => $slug]); if (!$category) { $this->redirect("/"); } if ('all' != $slug) { $catArr = []; $catArr[] = $category->id; if ($subcatList = $category->child) { foreach ($subcatList as $subcat) { $catArr[] = $subcat->id; } } $query->join('INNER JOIN', NewsHasCategory::tableName(), NewsHasCategory::tableName() . ".news_id = " . News::tableName() . ".id"); $query->where([NewsHasCategory::tableName() . '.category_id' => $catArr]); } $query->orderBy(['id' => SORT_DESC]); $provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 26]]); $breadCrumbs = []; $breadCrumbs[] = ['label' => 'Главная', 'url' => '/']; $breadCrumbs[] = ['label' => 'Категории', 'url' => '/category/all']; $breadCrumbs[] = ['label' => isset($category) ? $category->name : "Все новости"]; Yii::$app->view->title = isset($category) ? $category->name : "Все новости"; Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => (isset($category) ? $category->name : "Все новости") . ' новости, свежие новости, новости украины, новости сегодня, агрегатор новостей']); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Свежие новости со всех Украинских сайтов в одном сайте. Агрегатор новостей'], 'description'); Yii::$app->view->registerMetaTag(['name' => 'og:title', 'content' => Yii::$app->view->title], 'og:title'); return $this->render('index', ['provider' => $provider, 'slug' => $slug, 'category' => isset($category) ? $category->name : "Все новости", 'breadcrumbs' => $breadCrumbs]); }
public function actionIndex() { Yii::$app->view->title = 'Свежие новости'; Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => 'новости, свежие новости, новости украины, новости сегодня, агрегатор новостей']); Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => 'Свежие новости со всех Украинских сайтов в одном сайте. Агрегатор новостей'], 'description'); Yii::$app->view->registerMetaTag(['name' => 'og:title', 'content' => Yii::$app->view->title], 'og:title'); $this->layout = 'front'; $notInIds = []; $sliders = News::find()->where("created_at BETWEEN NOW() - INTERVAL '6 hour' AND NOW() AND thumb IS NOT NULL")->orderBy(["cnt" => SORT_DESC])->limit(8)->all(); foreach ($sliders as $item) { $notInIds[] = $item->id; } $topNews = News::find()->where("created_at BETWEEN NOW() - INTERVAL '6 hour' AND NOW() AND thumb IS NOT NULL AND id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["cnt" => SORT_DESC])->limit(4)->all(); foreach ($topNews as $item) { $notInIds[] = $item->id; } $hotNews = News::find()->where("thumb IS NOT NULL AND id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(4)->all(); foreach ($hotNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'ato']); $atoNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(7)->all(); foreach ($atoNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'economic']); $ecoNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(7)->all(); foreach ($ecoNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'sport']); $sportNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(3)->all(); foreach ($sportNews as $item) { $notInIds[] = $item->id; } $category = Categories::findOne(['slug' => 'politics']); $politicsNews = News::find()->joinWith(['newsHasCategories'])->where(NewsHasCategory::tableName() . ".category_id = {$category->id} AND " . News::tableName() . ".id NOT IN(" . implode(",", $notInIds) . ")")->orderBy(["id" => SORT_DESC])->limit(3)->all(); return $this->render('index', ['topNews' => $topNews, 'hotNews' => $hotNews, 'atoNews' => $atoNews, 'ecoNews' => $ecoNews, 'sportNews' => $sportNews, 'politicsNews' => $politicsNews, 'sliders' => $sliders]); }
protected function detectCategories($news_id, $pn_id) { $pn = PendingNews::findOne($pn_id); $content = mb_strtolower($pn->search_content, 'utf-8'); if ($pn->additonal_data) { $data = json_decode($pn->additonal_data); if (isset($data->category_id)) { if (!($nhc = NewsHasCategory::findOne(['category_id' => $data->category_id, 'news_id' => $news_id]))) { $nhc = new NewsHasCategory(); $nhc->news_id = $news_id; $nhc->category_id = $data->category_id; $nhc->save(); return true; } } if ($data->category) { $content = mb_strtolower($data->category, 'utf-8'); } } $categoryWords = CategoryWords::find()->all(); foreach ($categoryWords as $cw) { if (mb_strpos($content, mb_strtolower($cw->word, 'utf-8'), 0, 'utf-8') !== false) { if (!($nhc = NewsHasCategory::findOne(['category_id' => $cw->category_id, 'news_id' => $news_id]))) { $nhc = new NewsHasCategory(); $nhc->news_id = $news_id; $nhc->category_id = $cw->category_id; $nhc->save(); } } } }
public function getCategoryList() { return Categories::find()->join('inner join', NewsHasCategory::tableName(), NewsHasCategory::tableName() . ".category_id = " . Categories::tableName() . ".id")->where([NewsHasCategory::tableName() . ".news_id" => $this->id])->all(); }