[ticket/216] Add function for obtaining user's groups
B3P-216
This commit is contained in:
@@ -872,3 +872,35 @@ function check_file_src($value, $key, $module_id, $force_error = true)
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -181,17 +181,7 @@ class portal_calendar_module
|
|||||||
}
|
}
|
||||||
array_multisort($time_ary, SORT_NUMERIC, $events);
|
array_multisort($time_ary, SORT_NUMERIC, $events);
|
||||||
|
|
||||||
// get user's groups
|
$groups_ary = get_user_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);
|
|
||||||
|
|
||||||
foreach($events as $key => $cur_event)
|
foreach($events as $key => $cur_event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,18 +69,8 @@ class portal_links_module
|
|||||||
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
|
$links = $this->utf_unserialize($portal_config['board3_links_array_' . $module_id]);
|
||||||
|
|
||||||
// get user's groups
|
// get user's groups
|
||||||
$sql = 'SELECT group_id
|
$groups_ary = get_user_groups();
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($links); $i++)
|
for ($i = 0; $i < sizeof($links); $i++)
|
||||||
{
|
{
|
||||||
if($links[$i]['type'] == self::LINK_INT)
|
if($links[$i]['type'] == self::LINK_INT)
|
||||||
|
|||||||
@@ -68,20 +68,10 @@ class portal_main_menu_module
|
|||||||
$portal_config = obtain_portal_config();
|
$portal_config = obtain_portal_config();
|
||||||
|
|
||||||
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
|
$links = $this->utf_unserialize($portal_config['board3_menu_array_' . $module_id]);
|
||||||
|
|
||||||
// get user's groups
|
// get user's groups
|
||||||
$sql = 'SELECT group_id
|
$groups_ary = get_user_groups();
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($links); $i++)
|
for ($i = 0; $i < sizeof($links); $i++)
|
||||||
{
|
{
|
||||||
if($links[$i]['type'] == self::LINK_CAT)
|
if($links[$i]['type'] == self::LINK_CAT)
|
||||||
|
|||||||
Reference in New Issue
Block a user