public function editJsonAction() { $json = new stdClass(); $id = $this->_getParam('id'); $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale()); $unitModel = new RM_Units(); $unit = $unitModel->get($id, $iso); $config = new RM_UnitConfig(); $fields = $config->getEditFormByUnit($unit); $config = new RM_Config(); // view_preferences_1 provides non html editors, just raw editors foreach ($fields as $field) { if ($config->getValue('rm_config_editor') == "text" && $field->view_preferences_1 !== "") { $jsonFields[] = $field->view_preferences_1; } else { $jsonFields[] = $field->view_preferences; } } $reservationModel = new RM_Reservations(); $reservations = $reservationModel->fetchAllByUnit($unit); $jsonReservations = array(); /* * the reservation information required to add events to the calendar must include * the start and end date but also the unit color. */ foreach ($reservations as $reservation) { $jsonReservation = new stdClass(); $jsonReservation->start_date = $config->convertDates($reservation->start_datetime, RM_Config::MYSQL_DATEFORMAT, RM_Config::MYSQL_DATEFORMAT_SHORT); $jsonReservation->end_date = $config->convertDates($reservation->end_datetime, RM_Config::MYSQL_DATEFORMAT, RM_Config::MYSQL_DATEFORMAT_SHORT); $jsonReservation->color = $unit->color; // unit color $jsonReservations[] = $jsonReservation; } $priceSystems = RM_Environment::getInstance()->getPriceSystem()->getAllPriceSystems(); $jsonPriceSystems = array(); foreach ($priceSystems as $system) { $jsonPriceSystems[] = $system->name; } $priceSystem = RM_Environment::getInstance()->getPriceSystem()->getRealPriceSystem($unit); // group handling (only used when the groups is enabled) $isGroupTemplate = 0; if ($unit->isTemplateUnit() === (int) $unit->id) { $isGroupTemplate = 1; } elseif ($unit->isTemplateUnit() === null || $unit->isTemplateUnit() === 0) { // if this unit is not in a group then we set the isGroupTemplate true // as this is really the same as a template for the GUI $isGroupTemplate = 1; } $json = "{ unit : " . Zend_Json::encode($unitModel->convertToGUI($unit->toArray())) . ", isgrouptemplate: '" . $isGroupTemplate . "', fields : [" . implode(',', $jsonFields) . "], periods: " . Zend_Json::encode($jsonReservations) . ", language: '" . $iso . "', price: '" . $priceSystem->name . "', prices: " . Zend_Json::encode($jsonPriceSystems) . "}"; return array('data' => $json, 'encoded' => true); }