/** * Answer the agents that have roles that are greater than or equal to the role passed. * * @param object SegueRole $role * @param object Id $rootQualifierId * @param optional boolean $overrideAzCheck If true, not not check AZs. Used by admin functions to force-set a role. * @return array An array of Id objects * @access public * @since 11/29/07 */ public function getAgentsWithExplicitRoleAtLeast(SegueRole $role, Id $rootQualifierId, $overrideAzCheck = false) { $authZ = Services::getService("AuthZ"); $idMgr = Services::getService("Id"); if (!$overrideAzCheck) { if (!$authZ->isUserAuthorized($idMgr->getId("edu.middlebury.authorization.view_authorizations"), $rootQualifierId)) { throw new PermissionDeniedException("Cannot view authorizations here."); } } $qualifier = $authZ->getQualifier($rootQualifierId); // Go through each qualifier and see who can do all of the functions in the role $agentIdStrings = array(); $qualifierId = $qualifier->getId(); // Build up an array of what agents can do each function $agentsForFunctions = array(); foreach ($role->getFunctions() as $functionId) { $agentsForFunctions[$functionId->getIdString()] = array(); $explicitAZs = $authZ->getExplicitAZs(null, $functionId, $qualifierId); while ($explicitAZs->hasNext()) { $explicitAZ = $explicitAZs->next(); $agentIdString = $explicitAZ->getAgentId()->getIdString(); if (!in_array($agentIdString, $agentIdStrings)) { $agentsForFunctions[$functionId->getIdString()][] = $agentIdString; } } } // Loop through the agents that can do the first function, if they can // do all the others, then they match the role and can be added to the master list. foreach (current($agentsForFunctions) as $agentIdString) { $hasAllFunctions = true; foreach ($role->getFunctions() as $functionId) { if (!in_array($agentIdString, $agentsForFunctions[$functionId->getIdString()])) { $hasAllFunctions = false; break; } } if ($hasAllFunctions) { $agentIdStrings[] = $agentIdString; } } $agentIdStrings = array_unique($agentIdStrings); $agentIds = array(); foreach ($agentIdStrings as $idString) { $agentIds[] = $idMgr->getId($idString); } return $agentIds; }