1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-06 16:56:44 +02:00

Merge branch 'ticket/9549' into develop

* ticket/9549:
  [ticket/9549] Display users in their primary group instead of their first group
  [ticket/9549] Change default value of "sort legend by group name" to false.
  [ticket/9549] Fix displaying empty groups
  [ticket/9549] Fix language strings.
  [ticket/9549] Only add group to legend/teampage when the checkbox is checked.
  [ticket/9549] New method move() to move a group more than 1 up/down.
  [ticket/9549] Fix some minor issues with descriptions and coding-guidelines.
  [ticket/9549] Throw an error when the given field-name is invalid.
  [ticket/9549] Make the class non static and extend delete_group function.
  [ticket/9549] Add template changes for subsilver2.
  [ticket/9549] Enhance teampage and legend functionality
  [ticket/9549] Add the module and files for the ACP.
  [ticket/9549] Update database with the new config values and columns
  [ticket/9549] Enhance teampage functionality with a new class, group_positions.

Conflicts:
	phpBB/install/database_update.php
This commit is contained in:
Oleg Pudeyev
2011-03-01 16:57:00 -05:00
25 changed files with 1244 additions and 263 deletions

View File

@@ -35,6 +35,12 @@ class acp_groups
$form_key = 'acp_groups';
add_form_key($form_key);
if ($mode == 'position')
{
$this->manage_position();
return;
}
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
// Check and set some common vars
@@ -306,6 +312,7 @@ class acp_groups
'rank' => request_var('group_rank', 0),
'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
'legend' => isset($_REQUEST['group_legend']) ? 1 : 0,
'teampage' => isset($_REQUEST['group_teampage']) ? 1 : 0,
'message_limit' => request_var('group_message_limit', 0),
'max_recipients' => request_var('group_max_recipients', 0),
'founder_manage' => 0,
@@ -419,6 +426,7 @@ class acp_groups
'avatar_height' => 'int',
'receive_pm' => 'int',
'legend' => 'int',
'teampage' => 'int',
'message_limit' => 'int',
'max_recipients'=> 'int',
'founder_manage'=> 'int',
@@ -584,6 +592,7 @@ class acp_groups
'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
'GROUP_FOUNDER_MANAGE' => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '',
'GROUP_LEGEND' => (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '',
'GROUP_TEAMPAGE' => (isset($group_row['group_teampage']) && $group_row['group_teampage']) ? ' checked="checked"' : '',
'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
@@ -793,4 +802,122 @@ class acp_groups
}
}
}
public function manage_position()
{
global $config, $db, $template, $user;
$this->tpl_name = 'acp_groups_position';
$this->page_title = 'ACP_GROUPS_POSITION';
$field = request_var('field', '');
$action = request_var('action', '');
$group_id = request_var('g', 0);
if ($field && !in_array($field, array('legend', 'teampage')))
{
// Invalid mode
trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
else if ($field)
{
$group_position = new phpbb_group_positions($db, $field, $this->u_action);
}
switch ($action)
{
case 'set_config_legend':
set_config('legend_sort_groupname', request_var('legend_sort_groupname', 0));
break;
case 'set_config_teampage':
set_config('teampage_forums', request_var('teampage_forums', 0));
set_config('teampage_multiple', request_var('teampage_multiple', 0));
break;
case 'add':
$group_position->add_group($group_id);
break;
case 'delete':
$group_position->delete_group($group_id);
break;
case 'move_up':
$group_position->move_up($group_id);
break;
case 'move_down':
$group_position->move_down($group_id);
break;
}
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
FROM ' . GROUPS_TABLE . '
ORDER BY group_legend, group_name ASC';
$result = $db->sql_query($sql);
$s_group_select_legend = '';
while ($row = $db->sql_fetchrow($result))
{
$group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
if ($row['group_legend'])
{
$template->assign_block_vars('legend', array(
'GROUP_NAME' => $group_name,
'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '',
'GROUP_TYPE' => $user->lang[phpbb_group_positions::group_type_language($row['group_type'])],
'U_MOVE_DOWN' => "{$this->u_action}&field=legend&action=move_down&g=" . $row['group_id'],
'U_MOVE_UP' => "{$this->u_action}&field=legend&action=move_up&g=" . $row['group_id'],
'U_DELETE' => "{$this->u_action}&field=legend&action=delete&g=" . $row['group_id'],
));
}
else
{
$s_group_select_legend .= '<option value="' . (int) $row['group_id'] . '">' . $group_name . '</option>';
}
}
$db->sql_freeresult($result);
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_teampage
FROM ' . GROUPS_TABLE . '
ORDER BY group_teampage, group_name ASC';
$result = $db->sql_query($sql);
$s_group_select_teampage = '';
while ($row = $db->sql_fetchrow($result))
{
$group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
if ($row['group_teampage'])
{
$template->assign_block_vars('teampage', array(
'GROUP_NAME' => $group_name,
'GROUP_COLOUR' => ($row['group_colour']) ? ' style="color: #' . $row['group_colour'] . '"' : '',
'GROUP_TYPE' => $user->lang[phpbb_group_positions::group_type_language($row['group_type'])],
'U_MOVE_DOWN' => "{$this->u_action}&amp;field=teampage&amp;action=move_down&amp;g=" . $row['group_id'],
'U_MOVE_UP' => "{$this->u_action}&amp;field=teampage&amp;action=move_up&amp;g=" . $row['group_id'],
'U_DELETE' => "{$this->u_action}&amp;field=teampage&amp;action=delete&amp;g=" . $row['group_id'],
));
}
else
{
$s_group_select_teampage .= '<option value="' . (int) $row['group_id'] . '">' . $group_name . '</option>';
}
}
$db->sql_freeresult($result);
$template->assign_vars(array(
'U_ACTION' => $this->u_action,
'U_ACTION_LEGEND' => $this->u_action . '&amp;field=legend',
'U_ACTION_TEAMPAGE' => $this->u_action . '&amp;field=teampage',
'S_GROUP_SELECT_LEGEND' => $s_group_select_legend,
'S_GROUP_SELECT_TEAMPAGE' => $s_group_select_teampage,
'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false,
'DISPLAY_MULTIPLE' => ($config['teampage_multiple']) ? true : false,
'LEGEND_SORT_GROUPNAME' => ($config['legend_sort_groupname']) ? true : false,
));
}
}

