public function executeNewBooking(sfWebRequest $request) { $app_id = $request->getParameter('apid'); $date_from = $request->getParameter('start_date'); $days = $request->getParameter('days'); $pax = $request->getParameter('pax'); $date_to = date("Y-m-d", strtotime($date_from) + 86400 * $days); $app = Doctrine_Core::getTable('Apartment')->find($app_id); $form = new BookingForm(); $form->PublicBookingForm($app); $booking = new Booking(); $booking->date_from = $date_from; $booking->date_to = $date_to; if ($this->getUser()->isAuthenticated()) { if ($booking->StartBooking($app, $pax)) { /* @TODO: 1. Save request. Set comfirmed -> FALSE 2. Get reservation ID ?? */ $this->apartment = $app; $this->booking = $booking; $this->price = Booking::CalculatePrice($app, $date_from, $date_to); $this->pax = $pax; $this->form = new BookingForm(); $this->form->PublicPaymentForm($app->id, $booking->date_from, $booking->date_to, $pax); } else { /* Not avalible, return form and error */ $callback_url = 'http://localhost/symfonybooking/web/frontend_dev.php/en/apartment/' . $app->getId(); return $this->renderPartial('booking/booking_form', array('form' => $form, 'sign_in' => false, 'callback' => $callback_url, 'error' => 'Something is wrong, please check once more ...')); } } else { /* User in not singed in */ return $this->renderPartial('booking/booking_form', array('form' => $form, 'sign_in' => true, 'callback' => $callback_url)); } }
protected function processForm(sfWebRequest $request, sfForm $form) { $form->bind($request->getParameter($form->getName())); $params = $request->getParameter($this->form->getName()); if ($form->isValid()) { // $notice = $form->getObject()->isNew() ? 'Booking was created successfully.' : 'Booking was updated successfully.'; try { /* Start booking */ $apartment = Doctrine_Core::getTable('Apartment')->find($params['apartment_id']); $booking = $form->getObject(); $from = $params['date_from']['year'] . '-' . $params['date_from']['month'] . '-' . $params['date_from']['day']; $to = $params['date_to']['year'] . '-' . $params['date_to']['month'] . '-' . $params['date_to']['day']; $booking->date_from = $from; $booking->date_to = $to; if ($booking->StartBooking($apartment, $params['pax'])) { $booking->Apartment = $apartment; $booking->client_id = $params['client_id']; $booking->pax = $params['pax']; $booking->valid = $params['valid']; $booking->canceled = $params['canceled']; $booking->price = Booking::CalculatePrice($apartment, $from, $to); $booking->save(); // return sfView::SUCCESS; $this->redirect(array('sf_route' => 'booking_edit', 'sf_subject' => $booking)); $this->getUser()->setFlash('error', ' Booking successfully created. ', false); } else { $this->getUser()->setFlash('error', 'Apartment is unavalible for this dates !', false); return sfView::SUCCESS; } } catch (Doctrine_Validator_Exception $e) { $errorStack = $form->getObject()->getErrorStack(); $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: "; foreach ($errorStack as $field => $errors) { $message .= "{$field} (" . implode(", ", $errors) . "), "; } $message = trim($message, ', '); $this->getUser()->setFlash('error', $message); return sfView::SUCCESS; } $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $booking))); } else { $this->getUser()->setFlash('error', 'There are some errors ...', false); } }
public function CheckBookingPossibility(Apartment $app, $pax) { /* Avalibility check. Expecting TRUE or FALSE */ $avalibility = $app->CheckBookingsInPeriod($this->date_from, $this->date_to); /* Are dates valid for individual apartment ? */ $dates = true; /* Minimum or maximum pax for individual apartment or ... ? */ $pax_valid = false; if ($pax >= 1 && $pax <= $app->getMaxPax()) { $pax_valid = true; } /* Are there periods for dates... Can we get real price ? */ $price = false; if (Booking::CalculatePrice($app, $this->date_from, $this->date_to) > 0) { $price = true; } if ($dates === true && $avalibility === false && $pax_valid === true && $price === true) { return $this; } else { return false; } }