Exemple #1
0
 public function packages()
 {
     $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));
     $month = RequestMethods::get('month');
     $year = RequestMethods::get('year');
     $page = RequestMethods::get('page', 1);
     $limit = 9;
     if (RequestMethods::get('source')) {
         $count = Package::count(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year));
         $total_pages = $count / 9 + 1;
         for ($i = 1; $i <= $total_pages; $i++) {
             $pages[$i] = $i;
         }
         $packages = Package::all(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year, 'live = ?' => 1), array("*"), null, null, $limit, $page);
         $view->set('n', 'http://planyourtours.io/travels/packages?source=' . $source . '&dest=' . $dest . '&type=Group&month=' . $month . '&year=' . $year . '&page=')->set('source', $source_state)->set('dest', $dest_state)->set('month', $month)->set('year', $year);
     } else {
         $count = Package::count();
         $total_pages = $count / 9 + 1;
         for ($i = 1; $i <= $total_pages; $i++) {
             $pages[$i] = $i;
         }
         $packages = Package::all(array('live = ?' => 1), array("*"), null, null, $limit, $page);
         $view->set('n', 'http://planyourtours.io/travels/packages?&page=');
     }
     if (!empty($packages)) {
         $view->set('packages', $packages)->set('pages', $pages);
     }
 }
Exemple #2
0
 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>";
     }
 }