Beispiel #1
0
 public static function addMedia($fileName, $objType, $user_id, $route)
 {
     $file = Input::file($fileName);
     $currentMo = date('Y_M');
     $destination = "uploads/{$currentMo}";
     $filename = $file->getClientOriginalName();
     $filename = Exhibit::string_convert($filename);
     // $cleanFilename = Exhibit::permalink($filename);
     // Move the new file into the uploads directory
     $uploadSuccess = $file->move($destination, "{$filename}");
     $imgOrigDestination = $destination . '/' . $filename;
     // Check to make sure that upload was successful and add the content
     if ($uploadSuccess) {
         $imageMinDestination = $destination . '/min_' . $filename;
         $imageMin = Image::make($imgOrigDestination)->crop(250, 250, 10, 10)->save($imageMinDestination);
         // Saves the media and adds the appropriate foreign keys for the exhibit
         $media = $objType->media()->create(['user_id' => $user_id, 'img_min' => $imageMinDestination, 'img_big' => $imgOrigDestination]);
         $objType->media()->save($media);
         return $media->id;
     } else {
         if ($route == 'back') {
             return Redirect::back()->with('status', 'alert-error')->with('global', 'Something went wrong with uploading your photos.');
         }
         return Redirect::route($route)->with('status', 'alert-error')->with('global', 'Something went wrong with uploading your photos.');
     }
 }
 /**
  * Huge method for analyzing Exhibit forms.
  * @todo change this method so that it puts and updates
  */
 public function postAdd()
 {
     // --- Find Object by ID --- //
     $exhibit = Exhibit::find(Input::get('id'));
     // --- Validate Input Values --- //
     $validator = Validator::make(array('title' => Input::get('title'), 'video' => Input::get('video')), Exhibit::$rules);
     if ($validator->fails()) {
         if (!count($exhibit)) {
             return Redirect::route('exhibits-add')->withErrors($validator)->withInput();
         } else {
             return Redirect::to('exhibits/' . $exhibit->id . '/edit')->withErrors($validator)->withInput();
         }
     }
     // --- Validate Images if being sent --- //
     // -- per non-ajax request --- //
     if (Input::hasFile('file')) {
         $files = Input::file('file');
         foreach ($files as $file) {
             $rules = array('file' => 'mimes:png,gif,jpeg|max:20000');
             $validator = Validator::make(array('file' => $file), $rules);
             if ($validator->fails()) {
                 return Redirect::route('exhibits-add')->withErrors($validator)->withInput();
             }
         }
     }
     // --- Update Object --- //
     $user_id = Auth::user()->id;
     $cleanTitle = Exhibit::permalink(Input::get('title'));
     $exhibit = Exhibit::findOrCreate(Input::get('id'));
     $exhibit->update(array('user_id' => $user_id, 'title' => Input::get('title'), 'permalink' => $cleanTitle, 'details' => Input::get('details'), 'video' => Input::get('video'), 'published' => (bool) Input::get('published'), 'autodraft' => false));
     $mediaIDs = array();
     // --- Creates Media for the Object --- //
     // -- for non-ajax request --- //
     if ($exhibit) {
         $exhibit->save();
         if (Input::hasFile('file')) {
             $files = Input::file('file');
             foreach ($files as $file) {
                 $currentMo = date('Y_M');
                 $destination = "uploads/{$currentMo}";
                 $filename = $file->getClientOriginalName();
                 $filename = Exhibit::string_convert($filename);
                 // $cleanFilename = Exhibit::permalink($filename);
                 // Move the new file into the uploads directory
                 $uploadSuccess = $file->move($destination, "{$filename}");
                 $imgOrigDestination = $destination . '/' . $filename;
                 // Check to make sure that upload was successful and add the content
                 if ($uploadSuccess) {
                     $imageMinDestination = $destination . '/min_' . $filename;
                     $imageMin = Image::make($imgOrigDestination)->crop(250, 250, 10, 10)->save($imageMinDestination);
                     // Saves the media and adds the appropriate foreign keys for the exhibit
                     $media = $exhibit->media()->create(['user_id' => $user_id, 'img_min' => $imageMinDestination, 'img_big' => $imgOrigDestination]);
                     $exhibit->media()->save($media);
                     $mediaIDs[] = $media->id;
                 }
             }
         }
         // --- Creates Sortable Media Group --- //
         // -- for non-ajax request --- //
         $exhibit->media_ids = json_encode($mediaIDs);
         $exhibit->save();
         return Redirect::route('exhibits-show-single', $exhibit->permalink)->with('status', 'alert-success')->with('global', 'You have successfully created an exhibit.');
     }
 }