public function run() { $model = new Items(); $query = Items::find()->where(['app_id' => $this->app_id, 'flag' => $this->flag ? 1 : 0]); if (count($this->categories)) { $query->leftJoin(['c' => '{{%zoo_items_categories}}'], 'c.item_id = {{%zoo_items}}.id'); $query->andFilterWhere(['c.category_id' => $this->categories]); } if (!empty($this->sort) && !in_array($this->sort, $model->attributes())) { $query->leftJoin(['e' => '{{%zoo_items_elements}}'], "e.item_id = {{%zoo_items}}.id AND e.element = '" . $this->sort . "'"); if ($this->desc) { $query->orderBy('e.value_int DESC, e.value_string DESC'); } else { $query->orderBy('e.value_int ASC, e.value_string ASC'); } } else { if ($this->desc) { $query->orderBy('{{%zoo_items}}.' . $this->sort . ' DESC'); } else { $query->orderBy('{{%zoo_items}}.' . $this->sort . ' ASC'); } } $items = $query->all(); return $this->render('last-items', ['items' => $items]); }
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 data($params) { $this->load($params); $query = $this->search(); if (!$this->validate()) { //print_r($this->errors); // $query = $this->query(); } $sort = ['defaultOrder' => [$this->app->defaultOrder => $this->app->defaultOrderDesc ? SORT_DESC : SORT_ASC]]; if (!empty($this->search)) { $sort['attributes']['rel'] = ['desc' => ['REL' => SORT_ASC], 'asc' => ['REL' => SORT_DESC], 'default' => SORT_ASC, 'label' => 'релевантности']; $sort['defaultOrder'] = ['rel' => SORT_ASC]; } $dataProvider = new ActiveDataProvider(['query' => $query->groupBy(Items::tablename() . '.id'), 'sort' => $sort, 'pagination' => ['defaultPageSize' => Yii::$app->controller->app->defaultPageSize]]); return $dataProvider; }
public function run() { if ($this->id !== null && ($item = Items::findOne($this->id)) !== null) { $teaser = \worstinme\zoo\helpers\TemplateHelper::render($item, 'teaser'); return "<div class='item item-teaser'>" . $teaser . "</div>"; } if ($this->ids !== null) { $ids = explode(",", $this->ids); $items = Items::find()->where(['id' => $ids])->all(); $html = null; if (count($items)) { $html .= '<div class="uk-grid uk-grid-width-medium-1-2 uk-grid-large uk-grid-match" data-uk-grid-margin>'; foreach ($items as $item) { $teaser = \worstinme\zoo\helpers\TemplateHelper::render($item, 'teaser'); $html .= "<div><div class='item item-teaser'>" . $teaser . "</div></div>"; } $html .= '</div>'; } return $html; } return null; }
public function getItems() { return $this->hasMany(Items::className(), ['id' => 'item_id'])->viaTable('{{%zoo_items_categories}}', ['category_id' => 'id']); }
public function itemIds($params) { $this->load($params); if ($this->withoutCategory) { $query = Items::find()->select(Items::tablename() . '.id')->where([Items::tablename() . '.app_id' => $this->app_id]); $query->andWhere(Items::tablename() . '.id NOT IN (SELECT DISTINCT item_id FROM {{%zoo_items_categories}} WHERE category_id > 0)'); } elseif (!empty($this->category) && count($this->category)) { $query = Items::find()->select(Items::tablename() . '.id'); $query->leftJoin(['category' => '{{%zoo_items_categories}}'], "category.item_id = " . Items::tablename() . ".id"); $query->andFilterWhere(['category.category_id' => $this->category]); } else { $query = Items::find()->select(Items::tablename() . '.id')->where([Items::tablename() . '.app_id' => $this->app_id]); } foreach ($this->elements as $element) { $e = $element->name; if (!in_array($e, $this->attributes) && $element->filter) { if (!is_array($this->{$e}) && $this->{$e} !== null || is_array($this->{$e}) && count($this->{$e}) > 0) { $query->leftJoin([$e => '{{%zoo_items_elements}}'], $e . ".item_id = " . Items::tablename() . ".id AND " . $e . ".element = '" . $e . "'"); $query->andFilterWhere([$e . '.value_string' => $this->{$e}]); } } } $query->andFilterWhere(['LIKE', Items::tablename() . '.name', $this->search]); return $query->groupBy(Items::tablename() . '.id')->column(); }
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 '#'; }
public function getItems() { return $this->hasMany(Items::className(), ['app_id' => 'id'])->inverseOf('app')->where([Items::tablename() . '.state' => 1]); }
/** * Finds the Item model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Item the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Items::find()->where(['id' => $id])->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getItems() { $items = ArrayHelper::map(Items::find()->joinWith(['categories'])->where(['category_id' => $this->relatedCategories])->all(), 'id', 'name'); return $items; }