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]);
 }
示例#2
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  * @throws NotFoundHttpException
  */
 public function parseRequest($manager, $request)
 {
     $this->currentLanguage = Language::getCurrent();
     $this->pathInfo = $request->getPathInfo();
     if ($this->pathInfo == $this->albumsRoute) {
         if ($this->disableDefault) {
             throw new NotFoundHttpException();
         }
         if (!empty($request->getQueryParams()['id'])) {
             $id = $request->getQueryParams()['id'];
             $album = GalleryAlbum::findOne($id);
             if (!$album) {
                 return false;
             }
             $translation = $album->getTranslation($this->currentLanguage->id);
             if ($translation) {
                 if (!empty($translation->seoUrl)) {
                     throw new NotFoundHttpException();
                 }
             }
         }
     }
     if (!empty($this->prefix)) {
         if (strpos($this->pathInfo, $this->prefix) === 0) {
             $this->pathInfo = substr($this->pathInfo, strlen($this->prefix));
         } else {
             return false;
         }
     }
     $this->initRoutes($this->pathInfo);
     if (!empty($this->prefix) && $this->routesCount == 1) {
         return [$this->albumsRoute, []];
     } else {
         if ($this->routesCount == 2) {
             $seoUrl = $this->routes[1];
             /* @var SeoData $seoData */
             $seoData = SeoData::find()->where(['entity_name' => GalleryAlbumTranslation::className(), 'seo_url' => $seoUrl])->one();
             if ($seoData) {
                 /* @var GalleryAlbum $album */
                 $album = GalleryAlbum::find()->joinWith('translations translation')->where(['translation.id' => $seoData->entity_id, 'translation.language_id' => $this->currentLanguage->id])->one();
                 if ($album) {
                     return [$this->albumsRoute, ['id' => $album->id]];
                 }
             }
         }
     }
     return false;
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTranslations()
 {
     return $this->hasMany(GalleryAlbumTranslation::className(), ['album_id' => 'id']);
 }
示例#4
0
                            </ul>
                        <?php 
    }
    ?>
                    </div>
                <?php 
}
?>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-md-8">
                        <div class="row">
                            <div class="col-md-12">
                                <?php 
echo $form->field($image, 'album_id', ['inputOptions' => ['class' => 'form-control']])->dropDownList(['' => '-- ' . Yii::t('blcms-gallery/backend/image', 'no album') . ' --'] + ArrayHelper::map(GalleryAlbumTranslation::find()->groupBy('album_id')->all(), 'album_id', 'title'));
?>
                            </div>
                            <div class="col-md-12">
                                <?php 
echo $form->field($imageTranslation, 'title', ['inputOptions' => ['class' => 'form-control']]);
?>
                            </div>
                            <div class="col-md-12">
                                <?php 
echo $form->field($imageTranslation, 'alt', ['inputOptions' => ['class' => 'form-control']]);
?>
                            </div>
                            <div class="col-md-12">
                                <?php 
echo $form->field($image, 'show')->checkbox(['class' => 'i-checks']);