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 #3
0
echo $form->field($albumTranslation, 'title', ['inputOptions' => ['class' => 'form-control']]);
?>
                            </div>
                            <div class="col-md-12">
                                <?php 
echo $form->field($album, 'show')->checkbox(['class' => 'i-checks']);
?>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <?php 
if (!empty($album->image_name)) {
    ?>
                            <?php 
    echo Html::img(GalleryAlbum::getImageSrc($album->image_name, 'thumb'), ['class' => 'img-thumbnail']);
    ?>
                        <?php 
}
?>
                        <?php 
echo $form->field($album, 'image_file')->fileInput();
?>
                    </div>
                </div>
                <?php 
echo Html::submitButton(Yii::t('blcms-gallery/backend/album', 'Save Album'), ['class' => 'btn btn-primary pull-right']);
?>
            </div>
        </div>
    </div>
 public function actionRemove($id)
 {
     GalleryAlbum::deleteAll(['id' => $id]);
     return $this->goBack(Url::to(['list']));
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAlbum()
 {
     return $this->hasOne(GalleryAlbum::className(), ['id' => 'album_id']);
 }
Example #6
0
    ?>
</th>
                                    <th><?php 
    echo Yii::t('blcms-gallery/backend/main', 'Delete');
    ?>
</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
    foreach ($albums as $album) {
        ?>
                                    <tr>
                                        <td>
                                            <?php 
        echo Html::img(GalleryAlbum::getImageSrc($album->image_name, 'thumb'), ['height' => '50']);
        ?>
                                        </td>
                                        <td>
                                            <?php 
        echo $album->translation->title;
        ?>
                                        </td>
                                        <td>
                                            <?php 
        if (count($languages) > 1) {
            ?>
                                                <?php 
            $translations = ArrayHelper::index($album->translations, 'language_id');
            ?>
                                                <?php 
Example #7
0
 public function run()
 {
     return $this->controller->render('list', ['albums' => GalleryAlbum::find()->all()]);
 }
Example #8
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;
 }