コード例 #1
0
ファイル: BookingController.php プロジェクト: allanth4/taxibo
 public function book($userId, $post)
 {
     $offer = $this->getOffer($userId, $post['origin'], $post['destination'], $post['date'], $post['time']);
     $response = new \StdClass();
     $response->success = "no";
     if ($offer->success == "yes") {
         foreach (array('name', 'phone', 'email', 'passengerCount') as $fieldName) {
             ${$fieldName} = !empty($post[$fieldName]) ? $post[$fieldName] : '';
             if (!${$fieldName}) {
                 $response->errorText = "Fyll in alla felt";
                 print json_encode($response);
                 exit;
             }
         }
         $originCity = !empty($post['originCity']) ? $post['originCity'] : '';
         $destinationCity = !empty($post['destinationCity']) ? $post['destinationCity'] : '';
         // save to db
         $booking = new Booking();
         $booking->user_id = $userId;
         $booking->alphaId = "ZZZ" . substr("" + time(), 3, 7);
         $booking->origin = $offer->offerFrom;
         $booking->destination = $offer->offerTo;
         $booking->originCity = $originCity;
         $booking->destinationCity = $destinationCity;
         $booking->startUts = $offer->uts;
         $booking->endUts = $offer->uts + $offer->offerDurationValue;
         $booking->duration = $offer->offerDuration;
         $booking->distance = $offer->offerDistance;
         $booking->price = $offer->offerPrice;
         $booking->name = $name;
         $booking->email = $email;
         $booking->phone = $phone;
         $booking->passengerCount = $passengerCount;
         $booking->hash = md5($name . $email . $offer->offerFrom . time() . "38lx93øå");
         $response->bookingSaved = $booking->save();
         // mail to customer
         TaxiMail::sendBookingReceivedMail($booking, $userId);
         // mail to taxi company
         TaxiMail::sendNewBookingMail($booking, $userId);
         $response->success = "yes";
     }
     return $response;
 }