function editJsonAction() { $formID = $this->_getParam('formID'); $formModel = new RM_Forms(); $form = $formModel->find($formID)->current(); // check if there are any units $unitDAO = new RM_Units(); $unitTypeID = $this->_getParam('unitTypeID'); if ($unitTypeID === null) { return array('data' => "{ 'error': true }", 'encoded' => true); } $unitTypeModel = new RM_UnitTypes(); $unitType = $unitTypeModel->find($unitTypeID)->current(); $total = $unitDAO->getAll(new RM_Unit_Search_Criteria(array('type' => $unitType)))->count(); if ($unitTypeID == RM_UnitTypes::DEFAULT_TYPE && $total == 0) { $total = $unitDAO->getAll(new RM_Unit_Search_Criteria())->count(); } if ($total == 0) { return array('data' => "{ 'error': true }", 'encoded' => true); } $panelModel = new RM_FormPanels(); $panels = $panelModel->fetchByForm($formID); $jsonPanels = array(); foreach ($panels as $panel) { $jsonPanels[] = '{id : "' . $panel->id . '", name : "' . $panel->name . '"}'; } $unitTypeFormModel = new RM_UnitTypeForms(); $unitTypeForm = $unitTypeFormModel->fetchBy($form, $unitType); $json = "{\n formID: '" . $formID . "',\n formName: '" . $form->name . "',\n columns: " . $unitTypeForm->columns . ",\n max_columns: " . $form->max_columns . ",\n column1width: " . $unitTypeForm->column1width . ",\n column2width: " . $unitTypeForm->column2width . ",\n column3width: " . $unitTypeForm->column3width . ",\n panels: [" . implode(',', $jsonPanels) . "],\n formState: " . $unitTypeForm->state . ",\n unitTypeID: {$unitTypeID},\n unitTypeName: '" . $unitType->getName(RM_Environment::getInstance()->getLocale()) . "'\n }"; return array('data' => $json, 'encoded' => true); }
private function _getUnits() { $unitTypeDAO = new RM_UnitTypes(); $unitsdao = new RM_Units(); $units = $unitsdao->getAll(new RM_Unit_Search_Criteria()); return $units; }
/** * this creates the JSON for the unit selection on the coupons grid * @return array used to construct the json result */ public function unitlistJsonAction() { $dao = new RM_Units(); $units = $dao->getAll(new RM_Unit_Search_Criteria())->toArray(); $units[] = array('id' => '0', 'name' => RM_Environment::getInstance()->getTranslation()->_('Admin.Extras.Edit', 'AllUnits')); return array('data' => $units); }
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; }
public function advancedvalidateJsonAction() { $this->_withoutView(); $formModel = new RM_Forms(); $form = $formModel->find('advancedsearch')->current(); $formvalid = $form->validate($this->getRequest()); $data = $this->_getParam('search', array()); // count records to be returned $criteria = new RM_Unit_Search_Criteria($data); $criteria->publishedOnly = true; $unitModel = new RM_Units(); $totalUnits = $unitModel->getAll($criteria)->count(); // count records end if ($formvalid == false) { $errors = $form->getErrors(); $returnData = array('data' => array('success' => false, 'errors' => $errors, 'count' => $totalUnits)); } else { $errors = $form->getErrors(); $returnData = array('data' => array('success' => true, 'errors' => null, 'count' => $totalUnits)); } return $returnData; }
/** * Creates the unit CSS for the calendar rendering * This is just generated at boot */ public static function createUnitColorCSS() { $unitModel = new RM_Units(); $units = $unitModel->getAll(new RM_Unit_Search_Criteria()); $html = ""; foreach ($units as $unit) { if (isset($unit->color) && $unit->color !== "") { $color = $unit->color; } else { $color = '0033FF'; } $html .= "\n .x-cal-{$unit->id},\n .x-cal-{$unit->id}-x .ext-cal-evb,\n .ext-ie .x-cal-{$unit->id}-ad,\n .ext-opera .x-cal-{$unit->id}-ad {\n color: #{$color};\n }\n .ext-cal-day-col .x-cal-{$unit->id},\n .ext-dd-drag-proxy .x-cal-{$unit->id},\n .x-cal-{$unit->id}-ad,\n .x-cal-{$unit->id}-ad .ext-cal-evm,\n .x-cal-{$unit->id} .ext-cal-picker-icon,\n .x-cal-{$unit->id}-x dl,\n .x-calendar-list-menu li em .x-cal-{$unit->id} {\n background: #{$color};\n }\n "; } return $html; }
/** * 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 . " " . $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); }
/** * ListAction is the main search routine used to list units. Params are sent from the * search forms and either submitted data is used or the saved criteria. * * @param array search passed in post/get * @return objects to view */ function listAction() { // reset the returnAllUnits if it's set unset($_SESSION["returnAllUnits"]); // get the submitted search data $data = $this->_getParam('search', array()); // get the category if set explicitly $category = $this->_getParam('category', ""); // if category is not passed then set it to "" // if the category data sent in the request has data then add the category to the data array for use to create the criteria if ($category !== "true") { $data['categories'] = $category; } // if we are not re-ordering and have search data define a new search criteria if (!isset($data['reorder']) && !empty($data)) { // create a new criteria object $criteria = new RM_Unit_Search_Criteria($data); // reset the old criteria and save our new criteria RM_Reservation_Manager::getInstance()->resetCriteria()->setCriteria($criteria); } else { $criteria = RM_Reservation_Manager::getInstance()->getCriteria(); } // perform a check to make sure our criteria object is the correct instance // if it's not it will cause errors, so we check it and if it isn't we create // it as the correct object if (!$criteria instanceof RM_Unit_Search_Criteria) { $criteria = new RM_Unit_Search_Criteria($data); } // if the category passed in the request is empty and the criteria has a category set then blank it. if ($category === "" && $criteria->categories) { $criteria->categories = null; } // only show published units $criteria->publishedOnly = true; $criteria->groupsOnly = false; // define the default page ordering if no page ordering is passed if (!$criteria->order) { $criteria->order = RM_User_UnitController::getDefaultOrder(); } // if page re-ordering is called add this to the criteria and save it if (isset($data['reorder'])) { // if we are just re-odering the list get the saved criteria and use this. if (isset($data['order'])) { $criteria->order = $data['order']; // save the ordering to the criteria RM_Reservation_Manager::getInstance()->resetCriteria()->setCriteria($criteria); } } // get the default page lengths for the view $defaulCountPerPage = RM_Environment::getConnector()->getDefaultUnitListLength(); $unitModel = new RM_Units(); $units = $unitModel->getAll($criteria); if ($criteria->order == 'price') { $units = $this->_sortUnitsByPrice($criteria, $units); } $formModel = new RM_Forms(); $form = $formModel->find('unitlist')->current(); $this->view->form = $form; $this->view->criteria = $criteria; // get date formatting for the view $config = new RM_Config(); $dateFormat = $config->getJSDateformat(); if ($dateFormat == "d/m/Y") { $lng_dateFormat = "dd/mm/yyyy"; } else { $lng_dateFormat = "mm/dd/yyyy"; } $this->view->dateformat_short = $dateFormat; $this->view->dateformat_long = $lng_dateFormat; // criteria list header message $message = false; if ($criteria->start_datetime !== null && $criteria->end_datetime !== null && $criteria->start_datetime !== "" && $criteria->end_datetime !== "") { $message .= date($dateFormat, strtotime($criteria->start_datetime)) . " - " . date($dateFormat, strtotime($criteria->end_datetime)) . ", "; } if ((int) $criteria->image === 1) { $message .= $this->_translate->_('User.Unit.List', 'criteriaImage') . ", "; } if ((int) $criteria->flexible === 1) { $message .= $this->_translate->_('User.Unit.List', 'criteriaFlexible') . ", "; } if ((int) $criteria->map === 1) { $message .= $this->_translate->_('User.Unit.List', 'criteriaMap') . ", "; } if ((int) $criteria->prices_from !== 0) { $message .= $this->_translate->_('User.Unit.List', 'criteriaPricesFrom') . ": " . $criteria->prices_from . ", "; } if ($criteria->prices_to != "99999999" && $criteria->prices_to) { $message .= $this->_translate->_('User.Unit.List', 'criteriaPricesTo') . ": " . $criteria->prices_to . ", "; } if ((int) $criteria->adults > 1) { $message .= $this->_translate->_('User.Unit.List', 'criteriaAdults') . ": " . $criteria->adults . ", "; } if ((int) $criteria->children > 0) { $message .= $this->_translate->_('User.Unit.List', 'criteriaChildren') . ": " . $criteria->children . ", "; } if ((int) $criteria->infants > 0) { $message .= $this->_translate->_('User.Unit.List', 'criteriaInfants') . ": " . $criteria->infants . ", "; } $this->view->criteriaMessage = rtrim($message, ", "); $paginator = Zend_Paginator::factory($units); $paginator->setDefaultItemCountPerPage($defaulCountPerPage); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); $this->view->paginator = $paginator; }
public function newJsonAction() { // create the search criteria object $criteria = new RM_Unit_Search_Criteria(array(), true); // get the total number of units already added to the system. $dao = new RM_Units(); // TODO: we need to hide these queries if possible. //$unitTypesDAO = new RM_UnitTypes(); //$criteria->type = $unitTypesDAO->find($this->_defaultUnitType)->current(); $total = (int) $dao->getAll($criteria)->count(); $iso = $this->_getParam('iso', RM_Environment::getInstance()->getLocale()); $config = new RM_UnitConfig(); $fields = $config->getNewForm($this->_defaultUnitType); foreach ($fields as $field) { $jsonFields[] = $field->view_preferences; } $json = "{ fields : [" . implode(',', $jsonFields) . "], language: '" . $iso . "'}"; return array('data' => $json, 'encoded' => true); }
private function _getUnits() { $dao = new RM_Units(); $criteria = new RM_Unit_Search_Criteria(array('language' => RM_Environment::getInstance()->getLocale()), true); $units = $dao->getAll($criteria); $result = array(); if (count($units->toArray()) === 0) { return null; } // get all the master group units $count = 1; // the menu id $groupTracker = array(); foreach ($units as $unitRow) { $unit = $unitRow->toArray(); if (isset($unit['group_id'])) { if ($unitRow->isTemplateUnit() === (int) $unit['unit_id']) { // template units (root units) $std = new stdClass(); $std->id = 'Units_EditJson_' . $unit['id']; $std->text = $unit['name']; $std->expanded = 'true'; $std->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon'; $std->children = array(); $result[$count] = $std; $groupTracker[$count] = $unit['group_id']; $count += 1; } } else { // this is not a grouped unit - this is the standard unit (not grouped) $std = new stdClass(); $std->id = 'Units_EditJson_' . $unit['id']; $std->text = $unit['name']; $std->leaf = 'true'; $std->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon'; $result[$count] = $std; $groupTracker[$count] = 0; $count += 1; } } // now loop through all units and assign sub units to the template units // but only if they are a sub unit. foreach ($units as $unitRow) { $unit = $unitRow->toArray(); // handle groups if (isset($unit['group_id'])) { if ($unitRow->isTemplateUnit() !== (int) $unit['unit_id']) { // sub unit $childUnit = new stdClass(); $childUnit->id = 'Units_EditJson_' . $unit['id']; $childUnit->text = $unit['name']; $childUnit->leaf = 'true'; $childUnit->iconCls = 'RM_units_' . $unit['type_id'] . '_leaf_icon'; // add it to the parent leaf foreach ($groupTracker as $key => $value) { if ($unit['group_id'] == $value) { $result[$key]->children[] = $childUnit; } } } } } // we have to resort here as the menu needs consecutive numbering foreach ($result as $value) { $final[] = $value; } return $final; }