Esempio n. 1
0
 public function items($options = [])
 {
     if (!$this->_items) {
         $this->_items = [];
         //$with = ['seo'];
         $with = [];
         if (Yii::$app->getModule('populac')->activeModules['article']->settings['enableTags']) {
             $with[] = 'tags';
         }
         //$query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sortDate();
         $query = Item::find()->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sort();
         if (!empty($options['where'])) {
             $query->andFilterWhere($options['where']);
         }
         if (!empty($options['tags'])) {
             $query->innerJoinWith('tags', false)->andWhere([Tag::tableName() . '.name' => (new Item())->filterTagValues($options['tags'])])->addGroupBy('item_id');
         }
         $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]);
         foreach ($this->_adp->models as $model) {
             $this->_items[] = new ArticleObject($model);
         }
     }
     return $this->_items;
 }
Esempio n. 2
0
 private function findItem($id_slug)
 {
     $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one();
     if ($article) {
         $article->updateCounters(['views' => 1]);
         return new ArticleObject($article);
     } else {
         return null;
     }
 }