예제 #1
0
 public function store(array $inputs)
 {
     $photoSerie_id = $inputs['serie_id'];
     $photoSerie = GallerySerie::where('id', '=', $photoSerie_id)->firstOrFail();
     $photoCategory = GalleryCategory::where('id', '=', $photoSerie['category_id'])->firstOrFail();
     $path = config('gallery.path') . $photoCategory['slug'] . '/' . $photoSerie['slug'];
     $first = GalleryImage::where('serie_id', '=', $photoSerie_id)->count();
     $first > 0 ? $first = 0 : ($first = 1);
     $valid = true;
     $files_count = 0;
     $uploads_count = 0;
     $files = Input::file('images');
     foreach ($files as $file) {
         // Validate each file
         $rules = array('file' => 'image');
         $validator = Validator::make(array('file' => $file), $rules);
         if ($validator->fails()) {
             $valid = false;
         }
         $files_count++;
     }
     if ($valid == true) {
         foreach ($files as $file) {
             $extension = $file->getClientOriginalExtension();
             $image = new GalleryImage(array('extension' => $extension, 'path' => $path, 'serie_id' => $photoSerie_id, 'first' => $first));
             $image->save();
             $id = GalleryImage::max('id');
             //On sauve le fichier
             $destinationPath = public_path() . $path;
             if (!is_dir($destinationPath)) {
                 mkdir($destinationPath, 0777, true);
             }
             $filename = $id . '.' . $extension;
             $file->move($destinationPath, $filename);
             $img = IntImage::make($destinationPath . '/' . $filename)->orientate();
             $img->save($destinationPath . '/' . $id . '.' . $extension);
             $img->resize(null, 125, function ($constraint) {
                 $constraint->aspectRatio();
             });
             $img->save($destinationPath . '/' . $id . '_thumb.' . $extension);
             $uploads_count++;
         }
     }
     if ($uploads_count == $files_count) {
         $result = 'ok';
     } elseif ($files_count == 0) {
         $result = 'nf';
         //no files selected
     } elseif ($valid == false) {
         $result = 'valid_fails';
         //some files are not images
     } else {
         $result = 'pb';
         // a problem occurred
     }
     return $result;
 }
예제 #2
0
 public function reposition()
 {
     if (\Request::has('item')) {
         $i = 0;
         foreach (\Request::get('item') as $id) {
             $i++;
             $item = GalleryImage::find($id);
             $item->position = $i;
             $item->save();
         }
         return \Response::json(array('success' => true));
     } else {
         return \Response::json(array('success' => false));
     }
 }