/** * Returns all unit ids that are passed criteria option * * @param RM_Unit_Search_Criteria $criteria * @return array, false */ function getAdvancedSearchUnitIDs(RM_Unit_Search_Criteria $criteria) { if (!$criteria->categories || count($criteria->categories) == 0) { return false; } $model = new RM_UnitCategories(); $units = $model->getByCategories($criteria->categories); $unitIDs = array(); foreach ($units as $row) { $unitIDs[] = $row->unit_id; } //we need to add code to support Group Module //we need to include every unit ID of a groups that main unit in group assigned to a category if (class_exists('RM_Groups')) { $groupUnitIDs = array(); $groupsModel = new RM_Groups(); $unitsModel = new RM_Units(); foreach ($unitIDs as $unitID) { $unit = $unitsModel->get($unitID); if ($groupsModel->isMain($unit)) { $units = $groupsModel->getGroupUnitsByMain($unit); foreach ($units as $unit) { $groupUnitIDs[] = $unit->getId(); } } } $unitIDs = array_merge($unitIDs, $groupUnitIDs); $unitIDs = array_unique($unitIDs); } return $unitIDs; }
public function updateJsonAction() { $unit = $this->_getParam('edit_unit'); $unit['color'] = ltrim($this->_getParam('color'), "#"); $dao = new RM_Units(); // update the unit record $dao->updateUnit($unit); if (isset($unit['group_id'])) { // make sure that sub units are converted to the same unit type if (class_exists(RM_Groups)) { $groups = new RM_Groups(); // get the unit object $unitObject = $dao->get($unit['id'], null, array('description', 'summary')); if (!$groups->isMain($unitObject)) { // if it's not a main unit, then update the unit to the same unit type as the main unit $allGroupedUnits = $groups->getGroupUnitsByMain($unitObject); // find the main unit id... foreach ($allGroupedUnits as $groupUnit) { if ($groups->isMain($groupUnit)) { $mainUnitID = $groupUnit->id; } } // get the main unit object $mainUnitObject = $dao->get($mainUnitID, null, array('description', 'summary')); // get the type for the main unit $rmUnitTypes = new RM_UnitTypes(); $typeInfo = $rmUnitTypes->getByUnit($mainUnitObject)->toArray(); // update the subunit to the same type $unit['type_id'] = (int) $typeInfo['id']; $dao->updateUnit($unit); } } } return array('data' => array('success' => true, 'msg' => '')); }