public getReadableAccessLevel ( integer $entity_access_id ) : string | ||
$entity_access_id | integer | The entity's access id |
return | string |
function getReadableAccessLevel($entity_access_id)
{
$access = (int) $entity_access_id;
$translator = $this->translator;
// Check if entity access id is a defined global constant
$access_array = array(ACCESS_PRIVATE => $translator->translate("PRIVATE"), ACCESS_FRIENDS => $translator->translate("access:friends:label"), ACCESS_LOGGED_IN => $translator->translate("LOGGED_IN"), ACCESS_PUBLIC => $translator->translate("PUBLIC"));
if (array_key_exists($access, $access_array)) {
return $access_array[$access];
}
$user_guid = $this->session->getLoggedInUserGuid();
if (!$user_guid) {
// return 'Limited' if there is no logged in user
return $translator->translate('access:limited:label');
}
// Entity access id is probably a custom access collection
// Check if the user has write access to it and can see it's label
// Admins should always be able to see the readable version
$collection = $this->get($access);
if ($collection) {
if ($collection->owner_guid == $user_guid || $this->session->isAdminLoggedIn()) {
return $collection->name;
}
}
// return 'Limited' if the user does not have access to the access collection
return $translator->translate('access:limited:label');
}