本文整理汇总了PHP中ACLRole::getUserRoleNames方法的典型用法代码示例。如果您正苦于以下问题:PHP ACLRole::getUserRoleNames方法的具体用法?PHP ACLRole::getUserRoleNames怎么用?PHP ACLRole::getUserRoleNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACLRole
的用法示例。
在下文中一共展示了ACLRole::getUserRoleNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _displaySubPanels
/**
* Override - Called from process(). This method will display subpanels.
* include/MVC/View/SugarView.php
*/
protected function _displaySubPanels()
{
if (isset($this->bean) && !empty($this->bean->id) && (file_exists("modules/" . $this->module . "/metadata/subpaneldefs.php") || file_exists("custom/modules/" . $this->module . "/Ext/Layoutdefs/layoutdefs.ext.php"))) {
$GLOBALS["focus"] = $this->bean;
require_once 'include/SubPanel/SubPanelTiles.php';
$subpanel = new SubPanelTiles($this->bean, $this->module);
//Dependent Logic
global $current_user;
require_once 'modules/ACLRoles/ACLRole.php';
$role = new ACLRole();
$user_id = $current_user->id;
$roles = $role->getUserRoleNames($user_id);
if (in_array("Technical support", $roles)) {
//Subpanels to hide
$hide_subpanels = array("bugs");
if (isset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']["bugs"])) {
unset($subpanel->subpanel_definitions->layout_defs['subpanel_setup']["bugs"]);
}
}
echo $subpanel->display();
}
}
示例2: testgetUserRoleNames
public function testgetUserRoleNames()
{
$aclRole = new ACLRole();
//test with empty value
$result = $aclRole->getUserRoleNames('');
$this->assertTrue(is_array($result));
//test with non empty but non existing role id value
$result = $aclRole->getUserRoleNames('1');
$this->assertTrue(is_array($result));
}
示例3: check_role_membership
/**
* @return boolean true if the user is a member of the role_name, false otherwise
* @param string $role_name - Must be the exact name of the acl_role
* @param string $user_id - The user id to check for the role membership, empty string if current user
* @desc Determine whether or not a user is a member of an ACL Role. This function caches the
* results in the session or to prevent running queries after the first time executed.
* Portions created by SugarCRM are Copyright (C) SugarCRM, Inc..
* All Rights Reserved..
* Contributor(s): ______________________________________..
*/
function check_role_membership($role_name, $user_id = '')
{
global $current_user;
if (empty($user_id)) {
$user_id = $current_user->id;
}
// Check the Sugar External Cache to see if this users memberships were cached
$role_array = sugar_cache_retrieve("RoleMemberships_" . $user_id);
// If we are pulling the roles for the current user
if ($user_id == $current_user->id) {
// If the Session doesn't contain the values
if (!isset($_SESSION['role_memberships'])) {
// This means the external cache already had it loaded
if (!empty($role_array)) {
$_SESSION['role_memberships'] = $role_array;
} else {
$_SESSION['role_memberships'] = ACLRole::getUserRoleNames($user_id);
$role_array = $_SESSION['role_memberships'];
}
} else {
$role_array = $_SESSION['role_memberships'];
}
} else {
// If the external cache didn't contain the values, we get them and put them in cache
if (!$role_array) {
$role_array = ACLRole::getUserRoleNames($user_id);
sugar_cache_put("RoleMemberships_" . $user_id, $role_array);
}
}
// If the role doesn't exist in the list of the user's roles
if (!empty($role_array) && in_array($role_name, $role_array)) {
return true;
} else {
return false;
}
}