public function getPhotos() { if (!$this->_photos) { $this->_photos = []; foreach (Photo::find()->where(['class' => Item::className(), 'item_id' => $this->id])->sort()->all() as $model) { $this->_photos[] = new PhotoObject($model); } } return $this->_photos; }
public function items($options = []) { if (!$this->_items) { $this->_items = []; $with = ['seo']; if (Yii::$app->getModule('admin')->activeModules['bookmark']->settings['enableTags']) { $with[] = 'tags'; } $query = Item::find()->with('seo')->where(['category_id' => $this->id])->status(Item::STATUS_ON)->sortDate(); 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; }
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; } }