本文整理汇总了PHP中Role::getAllRoleObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::getAllRoleObjects方法的具体用法?PHP Role::getAllRoleObjects怎么用?PHP Role::getAllRoleObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::getAllRoleObjects方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setRole
public function setRole($roleId = null)
{
$roles = Config::get('loginEnabled') ? Role::getAllSessionRoles() : Role::getAllRoleObjects();
if (empty($roles) || $roleId == 0) {
$this->role = new Role(0);
} elseif (is_null($roleId)) {
$this->role = current($roles);
} elseif (isset($roleId)) {
if (!is_int($roleId)) {
throw new Exception("roleId must be an integer", 400);
}
foreach ($roles as $role) {
if ($role->id == $roleId) {
$this->role = $role;
}
}
if (!isset($this->role)) {
throw new Exception("You do not have access to the selected role", 401);
}
} else {
throw new Exception("No role could be selected", 500);
}
if (Config::get('loginEnabled')) {
$arr = array();
foreach ($roles as $role) {
$arr = array_merge($arr, $role->interfaces);
}
$this->accessibleInterfaces = array_unique($arr);
}
Notifications::addLog("Role " . $this->role->name . " selected", 'SESSION');
return $this->role->id;
}
示例2: getAllSessionRoles
public static function getAllSessionRoles()
{
$sessionRoleLabels = array();
$sessionRoles = array();
$interface = new InterfaceObject('SessionRoles');
$session = new Atom(session_id(), 'SESSION');
$sessionRoleLabels = array_keys((array) $session->getContent($interface, true));
foreach (Role::getAllRoleObjects() as $role) {
if (in_array($role->label, $sessionRoleLabels) || $role->id == 0) {
$sessionRoles[] = $role;
}
}
return $sessionRoles;
}
示例3: getSessionRoles
public function getSessionRoles()
{
if (isset($this->sessionRoles)) {
return $this->sessionRoles;
} else {
if (Config::get('loginEnabled')) {
$sessionRoleLabels = array();
$sessionRoles = array();
$interface = new InterfaceObject('SessionRoles');
$session = new Atom(session_id(), 'SESSION');
$sessionRoleLabels = array_keys((array) $session->getContent($interface, true));
foreach (Role::getAllRoleObjects() as $role) {
if (in_array($role->label, $sessionRoleLabels)) {
$sessionRoles[] = $role;
}
}
} else {
$sessionRoles = Role::getAllRoleObjects();
}
return $this->sessionRoles = $sessionRoles;
}
}
示例4: getNavBar
/**
* @url GET navBar
* @param int $roleId
*/
public function getNavBar($roleId = 0)
{
try {
$session = Session::singleton();
$session->setRole($roleId);
// top level interfaces
foreach ($session->role->getInterfacesForNavBar() as $ifc) {
$top[] = array('id' => $ifc->id, 'label' => $ifc->label, 'link' => '/' . $ifc->id);
}
// new interfaces
foreach ($session->role->getInterfacesToCreateAtom() as $ifc) {
$new[] = array('id' => $ifc->id, 'label' => $ifc->label, 'link' => '/' . $ifc->id);
}
// roles
$roles = array();
$allRoles = Config::get('loginEnabled') ? Role::getAllSessionRoles() : Role::getAllRoleObjects();
foreach ((array) $allRoles as $role) {
$roles[] = array('id' => $role->id, 'label' => $role->label);
}
return array('top' => $top, 'new' => $new, 'refreshMenu' => $GLOBALS['navBar']['refreshMenu'], 'appMenu' => $GLOBALS['navBar']['appMenu'], 'roleMenu' => $GLOBALS['navBar']['roleMenu'], 'roles' => $roles, 'defaultSettings' => array('notifications' => Notifications::getDefaultSettings()), 'notifications' => Notifications::getAll(), 'session' => array('id' => $session->id, 'loggedIn' => Session::sessionUserLoggedIn(), 'sessionRoles' => $roles), 'sessionVars' => Session::getSessionVars());
} catch (Exception $e) {
throw new RestException($e->getCode(), $e->getMessage());
}
}