From b7d3d57b700ecfc3c845085e0f1809ee0acbde33 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Feb 2011 21:02:18 +0100 Subject: [PATCH 01/14] [ticket/9549] Enhance teampage functionality with a new class, group_positions. PHPBB3-9549 --- phpBB/includes/group_positions.php | 220 ++++++++++++++++++ .../fixtures/group_positions.xml | 23 ++ .../group_positions/group_positions_test.php | 207 ++++++++++++++++ 3 files changed, 450 insertions(+) create mode 100644 phpBB/includes/group_positions.php create mode 100644 tests/group_positions/fixtures/group_positions.xml create mode 100644 tests/group_positions/group_positions_test.php diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php new file mode 100644 index 0000000000..1749ca0578 --- /dev/null +++ b/phpBB/includes/group_positions.php @@ -0,0 +1,220 @@ +sql_query($sql); + $current_value = $db->sql_fetchfield('group_' . $field); + $db->sql_freeresult($result); + + if ($current_value === false) + { + // Group not found. + global $user; + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + return (int) $current_value; + } + + /** + * Get number of groups, displayed on the teampage/legend + * @param string $field name of the field to be counted + * @return int value of the last group displayed + */ + static function get_group_count($field) + { + global $db; + + $sql = 'SELECT group_' . $field . ' + FROM ' . GROUPS_TABLE . ' + ORDER BY group_' . $field . ' DESC'; + $result = $db->sql_query_limit($sql, 1); + $group_count = (int) $db->sql_fetchfield('group_' . $field); + $db->sql_freeresult($result); + + return $group_count; + } + + /** + * Addes a group by group_id + * @param string $field name of the field the group is added to + * @param int $group_id group_id of the group to be added + * @return void + */ + static function add_group($field, $group_id) + { + $current_value = self::get_group_value($field, $group_id); + + if ($current_value == self::GROUP_DISABLED) + { + global $db; + + // Group is currently not displayed, add it at the end. + $next_value = 1 + self::get_group_count($field, $field); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = ' . $next_value . ' + WHERE group_' . $field . ' = ' . self::GROUP_DISABLED . ' + AND group_id = ' . (int) $group_id; + $db->sql_query($sql); + } + } + + /** + * Deletes a group by group_id + * @param string $field name of the field the group is deleted from + * @param int $group_id group_id of the group to be deleted + * @return void + */ + static function delete_group($field, $group_id) + { + $current_value = self::get_group_value($field, $group_id); + + if ($current_value != self::GROUP_DISABLED) + { + global $db; + + $db->sql_transaction('begin'); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = group_' . $field . ' - 1 + WHERE group_' . $field . ' > ' . $current_value; + $db->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = ' . self::GROUP_DISABLED . ' + WHERE group_id = ' . (int) $group_id; + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } + } + + /** + * Moves a group up by group_id + * @param string $field name of the field the group is moved by + * @param int $group_id group_id of the group to be moved + * @return void + */ + static function move_up($field, $group_id) + { + $current_value = self::get_group_value($field, $group_id); + + // Only move the group, if it is in the list and not already on top. + if ($current_value > 1) + { + global $db; + + $db->sql_transaction('begin'); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = group_' . $field . ' + 1 + WHERE group_' . $field . ' = ' . ($current_value - 1); + $db->sql_query($sql); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = ' . ($current_value - 1) . ' + WHERE group_id = ' . (int) $group_id; + $db->sql_query($sql); + + $db->sql_transaction('commit'); + } + } + + /** + * Moves a group down by group_id + * @param string $field name of the field the group is moved by + * @param int $group_id group_id of the group to be moved + * @return void + */ + static function move_down($field, $group_id) + { + $current_value = self::get_group_value($field, $group_id); + + if ($current_value != self::GROUP_DISABLED) + { + global $db; + + $db->sql_transaction('begin'); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = group_' . $field . ' - 1 + WHERE group_' . $field . ' = ' . ($current_value + 1); + $db->sql_query($sql); + + if ($db->sql_affectedrows() == 1) + { + // Only update when we move another one up, otherwise it was the last. + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_' . $field . ' = ' . ($current_value + 1) . ' + WHERE group_id = ' . (int) $group_id; + $db->sql_query($sql); + } + + $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 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'; + } + } +} diff --git a/tests/group_positions/fixtures/group_positions.xml b/tests/group_positions/fixtures/group_positions.xml new file mode 100644 index 0000000000..55b1c2e08d --- /dev/null +++ b/tests/group_positions/fixtures/group_positions.xml @@ -0,0 +1,23 @@ + + + + group_id + group_teampage + group_legend + + 1 + 0 + 0 + + + 2 + 1 + 0 + + + 3 + 2 + 1 + +
+
diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php new file mode 100644 index 0000000000..6955a084a2 --- /dev/null +++ b/tests/group_positions/group_positions_test.php @@ -0,0 +1,207 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/group_positions.xml'); + } + + public static function get_group_value_data() + { + return array( + array('teampage', 1, 0), + array('teampage', 2, 1), + array('legend', 1, 0), + array('legend', 3, 1), + ); + } + + /** + * @dataProvider get_group_value_data + */ + public function test_get_group_value($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + + $this->assertEquals($expected, phpbb_group_positions::get_group_value($field, $group_id)); + } + + public static function get_group_count_data() + { + return array( + array('teampage', 2), + array('legend', 1), + ); + } + + /** + * @dataProvider get_group_count_data + */ + public function test_get_group_count($field, $expected) + { + global $db; + + $db = $this->new_dbal(); + + $this->assertEquals($expected, phpbb_group_positions::get_group_count($field)); + } + + public static function add_group_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 3, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider add_group_data + */ + public function test_add_group($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + phpbb_group_positions::add_group($field, $group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function delete_group_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider delete_group_data + */ + public function test_delete_group($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + phpbb_group_positions::delete_group($field, $group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function move_up_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_up_data + */ + public function test_move_up($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + phpbb_group_positions::move_up($field, $group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } + + public static function move_down_data() + { + return array( + array('teampage', 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_down_data + */ + public function test_move_down($field, $group_id, $expected) + { + global $db; + + $db = $this->new_dbal(); + phpbb_group_positions::move_down($field, $group_id); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } +} + From 023a10208216a78c32994a5d7997299cf3b5fdae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Feb 2011 21:03:37 +0100 Subject: [PATCH 02/14] [ticket/9549] Update database with the new config values and columns PHPBB3-9549 --- phpBB/develop/create_schema_files.php | 3 +- phpBB/install/database_update.php | 65 ++++++++++++++++++++++- phpBB/install/schemas/firebird_schema.sql | 3 +- phpBB/install/schemas/mssql_schema.sql | 3 +- phpBB/install/schemas/mysql_40_schema.sql | 3 +- phpBB/install/schemas/mysql_41_schema.sql | 3 +- phpBB/install/schemas/oracle_schema.sql | 3 +- phpBB/install/schemas/postgres_schema.sql | 3 +- phpBB/install/schemas/schema_data.sql | 17 +++--- phpBB/install/schemas/sqlite_schema.sql | 3 +- 10 files changed, 89 insertions(+), 17 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index c0ec876397..5c648d44ad 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1146,7 +1146,8 @@ function get_schema_struct() 'group_receive_pm' => array('BOOL', 0), 'group_message_limit' => array('UINT', 0), 'group_max_recipients' => array('UINT', 0), - 'group_legend' => array('BOOL', 1), + 'group_legend' => array('UINT', 0), + 'group_teampage' => array('UINT', 0), ), 'PRIMARY_KEY' => 'group_id', 'KEYS' => array( diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 0c17c18b5e..9e8a063f44 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -920,8 +920,19 @@ function database_update_info() '3.0.7-PL1' => array(), // No changes from 3.0.8-RC1 to 3.0.8 '3.0.8-RC1' => array(), - // No changes from 3.1.0-dev to 3.1.0-A1 - '3.1.0-dev' => array(), + // Changes from 3.1.0-dev to 3.1.0-A1 + '3.1.0-dev' => array( + 'add_columns' => array( + GROUPS_TABLE => array( + 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), + ), + ), + 'change_columns' => array( + GROUPS_TABLE => array( + 'group_legend' => array('UINT', 0), + ), + ), + ), ); } @@ -1868,6 +1879,56 @@ function change_database_data(&$no_updates, $version) // Changes from 3.1.0-dev to 3.1.0-A1 case '3.1.0-dev': set_config('use_system_cron', 0); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 1 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'ADMINISTRATORS'"; + _sql($sql, $errored, $error_ary); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = 2 + WHERE group_type = ' . GROUP_SPECIAL . " + AND group_name = 'GLOBAL_MODERATORS'"; + _sql($sql, $errored, $error_ary); + + set_config('legend_sort_groupname', '1'); + set_config('teampage_multiple', '1'); + set_config('teampage_forums', '1'); + + $sql = 'SELECT group_id + FROM ' . GROUPS_TABLE . ' + WHERE group_legend = 1 + ORDER BY group_name ASC'; + $result = $db->sql_query($sql); + + $next_legend = 1; + while ($row = $db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_legend . ' + WHERE group_id = ' . (int) $row['group_id']; + _sql($sql, $errored, $error_ary); + + $next_legend++; + } + $db->sql_freeresult($result); + unset($next_legend); + + // Install modules + $modules_to_install = array( + 'position' => array( + 'base' => 'groups', + 'class' => 'acp', + 'title' => 'ACP_GROUPS_POSITION', + 'auth' => 'acl_a_group', + 'cat' => 'ACP_GROUPS', + ), + ); + + _add_modules($modules_to_install); + + $no_updates = false; break; } } diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index ab622e8fde..e16b4ab64c 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -444,7 +444,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm INTEGER DEFAULT 0 NOT NULL, group_message_limit INTEGER DEFAULT 0 NOT NULL, group_max_recipients INTEGER DEFAULT 0 NOT NULL, - group_legend INTEGER DEFAULT 1 NOT NULL + group_legend INTEGER DEFAULT 0 NOT NULL, + group_teampage INTEGER DEFAULT 0 NOT NULL );; ALTER TABLE phpbb_groups ADD PRIMARY KEY (group_id);; diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 068373c9a1..a14e246c8f 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -546,7 +546,8 @@ CREATE TABLE [phpbb_groups] ( [group_receive_pm] [int] DEFAULT (0) NOT NULL , [group_message_limit] [int] DEFAULT (0) NOT NULL , [group_max_recipients] [int] DEFAULT (0) NOT NULL , - [group_legend] [int] DEFAULT (1) NOT NULL + [group_legend] [int] DEFAULT (0) NOT NULL , + [group_teampage] [int] DEFAULT (0) NOT NULL ) ON [PRIMARY] GO diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 813cf8613f..35ef8e1af5 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -316,7 +316,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_message_limit mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_max_recipients mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - group_legend tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + group_legend mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + group_teampage mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (group_id), KEY group_legend_name (group_legend, group_name(255)) ); diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 97369d2bf7..7f503cdcdb 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -316,7 +316,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, group_message_limit mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, group_max_recipients mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - group_legend tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + group_legend mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + group_teampage mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, PRIMARY KEY (group_id), KEY group_legend_name (group_legend, group_name) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 7be7cd0756..d0b8943b5d 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -605,7 +605,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm number(1) DEFAULT '0' NOT NULL, group_message_limit number(8) DEFAULT '0' NOT NULL, group_max_recipients number(8) DEFAULT '0' NOT NULL, - group_legend number(1) DEFAULT '1' NOT NULL, + group_legend number(8) DEFAULT '0' NOT NULL, + group_teampage number(8) DEFAULT '0' NOT NULL, CONSTRAINT pk_phpbb_groups PRIMARY KEY (group_id) ) / diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 9cdf35024b..18110b29f4 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -459,7 +459,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm INT2 DEFAULT '0' NOT NULL CHECK (group_receive_pm >= 0), group_message_limit INT4 DEFAULT '0' NOT NULL CHECK (group_message_limit >= 0), group_max_recipients INT4 DEFAULT '0' NOT NULL CHECK (group_max_recipients >= 0), - group_legend INT2 DEFAULT '1' NOT NULL CHECK (group_legend >= 0), + group_legend INT4 DEFAULT '0' NOT NULL CHECK (group_legend >= 0), + group_teampage INT4 DEFAULT '0' NOT NULL CHECK (group_teampage >= 0), PRIMARY KEY (group_id) ); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 5ced24034c..7c4caeadba 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -151,6 +151,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_server', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_uid', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_user', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_user_filter', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('legend_sort_groupname', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('limit_load', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('limit_search_load', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_anon_lastread', '0'); @@ -238,6 +239,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_host', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_password', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_port', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('smtp_username', ''); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('teampage_multiple', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('teampage_forums', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('topics_per_page', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('tpl_allow_php', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('upload_icons_path', 'images/upload_icons'); @@ -520,13 +523,13 @@ INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_reg INSERT INTO phpbb_users (user_type, group_id, username, username_clean, user_regdate, user_password, user_email, user_lang, user_style, user_rank, user_colour, user_posts, user_permissions, user_ip, user_birthday, user_lastpage, user_last_confirm_key, user_post_sortby_type, user_post_sortby_dir, user_topic_sortby_type, user_topic_sortby_dir, user_avatar, user_sig, user_sig_bbcode_uid, user_from, user_icq, user_aim, user_yim, user_msnm, user_jabber, user_website, user_occ, user_interests, user_actkey, user_newpasswd) VALUES (3, 5, 'Admin', 'admin', 0, '21232f297a57a5a743894a0e4a801fc3', 'admin@yourdomain.com', 'en', 1, 1, 'AA0000', 1, '', '', '', '', '', 't', 'a', 't', 'd', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); # -- Groups -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 1, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, '', '', '', 0); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, '', '', '', 5); -INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GUESTS', 3, 0, '', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('REGISTERED_COPPA', 3, 0, '', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('GLOBAL_MODERATORS', 3, 0, '00AA00', 2, 2, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('ADMINISTRATORS', 3, 1, 'AA0000', 1, 1, '', '', '', 0); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('BOTS', 3, 0, '9E8DA7', 0, 0, '', '', '', 5); +INSERT INTO phpbb_groups (group_name, group_type, group_founder_manage, group_colour, group_legend, group_teampage, group_avatar, group_desc, group_desc_uid, group_max_recipients) VALUES ('NEWLY_REGISTERED', 3, 0, '', 0, 0, '', '', '', 5); # -- User -> Group INSERT INTO phpbb_user_group (group_id, user_id, user_pending, group_leader) VALUES (1, 1, 0, 0); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 34b4b05478..719e3e36fe 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -308,7 +308,8 @@ CREATE TABLE phpbb_groups ( group_receive_pm INTEGER UNSIGNED NOT NULL DEFAULT '0', group_message_limit INTEGER UNSIGNED NOT NULL DEFAULT '0', group_max_recipients INTEGER UNSIGNED NOT NULL DEFAULT '0', - group_legend INTEGER UNSIGNED NOT NULL DEFAULT '1' + group_legend INTEGER UNSIGNED NOT NULL DEFAULT '0', + group_teampage INTEGER UNSIGNED NOT NULL DEFAULT '0' ); CREATE INDEX phpbb_groups_group_legend_name ON phpbb_groups (group_legend, group_name); From 4f2b0d9d42869d743a04e6e2b2541383ffeff16c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Feb 2011 21:05:10 +0100 Subject: [PATCH 03/14] [ticket/9549] Add the module and files for the ACP. PHPBB3-9549 --- phpBB/adm/style/acp_groups_position.html | 158 +++++++++++++++++++++++ phpBB/includes/acp/acp_groups.php | 124 ++++++++++++++++++ phpBB/includes/acp/info/acp_groups.php | 1 + phpBB/includes/functions_user.php | 67 ++++++++++ phpBB/language/en/acp/common.php | 1 + phpBB/language/en/acp/groups.php | 17 +++ 6 files changed, 368 insertions(+) create mode 100644 phpBB/adm/style/acp_groups_position.html diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html new file mode 100644 index 0000000000..9b18701179 --- /dev/null +++ b/phpBB/adm/style/acp_groups_position.html @@ -0,0 +1,158 @@ + + + + +

{L_MANAGE_LEGEND}

+ +
enctype="multipart/form-data"> + +
+ {L_LEGEND_SETTINGS} +
+

{L_LEGEND_SORT_GROUPNAME_EXPLAIN}
+
+ + +
+
+ +

+   + + + {S_FORM_TOKEN} +

+
+
+ +

{L_LEGEND_EXPLAIN}

+ + + + + + + + + + + + + + + + + + + + + + + +
{L_GROUP}{L_GROUP_TYPE}{L_ACTION}
{legend.GROUP_NAME}{legend.GROUP_TYPE} + + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN} + + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} + + {ICON_MOVE_UP} + {ICON_MOVE_DOWN_DISABLED} + + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN_DISABLED} + + {ICON_DELETE} +
{L_NO_GROUPS_ADDED}
+ +
+
+ + + + {S_FORM_TOKEN} +
+
+ +

