function _menu_per_role_get_roles in Menu Per Role 7
Same name and namespace in other branches
- 6 menu_per_role.module \_menu_per_role_get_roles()
Gets all roles with access to the specified menu item.
No roles mean that access is granted by this module.
Parameters
int $mlid: The menu link id.
int $show: Set to 0 for show to roles, 1 for hide from roles.
Return value
array An array of roles.
2 calls to _menu_per_role_get_roles()
- menu_per_role_form_menu_edit_item_alter in ./
menu_per_role.module - Implements hook_form_FORM_ID_alter().
- _menu_per_role_access in ./
menu_per_role.module - Determines access for a given menu item id.
File
- ./
menu_per_role.module, line 278 - Allows restricting access to menu items per role.
Code
function _menu_per_role_get_roles($mlid, $show) {
static $menu_per_role;
if (!isset($menu_per_role)) {
// Read all the data ONCE, it is likely very small.
$menu_per_role = array();
$result = db_select('menu_per_role', 'mpr')
->fields('mpr')
->execute()
->fetchAll();
foreach ($result as $row) {
if ($row->rids || $row->hrids) {
if ($row->rids) {
$menu_per_role[$row->mlid][0] = _menu_per_role_unserialize_rids($row->rids);
}
else {
$menu_per_role[$row->mlid][0] = array();
}
if ($row->hrids) {
$menu_per_role[$row->mlid][1] = _menu_per_role_unserialize_rids($row->hrids);
}
else {
$menu_per_role[$row->mlid][1] = array();
}
}
}
}
if (isset($menu_per_role[$mlid])) {
return $menu_per_role[$mlid][$show];
}
// Not defined, everyone has the right to use it.
return array();
}