public function singleImagesUpdate()
 {
     $order = 0;
     if ($this->singleImageArray) {
         foreach ($this->singleImageArray as $field => $id) {
             $oldImages = Image::find()->where(['class' => $this->owner->className(), 'object_id' => $this->owner->id, 'field' => $field])->all();
             if ($oldImages) {
                 foreach ($oldImages as $oldImage) {
                     $oldImage->unsetit();
                 }
             }
             $img = Image::findOne($id);
             $img->object_id = $this->owner->id;
             $img->order = $order;
             $img->field = $field;
             $img->save();
             if (!$img->save()) {
                 print_r($img->getErrors());
             }
         }
     }
 }
 public function actionPreview()
 {
     $images = Image::find()->all();
     if ($images) {
         foreach ($images as $image) {
             $image->updatePreview();
             echo "updating {$image->id} <br>";
         }
     }
 }
Ejemplo n.º 3
0
 public function getImages()
 {
     if ($this->owner->id) {
         return Image::find()->orderBy('order')->where(['field' => null, 'object_id' => $this->owner->id, 'class' => \yii\helpers\StringHelper::basename(get_class($this->owner))])->all();
     }
 }