function getByCompanyIdArray($id) { $this->getFastTreeObject()->setTree($id); $children = $this->getFastTreeObject()->getAllChildren(NULL, 'RECURSE'); if ($children !== FALSE) { $uglf = new UserGroupListFactory(); foreach ($children as $object_id => $level) { if ($object_id !== 0) { $obj = $uglf->getById($object_id)->getCurrent(); $nodes[] = array('id' => $object_id, 'name' => $obj->getName(), 'level' => $level); } } if (isset($nodes)) { return $nodes; } } return FALSE; }
} Debug::Arr($ids, 'Selected Objects', __FILE__, __LINE__, __METHOD__, 10); $action = Misc::findSubmitButton(); switch ($action) { case 'add': Redirect::Page(URLBuilder::getURL(NULL, 'EditUserGroup.php', FALSE)); break; case 'delete' or 'undelete': if (strtolower($action) == 'delete') { $delete = TRUE; } else { $delete = FALSE; } $uglf = new UserGroupListFactory(); foreach ($ids as $id) { $uglf->getById($id); foreach ($uglf as $obj) { $obj->setDeleted($delete); $obj->Save(); } } Redirect::Page(URLBuilder::getURL(NULL, 'UserGroupList.php')); break; default: $uglf = new UserGroupListFactory(); $nodes = FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'HTML'); //For some reason smarty prints out a blank row if nodes is false. if ($nodes !== FALSE) { $smarty->assign_by_ref('rows', $nodes); } $smarty->assign_by_ref('sort_column', $sort_column);
function setGroup($ids) { Debug::text('Setting IDs...', __FILE__, __LINE__, __METHOD__, 10); if (is_array($ids)) { $tmp_ids = array(); if (!$this->isNew()) { //If needed, delete mappings first. $lf_a = new StationUserGroupListFactory(); $lf_a->getByStationId($this->getId()); foreach ($lf_a as $obj) { $id = $obj->getGroup(); Debug::text('Group ID: ' . $obj->getGroup() . ' ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10); //Delete users that are not selected. if (!in_array($id, $ids)) { Debug::text('Deleting: ' . $id, __FILE__, __LINE__, __METHOD__, 10); $obj->Delete(); } else { //Save ID's that need to be updated. Debug::text('NOT Deleting : ' . $id, __FILE__, __LINE__, __METHOD__, 10); $tmp_ids[] = $id; } } unset($id, $obj); } //Insert new mappings. $lf_b = new UserGroupListFactory(); foreach ($ids as $id) { if (isset($ids) and !in_array($id, $tmp_ids)) { $f = new StationUserGroupFactory(); $f->setStation($this->getId()); $f->setGroup($id); $obj = $lf_b->getById($id)->getCurrent(); if ($this->Validator->isTrue('group', $f->Validator->isValid(), TTi18n::gettext('Selected Group is invalid') . ' (' . $obj->getName() . ')')) { $f->save(); } } } return TRUE; } Debug::text('No IDs to set.', __FILE__, __LINE__, __METHOD__, 10); return FALSE; }