/** * 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))); } }
/** * Reset every information that user select during reservation process. * * @return RM_Reservation_Manager */ public function reset() { $methods = get_class_methods(get_class($this)); foreach ($methods as $method) { if (strpos($method, 'reset') === 0 && $method != 'reset' && $method != 'resetFormErrors' && $method != 'resetUser') { // We don't need to reset user in the same session $this->{$method}(); } } $this->_setReservationID(RM_Reservations::createReservationID()); return $this; }
/** * Creates the new reservation in the reservation temp tables and the json data for the form * * This generates a new reservation, a new reservation does not use the id value, but the reservation_id. * the reservation_id is created at the time this method is called and is not committed to the live * reservations (stored in rm_reservations) until save. * * @return json * @deprecated since RC2 */ public function wizardnewJsonAction() { $data = new stdClass(); $data->id = RM_Reservations::createReservationID(); $data->user_id = null; // this isn't available until the reservation is saved. $data->start_datetime = date("Y-m-d"); $data->end_datetime = date("Y-m-d"); // this is the form fields... $reservationConfigModel = new RM_ReservationConfig(); $fields = $reservationConfigModel->getWizardFields(); foreach ($fields as $field) { $jsonFields[] = $field->admin_view_wizard; } $json = "{\n data : " . Zend_Json::encode($data) . ",\n fields : [" . implode(',', $jsonFields) . "]\n }"; return array('data' => $json, 'encoded' => true); }
/** * Inserts a new row. * * @param array $data Column-value pairs. * @return mixed The primary key of the row inserted. */ public function insert(array $data) { if (isset($data['id']) == false) { $data['id'] = RM_Reservations::createReservationID(); } return parent::insert($data); }