Example #1
0
 public function afterUpload($data)
 {
     ImageDropzone::saveThumbnail($this->uploadDir . '/', $data['filename'], $this->thumbnail_width, $this->thumbnail_height);
     $image = new AlbumImage(['album_id' => $data['params']['productId'], 'filename' => $data['filename'], 'image' => $data['src'] . $data['filename'], 'thumb' => $data['src'] . 'small-' . $data['filename'], 'description' => '', 'sort_order' => 50]);
     if ($image->save()) {
         return $image->toArray();
     } else {
         return $image->getErrors();
     }
 }
Example #2
0
 public function run($id)
 {
     $image = AlbumImage::findOne(['id' => $id]);
     if ($image) {
         $filename = $image->image;
         $thumbname = $image->thumb;
         if (AlbumImage::deleteAll(['id' => $id])) {
             if (unlink(\Yii::getAlias($this->uploadDir . $filename))) {
                 if (unlink(\Yii::getAlias($this->uploadDir . $thumbname))) {
                     Yii::$app->response->redirect(Yii::$app->request->referrer);
                 }
             }
         }
     }
     return false;
 }
 /**
  * Updates an existing Album model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (isset(Yii::$app->request->post()['imageSort'])) {
             foreach (Yii::$app->request->post()['imageSort'] as $key => $sortOrder) {
                 AlbumImage::updateAll(['sort_order' => $sortOrder], ['id' => $key]);
             }
         }
         $albumImage = AlbumImage::find()->where(['album_id' => $id])->orderBy(['sort_order' => SORT_ASC])->one();
         if ($albumImage) {
             $model->image = $albumImage->image;
             $model->thumb = $albumImage->thumb;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Example #4
0
 public function getImages()
 {
     return $this->hasMany(AlbumImage::className(), ['album_id' => 'id']);
 }