예제 #1
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"]]);
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function getCatalog()
 {
     return $this->hasMany(Catalog::className(), array('category_id' => 'id'));
 }
예제 #3
0
<?php

use app\modules\catalog\models;
return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/catalog/migrations']]], 'modules' => ['catalog' => ['class' => app\modules\catalog\Catalog::className(), 'controllerNamespace' => 'app\\modules\\catalog\\controllers', 'modules' => ['admin' => ['class' => app\modules\catalog\modules\admin\Admin::className(), 'controllerNamespace' => 'app\\modules\\catalog\\modules\\admin\\controllers', 'menuItems' => function () {
    return [['label' => Yii::t('catalog/app', 'Catalog module'), 'icon' => 'glyphicon glyphicon-folder-open', 'items' => [['label' => Yii::t('catalog/app', 'Catalogs'), 'url' => ['/admin/catalog/catalog'], "permission" => ["listModels", ["model" => Yii::createObject(models\Catalog::className())]]], ['label' => Yii::t('catalog/app', 'Catalog Sections'), 'url' => ['/admin/catalog/catalog-section'], "permission" => ["listModels", ["model" => Yii::createObject(models\CatalogSection::className())]]], ['label' => Yii::t('catalog/app', 'Producers'), 'url' => ['/admin/catalog/producer'], "permission" => ["listModels", ["model" => Yii::createObject(models\Producer::className())]]]]]];
}]]]], 'components' => ['i18n' => ['translations' => ['catalog/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/catalog/messages', 'fileMap' => ['catalog/app' => 'app.php']]]], 'urlManager' => ['rules' => ['catalog/<section:[A-z0-9_-]+>/<code:[A-z0-9_-]+>' => 'catalog/catalog/detail', 'catalog/<section:[A-z0-9_-]+>' => 'catalog/catalog/index', 'catalog' => 'catalog/catalog/index']]]];
예제 #4
0
 public function getPosition()
 {
     return $this->hasOne(Catalog::className(), array('id' => 'catalog_id'));
 }