1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

Merge pull request #3383 from nickvergessen/ticket/9109

Ticket/9109 Properly document and calculate the group settings with value 0
This commit is contained in:
Tristan Darricau
2015-05-29 16:04:56 +02:00
5 changed files with 181 additions and 15 deletions

View File

@@ -2127,17 +2127,42 @@ function set_user_message_limit()
{
global $user, $db, $config;
// Get maximum about from user memberships - if it is 0, there is no limit set and we use the maximum value within the config.
$sql = 'SELECT MAX(g.group_message_limit) as max_message_limit
// Get maximum about from user memberships
$message_limit = phpbb_get_max_setting_from_group($db, $user->data['user_id'], 'message_limit');
// If it is 0, there is no limit set and we use the maximum value within the config.
$user->data['message_limit'] = (!$message_limit) ? $config['pm_max_msgs'] : $message_limit;
}
/**
* Get the maximum PM setting for the groups of the user
*
* @param \phpbb\db\driver\driver_interface $db
* @param int $user_id
* @param string $setting Only 'max_recipients' and 'message_limit' are supported
* @return int The maximum setting for all groups of the user, unless one group has '0'
* @throws \InvalidArgumentException If selected group setting is not supported
*/
function phpbb_get_max_setting_from_group(\phpbb\db\driver\driver_interface $db, $user_id, $setting)
{
if ($setting !== 'max_recipients' && $setting !== 'message_limit')
{
throw new InvalidArgumentException('Setting "' . $setting . '" is not supported');
}
// Get maximum number of allowed recipients
$sql = 'SELECT MIN(g.group_' . $setting . ') as min_setting, MAX(g.group_' . $setting . ') as max_setting
FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
WHERE ug.user_id = ' . $user->data['user_id'] . '
WHERE ug.user_id = ' . (int) $user_id . '
AND ug.user_pending = 0
AND ug.group_id = g.group_id';
$result = $db->sql_query($sql);
$message_limit = (int) $db->sql_fetchfield('max_message_limit');
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$max_setting = (int) $row['max_setting'];
$min_setting = (int) $row['min_setting'];
$user->data['message_limit'] = (!$message_limit) ? $config['pm_max_msgs'] : $message_limit;
return ($min_setting > 0) ? $max_setting : 0;
}
/**