Exemplo n.º 1
0
 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]);
 }
Exemplo n.º 2
0
 /**
  * Lists all Articles of a category.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = $this->getSearchModel();
     $request = \Yii::$app->request;
     $currentCategory = Categories::findOne(['uri' => $request->get('uri')]);
     $dataProvider = $searchModel->search($request->queryParams, $currentCategory->id);
     return $this->render('index', ['currentCategoryName' => $currentCategory->name, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Exemplo n.º 3
0
 /**
  * Возвращает массив подкатегорий (forum_name) для переданной категории
  *
  * @param null|integer $id
  * @return array
  */
 public static function subsForCat($id = null)
 {
     $query = Subcategory::find();
     if ($id != null && ($cat = Categories::findOne($id)) !== null) {
         $subcatsArr = array_keys(self::find()->where(['category_attr' => $id])->groupBy('forum_name_id_attr')->indexBy('forum_name_id_attr')->limit(10000)->asArray()->all());
         $query->andWhere(['id' => $subcatsArr]);
     }
     return ArrayHelper::map($query->asArray()->all(), 'id', 'forum_name');
 }
Exemplo n.º 4
0
 public function actionCategory()
 {
     $blog = Blog::getInstance();
     $category = Categories::findOne(['uri' => \Yii::$app->request->get('uri')]);
     if (!$category) {
         \Yii::$app->session->setFlash('incorrectCategoryUri', 'warning');
         return $this->redirect(['/category'], 302);
     }
     if (!($data = $blog->getArticlesPage($category))) {
         return $this->render('@note', ['msg' => 'noArticles']);
     }
     return $this->render('index', ['data' => $data]);
 }
Exemplo n.º 5
0
 public function actionUpdate($id)
 {
     $id = (int) $id;
     if (empty($id)) {
         return $this->redirect('index');
     }
     $categ = new Categories();
     $inco_ex = new IncoExpenso();
     $inco_ex = $inco_ex->find()->all();
     $sql = $categ->sqlAactivDelete($id);
     //проверяем активна запись для изменения
     $query = Categories::findBySql($sql)->count();
     if ($query == 0) {
         return $this->redirect('index');
     }
     if ($categ->load(Yii::$app->request->post()) && $categ->validate()) {
         $q = $categ->updateCateg($id);
         return $this->redirect('index');
     }
     $sql = $categ->findOne($id);
     return $this->render('update', ['categ' => $sql, 'inco_ex' => $inco_ex]);
 }
Exemplo n.º 6
0
 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]);
 }
Exemplo n.º 7
0
 public function actionUpdate($id)
 {
     $id = (int) $id;
     if (empty($id)) {
         return $this->redirect('index');
     }
     $categ = new Categories();
     $inco_ex = new IncoExpenso();
     $inco_ex = $inco_ex->find()->all();
     $sql = $this->sql_activ_delete($id);
     //проверяем активна запись для изменения
     $query = Categories::findBySql($sql)->count();
     if ($query == 0) {
         return $this->redirect('index');
     }
     $sql = $categ->findOne($id);
     if ($categ->load(Yii::$app->request->post()) && $sql->validate()) {
         //return print_r($_POST);
         $sql->updateAll(['categ_name' => $_POST['Categories']['categ_name'], 'inc_exp_id' => $_POST['Categories']['inc_exp_id']], ['categ_id' => $id]);
         return $this->redirect('index');
     }
     return $this->render('update', ['categ' => $sql, 'inco_ex' => $inco_ex]);
 }
 /**
  * Импорт категорий
  *
  * @param $path
  * @return array|\yii\db\ActiveRecord[]
  */
 private function importCategories($path)
 {
     $file = $path . DIRECTORY_SEPARATOR . 'category_info.csv';
     $row = 1;
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
             $row++;
             $this->stdout("Row " . $row . ":\n");
             $model = Categories::findOne($data[0]);
             if ($model === null) {
                 $model = new Categories(['id' => $data[0], 'category_name' => $data[1], 'file_name' => $data[2]]);
             }
             if ($model->save()) {
                 $this->stdout("Category {$model->id} with name '{$model->category_name}' imported\n");
             }
             $this->stdout("\n");
         }
     } else {
         return false;
     }
     return Categories::find()->all();
 }
Exemplo n.º 9
0
 /**
  * Finds the Categories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Categories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 10
0
" onblur="if(this.value=='') {this.value='Поиск.';
}"
                           onfocus="if(this.value=='Поиск.') {this.value='';
}" class="ft" name="q"/>
                    <input type="submit" value="" class="fs">
                </form>
            </div>

            <!-- Nav -->
            <nav id="nav">
                <ul class="sf-menu">
                    <?php 
if ($categories = \common\models\Categories::find()->where('parent_id IS NULL')->with('child')->orderBy('order ASC')->all()) {
    ?>
                        <?php 
    $current = \common\models\Categories::findOne(['slug' => isset(Yii::$app->requestedParams[0]) ? Yii::$app->requestedParams[0] : 'all']);
    ?>


                        <?php 
    foreach ($categories as $category) {
        ?>

                            <li <?php 
        if ($current && $current->id == $category->id) {
            ?>
class="current"<?php 
        }
        ?>
>
                                <a href="<?php 
Exemplo n.º 11
0
 * User: andrew72ru
 * Date: 01.01.16
 * Time: 13:15
 * File: index.php
 *
 * @var \yii\web\View $this
 * @var TorrentSearch $searchModel
 * @var \yii\sphinx\ActiveDataProvider $dataProvider
 */
$this->title = Yii::t('app', 'Rutracker Torrents Search');
use common\models\Categories;
use common\models\Subcategory;
use common\models\Torrents;
use common\models\TorrentSearch;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\Pjax;
?>

<?php 
Pjax::begin(['scrollTo' => 0]);
echo GridView::widget(['filterModel' => $searchModel, 'dataProvider' => $dataProvider, 'columns' => ['name_attr' => ['attribute' => 'name_attr', 'value' => function ($model) {
    return Html::a($model['name_attr'], 'http://rutracker.org/forum/viewtopic.php?t=' . $model['topic_id_attr'], ['target' => '_blank']);
}, 'format' => 'raw', 'contentOptions' => ['style' => ['white-space' => 'normal']]], ['attribute' => 'category_attr', 'value' => function ($model) {
    return Categories::findOne($model['category_attr'])->category_name;
}, 'filter' => TorrentSearch::catForSubs($searchModel->forum_name_id_attr)], ['attribute' => 'forum_name_id_attr', 'value' => function ($model) {
    return Subcategory::findOne($model['forum_name_id_attr'])->forum_name;
}, 'contentOptions' => ['style' => ['white-space' => 'normal']], 'filter' => TorrentSearch::subsForCat($searchModel->category_attr)], ['attribute' => 'size_attr', 'format' => 'shortSize', 'contentOptions' => ['class' => 'text-right'], 'filter' => false], ['attribute' => 'datetime_attr', 'format' => 'datetime', 'headerOptions' => ['class' => 'text-nowrap'], 'filter' => false], ['header' => null, 'value' => function ($model) {
    return Html::a(Html::tag('span', '', ['class' => 'glyphicon glyphicon-download-alt']), 'magnet:?xt=urn:btih:' . Torrents::findOne($model['id'])->hash . '&tr=http://bt.rutracker.cc/ann?magnet');
}, 'format' => 'raw']]]);
Pjax::end();