本文整理匯總了PHP中eZRole::fetchByUser方法的典型用法代碼示例。如果您正苦於以下問題:PHP eZRole::fetchByUser方法的具體用法?PHP eZRole::fetchByUser怎麽用?PHP eZRole::fetchByUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類eZRole
的用法示例。
在下文中一共展示了eZRole::fetchByUser方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testFetchByUser
/**
* Unit test for eZRole::fetchByUser
**/
public function testFetchByUser()
{
// test with an empty array
$roles = eZRole::fetchByUser(array());
$this->assertType('array', $roles, "eZRole::fetchByUser with an empty array should have returned an array");
$this->assertEquals(0, count($roles), "eZRole::fetchByUser with an empty array should have returned an empty array");
// test with users with no direct role assignment (group assignment)
// should return an empty array since anonymous/admin role is assigned
// by group
$parameter = array(self::$anonymousUserID, self::$adminUserID);
$roles = eZRole::fetchByUser($parameter);
$this->assertType('array', $roles, "eZRole::fetchByUser with admin & anonymous should have returned an array");
$this->assertEquals(0, count($roles), "eZRole::fetchByUser with admin & anonymous should have returned an empty array");
foreach ($roles as $role) {
$this->assertType('eZRole', $role, "Returned items should be roles");
}
// test with the same users, but recursively: should return anonymous
// and administrator roles
$parameter = array(self::$anonymousUserID, self::$adminUserID);
$roles = eZRole::fetchByUser($parameter, true);
$this->assertType('array', $roles, "recursive eZRole::fetchByUser with admin & anonymous should have returned an array");
$this->assertEquals(2, count($roles), "recursive eZRole::fetchByUser with admin & anonymous should have returned an empty array");
foreach ($roles as $role) {
$this->assertType('eZRole', $role, "Returned items should be roles");
}
}
示例2: testPolicyList
/**
* Test for eZRole::policyList()
* Checks that policyList doesn't return temporary policies
*/
public function testPolicyList()
{
$role = array_shift(eZRole::fetchByUser(array(self::$anonymousUserID), true));
$policy = array_shift($role->policyList());
// create a temporary copy of one of the role's policies
$policy->createTemporaryCopy();
// check that the role's policies all are final (not temporary)
foreach ($role->policyList() as $policy) {
$this->assertType('eZPolicy', $policy);
$this->assertEquals(0, $policy->attribute('original_id'));
}
}
示例3: roles
function roles()
{
$groups = $this->attribute('groups');
$groups[] = $this->attribute('contentobject_id');
return eZRole::fetchByUser($groups);
}
示例4: fetchMemberOf
/**
* Fetch role list
* Used by fetch( 'user', 'member_of', hash( 'id', $id ) ) template function.
*
* @param int $id User id or normal content object id in case of none user object (user group)
* @return array(string=>array)
*/
function fetchMemberOf($id)
{
$user = eZUser::fetch($id);
if ($user instanceof eZUser) {
$roleList = $user->roles();
} else {
// user group or other non user classes:
$roleList = eZRole::fetchByUser(array($id), true);
}
return array('result' => $roleList);
}
示例5: accessArrayByUserID
/**
* Return access array by passing in list of groups user belongs to and his user id
*
* @param array $idArray Array of eZContentObject IDs, either groups + user id or user id's only
* If only user id's, then remember to set $recursive to true
* @param bool $recursive See {@link eZRole::fetchByUser()}
* @return array Hash with complete access limitation description
*/
static function accessArrayByUserID($idArray, $recursive = false)
{
$roles = eZRole::fetchByUser($idArray, $recursive);
$userLimitation = false;
$accessArray = array();
foreach (array_keys($roles) as $roleKey) {
$accessArray = array_merge_recursive($accessArray, $roles[$roleKey]->accessArray());
if ($roles[$roleKey]->attribute('limit_identifier')) {
$userLimitation = true;
}
}
if ($userLimitation) {
foreach ($accessArray as $moduleKey => $functionList) {
foreach ($functionList as $functionKey => $policyList) {
foreach ($policyList as $policyKey => $limitationList) {
if (is_array($limitationList)) {
foreach ($limitationList as $limitationKey => $limitKeyArray) {
if (is_array($limitKeyArray)) {
$accessArray[$moduleKey][$functionKey][$policyKey][$limitationKey] = array_unique($limitKeyArray);
}
}
}
}
}
}
}
return $accessArray;
}