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; }
public function configupdateJsonAction() { $unitTypesModel = new RM_UnitTypes(); $prices = $this->_getParam("prices", array()); foreach ($prices as $unitID => $priceModuleName) { $unitType = $unitTypesModel->find($unitID)->current(); if ($unitType !== null) { $unitType->price = $priceModuleName; $unitType->save(); } } $defaultTypeID = $this->_getParam('rm_default_system_unit_type'); if ($defaultTypeID !== null) { $unitType = $unitTypesModel->find($defaultTypeID)->current(); if ($unitType !== null) { $module = new RM_Module_UnitTypeManager(); $module->makeDefault($unitType); } } return array('data' => array('success' => true)); }
/** * 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)); }
public function getDefaultUnitType() { $model = new RM_UnitTypes(); $row = $model->fetchRow($model->select()->where("`default`=1")); if ($row == null) { //We have a situation when no unit type is default. //We need to assign Default unit type to default. $row = $model->find($this->_defaultUnitType)->current(); if ($row !== null) { $this->makeDefault($row); } } return $row; }
public function allpanelsAction() { $unitModel = new RM_Units(); $unitTypeID = $this->_getParam('unitTypeID'); $unitTypeModel = new RM_UnitTypes(); $unitType = $unitTypeModel->find($unitTypeID)->current(); $unit = $unitModel->getAll(new RM_Unit_Search_Criteria(array('type' => $unitType, 'includeOptionUnits' => true, 'includeExcursionUnits' => true)))->current(); if ($unitTypeID == RM_UnitTypes::DEFAULT_TYPE && $unit == null) { $unit = $unitModel->getAll(new RM_Unit_Search_Criteria())->current(); } if ($unit == null) { $unit = $unitModel->createRow(); } $this->view->unit = $unit; $this->view->admin = true; // this is required by captcha $panelModel = new RM_FormPanels(); $panels = $panelModel->fetchAll(); $this->view->panels = $panels; }
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); }
/** * Get current price system for unit * * @param RM_Unit_Row $unit * @return RM_Prices_Interface */ private function _getPriceSystem(RM_Unit_Row $unit) { //TODO: maybe we need to change this later if (class_exists('RM_Module_UnitTypeManager') == false) { return $this->_getDefaultPriceSystem(); } $unitTypeModel = new RM_UnitTypes(); $unitType = $unitTypeModel->find($unit->type_id)->current(); if ($unitType == null) { return $this->_getDefaultPriceSystem(); } $priceModuleName = $unitType->price; if ($priceModuleName == "") { return $this->_getDefaultPriceSystem(); } $priceSystems = $this->_getAllPriceSystems(); foreach ($priceSystems as $priceSystem) { if ($priceSystem->name == $priceModuleName) { return $priceSystem; } } return $this->_getDefaultPriceSystem(); }
/** * Returns the list data for the Unit Assignment Grid. * * This creates a JS variable containing the list configuration/setup for * the reservation list. This is implicated in list.js * * @deprecated * @param request id the reservation id. * @param request type if this is a new or existing reservation. * @param request start list start used for pagenation * @param request limit list limit used for pagenation * @param request sort list sort parameter * @param request dir list direction Asc/desc * @param request filter an array of any filters applied * @return json information required to configure unit selection grid. */ public function listunitsJsonAction() { $id = $this->_getParam('id'); $type = $this->_getParam('type'); $offset = $this->_getParam('start'); $count = $this->_getParam('limit'); $sort = $this->_getParam('sort', 'id'); $direction = $this->_getParam('dir', 'DESC'); $language = $this->_translate->getAdapter()->getLocale(); $order = $sort . ' ' . $direction; $dao = new RM_ReservationDetails(); if ($type == "new") { $unitTypeDAO = new RM_UnitTypes(); $unitType = $unitTypeDAO->find('1')->current(); $details = $dao->getAll($unitType, $order, $count, $offset, $language, $filters)->toArray(); $total = $dao->getAll($unitType, $order, null, null, $language, $filters)->count(); } else { $reservationDAO = new RM_Reservations(); $reservation = $reservationDAO->find($id)->current(); $total = $dao->fetchAllByReservation($reservation, $order, null, null, $language)->count(); $details = $dao->fetchAllByReservation($reservation, $order, $count, $offset, $language)->toArray(); } $json = new stdClass(); $json->total = $total; $json->data = $details; return array('data' => $json); }
/** * Insert a unit by its primary key * * @param array $unit Array with all unit information * @param string $iso ISO language code ('cause we got all unit info with language dependent fields) * @param boolean $fromGUI This parameter told us was that data from GUI or it's internal usage. * @return mixed The primary key of the row inserted. */ public function insert($unit, $iso, $fromGUI = false) { $unitTypeDAO = new RM_UnitTypes(); $type = $unitTypeDAO->find($unit['type_id'])->current(); list($fields, $languageFields) = $this->_getFieldsByType($type); $unitArray = array(); $languageArray = array(); foreach ($fields as $field) { $unitArray[$field->column_name] = $unit[$field->column_name]; } foreach ($languageFields as $field) { $languageArray[$field->column_name] = $unit[$field->column_name]; } //TODO: this code need to be more flexible to do not use UnitTypeManager module $manager = new RM_Module_UnitTypeManager(); $unitArray['type_id'] = $manager->getDefaultUnitType()->id; if ($fromGUI) { $languageArray['unit_id'] = $this->insertFromGUI($unitArray); } else { $languageArray['unit_id'] = parent::insert($unitArray); } $unitModel = new RM_Units(); $newUnit = $unitModel->createRow(array('id' => $languageArray['unit_id'])); $mediaManager = new RM_Media_Unit_Manager($newUnit); $mediaManager->createFolder(); //we need to create a unit detail row for every language installed in the system $languageModel = new RM_Languages(); $languages = $languageModel->fetchAll(); $unitLanguageModel = new RM_UnitLanguageDetails(); foreach ($languages as $language) { $languageArray['iso'] = $language->iso; $unitLanguageModel->insert($languageArray); } return $languageArray['unit_id']; }