Пример #1
0
 public function actionA($a)
 {
     if (($category = Categories::find()->where(['alias' => $a, 'app_id' => $this->app->id])->one()) !== null) {
         // материал дефолтного приложения по алиасу
         return $this->renderCategory($category);
     } elseif (($model = $this->app->getItems()->where([Items::tablename() . '.alias' => $a])->orWhere([Items::tablename() . '.id' => $a])->one()) !== null) {
         // материал дефолтного приложения по алиасу
         return $this->renderItem($model);
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
Пример #2
0
 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;
 }
Пример #3
0
 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();
 }
Пример #4
0
 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 '#';
 }
Пример #5
0
 public function getItems()
 {
     return $this->hasMany(Items::className(), ['app_id' => 'id'])->inverseOf('app')->where([Items::tablename() . '.state' => 1]);
 }