示例#1
0
 public function update($formData, $bookingId)
 {
     $data = $formData['extra_id'];
     unset($formData["extra_id"]);
     $this->getDbTable()->update($formData, "booking_id='{$bookingId}'");
     $arr = array();
     $extraBooking = new Admin_Model_Extrabooking();
     $extraBooking->delete($bookingId);
     foreach ($data as $key => $val) {
         $arr['extra_id'] = $key;
         $arr['booking_id'] = $bookingId;
         $extraBooking->add($arr);
     }
 }
示例#2
0
 public function editBookingAction()
 {
     $form = new Admin_Form_BookingForm();
     $form->submit->setLabel("Save");
     $extraModel = new Admin_Model_Extra();
     $extras = $extraModel->getAll();
     $this->view->extra = $extras;
     $bookingModel = new Admin_Model_Booking();
     $bookingId = $this->_getParam('id', 0);
     if ($bookingId) {
         $data = $bookingModel->getDetailById($bookingId);
         $this->view->data = $data;
         $extrabookingModel = new Admin_Model_Extrabooking();
         $postData = $extrabookingModel->getAllbyBookingId($bookingId);
     } else {
         //needs to set index as action $form->setAction("index action");
         $session = Zend_Registry::get("defaultsession");
         $data = $session->first;
         $this->view->data = $data;
         $postData = array();
         if (array_key_exists("extra_id", $data)) {
             foreach ($data['extra_id'] as $key => $val) {
                 $postData[] = $key;
             }
         }
     }
     $form->populate($data);
     $this->view->form = $form;
     try {
         if ($this->getRequest()->isPost()) {
             $formData = $this->getRequest()->getPost();
             if ($form->isValid($formData)) {
                 unset($formData['submit']);
                 $bookingModel->update($formData, $bookingId);
                 $this->_helper->FlashMessenger->addMessage(array("success" => "Successfully edited booking information"));
                 $this->_helper->redirector('info-edit', "index", "default", array("id" => $bookingId));
             }
             if (array_key_exists("extra_id", $formData)) {
                 $extraIds = array();
                 foreach ($formData['extra_id'] as $key => $val) {
                     $extraIds[] = $key;
                 }
                 $postData = $extraIds;
             }
             $this->view->formData = $formData;
         }
         $this->view->postData = $postData;
     } catch (Exception $e) {
         $this->_helper->FlashMessenger->addMessage(array("error" => $e->getMessage()));
     }
 }