mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 14:00:31 +02:00
Merge remote-tracking branch 'remotes/nickv/ticket/10411-2' into develop
# By Joas Schilling # Via Joas Schilling * remotes/nickv/ticket/10411-2: (33 commits) [ticket/10411] Fix call to function on non-object $db->...() [ticket/10411] Remove ajax delete, so the page is refreshed [ticket/10411] Update schema file with new table and remove the column [ticket/10411] Add unit tests for move() with values >1 [ticket/10411] Add migrations file for teampage table [ticket/10411] Revert database_update.php changes from for easier update [ticket/10411] Add maxlength to category name input field [ticket/10411] Test for thrown exceptions when group does not exist [ticket/10411] Catch exceptions from grouppositions [ticket/10411] Throw exceptions instead of using trigger_error() [ticket/10411] Add return values to add/delete function [ticket/10411] Add return value to move functions [ticket/10411] Fix typehinting and change private to protected [ticket/10411] Use template loops instead of defining the html in php files [ticket/10411] Ensure we only get services that do exist [ticket/10411] Add a comment why we left join the group table [ticket/10411] Rename template variable CUR_ to CURRENT_ [ticket/10411] Move globals to the top and use array for cache destroy [ticket/10411] Use new ajax callback name row_up/row_down [ticket/10411] Fix logic error when editing/creating a group ...
This commit is contained in:
@@ -61,9 +61,11 @@ class acp_groups
|
||||
// Grab basic data for group, if group_id is set and exists
|
||||
if ($group_id)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . GROUPS_TABLE . "
|
||||
WHERE group_id = $group_id";
|
||||
$sql = 'SELECT g.*, t.teampage_position AS group_teampage
|
||||
FROM ' . GROUPS_TABLE . ' g
|
||||
LEFT JOIN ' . TEAMPAGE_TABLE . ' t
|
||||
ON (t.group_id = g.group_id)
|
||||
WHERE g.group_id = ' . $group_id;
|
||||
$result = $db->sql_query($sql);
|
||||
$group_row = $db->sql_fetchrow($result);
|
||||
$db->sql_freeresult($result);
|
||||
@@ -514,7 +516,7 @@ class acp_groups
|
||||
}
|
||||
}
|
||||
|
||||
$cache->destroy('sql', GROUPS_TABLE);
|
||||
$cache->destroy('sql', array(GROUPS_TABLE, TEAMPAGE_TABLE));
|
||||
|
||||
$message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
|
||||
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
|
||||
@@ -829,56 +831,112 @@ class acp_groups
|
||||
|
||||
public function manage_position()
|
||||
{
|
||||
global $config, $db, $template, $user;
|
||||
global $config, $db, $template, $user, $request, $phpbb_container;
|
||||
|
||||
$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);
|
||||
$field = $request->variable('field', '');
|
||||
$action = $request->variable('action', '');
|
||||
$group_id = $request->variable('g', 0);
|
||||
$teampage_id = $request->variable('t', 0);
|
||||
$category_id = $request->variable('c', 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)
|
||||
else if ($field && in_array($field, array('legend', 'teampage')))
|
||||
{
|
||||
$group_position = new phpbb_group_positions($db, $field, $this->u_action);
|
||||
|
||||
$group_position = $phpbb_container->get('groupposition.' . $field);
|
||||
}
|
||||
|
||||
switch ($action)
|
||||
if ($field == 'teampage')
|
||||
{
|
||||
case 'set_config_legend':
|
||||
set_config('legend_sort_groupname', request_var('legend_sort_groupname', 0));
|
||||
break;
|
||||
try
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
$group_position->add_group_teampage($group_id, $category_id);
|
||||
break;
|
||||
|
||||
case 'set_config_teampage':
|
||||
set_config('teampage_forums', request_var('teampage_forums', 0));
|
||||
set_config('teampage_memberships', request_var('teampage_memberships', 0));
|
||||
break;
|
||||
case 'add_category':
|
||||
$group_position->add_category_teampage($request->variable('category_name', '', true));
|
||||
break;
|
||||
|
||||
case 'add':
|
||||
$group_position->add_group($group_id);
|
||||
break;
|
||||
case 'delete':
|
||||
$group_position->delete_teampage($teampage_id);
|
||||
break;
|
||||
|
||||
case 'delete':
|
||||
$group_position->delete_group($group_id);
|
||||
break;
|
||||
case 'move_up':
|
||||
$group_position->move_up_teampage($teampage_id);
|
||||
break;
|
||||
|
||||
case 'move_up':
|
||||
$group_position->move_up($group_id);
|
||||
break;
|
||||
case 'move_down':
|
||||
$group_position->move_down_teampage($teampage_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
else if ($field == 'legend')
|
||||
{
|
||||
try
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'add':
|
||||
$group_position->add_group($group_id);
|
||||
break;
|
||||
|
||||
case 'move_down':
|
||||
$group_position->move_down($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;
|
||||
}
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()) . adm_back_link($this->u_action), E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ($action)
|
||||
{
|
||||
case 'set_config_teampage':
|
||||
$config->set('teampage_forums', $request->variable('teampage_forums', 0));
|
||||
$config->set('teampage_memberships', $request->variable('teampage_memberships', 0));
|
||||
break;
|
||||
|
||||
case 'set_config_legend':
|
||||
$config->set('legend_sort_groupname', $request->variable('legend_sort_groupname', 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (($action == 'move_up' || $action == 'move_down') && $request->is_ajax())
|
||||
{
|
||||
$json_response = new phpbb_json_response;
|
||||
$json_response->send(array('success' => true));
|
||||
}
|
||||
|
||||
$sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
ORDER BY group_legend, group_name ASC';
|
||||
ORDER BY group_legend ASC, group_type DESC, group_name ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$s_group_select_legend = '';
|
||||
@@ -888,57 +946,99 @@ class acp_groups
|
||||
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'])],
|
||||
'GROUP_NAME' => $group_name,
|
||||
'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '',
|
||||
'GROUP_TYPE' => $user->lang[phpbb_groupposition_legend::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'],
|
||||
'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>';
|
||||
$template->assign_block_vars('add_legend', array(
|
||||
'GROUP_ID' => (int) $row['group_id'],
|
||||
'GROUP_NAME' => $group_name,
|
||||
'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL),
|
||||
));
|
||||
}
|
||||
}
|
||||
$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';
|
||||
$category_url_param = (($category_id) ? '&c=' . $category_id : '');
|
||||
|
||||
$sql = 'SELECT t.*, g.group_name, g.group_colour, g.group_type
|
||||
FROM ' . TEAMPAGE_TABLE . ' t
|
||||
LEFT JOIN ' . GROUPS_TABLE . ' g
|
||||
ON (t.group_id = g.group_id)
|
||||
WHERE t.teampage_parent = ' . $category_id . '
|
||||
OR t.teampage_id = ' . $category_id . '
|
||||
ORDER BY t.teampage_position ASC';
|
||||
$result = $db->sql_query($sql);
|
||||
|
||||
$category_data = array();
|
||||
while ($row = $db->sql_fetchrow($result))
|
||||
{
|
||||
if ($row['teampage_id'] == $category_id)
|
||||
{
|
||||
$template->assign_vars(array(
|
||||
'CURRENT_CATEGORY_NAME' => $row['teampage_name'],
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($row['group_id'])
|
||||
{
|
||||
$group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
|
||||
$group_type = $user->lang[phpbb_groupposition_teampage::group_type_language($row['group_type'])];
|
||||
}
|
||||
else
|
||||
{
|
||||
$group_name = $row['teampage_name'];
|
||||
$group_type = '';
|
||||
}
|
||||
|
||||
$template->assign_block_vars('teampage', array(
|
||||
'GROUP_NAME' => $group_name,
|
||||
'GROUP_COLOUR' => ($row['group_colour']) ? '#' . $row['group_colour'] : '',
|
||||
'GROUP_TYPE' => $group_type,
|
||||
|
||||
'U_CATEGORY' => (!$row['group_id']) ? "{$this->u_action}&c=" . $row['teampage_id'] : '',
|
||||
'U_MOVE_DOWN' => "{$this->u_action}&field=teampage&action=move_down{$category_url_param}&t=" . $row['teampage_id'],
|
||||
'U_MOVE_UP' => "{$this->u_action}&field=teampage&action=move_up{$category_url_param}&t=" . $row['teampage_id'],
|
||||
'U_DELETE' => "{$this->u_action}&field=teampage&action=delete{$category_url_param}&t=" . $row['teampage_id'],
|
||||
));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type
|
||||
FROM ' . GROUPS_TABLE . ' g
|
||||
LEFT JOIN ' . TEAMPAGE_TABLE . ' t
|
||||
ON (t.group_id = g.group_id)
|
||||
WHERE t.teampage_id IS NULL
|
||||
ORDER BY g.group_type DESC, g.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}&field=teampage&action=move_down&g=" . $row['group_id'],
|
||||
'U_MOVE_UP' => "{$this->u_action}&field=teampage&action=move_up&g=" . $row['group_id'],
|
||||
'U_DELETE' => "{$this->u_action}&field=teampage&action=delete&g=" . $row['group_id'],
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$s_group_select_teampage .= '<option value="' . (int) $row['group_id'] . '">' . $group_name . '</option>';
|
||||
}
|
||||
$template->assign_block_vars('add_teampage', array(
|
||||
'GROUP_ID' => (int) $row['group_id'],
|
||||
'GROUP_NAME' => $group_name,
|
||||
'GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL),
|
||||
));
|
||||
}
|
||||
$db->sql_freeresult($result);
|
||||
|
||||
$template->assign_vars(array(
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_ACTION_LEGEND' => $this->u_action . '&field=legend',
|
||||
'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage',
|
||||
'U_ACTION' => $this->u_action,
|
||||
'U_ACTION_LEGEND' => $this->u_action . '&field=legend',
|
||||
'U_ACTION_TEAMPAGE' => $this->u_action . '&field=teampage' . $category_url_param,
|
||||
'U_ACTION_TEAMPAGE_CAT' => $this->u_action . '&field=teampage_cat',
|
||||
|
||||
'S_GROUP_SELECT_LEGEND' => $s_group_select_legend,
|
||||
'S_GROUP_SELECT_TEAMPAGE' => $s_group_select_teampage,
|
||||
'S_TEAMPAGE_CATEGORY' => $category_id,
|
||||
'DISPLAY_FORUMS' => ($config['teampage_forums']) ? true : false,
|
||||
'DISPLAY_MEMBERSHIPS' => $config['teampage_memberships'],
|
||||
'LEGEND_SORT_GROUPNAME' => ($config['legend_sort_groupname']) ? true : false,
|
||||
|
@@ -270,6 +270,7 @@ define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data');
|
||||
define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme');
|
||||
define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset');
|
||||
define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data');
|
||||
define('TEAMPAGE_TABLE', $table_prefix . 'teampage');
|
||||
define('TOPICS_TABLE', $table_prefix . 'topics');
|
||||
define('TOPICS_POSTED_TABLE', $table_prefix . 'topics_posted');
|
||||
define('TOPICS_TRACK_TABLE', $table_prefix . 'topics_track');
|
||||
|
104
phpBB/includes/db/migration/data/310/teampage.php
Normal file
104
phpBB/includes/db/migration/data/310/teampage.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package migration
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_db_migration_data_310_teampage extends phpbb_db_migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->db_tools->sql_table_exists($this->table_prefix . 'teampage');
|
||||
}
|
||||
|
||||
static public function depends_on()
|
||||
{
|
||||
return array('phpbb_db_migration_data_310_dev');
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return array(
|
||||
'add_tables' => array(
|
||||
$this->table_prefix . 'teampage' => array(
|
||||
'COLUMNS' => array(
|
||||
'teampage_id' => array('UINT', NULL, 'auto_increment'),
|
||||
'group_id' => array('UINT', 0),
|
||||
'teampage_name' => array('VCHAR_UNI:255', ''),
|
||||
'teampage_position' => array('UINT', 0),
|
||||
'teampage_parent' => array('UINT', 0),
|
||||
),
|
||||
'PRIMARY_KEY' => 'teampage_id',
|
||||
),
|
||||
),
|
||||
'drop_columns' => array(
|
||||
$this->table_prefix . 'groups' => array(
|
||||
'group_teampage',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return array(
|
||||
'drop_tables' => array(
|
||||
$this->table_prefix . 'teampage',
|
||||
),
|
||||
'add_columns' => array(
|
||||
$this->table_prefix . 'groups' => array(
|
||||
'group_teampage' => array('UINT', 0, 'after' => 'group_legend'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return array(
|
||||
array('custom', array(array($this, 'add_groups_teampage'))),
|
||||
);
|
||||
}
|
||||
|
||||
public function add_groups_teampage()
|
||||
{
|
||||
$sql = 'SELECT teampage_id
|
||||
FROM ' . TEAMPAGE_TABLE;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$added_groups_teampage = (bool) $this->db->sql_fetchfield('teampage_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (!$added_groups_teampage)
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
WHERE group_type = ' . GROUP_SPECIAL . "
|
||||
AND (group_name = 'ADMINISTRATORS'
|
||||
OR group_name = 'GLOBAL_MODERATORS')
|
||||
ORDER BY group_name ASC";
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$teampage_entries = array();
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$teampage_entries[] = array(
|
||||
'group_id' => (int) $row['group_id'],
|
||||
'teampage_name' => '',
|
||||
'teampage_position' => sizeof($teampage_entries) + 1,
|
||||
'teampage_parent' => 0,
|
||||
);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (sizeof($teampage_entries))
|
||||
{
|
||||
$this->db->sql_multi_insert(TEAMPAGE_TABLE, $teampage_entries);
|
||||
}
|
||||
unset($teampage_entries);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -2570,7 +2570,7 @@ function phpbb_avatar_explanation_string()
|
||||
*/
|
||||
function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow_desc_bbcode = false, $allow_desc_urls = false, $allow_desc_smilies = false)
|
||||
{
|
||||
global $phpbb_root_path, $config, $db, $user, $file_upload;
|
||||
global $phpbb_root_path, $config, $db, $user, $file_upload, $phpbb_container;
|
||||
|
||||
$error = array();
|
||||
|
||||
@@ -2594,22 +2594,32 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
|
||||
$error[] = $user->lang['GROUP_ERR_TYPE'];
|
||||
}
|
||||
|
||||
$group_teampage = !empty($group_attributes['group_teampage']);
|
||||
unset($group_attributes['group_teampage']);
|
||||
|
||||
if (!sizeof($error))
|
||||
{
|
||||
$current_legend = phpbb_group_positions::GROUP_DISABLED;
|
||||
$current_teampage = phpbb_group_positions::GROUP_DISABLED;
|
||||
$current_legend = phpbb_groupposition_legend::GROUP_DISABLED;
|
||||
$current_teampage = phpbb_groupposition_teampage::GROUP_DISABLED;
|
||||
|
||||
$legend = new phpbb_group_positions($db, 'legend');
|
||||
$teampage = new phpbb_group_positions($db, 'teampage');
|
||||
$legend = $phpbb_container->get('groupposition.legend');
|
||||
$teampage = $phpbb_container->get('groupposition.teampage');
|
||||
if ($group_id)
|
||||
{
|
||||
$current_legend = $legend->get_group_value($group_id);
|
||||
$current_teampage = $teampage->get_group_value($group_id);
|
||||
try
|
||||
{
|
||||
$current_legend = $legend->get_group_value($group_id);
|
||||
$current_teampage = $teampage->get_group_value($group_id);
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($group_attributes['group_legend']))
|
||||
{
|
||||
if (($group_id && ($current_legend == phpbb_group_positions::GROUP_DISABLED)) || !$group_id)
|
||||
if (($group_id && ($current_legend == phpbb_groupposition_legend::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();
|
||||
@@ -2620,44 +2630,26 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
|
||||
$group_attributes['group_legend'] = $current_legend;
|
||||
}
|
||||
}
|
||||
else if ($group_id && ($current_legend > phpbb_group_positions::GROUP_DISABLED))
|
||||
else if ($group_id && ($current_legend != phpbb_groupposition_legend::GROUP_DISABLED))
|
||||
{
|
||||
// Group is removed from the legend
|
||||
$legend->delete_group($group_id, true);
|
||||
$group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED;
|
||||
try
|
||||
{
|
||||
$legend->delete_group($group_id, true);
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
$group_attributes['group_legend'] = phpbb_groupposition_legend::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;
|
||||
$group_attributes['group_legend'] = phpbb_groupposition_legend::GROUP_DISABLED;
|
||||
}
|
||||
|
||||
// Unset the objects, we don't need them anymore.
|
||||
unset($legend);
|
||||
unset($teampage);
|
||||
|
||||
$user_ary = array();
|
||||
$sql_ary = array(
|
||||
@@ -2751,6 +2743,20 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
|
||||
$db->sql_query($sql);
|
||||
}
|
||||
|
||||
// Remove the group from the teampage, only if unselected and we are editing a group,
|
||||
// which is currently displayed.
|
||||
if (!$group_teampage && $group_id && $current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED)
|
||||
{
|
||||
try
|
||||
{
|
||||
$teampage->delete_group($group_id);
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$group_id)
|
||||
{
|
||||
$group_id = $db->sql_nextid();
|
||||
@@ -2761,6 +2767,31 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ($group_teampage && $current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED)
|
||||
{
|
||||
$teampage->add_group($group_id);
|
||||
}
|
||||
|
||||
if ($group_teampage)
|
||||
{
|
||||
if ($current_teampage == phpbb_groupposition_teampage::GROUP_DISABLED)
|
||||
{
|
||||
$teampage->add_group($group_id);
|
||||
}
|
||||
}
|
||||
else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED))
|
||||
{
|
||||
$teampage->delete_group($group_id);
|
||||
}
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
unset($teampage);
|
||||
|
||||
// Set user attributes
|
||||
$sql_ary = array();
|
||||
if (sizeof($group_attributes))
|
||||
@@ -2842,7 +2873,7 @@ function avatar_remove_db($avatar_name)
|
||||
*/
|
||||
function group_delete($group_id, $group_name = false)
|
||||
{
|
||||
global $db, $cache, $auth, $phpbb_root_path, $phpEx, $phpbb_dispatcher;
|
||||
global $db, $cache, $auth, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_container;
|
||||
|
||||
if (!$group_name)
|
||||
{
|
||||
@@ -2884,12 +2915,31 @@ 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);
|
||||
try
|
||||
{
|
||||
$legend = $phpbb_container->get('groupposition.legend');
|
||||
$legend->delete_group($group_id);
|
||||
unset($legend);
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
// The group we want to delete does not exist.
|
||||
// No reason to worry, we just continue the deleting process.
|
||||
//trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$teampage = $phpbb_container->get('groupposition.teampage');
|
||||
$teampage->delete_group($group_id);
|
||||
unset($teampage);
|
||||
}
|
||||
catch (phpbb_groupposition_exception $exception)
|
||||
{
|
||||
// The group we want to delete does not exist.
|
||||
// No reason to worry, we just continue the deleting process.
|
||||
//trigger_error($user->lang($exception->getMessage()));
|
||||
}
|
||||
|
||||
// Delete group
|
||||
$sql = 'DELETE FROM ' . GROUPS_TABLE . "
|
||||
|
23
phpBB/includes/groupposition/exception.php
Normal file
23
phpBB/includes/groupposition/exception.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package groupposition
|
||||
* @copyright (c) 2013 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @package groupposition
|
||||
*/
|
||||
class phpbb_groupposition_exception extends \Exception
|
||||
{
|
||||
}
|
84
phpBB/includes/groupposition/interface.php
Normal file
84
phpBB/includes/groupposition/interface.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to manage group positions in various places of phpbb
|
||||
*
|
||||
* The interface provides simple methods to add, delete and move a group
|
||||
*
|
||||
* @package phpBB3
|
||||
*/
|
||||
interface phpbb_groupposition_interface
|
||||
{
|
||||
/**
|
||||
* Returns the value 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);
|
||||
|
||||
/**
|
||||
* Get number of groups displayed
|
||||
*
|
||||
* @return int value of the last item displayed
|
||||
*/
|
||||
public function get_group_count();
|
||||
|
||||
/**
|
||||
* Addes a group by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be added
|
||||
* @return bool True if the group was added successfully
|
||||
*/
|
||||
public function add_group($group_id);
|
||||
|
||||
/**
|
||||
* Deletes a group by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be deleted
|
||||
* @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway.
|
||||
* @return bool True if the group was deleted successfully
|
||||
*/
|
||||
public function delete_group($group_id, $skip_group = false);
|
||||
|
||||
/**
|
||||
* Moves a group up by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be moved
|
||||
* @return bool True if the group was moved successfully
|
||||
*/
|
||||
public function move_up($group_id);
|
||||
|
||||
/**
|
||||
* Moves a group down by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be moved
|
||||
* @return bool True if the group was moved successfully
|
||||
*/
|
||||
public function move_down($group_id);
|
||||
|
||||
/**
|
||||
* 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 bool True if the group was moved successfully
|
||||
*/
|
||||
public function move($group_id, $delta);
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
@@ -16,13 +16,14 @@ if (!defined('IN_PHPBB'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Group Position class, containing all functions to manage the groups in the teampage and legend.
|
||||
* Legend group position class
|
||||
*
|
||||
* group_teampage/group_legend is an ascending list 1, 2, ..., n for groups which are displayed. 1 is the first group, n the last.
|
||||
* 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
|
||||
class phpbb_groupposition_legend implements phpbb_groupposition_interface
|
||||
{
|
||||
/**
|
||||
* Group is not displayed
|
||||
@@ -30,81 +31,73 @@ class phpbb_group_positions
|
||||
const GROUP_DISABLED = 0;
|
||||
|
||||
/**
|
||||
* phpbb-database object
|
||||
* Database object
|
||||
* @var phpbb_db_driver
|
||||
*/
|
||||
public $db = null;
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Name of the field we want to handle: either 'teampage' or 'legend'
|
||||
* User object
|
||||
* @var phpbb_user
|
||||
*/
|
||||
private $field = '';
|
||||
|
||||
/**
|
||||
* URI for the adm_back_link when there was an error.
|
||||
*/
|
||||
private $adm_back_link = '';
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param phpbb_db_driver $db Database object
|
||||
* @param phpbb_user $user User object
|
||||
*/
|
||||
public function __construct ($db, $field, $adm_back_link = '')
|
||||
public function __construct(phpbb_db_driver $db, phpbb_user $user)
|
||||
{
|
||||
$this->adm_back_link = $adm_back_link;
|
||||
|
||||
if (!in_array($field, array('teampage', 'legend')))
|
||||
{
|
||||
$this->error('NO_MODE');
|
||||
}
|
||||
|
||||
$this->db = $db;
|
||||
$this->field = $field;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Returns the group_legend for a given group, if the group exists.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_group_value($group_id)
|
||||
{
|
||||
$sql = 'SELECT group_' . $this->field . '
|
||||
$sql = 'SELECT group_legend
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$current_value = $this->db->sql_fetchfield('group_' . $this->field);
|
||||
$current_value = $this->db->sql_fetchfield('group_legend');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($current_value === false)
|
||||
{
|
||||
// Group not found.
|
||||
$this->error('NO_GROUP');
|
||||
throw new phpbb_groupposition_exception('NO_GROUP');
|
||||
}
|
||||
|
||||
return (int) $current_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of groups, displayed on the teampage/legend
|
||||
* Get number of groups, displayed on the legend
|
||||
*
|
||||
* @return int value of the last group displayed
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_group_count()
|
||||
{
|
||||
$sql = 'SELECT group_' . $this->field . '
|
||||
$sql = 'SELECT group_legend
|
||||
FROM ' . GROUPS_TABLE . '
|
||||
ORDER BY group_' . $this->field . ' DESC';
|
||||
ORDER BY group_legend DESC';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$group_count = (int) $this->db->sql_fetchfield('group_' . $this->field);
|
||||
$group_count = (int) $this->db->sql_fetchfield('group_legend');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $group_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Addes a group by group_id
|
||||
* Adds a group by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be added
|
||||
* @return null
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function add_group($group_id)
|
||||
{
|
||||
@@ -116,19 +109,20 @@ class phpbb_group_positions
|
||||
$next_value = 1 + $this->get_group_count();
|
||||
|
||||
$sql = 'UPDATE ' . GROUPS_TABLE . '
|
||||
SET group_' . $this->field . ' = ' . $next_value . '
|
||||
WHERE group_' . $this->field . ' = ' . self::GROUP_DISABLED . '
|
||||
SET group_legend = ' . $next_value . '
|
||||
WHERE group_legend = ' . self::GROUP_DISABLED . '
|
||||
AND group_id = ' . (int) $group_id;
|
||||
$this->db->sql_query($sql);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 null
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete_group($group_id, $skip_group = false)
|
||||
{
|
||||
@@ -139,58 +133,57 @@ class phpbb_group_positions
|
||||
$this->db->sql_transaction('begin');
|
||||
|
||||
$sql = 'UPDATE ' . GROUPS_TABLE . '
|
||||
SET group_' . $this->field . ' = group_' . $this->field . ' - 1
|
||||
WHERE group_' . $this->field . ' > ' . $current_value;
|
||||
SET group_legend = group_legend - 1
|
||||
WHERE group_legend > ' . $current_value;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
if (!$skip_group)
|
||||
{
|
||||
$sql = 'UPDATE ' . GROUPS_TABLE . '
|
||||
SET group_' . $this->field . ' = ' . self::GROUP_DISABLED . '
|
||||
SET group_legend = ' . self::GROUP_DISABLED . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a group up by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be moved
|
||||
* @return null
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move_up($group_id)
|
||||
{
|
||||
$this->move($group_id, 1);
|
||||
return $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 null
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move_down($group_id)
|
||||
{
|
||||
$this->move($group_id, -1);
|
||||
return $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 null
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move($group_id, $delta)
|
||||
{
|
||||
if (!is_int($delta) || !$delta)
|
||||
$delta = (int) $delta;
|
||||
if (!$delta)
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$move_up = ($delta > 0) ? true : false;
|
||||
@@ -203,10 +196,10 @@ class phpbb_group_positions
|
||||
// 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;
|
||||
SET group_legend = group_legend' . (($move_up) ? ' + 1' : ' - 1') . '
|
||||
WHERE group_legend > ' . self::GROUP_DISABLED . '
|
||||
AND group_legend' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . '
|
||||
AND group_legend' . (($move_up) ? ' < ' : ' > ') . $current_value;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// Because there might be fewer groups above/below the group than we wanted to move,
|
||||
@@ -218,20 +211,26 @@ class phpbb_group_positions
|
||||
// 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 . '
|
||||
SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return string name of the language variable for the given group-type.
|
||||
*/
|
||||
static public function group_type_language($group_type)
|
||||
{
|
||||
@@ -249,13 +248,4 @@ class phpbb_group_positions
|
||||
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);
|
||||
}
|
||||
}
|
604
phpBB/includes/groupposition/teampage.php
Normal file
604
phpBB/includes/groupposition/teampage.php
Normal file
@@ -0,0 +1,604 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package phpBB3
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Teampage group position class
|
||||
*
|
||||
* Teampage position is an ascending list 1, 2, ..., n for items which are displayed. 1 is the first item, n the last.
|
||||
*
|
||||
* @package phpBB3
|
||||
*/
|
||||
class phpbb_groupposition_teampage implements phpbb_groupposition_interface
|
||||
{
|
||||
/**
|
||||
* Group is not displayed
|
||||
*/
|
||||
const GROUP_DISABLED = 0;
|
||||
|
||||
/**
|
||||
* No parent item
|
||||
*/
|
||||
const NO_PARENT = 0;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
* @var phpbb_db_driver
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* User object
|
||||
* @var phpbb_user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Cache object
|
||||
* @var phpbb_cache_driver_interface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param phpbb_db_driver $db Database object
|
||||
* @param phpbb_user $user User object
|
||||
* @param phpbb_cache_driver_interface $cache Cache object
|
||||
*/
|
||||
public function __construct(phpbb_db_driver $db, phpbb_user $user, phpbb_cache_driver_interface $cache)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->user = $user;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teampage position for a given group, if the group exists.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_group_value($group_id)
|
||||
{
|
||||
// The join is required to ensure that the group itself exists
|
||||
$sql = 'SELECT g.group_id, t.teampage_position
|
||||
FROM ' . GROUPS_TABLE . ' g
|
||||
LEFT JOIN ' . TEAMPAGE_TABLE . ' t
|
||||
ON (t.group_id = g.group_id)
|
||||
WHERE g.group_id = ' . (int) $group_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($row === false)
|
||||
{
|
||||
// Group not found.
|
||||
throw new phpbb_groupposition_exception('NO_GROUP');
|
||||
}
|
||||
|
||||
return (int) $row['teampage_position'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the row for a given group, if the group exists.
|
||||
*
|
||||
* @param int $group_id group_id of the group to be selected
|
||||
* @return array Data row of the group
|
||||
*/
|
||||
public function get_group_values($group_id)
|
||||
{
|
||||
// The join is required to ensure that the group itself exists
|
||||
$sql = 'SELECT *
|
||||
FROM ' . GROUPS_TABLE . ' g
|
||||
LEFT JOIN ' . TEAMPAGE_TABLE . ' t
|
||||
ON (t.group_id = g.group_id)
|
||||
WHERE g.group_id = ' . (int) $group_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($row === false)
|
||||
{
|
||||
// Group not found.
|
||||
throw new phpbb_groupposition_exception('NO_GROUP');
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teampage position for a given teampage item, if the item exists.
|
||||
*
|
||||
* @param int $teampage_id Teampage_id of the selected item
|
||||
* @return int Teampage position of the item
|
||||
*/
|
||||
public function get_teampage_value($teampage_id)
|
||||
{
|
||||
$sql = 'SELECT teampage_position
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_id = ' . (int) $teampage_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$current_value = $this->db->sql_fetchfield('teampage_position');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($current_value === false)
|
||||
{
|
||||
// Group not found.
|
||||
throw new phpbb_groupposition_exception('NO_GROUP');
|
||||
}
|
||||
|
||||
return (int) $current_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teampage row for a given teampage item, if the item exists.
|
||||
*
|
||||
* @param int $teampage_id Teampage_id of the selected item
|
||||
* @return array Teampage row of the item
|
||||
*/
|
||||
public function get_teampage_values($teampage_id)
|
||||
{
|
||||
$sql = 'SELECT teampage_position, teampage_parent
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_id = ' . (int) $teampage_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($row === false)
|
||||
{
|
||||
// Group not found.
|
||||
throw new phpbb_groupposition_exception('NO_GROUP');
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of items displayed
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function get_group_count()
|
||||
{
|
||||
$sql = 'SELECT teampage_position
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
ORDER BY teampage_position DESC';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$group_count = (int) $this->db->sql_fetchfield('teampage_position');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $group_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a group by group_id
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function add_group($group_id)
|
||||
{
|
||||
return $this->add_group_teampage($group_id, self::NO_PARENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a group by group_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be added
|
||||
* @param int $parent_id Teampage ID of the parent item
|
||||
* @return bool True if the group was added successfully
|
||||
*/
|
||||
public function add_group_teampage($group_id, $parent_id)
|
||||
{
|
||||
$current_value = $this->get_group_value($group_id);
|
||||
|
||||
if ($current_value == self::GROUP_DISABLED)
|
||||
{
|
||||
if ($parent_id != self::NO_PARENT)
|
||||
{
|
||||
// Check, whether the given parent is a category
|
||||
$sql = 'SELECT teampage_id
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE group_id = 0
|
||||
AND teampage_id = ' . (int) $parent_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$parent_is_category = (bool) $this->db->sql_fetchfield('teampage_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($parent_is_category)
|
||||
{
|
||||
// Get value of last child from this parent and add group there
|
||||
$sql = 'SELECT teampage_position
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_parent = ' . (int) $parent_id . '
|
||||
OR teampage_id = ' . (int) $parent_id . '
|
||||
ORDER BY teampage_position DESC';
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$new_position = (int) $this->db->sql_fetchfield('teampage_position');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position + 1
|
||||
WHERE teampage_position > ' . $new_position;
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add group at the end
|
||||
$new_position = $this->get_group_count();
|
||||
}
|
||||
|
||||
$sql_ary = array(
|
||||
'group_id' => $group_id,
|
||||
'teampage_position' => $new_position + 1,
|
||||
'teampage_parent' => $parent_id,
|
||||
);
|
||||
|
||||
$sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new category
|
||||
*
|
||||
* @param string $category_name Name of the category to be added
|
||||
* @return bool True if the category was added successfully
|
||||
*/
|
||||
public function add_category_teampage($category_name)
|
||||
{
|
||||
if ($category_name === '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$num_entries = $this->get_group_count();
|
||||
|
||||
$sql_ary = array(
|
||||
'group_id' => 0,
|
||||
'teampage_position' => $num_entries + 1,
|
||||
'teampage_parent' => 0,
|
||||
'teampage_name' => truncate_string($category_name, 255, 255),
|
||||
);
|
||||
|
||||
$sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a group from the list and closes the gap in the position list.
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete_group($group_id, $skip_group = false)
|
||||
{
|
||||
$current_value = $this->get_group_value($group_id);
|
||||
|
||||
if ($current_value != self::GROUP_DISABLED)
|
||||
{
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position - 1
|
||||
WHERE teampage_position > ' . $current_value;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$sql = 'DELETE FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE group_id = ' . $group_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an item from the list and closes the gap in the position list.
|
||||
*
|
||||
* @param int $teampage_id teampage_id of the item 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 bool True if the item was deleted successfully
|
||||
*/
|
||||
public function delete_teampage($teampage_id, $skip_group = false)
|
||||
{
|
||||
$current_value = $this->get_teampage_value($teampage_id);
|
||||
|
||||
if ($current_value != self::GROUP_DISABLED)
|
||||
{
|
||||
$sql = 'DELETE FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_id = ' . $teampage_id . '
|
||||
OR teampage_parent = ' . $teampage_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$delta = (int) $this->db->sql_affectedrows();
|
||||
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position - ' . $delta . '
|
||||
WHERE teampage_position > ' . $current_value;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a group up by group_id
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move_up($group_id)
|
||||
{
|
||||
return $this->move($group_id, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an item up by teampage_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be moved
|
||||
* @return bool True if the group was moved successfully
|
||||
*/
|
||||
public function move_up_teampage($teampage_id)
|
||||
{
|
||||
return $this->move_teampage($teampage_id, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a group down by group_id
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move_down($group_id)
|
||||
{
|
||||
return $this->move($group_id, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Movesan item down by teampage_id
|
||||
*
|
||||
* @param int $group_id group_id of the group to be moved
|
||||
* @return bool True if the group was moved successfully
|
||||
*/
|
||||
public function move_down_teampage($teampage_id)
|
||||
{
|
||||
return $this->move_teampage($teampage_id, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a group up/down
|
||||
*
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function move($group_id, $delta)
|
||||
{
|
||||
$delta = (int) $delta;
|
||||
if (!$delta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$move_up = ($delta > 0) ? true : false;
|
||||
$data = $this->get_group_values($group_id);
|
||||
|
||||
$current_value = (int) $data['teampage_position'];
|
||||
if ($current_value != self::GROUP_DISABLED)
|
||||
{
|
||||
$this->db->sql_transaction('begin');
|
||||
|
||||
if (!$move_up && $data['teampage_parent'] == self::NO_PARENT)
|
||||
{
|
||||
// If we move items down, we need to grab the one sibling more,
|
||||
// so we do not ignore the children of the previous sibling.
|
||||
// We will remove the additional sibling later on.
|
||||
$delta = abs($delta) + 1;
|
||||
}
|
||||
|
||||
$sql = 'SELECT teampage_position
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_parent = ' . (int) $data['teampage_parent'] . '
|
||||
AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . '
|
||||
ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC');
|
||||
$result = $this->db->sql_query_limit($sql, $delta);
|
||||
|
||||
$sibling_count = 0;
|
||||
$sibling_limit = $delta;
|
||||
|
||||
// Reset the delta, as we recalculate the new real delta
|
||||
$delta = 0;
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$sibling_count++;
|
||||
$delta = $current_value - $row['teampage_position'];
|
||||
|
||||
if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit)
|
||||
{
|
||||
// Remove the additional sibling we added previously
|
||||
$delta++;
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($delta)
|
||||
{
|
||||
// First we move all items between our current value and the target value up/down 1,
|
||||
// so we have a gap for our item to move.
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position' . (($move_up) ? ' + 1' : ' - 1') . '
|
||||
WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . '
|
||||
AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
// And now finally, when we moved some other items and built a gap,
|
||||
// we can move the desired item to it.
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . '
|
||||
WHERE group_id = ' . (int) $group_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an item up/down
|
||||
*
|
||||
* @param int $teampage_id teampage_id of the item to be moved
|
||||
* @param int $delta number of steps:
|
||||
* - positive = move up
|
||||
* - negative = move down
|
||||
* @return bool True if the group was moved successfully
|
||||
*/
|
||||
public function move_teampage($teampage_id, $delta)
|
||||
{
|
||||
$delta = (int) $delta;
|
||||
if (!$delta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$move_up = ($delta > 0) ? true : false;
|
||||
$data = $this->get_teampage_values($teampage_id);
|
||||
|
||||
$current_value = (int) $data['teampage_position'];
|
||||
if ($current_value != self::GROUP_DISABLED)
|
||||
{
|
||||
$this->db->sql_transaction('begin');
|
||||
|
||||
if (!$move_up && $data['teampage_parent'] == self::NO_PARENT)
|
||||
{
|
||||
// If we move items down, we need to grab the one sibling more,
|
||||
// so we do not ignore the children of the previous sibling.
|
||||
// We will remove the additional sibling later on.
|
||||
$delta = abs($delta) + 1;
|
||||
}
|
||||
|
||||
$sql = 'SELECT teampage_id, teampage_position
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_parent = ' . (int) $data['teampage_parent'] . '
|
||||
AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . '
|
||||
ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC');
|
||||
$result = $this->db->sql_query_limit($sql, $delta);
|
||||
|
||||
$sibling_count = 0;
|
||||
$sibling_limit = $delta;
|
||||
|
||||
// Reset the delta, as we recalculate the new real delta
|
||||
$delta = 0;
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$sibling_count++;
|
||||
$delta = $current_value - $row['teampage_position'];
|
||||
|
||||
// Remove the additional sibling we added previously
|
||||
// But only, if we included it, this is not be the case
|
||||
// when we reached the end of our list
|
||||
if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit)
|
||||
{
|
||||
$delta++;
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if ($delta)
|
||||
{
|
||||
$sql = 'SELECT COUNT(teampage_id) as num_items
|
||||
FROM ' . TEAMPAGE_TABLE . '
|
||||
WHERE teampage_id = ' . (int) $teampage_id . '
|
||||
OR teampage_parent = ' . (int) $teampage_id;
|
||||
$result = $this->db->sql_query($sql);
|
||||
$num_items = (int) $this->db->sql_fetchfield('num_items');
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
// First we move all items between our current value and the target value up/down 1,
|
||||
// so we have a gap for our item to move.
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position' . (($move_up) ? ' + ' : ' - ') . $num_items . '
|
||||
WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . '
|
||||
AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . '
|
||||
AND NOT (teampage_id = ' . (int) $teampage_id . '
|
||||
OR teampage_parent = ' . (int) $teampage_id . ')';
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$delta = (!$move_up && $data['teampage_parent'] == self::NO_PARENT) ? (abs($delta) - ($num_items - 1)) : abs($delta);
|
||||
|
||||
// And now finally, when we moved some other items and built a gap,
|
||||
// we can move the desired item to it.
|
||||
$sql = 'UPDATE ' . TEAMPAGE_TABLE . '
|
||||
SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . $delta . '
|
||||
WHERE teampage_id = ' . (int) $teampage_id . '
|
||||
OR teampage_parent = ' . (int) $teampage_id;
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->db->sql_transaction('commit');
|
||||
}
|
||||
|
||||
$this->cache->destroy('sql', TEAMPAGE_TABLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user