Пример #1
0
 /**
  * Списочный вывод всех фотогалерей
  * @return string
  */
 public function actionIndex()
 {
     $cacheId = $this->getActionCacheId(static::LIST_CACHE_ID);
     $res = Yii::$app->cache->get($cacheId);
     if (empty($res)) {
         $model = Yii::createObject(['class' => Gallery::className()]);
         $dependency = Yii::createObject(TagDependency::className());
         $dataProvider = $model->publicSearch();
         $dataProvider->getSort()->defaultOrder = $this->orderBy;
         $dataProvider->getPagination()->pageSize = $this->pageSize;
         $dependency->addTag($model->setClassTagSafe());
         $dependency->setTagsFromModels($dataProvider->getModels());
         $res["html"] = $this->renderPartial('_grid', ["dataProvider" => $dataProvider]);
         Yii::$app->cache->set($cacheId, $res, Yii::$app->params["cacheDuration"], $dependency);
     }
     $this->view->title = Yii::t('photogallery/app', 'Photogallery');
     $this->view->addBreadCrumb(["label" => $this->view->title]);
     return $this->render("index", ["html" => $res["html"]]);
 }
Пример #2
0
 /**
  * Списочный вывод каталога
  * @param null|string $section символьный код категории каталога
  * @return string
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionIndex($section = null)
 {
     $cacheId = $this->getActionCacheId(static::LIST_CACHE_ID);
     $res = Yii::$app->cache->get($cacheId);
     $model = Yii::createObject(['class' => Catalog::className()]);
     $searchModel = Yii::createObject(['class' => CatalogSearch::className(), 'scenario' => ActiveRecord::SCENARIO_SEARCH]);
     $filter = $searchModel->load(Yii::$app->request->get());
     if (empty($res) or $filter) {
         $dependency = Yii::createObject(TagDependency::className());
         $res["sectionModel"] = null;
         if (empty($searchModel->sectionsIds) and $section) {
             $res["sectionModel"] = CatalogSection::find()->published()->andWhere(["code" => $section])->one();
             if (!$res["sectionModel"]) {
                 throw new NotFoundHttpException();
             }
             $dependency->addTag($res["sectionModel"]->setItemTagSafe());
             $searchModel->sectionsIds = $res["sectionModel"]->getFilterIds();
         }
         $dataProvider = $searchModel->publicSearch();
         $dataProvider->getSort()->defaultOrder = $this->orderBy;
         $dataProvider->getPagination()->pageSize = $this->pageSize;
         $dependency->addTag($model->setClassTagSafe());
         $dependency->setTagsFromModels($dataProvider->getModels());
         $res["html"] = $this->renderPartial('_grid', ["dataProvider" => $dataProvider, "previewImageWidth" => $this->previewImageWidth]);
         if (!$filter) {
             Yii::$app->cache->set($cacheId, $res, Yii::$app->params["cacheDuration"], $dependency);
         }
     }
     $this->view->addBreadCrumb(["label" => Yii::t('catalog/app', 'Catalog'), "url" => Url::toRoute(["/catalog/catalog/index"])]);
     if ($res["sectionModel"]) {
         $this->view->registerMetaTags($res["sectionModel"]);
         $crumbs = $res["sectionModel"]->getBreadCrumbsItems($res["sectionModel"]->id, function ($model) {
             return ['/catalog/catalog/index', 'section' => $model->code];
         });
         $this->view->addBreadCrumbs($crumbs);
     }
     return $this->render("index", ["sectionModel" => $res["sectionModel"], "model" => $model, "searchModel" => $searchModel, "html" => $res["html"]]);
 }
Пример #3
0
 /**
  * Списочный вывод новостей
  * @param null|string $section символьный код категории новости
  * @return string
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionIndex($section = null)
 {
     $cacheId = $this->getActionCacheId(static::LIST_CACHE_ID);
     $res = Yii::$app->cache->get($cacheId);
     if (empty($res)) {
         $dependency = Yii::createObject(TagDependency::className());
         $model = Yii::createObject(['class' => News::className(), 'scenario' => ActiveRecord::SCENARIO_SEARCH]);
         $res["sectionModel"] = null;
         $ids = null;
         if ($section) {
             $res["sectionModel"] = NewsSection::find()->published()->andWhere(["code" => $section])->one();
             if (!$res["sectionModel"]) {
                 throw new NotFoundHttpException();
             }
             $ids = $res["sectionModel"]->getFilterIds();
         }
         $dataProvider = $model->searchBySection($ids);
         $dataProvider->getSort()->defaultOrder = $this->orderBy;
         $dataProvider->getPagination()->pageSize = $this->pageSize;
         $dependency->addTag($model->setClassTagSafe());
         $dependency->setTagsFromModels($dataProvider->getModels());
         $res["html"] = $this->renderPartial('index', ["dataProvider" => $dataProvider, "sectionModel" => $res["sectionModel"], "previewImageWidth" => $this->previewImageWidth]);
         Yii::$app->cache->set($cacheId, $res, Yii::$app->params["cacheDuration"], $dependency);
     }
     if ($res["sectionModel"]) {
         $this->view->registerMetaTags($res["sectionModel"]);
         $crumbs = $res["sectionModel"]->getBreadCrumbsItems($res["sectionModel"]->id, function ($model) {
             return ['/news/news/index', 'section' => $model->code];
         });
         $this->view->addBreadCrumbs($crumbs);
     } else {
         $this->view->title = Yii::t('news/app', 'News');
         $this->view->addBreadCrumb(["label" => $this->view->title, "url" => Url::toRoute(["/news/news/index"])]);
     }
     return $this->renderHtml($res["html"]);
 }