Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id, $className = null)
 {
     $query = Image::find()->where(['itemId' => $id]);
     if ($className) {
         $query->andWhere(['modelName' => StringHelper::basename($className)]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['position' => SORT_DESC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'name' => $this->name]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Returns a model's image with a specific identifier
  * 
  * @param   string  $identifier     The identifier of the image
  * @return  array|null|ActiveRecord
  */
 public function getImageByIdentifier($identifier = '', $fallbackToPlaceholder = true, $placeHolderPath = null)
 {
     if ($identifier == '') {
         return $this->owner->getImage($fallbackToPlaceholder, $placeHolderPath);
     }
     if ($this->getModule()->className === null) {
         $imageQuery = Image::find();
     } else {
         $class = $this->getModule()->className;
         $imageQuery = $class::find();
     }
     $finder = $this->getImagesFinder(['identifier' => $identifier]);
     $imageQuery->where($finder);
     $img = $imageQuery->one();
     if (!$img && $fallbackToPlaceholder) {
         if (!$placeHolderPath) {
             return new PlaceHolder();
         } else {
             return new Image(['filePath' => basename(Yii::getAlias($placeHolderPath)), 'urlAlias' => basename($placeHolderPath)]);
         }
     }
     return $img;
 }
 /**
  *
  *
  * @param string $id
  * @return mixed
  */
 public function actionSort()
 {
     $gallery = Gallery::findOne(Yii::$app->session->get('gallery.gallery-id'));
     $images = Image::find()->where(['itemId' => $gallery->id, 'modelName' => 'Gallery'])->orderBy(['position' => SORT_DESC])->all();
     return $this->render('sort', ['gallery' => $gallery, 'images' => $images]);
 }
 /**
  *
  *
  * @param string $id
  * @return mixed
  */
 public function actionSort($sliderId)
 {
     $slider = Slider::findOne($sliderId);
     $images = Image::find()->where(['itemId' => $slider->id, 'modelName' => 'Slider'])->orderBy(['position' => SORT_DESC])->all();
     return $this->render('sort', ['slider' => $slider, 'images' => $images]);
 }