View File

@@ -21,6 +21,7 @@ class acp_groups_info
'version' => '1.0.0',
'modes' => array(
'manage' => array('title' => 'ACP_GROUPS_MANAGE', 'auth' => 'acl_a_group', 'cat' => array('ACP_GROUPS')),
'position' => array('title' => 'ACP_GROUPS_POSITION', 'auth' => 'acl_a_group', 'cat' => array('ACP_GROUPS')),
),
);
}

View File

@@ -2457,6 +2457,69 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
if (!sizeof($error))
{
$current_legend = phpbb_group_positions::GROUP_DISABLED;
$current_teampage = phpbb_group_positions::GROUP_DISABLED;
$legend = new phpbb_group_positions($db, 'legend');
$teampage = new phpbb_group_positions($db, 'teampage');
if ($group_id)
{
$current_legend = $legend->get_group_value($group_id);
$current_teampage = $teampage->get_group_value($group_id);
}
if (!empty($group_attributes['group_legend']))
{
if (($group_id && ($current_legend == phpbb_group_positions::GROUP_DISABLED)) || !$group_id)
{
// Old group currently not in the legend or new group, add at the end.
$group_attributes['group_legend'] = 1 + $legend->get_group_count();
}
else
{
// Group stayes in the legend
$group_attributes['group_legend'] = $current_legend;
}
}
else if ($group_id && ($current_legend > phpbb_group_positions::GROUP_DISABLED))
{
// Group is removed from the legend
$legend->delete_group($group_id, true);
$group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED;
}
else
{
$group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED;
}
if (!empty($group_attributes['group_teampage']))
{
if (($group_id && ($current_teampage == phpbb_group_positions::GROUP_DISABLED)) || !$group_id)
{
// Old group currently not on the teampage or new group, add at the end.
$group_attributes['group_teampage'] = 1 + $teampage->get_group_count();
}
else
{
// Group stayes on the teampage
$group_attributes['group_teampage'] = $current_teampage;
}
}
else if ($group_id && ($current_teampage > phpbb_group_positions::GROUP_DISABLED))
{
// Group is removed from the teampage
$teampage->delete_group($group_id, true);
$group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED;
}
else
{
$group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED;
}
// Unset the objects, we don't need them anymore.
unset($legend);
unset($teampage);
$user_ary = array();
$sql_ary = array(
'group_name' => (string) $name,
@@ -2681,6 +2744,14 @@ function group_delete($group_id, $group_name = false)
}
while ($start);
// Delete group from legend and teampage
$legend = new phpbb_group_positions($db, 'legend');
$legend->delete_group($group_id);
unset($legend);
$teampage = new phpbb_group_positions($db, 'teampage');
$teampage->delete_group($group_id);
unset($teampage);
// Delete group
$sql = 'DELETE FROM ' . GROUPS_TABLE . "
WHERE group_id = $group_id";

View File

@@ -0,0 +1,261 @@
<?php
/**
*
* @package phpBB3
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Group Position class, containing all functions to manage the groups in the teampage and legend.
*
* group_teampage/group_legend is an ascending list 1, 2, ..., n for groups which are displayed. 1 is the first group, n the last.
* If the value is 0 (self::GROUP_DISABLED) the group is not displayed.
* @package phpBB3
*/
class phpbb_group_positions
{
/**
* Group is not displayed
*/
const GROUP_DISABLED = 0;
/**
* phpbb-database object
*/
public $db = null;
/**
* Name of the field we want to handle: either 'teampage' or 'legend'
*/
private $field = '';
/**
* URI for the adm_back_link when there was an error.
*/
private $adm_back_link = '';
/**
* Constructor
*/
public function __construct ($db, $field, $adm_back_link = '')
{
$this->adm_back_link = $adm_back_link;
if (!in_array($field, array('teampage', 'legend')))
{
$this->error('NO_MODE');
}
$this->db = $db;
$this->field = $field;
}
/**
* Returns the group_{$this->field} for a given group, if the group exists.
* @param int $group_id group_id of the group to be selected
* @return int position of the group
*/
public function get_group_value($group_id)
{
$sql = 'SELECT group_' . $this->field . '
FROM ' . GROUPS_TABLE . '
WHERE group_id = ' . (int) $group_id;
$result = $this->db->sql_query($sql);
$current_value = $this->db->sql_fetchfield('group_' . $this->field);
$this->db->sql_freeresult($result);
if ($current_value === false)
{
// Group not found.
$this->error('NO_GROUP');
}
return (int) $current_value;
}
/**
* Get number of groups, displayed on the teampage/legend
*
* @return int value of the last group displayed
*/
public function get_group_count()
{
$sql = 'SELECT group_' . $this->field . '
FROM ' . GROUPS_TABLE . '
ORDER BY group_' . $this->field . ' DESC';
$result = $this->db->sql_query_limit($sql, 1);
$group_count = (int) $this->db->sql_fetchfield('group_' . $this->field);
$this->db->sql_freeresult($result);
return $group_count;
}
/**
* Addes a group by group_id
*
* @param int $group_id group_id of the group to be added
* @return void
*/
public function add_group($group_id)
{
$current_value = $this->get_group_value($group_id);
if ($current_value == self::GROUP_DISABLED)
{
// Group is currently not displayed, add it at the end.
$next_value = 1 + $this->get_group_count();
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_' . $this->field . ' = ' . $next_value . '
WHERE group_' . $this->field . ' = ' . self::GROUP_DISABLED . '
AND group_id = ' . (int) $group_id;
$this->db->sql_query($sql);
}
}
/**
* Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list.
*
* @param int $group_id group_id of the group to be deleted
* @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway.
* @return void
*/
public function delete_group($group_id, $skip_group = false)
{
$current_value = $this->get_group_value($group_id);
if ($current_value != self::GROUP_DISABLED)
{
$this->db->sql_transaction('begin');
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_' . $this->field . ' = group_' . $this->field . ' - 1
WHERE group_' . $this->field . ' > ' . $current_value;
$this->db->sql_query($sql);
if (!$skip_group)
{
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_' . $this->field . ' = ' . self::GROUP_DISABLED . '
WHERE group_id = ' . (int) $group_id;
$this->db->sql_query($sql);
}
$this->db->sql_transaction('commit');
}
}
/**
* Moves a group up by group_id
*
* @param int $group_id group_id of the group to be moved
* @return void
*/
public function move_up($group_id)
{
$this->move($group_id, 1);
}
/**
* Moves a group down by group_id
*
* @param int $group_id group_id of the group to be moved
* @return void
*/
public function move_down($group_id)
{
$this->move($group_id, -1);
}
/**
* Moves a group up/down
*
* @param int $group_id group_id of the group to be moved
* @param int $delta number of steps:
* - positive = move up
* - negative = move down
* @return void
*/
public function move($group_id, $delta)
{
if (!is_int($delta) || !$delta)
{
return;
}
$move_up = ($delta > 0) ? true : false;
$current_value = $this->get_group_value($group_id);
if ($current_value != self::GROUP_DISABLED)
{
$this->db->sql_transaction('begin');
// First we move all groups between our current value and the target value up/down 1,
// so we have a gap for our group to move.
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_' . $this->field . ' = group_' . $this->field . (($move_up) ? ' + 1' : ' - 1') . '
WHERE group_' . $this->field . ' > ' . self::GROUP_DISABLED . '
AND group_' . $this->field . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . '
AND group_' . $this->field . (($move_up) ? ' < ' : ' > ') . $current_value;
$this->db->sql_query($sql);
// Because there might be fewer groups above/below the group than we wanted to move,
// we use the number of changed groups, to update the group.
$delta = (int) $this->db->sql_affectedrows();
if ($delta)
{
// And now finally, when we moved some other groups and built a gap,
// we can move the desired group to it.
$sql = 'UPDATE ' . GROUPS_TABLE . '
SET group_' . $this->field . ' = group_' . $this->field . (($move_up) ? ' - ' : ' + ') . $delta . '
WHERE group_id = ' . (int) $group_id;
$this->db->sql_query($sql);
}
$this->db->sql_transaction('commit');
}
}
/**
* Get group type language var
*
* @param int $group_type group_type from the groups-table
* @return string name of the language variable for the given group-type.
*/
static public function group_type_language($group_type)
{
switch ($group_type)
{
case GROUP_OPEN:
return 'GROUP_REQUEST';
case GROUP_CLOSED:
return 'GROUP_CLOSED';
case GROUP_HIDDEN:
return 'GROUP_HIDDEN';
case GROUP_SPECIAL:
return 'GROUP_SPECIAL';
case GROUP_FREE:
return 'GROUP_OPEN';
}
}
/**
* Error
*/
public function error($message)
{
global $user;
trigger_error($user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING);
}
}