Merge pull request #104 from marc1706/ticket/216

[ticket/216] Add function for obtaining user's groups
This commit is contained in:
Marc Alexander
2012-12-06 16:04:02 -08:00
4 changed files with 38 additions and 36 deletions

View File

@@ -872,3 +872,35 @@ function check_file_src($value, $key, $module_id, $force_error = true)
return false;
}
}
/**
* Get the groups a user is in
*
* @return array Array containing the user's groups
*/
function get_user_groups()
{
global $cache, $db, $user;
$groups_ary = $cache->get('_user_groups_' . $user->data['user_id']);
if ($groups_ary === false)
{
// get user's groups
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
// save data in cache for 60 seconds
$cache->put('_user_groups_' . $user->data['user_id'], $groups_ary, 60);
}
return $groups_ary;
}

View File

@@ -181,17 +181,7 @@ class portal_calendar_module
}
array_multisort($time_ary, SORT_NUMERIC, $events);
// get user's groups
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
$groups_ary = get_user_groups();
foreach($events as $key => $cur_event)
{

View File

@@ -69,18 +69,8 @@ class portal_links_module
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
// get user's groups
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
$groups_ary = get_user_groups();
for ($i = 0; $i < sizeof($links); $i++)
{
if($links[$i]['type'] == self::LINK_INT)

View File

@@ -68,20 +68,10 @@ class portal_main_menu_module
$portal_config = obtain_portal_config();
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
// get user's groups
$sql = 'SELECT group_id
FROM ' . USER_GROUP_TABLE . '
WHERE user_id = ' . (int) $user->data['user_id'] . '
ORDER BY group_id ASC';
$result = $db->sql_query($sql);
while($row = $db->sql_fetchrow($result))
{
$groups_ary[] = $row['group_id'];
}
$db->sql_freeresult($result);
$groups_ary = get_user_groups();
for ($i = 0; $i < sizeof($links); $i++)
{
if($links[$i]['type'] == self::LINK_CAT)