{L_MANAGE_TEAMPAGE}

+ +
enctype="multipart/form-data"> + +
+ {L_TEAMPAGE_SETTINGS} +
+

{L_TEAMPAGE_MULTIPLE_EXPLAIN}
+
+ + +
+
+
+

{L_TEAMPAGE_FORUMS_EXPLAIN}
+
+ + +
+
+ +

+   + + + {S_FORM_TOKEN} +

+
+
+ +

{L_TEAMPAGE_EXPLAIN}

+ + + + + + + + + + + + + + + + + + + + + + + +
{L_GROUP}{L_GROUP_TYPE}{L_ACTION}
{teampage.GROUP_NAME}{teampage.GROUP_TYPE} + + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN} + + {ICON_MOVE_UP} + {ICON_MOVE_DOWN} + + {ICON_MOVE_UP} + {ICON_MOVE_DOWN_DISABLED} + + {ICON_MOVE_UP_DISABLED} + {ICON_MOVE_DOWN_DISABLED} + + {ICON_DELETE} +
{L_NO_GROUPS_ADDED}
+ +
+
+ + + + {S_FORM_TOKEN} +
+
+ + \ No newline at end of file diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index d47c12eafd..5e6ebcaa7d 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -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,119 @@ 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); + } + + 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': + phpbb_group_positions::add_group($field, $group_id); + break; + + case 'delete': + phpbb_group_positions::delete_group($field, $group_id); + break; + + case 'move_up': + phpbb_group_positions::move_up($field, $group_id); + break; + + case 'move_down': + phpbb_group_positions::move_down($field, $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 .= ''; + } + } + $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}&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 .= ''; + } + } + $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', + + '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, + )); + } } diff --git a/phpBB/includes/acp/info/acp_groups.php b/phpBB/includes/acp/info/acp_groups.php index bbf92d670e..36e8793007 100644 --- a/phpBB/includes/acp/info/acp_groups.php +++ b/phpBB/includes/acp/info/acp_groups.php @@ -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')), ), ); } diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 317578cd54..fba96f93e9 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2495,6 +2495,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; + if ($group_id) + { + $current_legend = phpbb_group_positions::get_group_value('legend', $group_id); + $current_teampage = phpbb_group_positions::get_group_value('teampage', $group_id); + } + + if (isset($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 + phpbb_group_positions::get_group_count('legend'); + } + 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 + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = group_teampage - 1 + WHERE group_teampage > ' . $current_legend; + $db->sql_query($sql); + $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; + } + else + { + $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; + } + + if (isset($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 + phpbb_group_positions::get_group_count('teampage'); + } + 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 + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_teampage = group_teampage - 1 + WHERE group_teampage > ' . $current_teampage; + $db->sql_query($sql); + $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; + } + else + { + $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; + } + $user_ary = array(); $sql_ary = array( 'group_name' => (string) $name, @@ -2719,6 +2782,10 @@ function group_delete($group_id, $group_name = false) } while ($start); + // Delete group from legend and teampage + phpbb_group_positions::delete_group('legend', $group_id); + phpbb_group_positions::delete_group('teampage', $group_id); + // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " WHERE group_id = $group_id"; diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 25a020d8a2..847e763ae8 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -100,6 +100,7 @@ $lang = array_merge($lang, array( 'ACP_GROUPS_MANAGE' => 'Manage groups', 'ACP_GROUPS_MANAGEMENT' => 'Group management', 'ACP_GROUPS_PERMISSIONS' => 'Groups’ permissions', + 'ACP_GROUPS_POSITION' => 'Manage group positions', 'ACP_ICONS' => 'Topic icons', 'ACP_ICONS_SMILIES' => 'Topic icons/smilies', diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index 3b3953ac36..9cc386f6fd 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -97,6 +97,8 @@ $lang = array_merge($lang, array( 'GROUP_SETTINGS_SAVE' => 'Group wide settings', 'GROUP_SKIP_AUTH' => 'Exempt group leader from permissions', 'GROUP_SKIP_AUTH_EXPLAIN' => 'If enabled group leader no longer inherit permissions from the group.', + 'GROUP_SPECIAL' => 'Pre-defined', + 'GROUP_TEAMPAGE' => 'Display group on teampage', 'GROUP_TYPE' => 'Group type', 'GROUP_TYPE_EXPLAIN' => 'This determines which users can join or view this group.', 'GROUP_UPDATED' => 'Group preferences updated successfully.', @@ -105,19 +107,34 @@ $lang = array_merge($lang, array( 'GROUP_USERS_EXIST' => 'The selected users are already members.', 'GROUP_USERS_REMOVE' => 'Users removed from group and new defaults set successfully.', + 'LEGEND_EXPLAIN' => 'These are the groups, which are viewed on the group legend:', + 'LEGEND_SETTINGS' => 'Legend settings', + 'LEGEND_SORT_GROUPNAME' => 'Sort legend by group name', + 'LEGEND_SORT_GROUPNAME_EXPLAIN' => 'The order from bellow is ignored when this option is enabled.', + + 'MANAGE_LEGEND' => 'Manage group legend', + 'MANAGE_TEAMPAGE' => 'Manage teampage', 'MAKE_DEFAULT_FOR_ALL' => 'Make default group for every member', 'MEMBERS' => 'Members', 'NO_GROUP' => 'No group specified.', + 'NO_GROUPS_ADDED' => 'No groups added yet.', 'NO_GROUPS_CREATED' => 'No groups created yet.', 'NO_PERMISSIONS' => 'Do not copy permissions', 'NO_USERS' => 'You haven’t entered any users.', 'NO_USERS_ADDED' => 'No users were added to the group.', 'NO_VALID_USERS' => 'You haven’t entered any users eligible for that action.', + 'SELECT_GROUP' => 'Select a group', 'SPECIAL_GROUPS' => 'Pre-defined groups', 'SPECIAL_GROUPS_EXPLAIN' => 'Pre-defined groups are special groups, they cannot be deleted or directly modified. However you can still add users and alter basic settings.', + 'TEAMPAGE_EXPLAIN' => 'These are the groups, which are viewed on the teampage:', + 'TEAMPAGE_FORUMS' => 'Display moderator forums', + 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums, where they have moderator permissions, in their row. This can be very SQL intensive for big boards.', + 'TEAMPAGE_MULTIPLE' => 'Display users in all groups', + 'TEAMPAGE_MULTIPLE_EXPLAIN' => 'If set to no, the users will only be displayed in their first group.', + 'TEAMPAGE_SETTINGS' => 'Teampage settings', 'TOTAL_MEMBERS' => 'Members', 'USERS_APPROVED' => 'Users approved successfully.', From 663220418e9ba925db62d835307af6595307222f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Feb 2011 21:06:37 +0100 Subject: [PATCH 04/14] [ticket/9549] Enhance teampage and legend functionality PHPBB3-9549 --- phpBB/index.php | 13 +- phpBB/memberlist.php | 305 +++++++++--------- .../template/memberlist_leaders.html | 59 +--- phpBB/viewonline.php | 13 +- 4 files changed, 180 insertions(+), 210 deletions(-) diff --git a/phpBB/index.php b/phpBB/index.php index 95bdade42f..0830dd0686 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -36,17 +36,18 @@ $l_total_user_s = ($total_users == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER' $l_total_post_s = ($total_posts == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER'; $l_total_topic_s = ($total_topics == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER'; +$order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; // Grab group details for legend display if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) { - $sql = 'SELECT group_id, group_name, group_colour, group_type + $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend FROM ' . GROUPS_TABLE . ' - WHERE group_legend = 1 - ORDER BY group_name ASC'; + WHERE group_legend > 0 + ORDER BY ' . $order_legend . ' ASC'; } else { - $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type + $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON ( @@ -54,9 +55,9 @@ else AND ug.user_id = ' . $user->data['user_id'] . ' AND ug.user_pending = 0 ) - WHERE g.group_legend = 1 + WHERE g.group_legend > 0 AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ') - ORDER BY g.group_name ASC'; + ORDER BY g.' . $order_legend . ' ASC'; } $result = $db->sql_query($sql); diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 0b2fd24871..41b440ccf9 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -77,189 +77,186 @@ switch ($mode) $page_title = $user->lang['THE_TEAM']; $template_html = 'memberlist_leaders.html'; - $user_ary = $auth->acl_get_list(false, array('a_', 'm_'), false); + $sql_ary = array( + 'SELECT' => 'g.group_id, g.group_name, g.group_colour, g.group_type, g.group_teampage, ug.user_id as ug_user_id', - $admin_id_ary = $global_mod_id_ary = $mod_id_ary = $forum_id_ary = array(); - foreach ($user_ary as $forum_id => $forum_ary) - { - foreach ($forum_ary as $auth_option => $id_ary) - { - if (!$forum_id) - { - if ($auth_option == 'a_') - { - $admin_id_ary = array_merge($admin_id_ary, $id_ary); - } - else - { - $global_mod_id_ary = array_merge($global_mod_id_ary, $id_ary); - } - continue; - } - else - { - $mod_id_ary = array_merge($mod_id_ary, $id_ary); - } - - if ($forum_id) - { - foreach ($id_ary as $id) - { - $forum_id_ary[$id][] = $forum_id; - } - } - } - } - - $admin_id_ary = array_unique($admin_id_ary); - $global_mod_id_ary = array_unique($global_mod_id_ary); - - $mod_id_ary = array_merge($mod_id_ary, $global_mod_id_ary); - $mod_id_ary = array_unique($mod_id_ary); - - // Admin group id... - $sql = 'SELECT group_id - FROM ' . GROUPS_TABLE . " - WHERE group_name = 'ADMINISTRATORS'"; - $result = $db->sql_query($sql); - $admin_group_id = (int) $db->sql_fetchfield('group_id'); - $db->sql_freeresult($result); - - // Get group memberships for the admin id ary... - $admin_memberships = group_memberships($admin_group_id, $admin_id_ary); - - $admin_user_ids = array(); - - if (!empty($admin_memberships)) - { - // ok, we only need the user ids... - foreach ($admin_memberships as $row) - { - $admin_user_ids[$row['user_id']] = true; - } - } - unset($admin_memberships); - - $sql = 'SELECT forum_id, forum_name - FROM ' . FORUMS_TABLE; - $result = $db->sql_query($sql); - - $forums = array(); - while ($row = $db->sql_fetchrow($result)) - { - $forums[$row['forum_id']] = $row['forum_name']; - } - $db->sql_freeresult($result); - - $sql = $db->sql_build_query('SELECT', array( - 'SELECT' => 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id, g.group_name, g.group_colour, g.group_type, ug.user_id as ug_user_id', - - 'FROM' => array( - USERS_TABLE => 'u', - GROUPS_TABLE => 'g' - ), + 'FROM' => array(GROUPS_TABLE => 'g'), 'LEFT_JOIN' => array( array( 'FROM' => array(USER_GROUP_TABLE => 'ug'), - 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . $user->data['user_id'] - ) + 'ON' => 'ug.group_id = g.group_id AND ug.user_pending = 0 AND ug.user_id = ' . (int) $user->data['user_id'], + ), ), - 'WHERE' => $db->sql_in_set('u.user_id', array_unique(array_merge($admin_id_ary, $mod_id_ary)), false, true) . ' - AND u.group_id = g.group_id', + 'WHERE' => '', - 'ORDER_BY' => 'g.group_name ASC, u.username_clean ASC' - )); - $result = $db->sql_query($sql); + 'ORDER_BY' => 'g.group_teampage ASC', + ); + $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); + + $group_ids = $groups_ary = array(); while ($row = $db->sql_fetchrow($result)) { - $which_row = (in_array($row['user_id'], $admin_id_ary)) ? 'admin' : 'mod'; - - // We sort out admins not within the 'Administrators' group. - // Else, we will list those as admin only having the permission to view logs for example. - if ($which_row == 'admin' && empty($admin_user_ids[$row['user_id']])) + if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id']) { - // Remove from admin_id_ary, because the user may be a mod instead - unset($admin_id_ary[array_search($row['user_id'], $admin_id_ary)]); - - if (!in_array($row['user_id'], $mod_id_ary) && !in_array($row['user_id'], $global_mod_id_ary)) - { - continue; - } - else - { - $which_row = 'mod'; - } + $row['group_name'] = $user->lang['GROUP_UNDISCLOSED']; + $row['u_group'] = ''; + } + else + { + $row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; + $row['u_group'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']); } - $s_forum_select = ''; - $undisclosed_forum = false; - - if (isset($forum_id_ary[$row['user_id']]) && !in_array($row['user_id'], $global_mod_id_ary)) + if ($row['group_teampage']) { - if ($which_row == 'mod' && sizeof(array_diff(array_keys($forums), $forum_id_ary[$row['user_id']]))) + // Only put groups into the array we want to display. + // We are fetching all groups, to ensure we got all data for default groups. + $group_ids[] = (int) $row['group_id']; + } + $groups_ary[(int) $row['group_id']] = $row; + } + $db->sql_freeresult($result); + + $sql_ary = array( + 'SELECT' => 'u.user_id, u.group_id as default_group, u.username, u.username_clean, u.user_colour, u.user_rank, u.user_posts, u.user_allow_pm, g.group_id', + + 'FROM' => array( + USER_GROUP_TABLE => 'ug', + ), + + 'LEFT_JOIN' => array( + array( + 'FROM' => array(USERS_TABLE => 'u'), + 'ON' => 'ug.user_id = u.user_id AND ug.user_pending = 0', + ), + array( + 'FROM' => array(GROUPS_TABLE => 'g'), + 'ON' => 'ug.group_id = g.group_id', + ), + ), + + 'WHERE' => $db->sql_in_set('g.group_id', $group_ids, false, true), + + 'ORDER_BY' => 'u.username_clean ASC', + ); + + $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary)); + + $user_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['forums'] = ''; + $row['forums_ary'] = array(); + $user_ary[(int) $row['user_id']] = $row; + $user_ids[] = (int) $row['user_id']; + $group_users[(int) $row['group_id']][] = (int) $row['user_id']; + } + $db->sql_freeresult($result); + + if ($config['teampage_forums']) + { + $template->assign_var('S_DISPLAY_MODERATOR_FORUMS', true); + // Get all moderators + $perm_ary = $auth->acl_get_list(array_unique($user_ids), array('m_'), false); + + foreach ($perm_ary as $forum_id => $forum_ary) + { + foreach ($forum_ary as $auth_option => $id_ary) { - foreach ($forum_id_ary[$row['user_id']] as $forum_id) + foreach ($id_ary as $id) { - if (isset($forums[$forum_id])) + if (!$forum_id) { - if ($auth->acl_get('f_list', $forum_id)) - { - $s_forum_select .= ''; - } - else - { - $undisclosed_forum = true; - } + $user_ary[$id]['forums'] = $user->lang['ALL_FORUMS']; + } + else + { + $user_ary[$id]['forums_ary'][] = $forum_id; } } } } - // If the mod is only moderating non-viewable forums we skip the user. There is no gain in displaying the person then... - if (!$s_forum_select && $undisclosed_forum) + $sql = 'SELECT forum_id, forum_name + FROM ' . FORUMS_TABLE; + $result = $db->sql_query($sql); + + $forums = array(); + while ($row = $db->sql_fetchrow($result)) { -// $s_forum_select = ''; - continue; + $forums[$row['forum_id']] = $row['forum_name']; } + $db->sql_freeresult($result); - // The person is moderating several "public" forums, therefore the person should be listed, but not giving the real group name if hidden. - if ($row['group_type'] == GROUP_HIDDEN && !$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') && $row['ug_user_id'] != $user->data['user_id']) + foreach ($user_ary as $user_id => $user_data) { - $group_name = $user->lang['GROUP_UNDISCLOSED']; - $u_group = ''; + if (!$user_data['forums']) + { + foreach ($user_data['forums_ary'] as $forum_id) + { + $user_ary[$user_id]['forums_options'] = true; + if (isset($forums[$forum_id])) + { + if ($auth->acl_get('f_list', $forum_id)) + { + $user_ary[$user_id]['forums'] .= ''; + } + } + } + } + } + } + + foreach ($groups_ary as $group_id => $group_data) + { + if (!empty($group_users[$group_id])) + { + $template->assign_block_vars('group', array( + 'GROUP_NAME' => $group_data['group_name'], + 'GROUP_COLOR' => $group_data['group_colour'], + 'U_GROUP' => $group_data['u_group'], + )); + foreach ($group_users[$group_id] as $user_id) + { + if (isset($user_ary[$user_id])) + { + $row = $user_ary[$user_id]; + + $rank_title = $rank_img = $rank_img_src = ''; + get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); + + $template->assign_block_vars('group.user', array( + 'USER_ID' => $row['user_id'], + 'FORUMS' => $row['forums'], + 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false, + 'RANK_TITLE' => $rank_title, + + 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'], + 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'], + 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'], + + 'RANK_IMG' => $rank_img, + 'RANK_IMG_SRC' => $rank_img_src, + + 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '', + + 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), + 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), + 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), + 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), + )); + + if (!$config['teampage_multiple']) + { + unset($user_ary[$user_id]); + } + } + } } - else - { - $group_name = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']; - $u_group = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']); - } - - $rank_title = $rank_img = ''; - get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); - - $template->assign_block_vars($which_row, array( - 'USER_ID' => $row['user_id'], - 'FORUMS' => $s_forum_select, - 'RANK_TITLE' => $rank_title, - 'GROUP_NAME' => $group_name, - 'GROUP_COLOR' => $row['group_colour'], - - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, - - 'U_GROUP' => $u_group, - 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '', - - 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), - 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), - 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), - 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), - )); } - $db->sql_freeresult($result); $template->assign_vars(array( 'PM_IMG' => $user->img('icon_contact_pm', $user->lang['SEND_PRIVATE_MESSAGE'])) diff --git a/phpBB/styles/prosilver/template/memberlist_leaders.html b/phpBB/styles/prosilver/template/memberlist_leaders.html index 090476e365..1a63793bc3 100644 --- a/phpBB/styles/prosilver/template/memberlist_leaders.html +++ b/phpBB/styles/prosilver/template/memberlist_leaders.html @@ -4,72 +4,43 @@
+
- + - + - - - - + + - + + + - + - +
{L_RANK} {L_ADMINISTRATORS}{L_RANK} {group.GROUP_NAME}{group.GROUP_NAME} {L_PRIMARY_GROUP}{L_FORUMS}{L_MODERATOR}
{admin.RANK_IMG}{admin.RANK_TITLE}{admin.USERNAME_FULL} - style="font-weight: bold; color:#{admin.GROUP_COLOR}" href="{admin.U_GROUP}">{admin.GROUP_NAME} + +
{group.user.RANK_IMG}{group.user.RANK_TITLE}{group.user.USERNAME_FULL} + style="font-weight: bold; color: #{group.user.GROUP_COLOR}" href="{group.user.U_GROUP}">{group.user.GROUP_NAME} - {admin.GROUP_NAME} + {group.user.GROUP_NAME} -{group.user.FORUMS}-
{L_NO_ADMINISTRATORS}{L_NO_MEMBERS}
+ -
-
- - - - - - - - - - - - - - - - - - - - - - -
{L_MODERATORS}  
{mod.RANK_IMG}{mod.RANK_TITLE}{mod.USERNAME_FULL} - style="font-weight: bold; color:#{mod.GROUP_COLOR}" href="{mod.U_GROUP}">{mod.GROUP_NAME} - - {mod.GROUP_NAME} - {L_ALL_FORUMS}
{L_NO_MODERATORS}
- -
-
-
diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index ff4e018d12..74ad7eba0d 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -371,17 +371,18 @@ unset($vars_online); $pagination = generate_pagination(append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&sk=$sort_key&sd=$sort_dir"), $counter, $config['topics_per_page'], $start); +$order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; // Grab group details for legend display if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) { - $sql = 'SELECT group_id, group_name, group_colour, group_type + $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend FROM ' . GROUPS_TABLE . ' - WHERE group_legend = 1 - ORDER BY group_name ASC'; + WHERE group_legend = > 0 + ORDER BY ' . $order_legend . ' ASC'; } else { - $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type + $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON ( @@ -389,9 +390,9 @@ else AND ug.user_id = ' . $user->data['user_id'] . ' AND ug.user_pending = 0 ) - WHERE g.group_legend = 1 + WHERE g.group_legend > 0 AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ') - ORDER BY g.group_name ASC'; + ORDER BY g.' . $order_legend . ' ASC'; } $result = $db->sql_query($sql); From 750fc3aca81568e264921e42611249b69b5900e7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 9 Feb 2011 21:14:18 +0100 Subject: [PATCH 05/14] [ticket/9549] Add template changes for subsilver2. PHPBB3-9549 --- .../template/memberlist_leaders.html | 51 ++++++------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/phpBB/styles/subsilver2/template/memberlist_leaders.html b/phpBB/styles/subsilver2/template/memberlist_leaders.html index 57f5838e7f..75fff9f98a 100644 --- a/phpBB/styles/subsilver2/template/memberlist_leaders.html +++ b/phpBB/styles/subsilver2/template/memberlist_leaders.html @@ -5,57 +5,36 @@ - + + - + - - + + - - + + - - + + - + - - - - - - - - - - - - - - - - - - + +
{L_USERNAME}{L_FORUMS}{L_FORUMS} {L_PRIMARY_GROUP} {L_RANK} {L_SEND_MESSAGE}
{L_ADMINISTRATORS}{group.GROUP_NAME}{group.GROUP_NAME}
{admin.USERNAME_FULL} {group.user.USERNAME_FULL}{group.user.FORUMS}-   - - style="font-weight: bold; color:#{admin.GROUP_COLOR}" href="{admin.U_GROUP}">{admin.GROUP_NAME} + + style="font-weight: bold; color:#{group.user.GROUP_COLOR}" href="{group.user.U_GROUP}">{group.user.GROUP_NAME} - {admin.GROUP_NAME} + {group.user.GROUP_NAME}  {admin.RANK_IMG}{admin.RANK_TITLE} {PM_IMG} {group.user.RANK_IMG}{group.user.RANK_TITLE} {PM_IMG} 
{L_NO_ADMINISTRATORS}{L_NO_MEMBERS}
{L_MODERATORS}
{mod.USERNAME_FULL}{L_ALL_FORUMS}   - - style="font-weight: bold; color:#{mod.GROUP_COLOR}" href="{mod.U_GROUP}">{mod.GROUP_NAME} - - {mod.GROUP_NAME} - -  {mod.RANK_IMG}{mod.RANK_TITLE} {PM_IMG} 
{L_NO_MODERATORS}
From 8d12838aedeaa23cccf128e98e93d05507edda4d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Feb 2011 16:09:09 +0100 Subject: [PATCH 06/14] [ticket/9549] Make the class non static and extend delete_group function. delete_group() can now be used, so it does not update the actual group. This can save a query, when you update the group anyway. PHPBB3-9549 --- phpBB/includes/acp/acp_groups.php | 13 +- phpBB/includes/functions_user.php | 34 ++-- phpBB/includes/group_positions.php | 175 ++++++++++-------- phpBB/install/database_update.php | 1 + .../group_positions/group_positions_test.php | 41 +++- 5 files changed, 154 insertions(+), 110 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 5e6ebcaa7d..015be3c30e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -819,6 +819,10 @@ class acp_groups // 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); + } switch ($action) { @@ -826,26 +830,25 @@ class acp_groups 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': - phpbb_group_positions::add_group($field, $group_id); + $group_position->add_group($group_id); break; case 'delete': - phpbb_group_positions::delete_group($field, $group_id); + $group_position->delete_group($group_id); break; case 'move_up': - phpbb_group_positions::move_up($field, $group_id); + $group_position->move_up($group_id); break; case 'move_down': - phpbb_group_positions::move_down($field, $group_id); + $group_position->move_down($group_id); break; } diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index fba96f93e9..ab2481a5dd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2495,13 +2495,15 @@ 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 = phpbb_group_positions::get_group_value('legend', $group_id); - $current_teampage = phpbb_group_positions::get_group_value('teampage', $group_id); + $current_legend = $legend->get_group_value($group_id); + $current_teampage = $teampage->get_group_value($group_id); } if (isset($group_attributes['group_legend'])) @@ -2509,7 +2511,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow 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 + phpbb_group_positions::get_group_count('legend'); + $group_attributes['group_legend'] = 1 + $legend->get_group_count(); } else { @@ -2520,10 +2522,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow else if ($group_id && ($current_legend > phpbb_group_positions::GROUP_DISABLED)) { // Group is removed from the legend - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = group_teampage - 1 - WHERE group_teampage > ' . $current_legend; - $db->sql_query($sql); + $legend->delete_group($group_id, true); $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; } else @@ -2536,7 +2535,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow 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 + phpbb_group_positions::get_group_count('teampage'); + $group_attributes['group_teampage'] = 1 + $teampage->get_group_count(); } else { @@ -2547,10 +2546,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow else if ($group_id && ($current_teampage > phpbb_group_positions::GROUP_DISABLED)) { // Group is removed from the teampage - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_teampage = group_teampage - 1 - WHERE group_teampage > ' . $current_teampage; - $db->sql_query($sql); + $teampage->delete_group($group_id, true); $group_attributes['group_teampage'] = phpbb_group_positions::GROUP_DISABLED; } else @@ -2558,6 +2554,10 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $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, @@ -2783,8 +2783,12 @@ function group_delete($group_id, $group_name = false) while ($start); // Delete group from legend and teampage - phpbb_group_positions::delete_group('legend', $group_id); - phpbb_group_positions::delete_group('teampage', $group_id); + $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 . " diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index 1749ca0578..e63e17c384 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -31,21 +31,41 @@ class phpbb_group_positions const GROUP_DISABLED = 0; /** - * Returns the group_{$field} for a given group, if the group exists. - * @param string $field name of the field to be selected - * @param int $group_id group_id of the group to be selected - * @return int position of the group + * phpbb-database object */ - static function get_group_value($field, $group_id) - { - global $db; + public $db = null; - $sql = 'SELECT group_' . $field . ' + /** + * Name of the field we want to handle: either 'teampage' or 'legend' + */ + private $field = ''; + + /** + * Constructor + */ + public function __construct ($db, $field) + { + if (!in_array($field, array('teampage', 'legend'))) + { + + } + $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 = $db->sql_query($sql); - $current_value = $db->sql_fetchfield('group_' . $field); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $current_value = $this->db->sql_fetchfield('group_' . $this->field); + $this->db->sql_freeresult($result); if ($current_value === false) { @@ -59,149 +79,144 @@ class phpbb_group_positions /** * Get number of groups, displayed on the teampage/legend - * @param string $field name of the field to be counted - * @return int value of the last group displayed + * + * @return int value of the last group displayed */ - static function get_group_count($field) + public function get_group_count() { - global $db; - - $sql = 'SELECT group_' . $field . ' + $sql = 'SELECT group_' . $this->field . ' FROM ' . GROUPS_TABLE . ' - ORDER BY group_' . $field . ' DESC'; - $result = $db->sql_query_limit($sql, 1); - $group_count = (int) $db->sql_fetchfield('group_' . $field); - $db->sql_freeresult($result); + 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 string $field name of the field the group is added to - * @param int $group_id group_id of the group to be added - * @return void + * + * @param int $group_id group_id of the group to be added + * @return void */ - static function add_group($field, $group_id) + public function add_group($group_id) { - $current_value = self::get_group_value($field, $group_id); + $current_value = $this->get_group_value($group_id); if ($current_value == self::GROUP_DISABLED) { - global $db; - // Group is currently not displayed, add it at the end. - $next_value = 1 + self::get_group_count($field, $field); + $next_value = 1 + $this->get_group_count(); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = ' . $next_value . ' - WHERE group_' . $field . ' = ' . self::GROUP_DISABLED . ' + SET group_' . $this->field . ' = ' . $next_value . ' + WHERE group_' . $this->field . ' = ' . self::GROUP_DISABLED . ' AND group_id = ' . (int) $group_id; - $db->sql_query($sql); + $this->db->sql_query($sql); } } /** * Deletes a group by group_id - * @param string $field name of the field the group is deleted from - * @param int $group_id group_id of the group to be deleted - * @return void + * + * @param int $group_id group_id of the group to be deleted + * @param bool $skip_group Skip the group itself, to save the query, when you need to update it anyway. + * @return void */ - static function delete_group($field, $group_id) + public function delete_group($group_id, $skip_group = false) { - $current_value = self::get_group_value($field, $group_id); + $current_value = $this->get_group_value($group_id); if ($current_value != self::GROUP_DISABLED) { - global $db; - - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = group_' . $field . ' - 1 - WHERE group_' . $field . ' > ' . $current_value; - $db->sql_query($sql); + SET group_' . $this->field . ' = group_' . $this->field . ' - 1 + WHERE group_' . $this->field . ' > ' . $current_value; + $this->db->sql_query($sql); - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = ' . self::GROUP_DISABLED . ' - WHERE group_id = ' . (int) $group_id; - $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); + } - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); } } /** * Moves a group up by group_id - * @param string $field name of the field the group is moved by - * @param int $group_id group_id of the group to be moved - * @return void + * + * @param int $group_id group_id of the group to be moved + * @return void */ - static function move_up($field, $group_id) + public function move_up($group_id) { - $current_value = self::get_group_value($field, $group_id); + $current_value = $this->get_group_value($group_id); // Only move the group, if it is in the list and not already on top. if ($current_value > 1) { - global $db; - - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = group_' . $field . ' + 1 - WHERE group_' . $field . ' = ' . ($current_value - 1); - $db->sql_query($sql); + SET group_' . $this->field . ' = group_' . $this->field . ' + 1 + WHERE group_' . $this->field . ' = ' . ($current_value - 1); + $this->db->sql_query($sql); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = ' . ($current_value - 1) . ' + SET group_' . $this->field . ' = ' . ($current_value - 1) . ' WHERE group_id = ' . (int) $group_id; - $db->sql_query($sql); + $this->db->sql_query($sql); - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); } } /** * Moves a group down by group_id - * @param string $field name of the field the group is moved by - * @param int $group_id group_id of the group to be moved - * @return void + * + * @param int $group_id group_id of the group to be moved + * @return void */ - static function move_down($field, $group_id) + public function move_down($group_id) { - $current_value = self::get_group_value($field, $group_id); + $current_value = $this->get_group_value($group_id); if ($current_value != self::GROUP_DISABLED) { - global $db; - - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = group_' . $field . ' - 1 - WHERE group_' . $field . ' = ' . ($current_value + 1); - $db->sql_query($sql); + SET group_' . $this->field . ' = group_' . $this->field . ' - 1 + WHERE group_' . $this->field . ' = ' . ($current_value + 1); + $this->db->sql_query($sql); - if ($db->sql_affectedrows() == 1) + if ($this->db->sql_affectedrows() == 1) { // Only update when we move another one up, otherwise it was the last. $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $field . ' = ' . ($current_value + 1) . ' + SET group_' . $this->field . ' = ' . ($current_value + 1) . ' WHERE group_id = ' . (int) $group_id; - $db->sql_query($sql); + $this->db->sql_query($sql); } - $db->sql_transaction('commit'); + $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. + * + * @param int $group_type group_type from the groups-table + * @return string name of the language variable for the given group-type. */ - static function group_type_language($group_type) + static public function group_type_language($group_type) { switch ($group_type) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 9e8a063f44..792e33245e 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -920,6 +920,7 @@ function database_update_info() '3.0.7-PL1' => array(), // No changes from 3.0.8-RC1 to 3.0.8 '3.0.8-RC1' => array(), + // Changes from 3.1.0-dev to 3.1.0-A1 '3.1.0-dev' => array( 'add_columns' => array( diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php index 6955a084a2..449217c9b7 100644 --- a/tests/group_positions/group_positions_test.php +++ b/tests/group_positions/group_positions_test.php @@ -34,7 +34,8 @@ class phpbb_group_positions_test extends phpbb_database_test_case $db = $this->new_dbal(); - $this->assertEquals($expected, phpbb_group_positions::get_group_value($field, $group_id)); + $test_class = new phpbb_group_positions($db, $field); + $this->assertEquals($expected, $test_class->get_group_value($group_id)); } public static function get_group_count_data() @@ -54,7 +55,8 @@ class phpbb_group_positions_test extends phpbb_database_test_case $db = $this->new_dbal(); - $this->assertEquals($expected, phpbb_group_positions::get_group_count($field)); + $test_class = new phpbb_group_positions($db, $field); + $this->assertEquals($expected, $test_class->get_group_count()); } public static function add_group_data() @@ -81,7 +83,8 @@ class phpbb_group_positions_test extends phpbb_database_test_case global $db; $db = $this->new_dbal(); - phpbb_group_positions::add_group($field, $group_id); + $test_class = new phpbb_group_positions($db, $field); + $test_class->add_group($group_id); $result = $db->sql_query('SELECT group_id, group_teampage, group_legend FROM ' . GROUPS_TABLE . ' @@ -93,33 +96,49 @@ class phpbb_group_positions_test extends phpbb_database_test_case public static function delete_group_data() { return array( - array('teampage', 1, array( + array('teampage', 1, false, array( array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), )), - array('teampage', 2, array( + array('teampage', 2, false, array( array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), array('group_id' => 2, 'group_teampage' => 0, 'group_legend' => 0), array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), )), - array('teampage', 3, array( + array('teampage', 3, false, array( array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), array('group_id' => 3, 'group_teampage' => 0, 'group_legend' => 1), )), + array('teampage', 1, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, true, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), ); } /** * @dataProvider delete_group_data */ - public function test_delete_group($field, $group_id, $expected) + public function test_delete_group($field, $group_id, $skip_group, $expected) { global $db; $db = $this->new_dbal(); - phpbb_group_positions::delete_group($field, $group_id); + $test_class = new phpbb_group_positions($db, $field); + $test_class->delete_group($group_id, $skip_group); $result = $db->sql_query('SELECT group_id, group_teampage, group_legend FROM ' . GROUPS_TABLE . ' @@ -157,7 +176,8 @@ class phpbb_group_positions_test extends phpbb_database_test_case global $db; $db = $this->new_dbal(); - phpbb_group_positions::move_up($field, $group_id); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move_up($group_id); $result = $db->sql_query('SELECT group_id, group_teampage, group_legend FROM ' . GROUPS_TABLE . ' @@ -195,7 +215,8 @@ class phpbb_group_positions_test extends phpbb_database_test_case global $db; $db = $this->new_dbal(); - phpbb_group_positions::move_down($field, $group_id); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move_down($group_id); $result = $db->sql_query('SELECT group_id, group_teampage, group_legend FROM ' . GROUPS_TABLE . ' From ad05f32c494d6622eca97c028cbde53e44a54647 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Feb 2011 16:43:56 +0100 Subject: [PATCH 07/14] [ticket/9549] Throw an error when the given field-name is invalid. Also the code now only appends an adm_back_link, when we are in the ACP. PHPBB3-9549 --- phpBB/includes/acp/acp_groups.php | 2 +- phpBB/includes/group_positions.php | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 015be3c30e..dde556c19e 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -821,7 +821,7 @@ class acp_groups } else if ($field) { - $group_position = new phpbb_group_positions($db, $field); + $group_position = new phpbb_group_positions($db, $field, $this->u_action); } switch ($action) diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index e63e17c384..a697d96f66 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -40,15 +40,23 @@ class phpbb_group_positions */ private $field = ''; + /** + * URI for the adm_back_link when there was an error. + */ + private $adm_back_link = ''; + /** * Constructor */ - public function __construct ($db, $field) + 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; } @@ -70,8 +78,7 @@ class phpbb_group_positions if ($current_value === false) { // Group not found. - global $user; - trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING); + $this->error('NO_GROUP'); } return (int) $current_value; @@ -232,4 +239,13 @@ 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); + } } From d2e2ccf8a49a3d62d3de3145e114d3ed0b255465 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 16 Feb 2011 10:47:41 +0100 Subject: [PATCH 08/14] [ticket/9549] Fix some minor issues with descriptions and coding-guidelines. PHPBB3-9549 --- phpBB/adm/style/acp_groups_position.html | 2 +- phpBB/includes/group_positions.php | 11 +++++------ phpBB/language/en/acp/groups.php | 4 ++-- tests/group_positions/group_positions_test.php | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/phpBB/adm/style/acp_groups_position.html b/phpBB/adm/style/acp_groups_position.html index 9b18701179..bf6fda8742 100644 --- a/phpBB/adm/style/acp_groups_position.html +++ b/phpBB/adm/style/acp_groups_position.html @@ -155,4 +155,4 @@ - \ No newline at end of file + diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index a697d96f66..951014c0c0 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -2,8 +2,7 @@ /** * * @package phpBB3 -* @version $Id$ -* @copyright (c) 2005 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ @@ -125,10 +124,10 @@ class phpbb_group_positions } /** - * Deletes a group by group_id + * 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 the group itself, to save the query, when you need to update it anyway. + * @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) @@ -177,7 +176,7 @@ class phpbb_group_positions $this->db->sql_query($sql); $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = ' . ($current_value - 1) . ' + SET group_' . $this->field . ' = group_' . $this->field . ' - 1 WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); @@ -208,7 +207,7 @@ class phpbb_group_positions { // Only update when we move another one up, otherwise it was the last. $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = ' . ($current_value + 1) . ' + SET group_' . $this->field . ' = group_' . $this->field . ' + 1 WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); } diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index 9cc386f6fd..1fcf213c43 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -110,7 +110,7 @@ $lang = array_merge($lang, array( 'LEGEND_EXPLAIN' => 'These are the groups, which are viewed on the group legend:', 'LEGEND_SETTINGS' => 'Legend settings', 'LEGEND_SORT_GROUPNAME' => 'Sort legend by group name', - 'LEGEND_SORT_GROUPNAME_EXPLAIN' => 'The order from bellow is ignored when this option is enabled.', + 'LEGEND_SORT_GROUPNAME_EXPLAIN' => 'The order below is ignored when this option is enabled.', 'MANAGE_LEGEND' => 'Manage group legend', 'MANAGE_TEAMPAGE' => 'Manage teampage', @@ -131,7 +131,7 @@ $lang = array_merge($lang, array( 'TEAMPAGE_EXPLAIN' => 'These are the groups, which are viewed on the teampage:', 'TEAMPAGE_FORUMS' => 'Display moderator forums', - 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums, where they have moderator permissions, in their row. This can be very SQL intensive for big boards.', + 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums, where they have moderator permissions, in their row. This can be very database intensive for big boards.', 'TEAMPAGE_MULTIPLE' => 'Display users in all groups', 'TEAMPAGE_MULTIPLE_EXPLAIN' => 'If set to no, the users will only be displayed in their first group.', 'TEAMPAGE_SETTINGS' => 'Teampage settings', diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php index 449217c9b7..7454402194 100644 --- a/tests/group_positions/group_positions_test.php +++ b/tests/group_positions/group_positions_test.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2011 phpBB Group * @license http://opensource.org/licenses/gpl-license.php GNU Public License * */ From f908a016612c47542971d829b9aeed95db829b77 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 16 Feb 2011 18:15:52 +0100 Subject: [PATCH 09/14] [ticket/9549] New method move() to move a group more than 1 up/down. PHPBB3-9549 --- phpBB/includes/group_positions.php | 59 +++++++++++-------- .../group_positions/group_positions_test.php | 59 +++++++++++++++++++ 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index 951014c0c0..fc44e3249d 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -163,25 +163,7 @@ class phpbb_group_positions */ public function move_up($group_id) { - $current_value = $this->get_group_value($group_id); - - // Only move the group, if it is in the list and not already on top. - if ($current_value > 1) - { - $this->db->sql_transaction('begin'); - - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = group_' . $this->field . ' + 1 - WHERE group_' . $this->field . ' = ' . ($current_value - 1); - $this->db->sql_query($sql); - - $sql = 'UPDATE ' . GROUPS_TABLE . ' - SET group_' . $this->field . ' = group_' . $this->field . ' - 1 - WHERE group_id = ' . (int) $group_id; - $this->db->sql_query($sql); - - $this->db->sql_transaction('commit'); - } + $this->move($group_id, 1); } /** @@ -192,22 +174,51 @@ class phpbb_group_positions */ 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 . ' - 1 - WHERE group_' . $this->field . ' = ' . ($current_value + 1); + 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); - if ($this->db->sql_affectedrows() == 1) + // 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) { - // Only update when we move another one up, otherwise it was the last. + // 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 . ' + 1 + SET group_' . $this->field . ' = group_' . $this->field . (($move_up) ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); } diff --git a/tests/group_positions/group_positions_test.php b/tests/group_positions/group_positions_test.php index 7454402194..b68f205b37 100644 --- a/tests/group_positions/group_positions_test.php +++ b/tests/group_positions/group_positions_test.php @@ -224,5 +224,64 @@ class phpbb_group_positions_test extends phpbb_database_test_case $this->assertEquals($expected, $db->sql_fetchrowset($result)); } + + public static function move_data() + { + return array( + array('teampage', 1, 1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 1, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 3, 3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 2, 0, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + array('teampage', 2, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 2, -3, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 2, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 1, 'group_legend' => 1), + )), + array('teampage', 3, -1, array( + array('group_id' => 1, 'group_teampage' => 0, 'group_legend' => 0), + array('group_id' => 2, 'group_teampage' => 1, 'group_legend' => 0), + array('group_id' => 3, 'group_teampage' => 2, 'group_legend' => 1), + )), + ); + } + + /** + * @dataProvider move_data + */ + public function test_move($field, $group_id, $increment, $expected) + { + global $db; + + $db = $this->new_dbal(); + $test_class = new phpbb_group_positions($db, $field); + $test_class->move($group_id, $increment); + + $result = $db->sql_query('SELECT group_id, group_teampage, group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_id ASC'); + + $this->assertEquals($expected, $db->sql_fetchrowset($result)); + } } From d9f092a18b149d62afd5ac8a1c6f7d8e7263d17b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Feb 2011 23:53:05 +0100 Subject: [PATCH 10/14] [ticket/9549] Only add group to legend/teampage when the checkbox is checked. The checkbox for the teampage was also missing from the template file. PHPBB3-9549 --- phpBB/adm/style/acp_groups.html | 4 ++++ phpBB/includes/functions_user.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 07f7d072e8..2f812c443d 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -70,6 +70,10 @@
+
+
+
+

{L_GROUP_RECEIVE_PM_EXPLAIN}
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index ab2481a5dd..087a85a583 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2506,7 +2506,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $current_teampage = $teampage->get_group_value($group_id); } - if (isset($group_attributes['group_legend'])) + if (!empty($group_attributes['group_legend'])) { if (($group_id && ($current_legend == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) { @@ -2530,7 +2530,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow $group_attributes['group_legend'] = phpbb_group_positions::GROUP_DISABLED; } - if (isset($group_attributes['group_teampage'])) + if (!empty($group_attributes['group_teampage'])) { if (($group_id && ($current_teampage == phpbb_group_positions::GROUP_DISABLED)) || !$group_id) { From 6e9aecec796d9aeacd82c5da2c56103f729f29a4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Feb 2011 00:06:06 +0100 Subject: [PATCH 11/14] [ticket/9549] Fix language strings. PHPBB3-9549 --- phpBB/language/en/acp/groups.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index 1fcf213c43..eb83dec576 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -107,7 +107,7 @@ $lang = array_merge($lang, array( 'GROUP_USERS_EXIST' => 'The selected users are already members.', 'GROUP_USERS_REMOVE' => 'Users removed from group and new defaults set successfully.', - 'LEGEND_EXPLAIN' => 'These are the groups, which are viewed on the group legend:', + 'LEGEND_EXPLAIN' => 'These are the groups which are displayed in the group legend:', 'LEGEND_SETTINGS' => 'Legend settings', 'LEGEND_SORT_GROUPNAME' => 'Sort legend by group name', 'LEGEND_SORT_GROUPNAME_EXPLAIN' => 'The order below is ignored when this option is enabled.', @@ -129,9 +129,9 @@ $lang = array_merge($lang, array( 'SPECIAL_GROUPS' => 'Pre-defined groups', 'SPECIAL_GROUPS_EXPLAIN' => 'Pre-defined groups are special groups, they cannot be deleted or directly modified. However you can still add users and alter basic settings.', - 'TEAMPAGE_EXPLAIN' => 'These are the groups, which are viewed on the teampage:', - 'TEAMPAGE_FORUMS' => 'Display moderator forums', - 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums, where they have moderator permissions, in their row. This can be very database intensive for big boards.', + 'TEAMPAGE_EXPLAIN' => 'These are the groups which are displayed on the teampage:', + 'TEAMPAGE_FORUMS' => 'Display moderated forums', + 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums where they have moderator permissions displayed in their row. This can be very database intensive for big boards.', 'TEAMPAGE_MULTIPLE' => 'Display users in all groups', 'TEAMPAGE_MULTIPLE_EXPLAIN' => 'If set to no, the users will only be displayed in their first group.', 'TEAMPAGE_SETTINGS' => 'Teampage settings', From e5b1cfe93b105d6d29719777df1d2dcaa307059a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Feb 2011 02:05:03 +0100 Subject: [PATCH 12/14] [ticket/9549] Fix displaying empty groups PHPBB3-9549 --- phpBB/memberlist.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index 41b440ccf9..f417215dab 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -212,13 +212,18 @@ switch ($mode) foreach ($groups_ary as $group_id => $group_data) { - if (!empty($group_users[$group_id])) + if ($group_data['group_teampage']) { $template->assign_block_vars('group', array( 'GROUP_NAME' => $group_data['group_name'], 'GROUP_COLOR' => $group_data['group_colour'], 'U_GROUP' => $group_data['u_group'], )); + } + + // Display group members. + if (!empty($group_users[$group_id])) + { foreach ($group_users[$group_id] as $user_id) { if (isset($user_ary[$user_id])) @@ -229,24 +234,24 @@ switch ($mode) get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src); $template->assign_block_vars('group.user', array( - 'USER_ID' => $row['user_id'], - 'FORUMS' => $row['forums'], - 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false, - 'RANK_TITLE' => $rank_title, + 'USER_ID' => $row['user_id'], + 'FORUMS' => $row['forums'], + 'FORUM_OPTIONS' => (isset($row['forums_options'])) ? true : false, + 'RANK_TITLE' => $rank_title, - 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'], - 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'], - 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'], + 'GROUP_NAME' => $groups_ary[$row['default_group']]['group_name'], + 'GROUP_COLOR' => $groups_ary[$row['default_group']]['group_colour'], + 'U_GROUP' => $groups_ary[$row['default_group']]['u_group'], - 'RANK_IMG' => $rank_img, - 'RANK_IMG_SRC' => $rank_img_src, + 'RANK_IMG' => $rank_img, + 'RANK_IMG_SRC' => $rank_img_src, - 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '', + 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_'))) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $row['user_id']) : '', - 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), - 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), - 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), - 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), + 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), + 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), + 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), + 'U_VIEW_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), )); if (!$config['teampage_multiple']) From fd7daf2a2b04463deb07b350ffb99d2c99e982c4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 24 Feb 2011 02:05:48 +0100 Subject: [PATCH 13/14] [ticket/9549] Change default value of "sort legend by group name" to false. PHPBB3-9549 --- phpBB/install/database_update.php | 2 +- phpBB/install/schemas/schema_data.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 792e33245e..b3d575ef63 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1893,7 +1893,7 @@ function change_database_data(&$no_updates, $version) AND group_name = 'GLOBAL_MODERATORS'"; _sql($sql, $errored, $error_ary); - set_config('legend_sort_groupname', '1'); + set_config('legend_sort_groupname', '0'); set_config('teampage_multiple', '1'); set_config('teampage_forums', '1'); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 7c4caeadba..b9a29c95d1 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -151,7 +151,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_server', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_uid', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_user', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('ldap_user_filter', ''); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('legend_sort_groupname', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('legend_sort_groupname', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('limit_load', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('limit_search_load', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_anon_lastread', '0'); From 4ac8eaf9e3421f394136dc722542198b3048f4f8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 25 Feb 2011 15:47:34 +0100 Subject: [PATCH 14/14] [ticket/9549] Display users in their primary group instead of their first group PHPBB3-9549 --- phpBB/language/en/acp/groups.php | 2 +- phpBB/memberlist.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/phpBB/language/en/acp/groups.php b/phpBB/language/en/acp/groups.php index eb83dec576..11342bf4f2 100644 --- a/phpBB/language/en/acp/groups.php +++ b/phpBB/language/en/acp/groups.php @@ -133,7 +133,7 @@ $lang = array_merge($lang, array( 'TEAMPAGE_FORUMS' => 'Display moderated forums', 'TEAMPAGE_FORUMS_EXPLAIN' => 'If set to yes, moderators will have a list with all of the forums where they have moderator permissions displayed in their row. This can be very database intensive for big boards.', 'TEAMPAGE_MULTIPLE' => 'Display users in all groups', - 'TEAMPAGE_MULTIPLE_EXPLAIN' => 'If set to no, the users will only be displayed in their first group.', + 'TEAMPAGE_MULTIPLE_EXPLAIN' => 'If set to no, the users will only be displayed in their primary group (If the primary group is not listed, the users will be displayed in their first displayed group).', 'TEAMPAGE_SETTINGS' => 'Teampage settings', 'TOTAL_MEMBERS' => 'Members', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index f417215dab..06212c2d77 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -229,6 +229,11 @@ switch ($mode) if (isset($user_ary[$user_id])) { $row = $user_ary[$user_id]; + if (!$config['teampage_multiple'] && ($group_id != $groups_ary[$row['default_group']]['group_id']) && $groups_ary[$row['default_group']]['group_teampage']) + { + // Display users in their primary group, instead of the first group, when it is displayed on the teampage. + continue; + } $rank_title = $rank_img = $rank_img_src = ''; get_user_rank($row['user_rank'], (($row['user_id'] == ANONYMOUS) ? false : $row['user_posts']), $rank_title, $rank_img, $rank_img_src);