public function configure() { parent::configure(); //-------------------------------------------------------------------------- // when creating a new reservation, the client id comes either from the // session (user is logged in) or the client form must be embedded //-------------------------------------------------------------------------- if ($this->isNew()) { if ($client_id = $this->getOption('client_id')) { $this->setDefault('client_id', $client_id); } else { unset($this['client_id']); $this->embedForm('client', new ClientForm()); } } }
public function executeRepeatResult(sfWebRequest $request) { // print 'executeRepeatList<br />'; $this->forward404Unless($request->isMethod('post')); $this->forward404Unless($this->reservation = ReservationPeer::retrieveByPk($request->getParameter('id')), sprintf('Object reservation does not exist (%s).', $request->getParameter('id'))); $this->room = $this->reservation->getRoomprofile()->getRoom(); $next_id = $this->reservation->getId(); $result = true; // $formRepeat = $this->getUser()->getAttribute('form_tmp'); // -------------------- $formRepeat->bind($request->getParameter($formRepeat->getName()), $request->getFiles($formRepeat->getName())); $this->forms = $formRepeat->getReservationForms(); $checked_list = $request->getPostParameters(); // var_dump($checked_list); // var_dump($forms); $ids = array(); foreach ($checked_list as $id) { array_push($ids, $id); } // var_dump($ids); if (empty($ids) || is_null($ids)) { $this->setTemplate('processRepeat'); } $j = 0; $this->formsResult = array(); foreach ($this->forms as $form) { // print '============><br />'.$j.' '.count($this->forms).'<br />'; $i = 0; $checked = false; while (!$checked && $i < count($ids)) { // print $i.' : '.$ids[$i].'<br />'; // if($this->forms[$j]->getObject()->getId() == $ids[$i]) if ($form->getObject()->getId() == $ids[$i]) { // print 'FORM '.$this->forms[$j]->getObject()->getId().' is checked<br />'; $checked = true; } $i++; } if ($checked) { // $reservation = $this->forms[$j]->getObject()->copy(); $reservation = $form->getObject()->copy(); $reservation->setReservationparentId($next_id); $resDate = $reservation->getDate(); // $this->forms[$j] = new ReservationForm($reservation); // $this->forms[$j]->bindObject($reservation); $form = new ReservationForm($reservation); $form->bindObject($reservation); // if ($this->forms[$j]->isValid()) if ($form->isValid()) { // print 'IS VALID<br />'; // var_dump($this->forms[$j]->getObject()); // var_dump($form->getObject()); // $reservation = $this->forms[$j]->save(); $reservation = $form->save(); $next_id = $reservation->getId(); foreach ($this->reservation->getReservationOtherMemberss() as $value) { $other_members = new ReservationOtherMembers(); $other_members->setReservationId($next_id); $other_members->setUserId($value->getUserId()); $other_members->save(); // print('Reservation : '.$value.'<br/>Id user : '******'<br/>'); } } else { // print 'NOT VALID<br />'; $result = false; } if ($checked) { $form->getObject()->setDate($resDate); } $this->formsResult[] = $form; // print $this->forms[$j]->renderErrors(); // print $form->renderErrors(); } $j++; } if ($result) { $this->redirect('reservation/index?roomId=' . $this->reservation->getRoomprofile()->getRoomId()); } }
* @param int $step */ public function setStep($step) { $this->step = $step; } /** * @return int */ public function getStep() { return $this->step; } } $step = isset($_GET['step']) ? $_GET['step'] : 1; $form = new ReservationForm($_POST, $step); if ($_SERVER['REQUEST_METHOD'] == 'POST' && $form->getStep() == 4) { $params = $_POST; $params['book_date_from'] = Manager::convertDate($_POST['book_date_from']); $params['book_date_to'] = Manager::convertDate($_POST['book_date_to']); $result = Manager::booking($params); if (!isset($result['error'])) { echo <<<HTML <script type="text/javascript"> window.location = window.location.href+'&success=1'; </script> HTML; exit; } } ?>