public function actionAbc($a, $b, $c) { if (($app = Applications::find()->where(['name' => $a])->one()) !== null) { if (($parent_cat = Categories::find()->where(['app_id' => $app->id, 'alias' => $b])->one()) !== null) { // приложение -> категория по алиасу if (($category = Categories::find()->where(['app_id' => $app->id, 'parent_id' => $parent_cat->id, 'alias' => $c])->one()) !== null) { return $this->renderCategory($category); } elseif (($model = Items::find()->where(['app_id' => $app->id, 'alias' => $c])->one()) !== null) { // приложение -> материал по алиасу return $this->renderItem($model); } elseif (($model = Items::find()->where(['app_id' => $app->id, 'id' => $c])->one()) !== null) { // приложение -> материал по ID return $this->renderItem($model); } } } else { if (($category = Categories::find()->where(['app_id' => 1, 'alias' => $a])->one()) !== null) { if (($model = Items::find()->where(['app_id' => 1, 'alias' => $b])->one()) !== null && $model->parentCategory->alias == $a) { // приложение -> материал по алиасу return $this->renderItem($model); } elseif (($model = Items::find()->where(['app_id' => 1, 'id' => $b])->one()) !== null && $model->parentCategory->alias == $a) { // приложение -> материал по ID return $this->renderItem($model); } } // категория дефолтного приложения -> материал } throw new NotFoundHttpException('The requested page does not exist.'); }
public function getCategories() { $categories = $this->hasMany(Categories::className(), ['app_id' => 'id'])->where(['state' => 1]); if (count(Yii::$app->zoo->languages) > 1) { $categories->andWhere(['lang' => Yii::$app->zoo->lang]); } return $categories->orderBy('sort ASC')->inverseOf('app'); }
public function getCategory($redirect = false) { $category_id = Yii::$app->request->get('category'); $category = Categories::findOne($category_id); if ($category === null && $redirect) { Yii::$app->getSession()->setFlash('warning', Yii::t('backend', 'Категория не существует')); return $this->redirect(['categories']); } elseif ($category === null) { return new Categories(); } return $category; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Categories::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type' => $this->type, 'parent_id' => $this->parent_id, 'app_id' => $this->app_id, 'sort' => $this->sort, 'state' => $this->state, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'params', $this->params]); return $dataProvider; }
public function search($params = null) { if ($params !== null) { $this->load($params); } $this->query = $this->app->getItems()->with(['itemsElements', 'app'])->joinWith(['categories']); $this->query->andFilterWhere([Categories::tablename() . '.id' => $this->categoryTree($this->category)]); foreach ($this->elements as $element) { $e = $element->name; if (!in_array($e, $this->attributes()) && ($element->filter || $element->search || $e == $this->app->defaultOrder)) { $value = $this->{$e}; if ($e == $this->app->defaultOrder || (is_array($value) && count($value) > 0 || !is_array($value) && !empty($value))) { $this->query->leftJoin([$e => ItemsElements::tablename()], $e . ".item_id = " . Items::tablename() . ".id AND " . $e . ".element = '" . $e . "'"); $this->query->andFilterWhere([$e . '.value_string' => $value]); } } } if (!empty($this->search)) { $this->query->select(Items::tablename() . '.*, MATCH (node) AGAINST (:text) as REL')->andWhere('MATCH (node) AGAINST (:text)', [':text' => $this->search]); } return $this->query; }
public function getParent() { return $this->hasOne(Categories::className(), ['id' => 'parent_id'])->orderBy('sort ASC'); }
<?php echo Html::activeDropDownList($model, $attribute . '[0]', $parent_categories, ['id' => 'item-' . $attribute, 'prompt' => 'выбрать из списка', 'class' => 'uk-width-1-1 category-select']); ?> <?php if (count($model->category)) { ?> <?php $i = 0; foreach ($model->category as $key => $category_id) { ?> <?php if ($category_id > 0) { ?> <?php $related_cats = ArrayHelper::map(\worstinme\zoo\models\Categories::find()->where(['parent_id' => $category_id])->all(), 'id', 'name'); ?> <?php if (count($related_cats)) { $i++; ?> <div class="related-category-select uk-margin-top"> <?php echo Html::activeDropDownList($model, $attribute . '[' . ($key + 1) . ']', $related_cats, ['prompt' => 'выбрать из списка', 'class' => 'uk-width-1-1 category-select']); ?> <?php } ?> <?php }
public function getCategories() { return $this->hasMany(Categories::className(), ['id' => 'category_id'])->viaTable('{{%zoo_items_categories}}', ['item_id' => 'id']); }
public function getUrl() { if ($this->type == 4) { return \yii\helpers\Json::decode($this->url); } elseif ($this->type == 5) { return $this->url; } elseif ($this->type == 1) { if (($application = Applications::findOne($this->application_id)) !== null) { return $application->url; } } elseif ($this->type == 2) { if (($category = Categories::findOne($this->category_id)) !== null) { return $category->url; } } elseif ($this->type == 3) { $item = Items::find()->where([Items::tablename() . '.id' => $this->item_id])->one(); if ($item !== null) { return $item->url; } } return '#'; }