示例#1
0
 /**
  * saves the new reservation selection
  *
  * @return JSON
  */
 public function insertJsonAction()
 {
     // get the data
     $data = Zend_Json::decode($this->_getParam('data'));
     $unitID = $data['cid'];
     $userID = $data['uid'];
     $start = $data['start'];
     $end = $data['end'];
     // get the unit object
     $unitModel = new RM_Units();
     $unit = $unitModel->get($unitID);
     // convert the date selection to a period object
     $periodObj = new RM_Reservation_Period(new RM_Date(strtotime($start)), new RM_Date(strtotime($end)));
     // check if the dates are allowed
     $reservationModel = new RM_ReservationDetails();
     $currentReservationCount = $reservationModel->getReservationCount($unit, $periodObj);
     if ($currentReservationCount > 0) {
         return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservations.Edit', 'InvalidSelection')));
         die;
     }
     $unitDetails = null;
     // reset the unit array for safe keeping
     $unitDetails = array(new RM_Reservation_Details($unit, $periodObj, new RM_Reservation_Persons()));
     $userModel = new RM_Users();
     $user = $userModel->find($userID)->current();
     // get the "system user"
     // get a reservation ID
     $reservationID = RM_Reservations::createReservationID();
     $reservationModel = new RM_Reservations();
     $result = $reservationModel->insertNewReservation($user, $unitDetails, 0, 1, $reservationID);
     if (!$result) {
         return array('data' => array('success' => false, 'message' => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_ERRORS)->_('Admin.Reservation.Edit', 'ServerError')));
     } else {
         // mark the new block as paid
         $reservation = $reservationModel->find($reservationID)->current();
         if ($userID === "") {
             $reservationModel->markPaid($reservation);
         }
         $idArray = explode("-", $reservationID);
         $id = (int) $idArray[1];
         // check time
         $ad = true;
         // all day
         $starttime = explode(" ", $start);
         if ($starttime[1] !== "00:00:00") {
             $ad = false;
         }
         $endtime = explode(" ", $end);
         if ($endtime[1] !== "00:00:00") {
             $ad = false;
         }
         return array('data' => array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => array("id" => $id, "cid" => $unitID, "uid" => (int) $userID, "title" => $reservationID, "start" => $start, "end" => $end, "ad" => $ad)));
     }
 }
 /**
  * This is used for the reservation list to mark it paid
  */
 public function markpaidJsonAction()
 {
     $ids = $this->_getParam('ids', array());
     $model = new RM_Reservations();
     foreach ($ids as $id) {
         $reservation = $model->find($id)->current();
         if ($reservation == null || $reservation->isPaid()) {
             continue;
         }
         $model->markPaid($reservation);
     }
     return array('data' => array('success' => true));
 }