/** * 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; }
function assignJsonAction() { $categoryID = $this->_getParam('category_id', 0); $unitID = $this->_getParam('unit_id', 0); $checked = $this->_getParam('checked'); if ($checked === 'false') { $checked = false; } else { $checked = true; } $model = new RM_UnitCategories(); $row = $model->find($unitID, $categoryID)->current(); if ($checked) { if ($row == null) { $data = array('unit_id' => $unitID, 'category_id' => $categoryID); $model->insert($data); } } else { if ($row !== null) { $row->delete(); } } return array('data' => array('success' => true)); }