コード例 #1
0
 public function destroy($kitTypeID)
 {
     // This Shall be fun!
     // We have to deconstruct the types based on the forign key dependencys
     // First iterate all the kits, for each kit remove all contents,
     // and then all bookings (and all booking details)
     // then finally we can remove the kit type and then all the logs for that
     // kit type.
     foreach (Kits::where('KitType', '=', $kitTypeID)->get() as $kit) {
         foreach (KitContents::where("KitID", '=', $kit->ID)->get() as $content) {
             KitContents::destroy($content->ID);
         }
         foreach (Booking::where("KitID", '=', $kit->ID)->get() as $booking) {
             foreach (BookingDetails::where("BookingID", '=', $booking->ID)->get() as $detail) {
                 BookingDetails::destroy($detail->ID);
             }
             Booking::destroy($booking->ID);
         }
         Kits::destroy($kit->ID);
     }
     KitTypes::destroy($kitTypeID);
     // Do the logs last, as all the deletes will log the changes of deleting the bits.
     Logs::where('LogKey1', '=', $kitTypeID)->delete();
     return "OK";
 }
コード例 #2
0
 public function getAvailableKit()
 {
     if (!Request::ajax()) {
         return "not a json request";
     }
     $post = Input::all();
     $kitsOfType = Kits::where('Available', '1')->where('KitType', $post['KitTypeID'])->orderBy('Specialized', 'asc')->get();
     foreach ($kitsOfType as $kit) {
         $query = "select B.ID " . "from Booking as B " . "inner join Kits as K " . "on B.KitID = K.ID " . "where B.KitID = " . $kit->ID . " " . "and (" . "('" . $post['StartDate'] . "' between CAST(B.StartDate as Date) and CAST(B.EndDate as Date)) " . "or ('" . $post['EndDate'] . "' between CAST(B.StartDate as Date) and CAST(B.EndDate as Date))" . ")";
         $bookings = DB::select(DB::raw($query));
         if (intval(count($bookings)) == 0) {
             return $kit;
         }
     }
     return "";
 }