Пример #1
0
 public function saveReservationOtherMembers($con = null)
 {
     $oneshot_values = $this->getValue('reservation_has_user_list');
     //print('Oneshot : '.$oneshot_values);
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['reservation_has_user_list'])) {
         return false;
     }
     if (!is_null($oneshot_values)) {
         // For each user checked...
         foreach ($oneshot_values as $value) {
             $new_other_members_group = new ReservationOtherMembers();
             // Get the current Reservation ID
             $new_other_members_group->setReservationId($this->getObject()->getId());
             $new_other_members_group->setUserId($value);
             $new_other_members_group->save();
             //print('User id: '.$value.' Reservation id: '.$this->getObject()->getId());
         }
     }
     return true;
 }
Пример #2
0
 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());
     }
 }