public function actionSwitchShow($id)
 {
     /* @var GalleryAlbum $album */
     $album = GalleryAlbum::findOne($id);
     if (!empty($album)) {
         $album->show = !$album->show;
         $album->save();
     }
     return $this->goBack(Url::to(['list']));
 }
 public function run($id = null, $langId = null)
 {
     /* @var GalleryAlbum $album */
     /* @var GalleryAlbumTranslation $albumTranslation */
     $language = $langId == null ? Language::getDefault() : Language::findOne($langId);
     if (empty($id)) {
         $album = new GalleryAlbum();
         $album->show = true;
         $albumTranslation = new GalleryAlbumTranslation();
     } else {
         $album = GalleryAlbum::findOne($id);
         if (empty($album)) {
             return $this->controller->redirect('/gallery/album/list');
         }
         $albumTranslation = $album->getTranslation($language->id);
         if (empty($albumTranslation)) {
             $albumTranslation = new GalleryAlbumTranslation();
         }
     }
     if (Yii::$app->request->isPost) {
         $post = Yii::$app->request->post();
         if ($album->load($post) && $albumTranslation->load($post)) {
             $album->image_file = UploadedFile::getInstance($album, 'image_file');
             if (!empty($album->image_file)) {
                 try {
                     // save image
                     $fileName = $this->generateFileName($album->image_file->baseName);
                     $imagine = new Imagine();
                     $imagine->open($album->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'));
                     $album->image_name = $fileName;
                 } catch (\Exception $ex) {
                     die($ex);
                     $album->addError('image_file', 'File save failed');
                 }
             }
             if ($album->validate() && $albumTranslation->validate()) {
                 $album->save();
                 $albumTranslation->album_id = $album->id;
                 $albumTranslation->language_id = $language->id;
                 $albumTranslation->save();
                 $this->controller->redirect(['edit', 'id' => $album->id, 'langId' => $language->id]);
             }
         }
     }
     return $this->controller->render('create-edit', ['album' => $album, 'albumTranslation' => $albumTranslation, '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]);
 }
Example #4
0
 /**
  * Creates a URL according to the given route and parameters.
  * @param UrlManager $manager the URL manager
  * @param string $route the route. It should not have slashes at the beginning or the end.
  * @param array $params the parameters
  * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL.
  */
 public function createUrl($manager, $route, $params)
 {
     if ($route == $this->albumsRoute) {
         if (empty($params['id'])) {
             return $this->prefix;
         } else {
             $id = $params['id'];
             $language = Language::findOne(['lang_id' => $manager->language]);
             $album = GalleryAlbum::findOne($id);
             if ($album) {
                 $translation = $album->getTranslation($language->id);
                 if (!empty($translation)) {
                     if (!empty($translation->seoUrl)) {
                         return $this->prefix . '/' . $translation->seoUrl;
                     }
                 }
             }
         }
     }
     return false;
 }