public function getPhotos() { if (!$this->_photos) { $this->_photos = []; foreach (Photo::find()->where(['class' => NewsModel::className(), 'item_id' => $this->id])->sort()->all() as $model) { $this->_photos[] = new PhotoObject($model); } } return $this->_photos; }
public function photos($options = []) { if (!$this->_photos) { $this->_photos = []; $query = Photo::find()->where(['class' => Category::className(), 'item_id' => $this->id])->sort(); if (!empty($options['where'])) { $query->andFilterWhere($options['where']); } $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => !empty($options['pagination']) ? $options['pagination'] : []]); foreach ($this->_adp->models as $model) { $this->_photos[] = new PhotoObject($model); } } return $this->_photos; }
private function findAlbum($id_slug) { $album = Album::find()->where(['or', 'album_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->one(); if (!$album) { return $this->notFound($id_slug); } if ($album->status != Album::STATUS_ON) { return Yii::$app->user->isGuest ? $this->createObject('') : $this->createObject($this->errorText('ALBUM IS OFF')); } $this->_adp = new ActiveDataProvider(['query' => Photo::find()->where(['model' => Album::className(), 'item_id' => $album->primaryKey])->sort(), 'pagination' => ['pageSize' => $this->_albumOptions['pageSize']]]); $albumObject = $this->parseAlbum($album); $albumObject->photos = $this->parsePhotos($this->_adp->models); $albumObject->seo_h1 = $album->seo_h1; $albumObject->seo_title = $album->seo_title; $albumObject->seo_keywords = $album->seo_keywords; $albumObject->seo_description = $album->seo_description; return $albumObject; }
public function api_last($limit = 1, $where = null) { if ($limit === 1 && $this->_last) { return $this->_last; } $result = []; $query = Photo::find()->where(['class' => Category::className()])->sort()->limit($limit); if ($where) { $query->andWhere($where); } foreach ($query->all() as $item) { $photoObject = new PhotoObject($item); $photoObject->rel = 'last'; $result[] = $photoObject; } if ($limit > 1) { return $result; } else { $this->_last = count($result) ? $result[0] : null; return $this->_last; } }
public function run() { $photos = Photo::find()->where(['model' => get_class($this->model), 'item_id' => $this->model->primaryKey])->sort()->all(); echo $this->render('photos', ['photos' => $photos]); }
public static function findWithPhotoCount() { return self::find()->select([self::tableName() . '.*', 'COUNT(p.photo_id) as photo_count'])->join('LEFT JOIN', ['p' => Photo::find()->where(['model' => Album::className()])], self::tableName() . '.album_id = p.item_id')->groupBy(self::tableName() . '.album_id'); }
public function getPhotos($index = null) { 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); } } if (is_numeric($index)) { if (isset($this->_photos[$index])) { return $this->_photos[$index]; } else { return null; } } return $this->_photos; }