public function search() { $view = $this->getActionView(); $states = State::all(); $view->set('states', $states); $source = RequestMethods::get('source'); $source_state = State::first(array('id = ?' => $source)); $dest = RequestMethods::get('dest'); $dest_state = State::first(array('id = ?' => $dest)); $people = RequestMethods::get('people'); $start = RequestMethods::get('start'); $end = RequestMethods::get('end'); $drivers = CabDriver::all(array('state = ?' => RequestMethods::get('source'))); $startdate = strtotime($start); $enddate = strtotime($end); $today = strtotime(date('Y-m-d')); $i = 0; foreach ($drivers as $driver) { $bookings = CabBooking::all(array('driver_id = ?' => $driver->id)); $flag = 0; foreach ($bookings as $booking) { $booking_startdate = strtotime($booking->startdate); $booking_enddate = strtotime($booking->enddate); if ($startdate < $enddate) { $flag = 1; break; } if ($startdate < $today) { $flag = 1; break; } if ($startdate >= $booking_startdate && $enddate <= $booking_enddate || $startdate <= $booking_startdate && $enddate >= $booking_enddate || $startdate <= $booking_startdate && $enddate <= $booking_enddate && $enddate >= $booking_startdate || $startdate >= $booking_startdate && $startdate <= $booking_enddate && $enddate >= $booking_enddate) { $flag = 1; break; } } if ($driver->seater < RequestMethods::get('people')) { $flag = 1; } if ($flag == 0) { $available_drivers[$i] = $driver->id; $i++; } } $view->set('source', $source_state)->set('dest', $dest_state)->set('start', $start)->set('end', $end)->set('people', $people); if (!empty($available_drivers)) { $view->set('drivers', $available_drivers); foreach ($available_drivers as $driver) { $type_e = CabDriver::first(array('id = ?' => $driver)); if ($type_e->type == 'economy') { $view->set('type1', ''); break; } } foreach ($available_drivers as $driver) { $type_e = CabDriver::first(array('id = ?' => $driver)); if ($type_e->type == 'premium') { $view->set('type2', ''); break; } } } if ($this->user) { if (RequestMethods::post('car')) { foreach ($available_drivers as $driver) { $cab = CabDriver::first(array('id = ?' => $driver, 'car_name = ?' => RequestMethods::post('car'))); break; } if ($cab) { $booking = new CabBooking(array('user_id' => $this->user->id, 'driver_id' => $cab->id, 'startdate' => $start, 'enddate' => $end, 'startplace' => $source, 'endplace' => $dest)); if ($booking->validate()) { $booking->save(); header('/cab/confirmation/' . $booking->id); } } else { echo "<script> alert('Something went wrong') </script>"; } } } else { echo "<script> alert('login first') </script>"; } }
/** * @before _secure, changeLayout */ public function d_requests($imgid = '') { $this->seo(array("title" => "Dashboard", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (!empty($imgid)) { $ext = CabDriver::first(array('id = ?' => $imgid)); if (!empty($ext)) { $view->set('imgid', $imgid)->set('lic_img_ext', $ext->lic_img_ext)->set('v_ins_img_ext', $ext->v_ins_img_ext)->set('r_cer_img_ext', $ext->r_cer_img_ext); } } if (RequestMethods::post('appid')) { $d = CabDriver::first(array('id = ?' => RequestMethods::post('appid'))); $d->approval = 1; $d->save(); } if (RequestMethods::post('disappid')) { $d = CabDriver::first(array('id = ?' => RequestMethods::post('disappid'))); $d->approval = 0; $d->save(); } $drivers = CabDriver::all(array('doc_flag = ?' => '1')); $view->set('drivers', $drivers); }