コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $allReservations = DB::table('reservations')->where('artwork_id', '=', Input::get('artwork-id'))->get();
     $reservation = new Reservation();
     $reservation->user_id = Auth::user()->id;
     $reservation->artwork_id = Input::get('artwork-id');
     $reservation->from_date = Input::get('from-date');
     $reservation->to_date = Input::get('to-date');
     $reservation->delivery_adress = Input::get('delivery_adress');
     $artwork = Artwork::findOrFail(Input::get('artwork-id'));
     $overlap = false;
     foreach ($allReservations as $key) {
         if (Input::get('from-date') < $key->to_date && Input::get('from-date') > $key->from_date) {
             $overlap = true;
         } elseif (Input::get('to-date') > $key->from_date && Input::get('to-date') < $key->to_date) {
             $overlap = true;
         } elseif (Input::get('from-date') == $key->from_date) {
             $overlap = true;
         }
     }
     if (!$overlap) {
         $artwork->reserved += 1;
         $reservation->save();
         $artwork->update(['reserved' => $artwork->reserved]);
         return Response::json([0 => 'Reservering geslaagd. Klik <a href="/gallery">hier</a> om terug te gaan'], HttpCode::Ok);
     } else {
         $latest = "";
         foreach ($allReservations as $key) {
             if (is_null($latest)) {
                 $latest = $key->to_date;
             } elseif ($key->to_date > $latest) {
                 $latest = $key->to_date;
             }
         }
         return Response::json([0 => 'Het kunstwerk is al gereserveerd op deze datum.'], HttpCode::Conflict);
     }
 }
コード例 #2
0
 public function archive($id)
 {
     if (Auth::check() && Auth::user()->hasOnePrivelege(['Moderator', 'Administrator'])) {
         $artwork = Artwork::findOrFail($id);
         if ($artwork->state === 0) {
             $artwork->state = 1;
             $artwork->save();
             return Redirect()->action('ArtworkController@showArchived');
         } else {
             $artwork->state = 0;
             $artwork->save();
             return Redirect()->action('ArtworkController@index');
         }
     } else {
         return View::make('errors/' . HttpCode::NotFound);
     }
 }