/** * Returns the list configuration for the unit assignment. * * This creates a JS variable containing the list configuration/setup for * the reservation list. This is implicated in list.js * * @param request id the reservation id. * @param request type if this is a new or existing reservation. * @param request start_datetime the selected start date. * @param request end_datetime the selected end date. * @return json information required to configure unit selection grid. */ public function unitgridJsonAction() { $fieldsDAO = new RM_ReservationConfig(); $configFields = $fieldsDAO->getAdminEdit()->toArray(); foreach ($configFields as $key => $configField) { $metainfo[] = $configField['admin_edit_preferences']; } $fieldsDAO = new RM_UnitConfig(); $configFields = $fieldsDAO->getAllReservationFields()->toArray(); foreach ($configFields as $key => $configField) { //We need to check reservations and //TODO: this is some kind of hardcode we need to remove this later and create some other GOOD code :) if ($configField['column_name'] == 'id') { $id = $this->_getParam('id'); //reservation ID $type = $this->_getParam('type'); //indicates if this is a new reservation. $reservationModel = new RM_Reservations(); // if the type = new there will not be any reservation information for this // so we need to construct some information so that we can return the available units. if ($type == 'new') { $reservation->id = $id; $reservation->start_datetime = $this->_getParam('start_datetime'); $reservation->end_datetime = $this->_getParam('end_datetime'); } else { // if this is not new then load the reservation info... $reservation = $reservationModel->find($id)->current(); } $unitModel = new RM_Units(); $availableUnits = $unitModel->getAllAvailableForReservation($reservation, $reservationModel); foreach ($availableUnits as $unit) { $editorStore[] = "['{$unit->id}', '{$unit->id}']"; } $editorStore = "[" . implode(',', $editorStore) . "]"; if ($type == 'new') { $metainfo[] = str_replace("'---store---'", $editorStore, $configField['admin_new_reservation_preferences']); } else { $metainfo[] = str_replace("'---store---'", $editorStore, $configField['admin_edit_reservation_preferences']); } } else { if ($type == 'new') { $metainfo[] = $configField['admin_new_reservation_preferences']; } else { $metainfo[] = $configField['admin_edit_reservation_preferences']; } } } return array('data' => "{fields:[" . implode(',', $metainfo) . "]}", 'encoded' => true); }