コード例 #1
0
ファイル: dashboard.php プロジェクト: jvillasante/cubanartjb
 public function post_slideshow($num)
 {
     $input = Input::all();
     if (empty($input["image{$num}"])) {
         $image = DB::table('slideshow_images')->where('number', '=', $num)->first();
         if ($image) {
             $affected = DB::table('slideshow_images')->where('number', '=', $num)->delete();
             if ($affected) {
                 $directory = path('public') . 'uploads/slideshow/' . sha1("image{$num}");
                 File::rmdir($directory);
             }
             return Redirect::to(URL::to_route('dashboard.slideshow'))->with('status_success', __('application.slideshow_deleted'));
         }
     }
     try {
         $validator = new Services\Dashboard\Slideshow\Validator($input, $num);
         $validator->publish();
     } catch (ValidateException $errors) {
         return Redirect::to(URL::to_route('dashboard.slideshow'))->with_input()->with_errors($errors->get());
     }
     $errors = new Laravel\Messages();
     $extension = File::extension($input["image{$num}"]['name']);
     $directory = path('public') . 'uploads/slideshow/' . sha1("image{$num}");
     $filename = "original.{$extension}";
     $upload_success = ImageUtils::upload_slideshow("image{$num}", $directory, $filename);
     $image_path = URL::base() . '/uploads/slideshow/' . sha1("image{$num}");
     if ($upload_success) {
         $image = DB::table('slideshow_images')->where('number', '=', $num)->first();
         if ($image) {
             DB::table('slideshow_images')->where('number', '=', $num)->update(array('image_path' => $image_path));
         } else {
             DB::table('slideshow_images')->insert(array('number' => $num, 'image_path' => $image_path));
         }
         return Redirect::to(URL::to_route('dashboard.slideshow'))->with('status_success', __('application.slideshow_added'));
     } else {
         $errors->add('errors', __('application.generic_error'));
         return Redirect::to(URL::to_route('dashboard.slideshow'))->with_input()->with_errors($errors);
     }
 }