From 169b406e2354db72ba25d93b12a586ad834735f5 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Mon, 26 Sep 2011 16:28:53 +0000 Subject: [PATCH] [gh-233] Merging from testing into staging git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1077 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- sites/all/modules/unl/unl.module | 43 +++++++++++++++++++++ sites/all/modules/unl/unl_site_creation.php | 42 ++++++++++++++------ 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/sites/all/modules/unl/unl.module b/sites/all/modules/unl/unl.module index c3d2bfe7..c28a594c 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 ef93eb32..f8304210 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; } /** -- GitLab