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' => '')); }