public function reservationsJsonAction()
 {
     $unitID = $this->_getParam('unit_id', null);
     $startdate = $this->_getParam('startdate', null);
     $enddate = $this->_getParam('enddate', null);
     // unit dao
     $unitsDAO = new RM_Units();
     $unitObject = $unitsDAO->find($unitID)->current();
     $filter[] = array('field' => 'start_datetime', 'data' => array('type' => 'date', 'value' => $startdate, 'comparison' => 'gt'));
     $filter[] = array('field' => 'end_datetime', 'data' => array('type' => 'date', 'value' => $enddate, 'comparison' => 'lt'));
     $filters[] = array('field' => 'confirmed', 'data' => array('type' => 'numeric', 'value' => 1, 'comparison' => 'eq'));
     // reservation data
     $reservationsDAO = new RM_Reservations();
     $reservations = $reservationsDAO->fetchAllByUnit($unitObject, $filter);
     foreach ($reservations as $reservation) {
         $detailJson = new stdClass();
         $detailJson->Id = $reservation->id;
         $detailJson->ResourceId = $unitID;
         $detailJson->StartDate = $reservation->start_datetime;
         $detailJson->Color = 'red';
         $detailJson->EndDate = $reservation->end_datetime;
         $detailsJson[] = $detailJson;
     }
     return array('data' => $detailsJson);
 }
示例#2
0
 /**
  * Gets the calendar Data
  *
  * @return JSON
  */
 private function _getdata($startRange = false, $endRange = false)
 {
     if (!$startRange || !$endRange) {
         $startRange = date("Y-m-d");
         $endRange = date("Y-m-d");
     }
     $unitModel = new RM_Units();
     $units = $unitModel->getAll(new RM_Unit_Search_Criteria());
     $unitModel = new RM_Units();
     $reservationModel = new RM_Reservations();
     $config = new RM_Config();
     $evtsArray = array();
     // add 6 months to either side of the reservation
     $RMDate = new RM_Date();
     $start = $RMDate->dateSub($startRange, 180);
     $end = $RMDate->dateAdd($endRange, 180);
     $filter = array();
     $filter['data']['type'] = 'date';
     $filter['field'] = 'start_datetime';
     $filter['data']['comparison'] = 'gt';
     $filter['data']['value'] = $start;
     $filterArray[] = $filter;
     $filter = array();
     $filter['data']['type'] = 'date';
     $filter['field'] = 'end_datetime';
     $filter['data']['comparison'] = 'lt';
     $filter['data']['value'] = $end;
     $filterArray[] = $filter;
     $filter = array();
     $filter['data']['type'] = 'numeric';
     $filter['field'] = 'in_progress';
     $filter['data']['comparison'] = 'eq';
     $filter['data']['value'] = 0;
     $filterArray[] = $filter;
     foreach ($units as $unit) {
         $unit = $unitModel->get($unit->id);
         $reservations = $reservationModel->fetchAllByUnit($unit, $filterArray);
         foreach ($reservations as $period) {
             $idArray = explode("-", $period->id);
             $id = (int) $idArray[1];
             // check time
             $ad = true;
             // all day
             $starttime = explode(" ", $period->start_datetime);
             if ($starttime[1] !== "00:00:00") {
                 $ad = false;
             }
             $endtime = explode(" ", $period->end_datetime);
             if ($endtime[1] !== "23:30:00") {
                 $ad = false;
             }
             $evtsArray[] = array("id" => $id, "cid" => $unit->id, "uid" => (int) $period->user_id, "title" => "<span style='text-align:center;width:70%;'>" . $period->id . "&nbsp;&nbsp;&nbsp;" . $unit->name . "(" . $unit->id . ")</span>", "start" => $period->start_datetime, "end" => $period->end_datetime, "ad" => $ad);
         }
     }
     return array("success" => true, "message" => RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN)->_('Admin.Reservation.Edit', "LoadedData"), "data" => $evtsArray);
 }
示例#3
0
 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);
 }