Пример #1
0
 /**
  * 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]);
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->category_id) {
         throw new InvalidConfigException('The "category_id" property must be set.');
     }
     $query = Catalog::find()->select(['id', 'title', 'cost', 'category_id'])->where(['category_id' => $this->category_id]);
     $this->categoryAttributes = CatalogAttributes::find()->where(['category_id' => $this->category_id])->orderBy('id')->all();
     $query = (new \yii\db\Query())->select(['t.id', 't.title', 't.cost', 't.category_id'])->from(['t' => $query]);
     foreach ($this->categoryAttributes as $x) {
         $query->addSelect([$x->code . '.value as ' . $x->code]);
         $query->leftJoin([$x->code => (new \yii\db\Query())->from(CatalogValues::tableName())], $x->code . '.catalog_id = t.id and ' . $x->code . '.attribute_id = ' . $x->id);
         $query->addSelect(['categoryAttribute[' . $x->id . ']' => 'categoryAttribute[' . $x->id . '].value']);
         $query->leftJoin(['categoryAttribute[' . $x->id . ']' => (new \yii\db\Query())->from(CatalogValues::tableName())], ['categoryAttribute[' . $x->id . '].catalog_id' => 't.id', 'categoryAttribute[' . $x->id . '].attribute_id' => $x->id]);
     }
     $query = (new \yii\db\Query())->select(['t.*'])->from(['t' => $query]);
     $this->query = $query;
     parent::init();
 }
Пример #3
0
 public function actionIndex()
 {
     $model = Catalog::find()->all();
     return $this->render('index', ['model' => $model]);
 }
Пример #4
0
 /**
  * Отображение карточки элемента каталога
  * @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]);
 }