private function _getForm($unitTypeID = null) { if ($unitTypeID == null) { $unitTypeID = RM_UnitTypes::DEFAULT_TYPE; } $unitTypesModel = new RM_UnitTypes(); $unitType = $unitTypesModel->find($unitTypeID)->current(); $unitTypeFormsModel = new RM_UnitTypeForms(); $unitTypeForm = $unitTypeFormsModel->fetchBy($this, $unitType); return $unitTypeForm; }
/** * Saving form state into database * * @param formID * @param value * @return json information for the front-end */ function savestateJsonAction() { $formID = $this->_getParam('formID'); $state = $this->_getParam('state'); $columns = $this->_getParam('columns'); $column1width = $this->_getParam('column1width'); $column2width = $this->_getParam('column2width'); $column3width = $this->_getParam('column3width'); $unitTypeID = $this->_getParam('unitTypeID', RM_UnitTypes::DEFAULT_TYPE); $model = new RM_Forms(); $form = $model->find($formID)->current(); $unitTypesModel = new RM_UnitTypes(); $unitType = $unitTypesModel->find($unitTypeID)->current(); if ($unitType == null) { $unitTypeID = RM_UnitTypes::DEFAULT_TYPE; $unitType = $unitTypesModel->find($unitTypeID)->current(); } $unitTypeFormsModel = new RM_UnitTypeForms(); if ($unitTypeFormsModel->check($form, $unitType)) { $unitTypeForm = $unitTypeFormsModel->fetchBy($form, $unitType); } else { //We need to create a new row for this unit type $unitTypeForm = $unitTypeFormsModel->createRow(); $unitTypeForm->form_id = $form->id; $unitTypeForm->unit_type_id = $unitTypeID; } $unitTypeForm->columns = $columns; $unitTypeForm->column1width = $column1width; $unitTypeForm->column2width = $column2width; $unitTypeForm->column3width = $column3width; $unitTypeForm->state = $state; $result = $unitTypeForm->save(); $resultJson = false; if ($result) { $resultJson = true; } return array('data' => array('success' => $resultJson)); }
function detailsAction() { // reset the returnAllUnits if it's set unset($_SESSION["returnAllUnits"]); $unitID = $this->_getParam('unit_id', null); $isGroup = $this->_getParam('isGroup', 0); if ($unitID == null) { $this->_redirect('Unit', 'list'); return; } $unitModel = new RM_Units(); $language = RM_Environment::getInstance()->getLocale(); $availableSubUnits = array(); $mainFound = false; // if this is a group we need to get an available unit from the 'pool' if ($isGroup) { $masterUnit = $unitModel->get($unitID, $language); $qty = $this->_getParam('qty', 1); // define how many subunits to pick if (!isset($qty) || $qty == 0) { $qty = 1; } $criteria = RM_Reservation_Manager::getInstance()->getCriteria(); if (!$criteria) { $criteria = new RM_Unit_Search_Criteria(); } if ($criteria->showOptionUnits === "1" || $criteria->showExcursionUnits === "1") { $criteria = new RM_Unit_Search_Criteria(); } $groupsModel = new RM_Groups(); // get available sub units $AllavailableSubUnits = $masterUnit->getAllSubUnits($criteria, $masterUnit); // the groups module will return a free unit using the method above // this means if there are no subunits it will return the available // main unit. This causes us a problem as if the unit returned is not // the main unit then we need to + one to the available units as the // main unit is also available for reservation. foreach ($AllavailableSubUnits as $subunit) { if ($subunit->getGroupId() === $masterUnit->getGroupId()) { if ($groupsModel->isMain($subunit)) { // if it's the main unit set a flag $mainFound = true; } $availableSubUnits[] = $subunit; } } $unit = $masterUnit; if (count($availableSubUnits) < $qty) { $availableSubUnits[] = $masterUnit; } } else { $unit = $unitModel->get($unitID, $language); } if ($unit == null) { $this->_redirect('Unit', 'list'); return; } $qtyAvailable = count($availableSubUnits); // if the main unit was not found add one to the quantity // total as the main unit + the sub unit is available. if (!$mainFound) { $qtyAvailable += 1; } $this->view->unit = $unit; $this->view->subunits = $availableSubUnits; $this->view->quantity = $qtyAvailable; // set the page title RM_Environment::getConnector()->setPageTitle($unit->name); $formModel = new RM_Forms(); $form = $formModel->find('unitdetails')->current(); $this->view->form = $form; $this->view->state = $form->getState($unit->type_id); $unitTypeModel = new RM_UnitTypes(); $unitType = $unitTypeModel->find($unit->type_id)->current(); $unitTypeFormsModel = new RM_UnitTypeForms(); $this->view->unitTypeForm = $unitTypeFormsModel->fetchBy($form, $unitType); }