diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index c3d2bfe7d33e2353eddbcc33b0546f17236519e1..c28a594ce448249def444a8e25995436ded23018 100644 --- a/sites/all/modules/unl/unl.module +++ b/sites/all/modules/unl/unl.module @@ -1144,5 +1144,48 @@ function _unl_limit_menu_depth($menu_links, $depth) { +/** + * Implements hook_block_info() + */ +function unl_block_info() { + $blocks = array(); + + $blocks['my_sites'] = array( + 'info' => 'My Sites', + ); + + return $blocks; +} + +/** + * Implements hook_block_view() + */ +function unl_block_view($delta = '') { + switch ($delta) { + case 'my_sites': + return unl_block_view_my_sites(); + break; + default: + return array(); + } +} + +/** + * Implements hook_block_view('my_sites'). + * Displays the list of sites/roles for the current user. + */ +function unl_block_view_my_sites() +{ + require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'unl_site_creation.php'; + + $block = array(); + $block['content'] = _unl_get_user_audit_content($GLOBALS['user']->name); + + return $block; +} + + + + diff --git a/sites/all/modules/unl/unl_site_creation.php b/sites/all/modules/unl/unl_site_creation.php index ef93eb3261101e62a9907d164ec09d83e5dc34b1..f83042100b30b385aa602128ed8964b2798504cc 100644 --- a/sites/all/modules/unl/unl_site_creation.php +++ b/sites/all/modules/unl/unl_site_creation.php @@ -695,34 +695,54 @@ function unl_user_audit($form, &$form_state) { // Otherwise, since we have a username, we can query the sub-sites and return a list of roles for each. $username = $form_state['values']['username']; + + $form['results'] = array( + '#type' => 'fieldset', + '#title' => 'Results', + ); + + $form['results']['roles'] = _unl_get_user_audit_content($username); + + return $form; +} + +/** + * Returns an array that can be passed to drupal_render() of the given user's sites/roles. + * @param string $username + */ +function _unl_get_user_audit_content($username) { $audit_map = array(); + foreach (unl_get_site_user_map('username', $username) as $site_id => $site) { $audit_map[] = array( 'data' => l($site['uri'], $site['uri']), 'children' => $site['roles'], ); } - - $form['results'] = array( - '#type' => 'fieldset', - '#title' => 'Results', - ); - + if (count($audit_map) > 0) { - $form['results']['roles'] = array( + $content = array( '#theme' => 'item_list', - '#title' => 'The user "' . $username . '" belongs to the following sites as a member of the listed roles.', '#type' => 'ul', '#items' => $audit_map, ); + if ($username == $GLOBALS['user']->name) { + $content['#title'] = 'You belong to the following sites as a member of the listed roles.'; + } else { + $content['#title'] = 'The user "' . $username . '" belongs to the following sites as a member of the listed roles.'; + } } else { - $form['results']['roles'] = array( + $content = array( '#type' => 'item', - '#title' => 'The user "' . $username . '" does not belong to any roles on any sites.', ); + if ($username == $GLOBALS['user']->name) { + $content['#title'] = 'You do not belong to any roles on any sites.'; + } else { + $content['#title'] = 'The user "' . $username . '" does not belong to any roles on any sites.'; + } } - return $form; + return $content; } /**