How to Get a List of All Managers in uKnowva

Sometimes you need to get a list of all users who have some reportees, i.e., other users reporting to them.

You can get this list using a simple function.

For uKnowva versions 2.5.1 and above, use the following code:

$managers = ConvHelper::getAllManagers();

For Older versions, use the following function:

/**
* this function returns all users who have some reportee with them .i.e. they are all managers
* @param bool $return_all, if true, then all users will be returned irrespective of whether they are blocked or not */
function getAllManagers($return_all = false){
$cacheid = __CLASS__.__FUNCTION__.$return_all;
$users = self::getFromCache($cacheid,'_users');
if($users && count($users)>0)
return $users;


$db = uKnowvaFactory::getDBO();
$sql = 'select distinct reports_to from #__users where reports_to != ""';
$rows = $db->setQuery($sql)->loadResultArray();
$users = array();
//purify the list
foreach ($rows as $row){
$row = array_filter(explode(",",str_replace("'","",$row)));
foreach ($row as $userid)
if(!is_numeric($row))
$users[] = $userid;
}

$users = array_filter(array_unique($rows));
if(!$return_all){
//return only the ones which are enabled
if(count($users)>0){
$users = $db->setQuery('select id from #__users where block=0 and id in ('.implode(",",$users).')') ->loadResultArray();
}
}
self::setInCache($users, $cacheid, '_users');
return $users;
}

{jcomments on}

Was this Article helpful?