Blame view

frontend/modules/news/controllers/ListController.php 2.17 KB
d1f8bd40   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
  <?php
  
  namespace frontend\modules\news\controllers;
  
  use Yii;
  use yii\helpers\Url;
  use yii\web\NotFoundHttpException;
  use yii\filters\VerbFilter;
  //
  use thread\actions\ListQuery;
  //
  use frontend\components\BaseController;
  use frontend\modules\news\models\{
      Article, Group, search\Articles
  };
  
  /**
   * Class ListController
   *
   * @package frontend\modules\news\controllers
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class ListController extends BaseController
  {
      public $label = "News";
      public $title = "News";
      public $defaultAction = 'index';
      public $layout = "@app/layouts/base";
  
      /**
       *
       */
      public function init()
      {
          parent::init();
  
          $this->breadcrumbs = [
              [
                  'label' => Yii::t('news', 'Blog'),
              ]
          ];
      }
  
      /**
       * @return array
       */
      public function behaviors()
      {
          return [
              'verbs' => [
                  'class' => VerbFilter::class,
                  'actions' => [
                      'index' => ['get'],
                  ],
              ],
          ];
      }
  
      /**
       * @return array
       * @throws NotFoundHttpException
       */
      public function actions()
      {
          return [
              'index' => [
                  'class' => ListQuery::class,
                  'query' => Article::find(),
                  'recordOnPage' => 3,
                  'layout' => $this->layout
              ],
          ];
      }
  
      /**
       * @param $alias
       * @return string
       * @throws NotFoundHttpException
       */
      public function actionByGroup($alias)
      {
          $model = Group::getByAlias($alias);
          if ($model == null) {
              throw new NotFoundHttpException;
          }
          //
          $this->breadcrumbs[] = [
              'label' => $model['lang']['title'],
              'url' => $model->getUrl()
          ];
          //SEO
          Yii::$app->metatag->registerModel($model);
          //SEO
          $provider = (new Articles())->search($model);
  
          return $this->render('list', [
              'group' => $model,
              'models' => $provider->getModels(),
              'pages' => $provider->getPagination()
          ]);
      }
  }