public function run($albumId = null)
 {
     $images = GalleryImage::find();
     if (!empty($albumId)) {
         $images->where(['album_id' => $albumId]);
     }
     $images = $images->all();
     return $this->controller->render('list', ['images' => $images]);
 }
 public function run($id = null, $langId = null)
 {
     /* @var GalleryImage $image */
     /* @var GalleryImageTranslation $imageTranslation */
     $language = $langId == null ? Language::getDefault() : Language::findOne($langId);
     if (empty($id)) {
         $image = new GalleryImage();
         $image->show = true;
         $imageTranslation = new GalleryImageTranslation();
     } else {
         $image = GalleryImage::findOne($id);
         if (empty($image)) {
             return $this->controller->redirect('/gallery/album/list');
         }
         $imageTranslation = $image->getTranslation($language->id);
         if (empty($imageTranslation)) {
             $imageTranslation = new GalleryImageTranslation();
         }
     }
     if (Yii::$app->request->isPost) {
         $post = Yii::$app->request->post();
         if ($image->load($post) && $imageTranslation->load($post)) {
             $image->image_file = UploadedFile::getInstance($image, 'image_file');
             if (!empty($image->image_file)) {
                 try {
                     // save image
                     $fileName = $this->generateFileName($image->image_file->baseName);
                     //                        die(\Imagick::getVersion());
                     $imagine = new Imagine();
                     $imagine->open($image->image_file->tempName)->save(Yii::getAlias($this->controller->module->imagesPath . '/' . $fileName . '-original.jpg'))->thumbnail(new Box(400, 400), ImageInterface::THUMBNAIL_OUTBOUND)->save(Yii::getAlias($this->controller->module->imagesPath . '/' . $fileName . '-thumb.jpg'));
                     $image->file_name = $fileName;
                 } catch (\Exception $ex) {
                     $image->addError('image_file', 'File save failed');
                 }
             }
             if ($image->validate() && $imageTranslation->validate()) {
                 $image->save();
                 $imageTranslation->image_id = $image->id;
                 $imageTranslation->language_id = $language->id;
                 $imageTranslation->save();
                 $this->controller->redirect(['edit', 'id' => $image->id, 'langId' => $language->id]);
             }
         }
     }
     return $this->controller->render('create-edit', ['image' => $image, 'imageTranslation' => $imageTranslation, 'currentLanguage' => $language]);
 }
 public function actionView($id = null)
 {
     $images = GalleryImage::find()->from('gallery_album_image image')->joinWith('album album')->where(['image.show' => true, 'album.show' => true]);
     $album = null;
     if (!empty($id)) {
         $album = GalleryAlbum::findOne($id);
         if (!empty($album)) {
             $images->andWhere(['album.id' => $id]);
             $albumTranslation = $album->translation;
             if (!empty($albumTranslation)) {
                 $this->view->title = $albumTranslation->seoTitle;
                 $this->view->registerMetaTag(['name' => 'description', 'content' => html_entity_decode($albumTranslation->seoDescription)]);
                 $this->view->registerMetaTag(['name' => 'keywords', 'content' => html_entity_decode($albumTranslation->seoKeywords)]);
             }
         }
     } else {
         $this->registerStaticSeoData();
     }
     return $this->render('view', ['album' => $album, 'images' => $images->all(), 'albums' => GalleryAlbum::findAll(['show' => true]), 'albumId' => $id]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImage()
 {
     return $this->hasOne(GalleryImage::className(), ['id' => 'image_id']);
 }
 public function actionRemove($id)
 {
     GalleryImage::deleteAll(['id' => $id]);
     return $this->goBack(Url::to(['list']));
 }