Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
     }
 }
Пример #4
0
 public function run()
 {
     $photos = Photo::find()->where(['class' => get_class($this->model), 'item_id' => $this->model->primaryKey])->sort()->all();
     echo $this->render('photos', ['photos' => $photos]);
 }