Наследование: extends rico\yii2images\models\Image
Пример #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;
 }
Пример #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;
 }
 /**
  * Set as main image
  * @param string $id
  * @return mixed
  */
 public function actionMain()
 {
     // Reset previous main image
     Image::updateAll(['isMain' => 0], ['isMain' => 1, 'itemId' => Yii::$app->session->get('gallery.gallery-id'), 'modelName' => StringHelper::basename(Gallery::className())]);
     // Set new main image
     $model = $this->findModel(Yii::$app->request->post('id'));
     $model->isMain = 1;
     $model->active = 1;
     return $model->save();
 }
 /**
  * Finds the Image model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Image the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Image::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested item does not exist'));
     }
 }
 /**
  * Get the popup image for images gridview
  *
  * @return string
  */
 public function getPopupImage($id = null)
 {
     $image = Image::findOne($id);
     return '<a class="fancybox" data-pjax="0" rel="fancybox" href="' . $image->getUrl("{$this->width}x{$this->height}") . '"><img src="' . $image->getUrl('80x80') . '" /></a>';
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImage()
 {
     return $this->hasOne(Image::className(), ['id' => 'image_id']);
 }