public function actionIndex($action = null, $gallery_groups_id = null)
 {
     $gallery_types = GalleryTypes::find()->where(['visible' => 1])->orderBy(['comment' => SORT_ASC])->all();
     $gallery_groups = GalleryGroups::find()->innerJoinWith('galleryType')->where(['visible' => 1])->orderBy(['id' => SORT_DESC])->all();
     $gallery_group = false;
     if ($action) {
         if ($action == 'add') {
             $gallery_group = new GalleryGroups();
             $gallery_group->gallery_types_id = Yii::$app->request->get('gallery_types_id');
         } else {
             if ($action == 'ch' && $gallery_groups_id) {
                 $gallery_group = GalleryGroups::find()->where(['id' => $gallery_groups_id])->one();
             }
         }
         if ($gallery_group->load(Yii::$app->request->post()) && $gallery_group->save()) {
             return $this->redirect(['', 'action' => 'ch', 'gallery_groups_id' => $gallery_group->id]);
         }
     }
     return $this->render('gallery', ['gallery_types' => $gallery_types, 'gallery_groups' => $gallery_groups, 'gallery_group' => $gallery_group]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGalleryType()
 {
     return $this->hasOne(GalleryTypes::className(), ['id' => 'gallery_types_id']);
 }
Exemple #3
0
 public function saveImage($src_image, $gallery_types_id, $gallery_groups_id)
 {
     $type = GalleryTypes::find()->where(['id' => $gallery_types_id])->asArray()->one();
     $gallery = new Gallery();
     $size = $gallery->getSize($src_image, $type);
     $path = Yii::getAlias('@frontend/web') . $type['destination'];
     if (!is_dir($path)) {
         $helper = new Helpers();
         $helper->makeDirectory($path);
     }
     $file_info = new \SplFileInfo($src_image);
     $image_small = $gallery->renderFilename($path, $file_info->getExtension());
     $image_large = $gallery->renderFilename($path, $file_info->getExtension());
     Image::thumbnail($src_image, $size['small_width'], $size['small_height'])->save($path . '/' . $image_small . '.' . $file_info->getExtension(), ['quality' => $type['quality']]);
     Image::thumbnail($src_image, $size['large_width'], $size['large_height'])->save($path . '/' . $image_large . '.' . $file_info->getExtension(), ['quality' => $type['quality']]);
     return ['small' => $type['destination'] . '/' . $image_small . '.' . $file_info->getExtension(), 'large' => $type['destination'] . '/' . $image_large . '.' . $file_info->getExtension(), 'seq' => $gallery->getLastSequence($gallery_groups_id) + 1];
 }