/**
  * Creates a new Catalog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($category_id)
 {
     $model = new Catalog();
     $model->category_id = $category_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * @inheritdoc
  */
 public function setSort($value)
 {
     parent::setSort($value);
     if (($sort = $this->getSort()) !== false && empty($sort->attributes)) {
         $model = new Catalog();
         foreach ($model->attributes() as $attribute) {
             $sort->attributes[$attribute] = ['asc' => [$attribute => SORT_ASC], 'desc' => [$attribute => SORT_DESC], 'label' => $model->getAttributeLabel($attribute)];
         }
         foreach ($this->categoryAttributes as $attribute) {
             $sort->attributes[$attribute->code] = ['asc' => [$attribute->code => SORT_ASC], 'desc' => [$attribute->code => SORT_DESC], 'label' => $attribute->title];
         }
     }
 }
 /**
  * Displays a single User model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $user = User::findOne($id);
     if (!$user) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $positions = Catalog::find()->where(['author_id' => $user->id])->all();
     return $this->render('profile', ['model' => $user, 'positions' => $positions]);
 }
Beispiel #4
0
 public function search($q)
 {
     $sub = explode(' ', $q);
     /* get from catalog */
     $rows_query = (new \yii\db\Query())->select(["CONCAT('catalog') AS module", 'id' => 'id', 'text' => 'title'])->from(['t' => \app\modules\catalog\models\Catalog::tableName()]);
     foreach ($sub as $word) {
         $rows_query->andWhere(['or', ['like', 'title', $word], ['like', 'content', $word], ['exists', (new \yii\db\Query())->select(['id'])->from(['v' => \app\modules\catalog\models\CatalogValues::tableName()])->where('v.catalog_id = t.id')->andWhere(['like', 'value', $word])]]);
     }
     foreach ($rows_query->all() as $row) {
         $this->_results[] = ['url' => Url::to(['/catalog/position/view', 'id' => $row['id']]), 'text' => $row['text']];
     }
     return $this->_results;
 }
Beispiel #5
0
 public function actionIndex()
 {
     $model = Catalog::find()->all();
     return $this->render('index', ['model' => $model]);
 }
 /**
  * @inheritdoc
  */
 public function getCatalog()
 {
     return $this->hasMany(Catalog::className(), array('category_id' => 'id'));
 }
Beispiel #7
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']]]];
Beispiel #8
0
 public function getPosition()
 {
     return $this->hasOne(Catalog::className(), array('id' => 'catalog_id'));
 }
 /**
  * Отображение карточки элемента каталога
  * @param string $code символьный идентификатор элемента каталога
  * @param string $section символьный идентификатор категории каталога
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionDetail($code, $section)
 {
     $model = Catalog::find()->published()->andWhere(["code" => $code])->one();
     if (!$model) {
         throw new NotFoundHttpException();
     }
     $sectionModel = CatalogSection::find()->published()->andWhere(["code" => $section])->one();
     $this->view->addBreadCrumbs($sectionModel->getBreadCrumbsItems($sectionModel, function ($model) {
         return ['/catalog/catalog/index', 'section' => $model->code];
     }));
     $this->view->addBreadCrumb(["label" => $model->title, "url" => Url::toRoute(["/catalog/catalog/detail", "code" => $code, "section" => $section])]);
     $this->view->registerMetaTags($model);
     return $this->render('detail', ["model" => $model, "detailImageWidth" => $this->detailImageWidth]);
 }