From ff7465e75f129d23a0f9f4fd6a1c556ec2b7bb13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 11:22:30 +0100 Subject: [ticket/10411] New class interface and unit tests for legend and teampage PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 92 ++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 phpBB/includes/groupposition/interface.php (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php new file mode 100644 index 0000000000..b5d8a6b097 --- /dev/null +++ b/phpBB/includes/groupposition/interface.php @@ -0,0 +1,92 @@ + Date: Tue, 13 Nov 2012 11:33:22 +0100 Subject: [ticket/10411] Add new classes for legend and teampage handling PHPBB3-10411 --- phpBB/includes/groupposition/legend.php | 251 ++++++++++++++ phpBB/includes/groupposition/teampage.php | 548 ++++++++++++++++++++++++++++++ 2 files changed, 799 insertions(+) create mode 100644 phpBB/includes/groupposition/legend.php create mode 100644 phpBB/includes/groupposition/teampage.php (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php new file mode 100644 index 0000000000..4bd4d43ece --- /dev/null +++ b/phpBB/includes/groupposition/legend.php @@ -0,0 +1,251 @@ +adm_back_link = $adm_back_link; + $this->db = $db; + $this->user = $user; + } + + /** + * Returns the group_legend for a given group, if the group exists. + * + * {@inheritDoc} + */ + public function get_group_value($group_id) + { + $sql = 'SELECT group_legend + FROM ' . GROUPS_TABLE . ' + WHERE group_id = ' . (int) $group_id; + $result = $this->db->sql_query($sql); + $current_value = $this->db->sql_fetchfield('group_legend'); + $this->db->sql_freeresult($result); + + if ($current_value === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return (int) $current_value; + } + + /** + * Get number of groups, displayed on the legend + * + * {@inheritDoc} + */ + public function get_group_count() + { + $sql = 'SELECT group_legend + FROM ' . GROUPS_TABLE . ' + ORDER BY group_legend DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $group_count = (int) $this->db->sql_fetchfield('group_legend'); + $this->db->sql_freeresult($result); + + return $group_count; + } + + /** + * Adds a group by group_id + * + * {@inheritDoc} + */ + public function add_group($group_id) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value == self::GROUP_DISABLED) + { + // Group is currently not displayed, add it at the end. + $next_value = 1 + $this->get_group_count(); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . $next_value . ' + WHERE group_legend = ' . self::GROUP_DISABLED . ' + AND group_id = ' . (int) $group_id; + $this->db->sql_query($sql); + } + } + + /** + * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. + * + * {@inheritDoc} + */ + public function delete_group($group_id, $skip_group = false) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value != self::GROUP_DISABLED) + { + $this->db->sql_transaction('begin'); + + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = group_legend - 1 + WHERE group_legend > ' . $current_value; + $this->db->sql_query($sql); + + if (!$skip_group) + { + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = ' . self::GROUP_DISABLED . ' + WHERE group_id = ' . (int) $group_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Moves a group up by group_id + * + * {@inheritDoc} + */ + public function move_up($group_id) + { + $this->move($group_id, 1); + } + + /** + * Moves a group down by group_id + * + * {@inheritDoc} + */ + public function move_down($group_id) + { + $this->move($group_id, -1); + } + + /** + * Moves a group up/down + * + * {@inheritDoc} + */ + 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_legend = group_legend' . (($move_up) ? ' + 1' : ' - 1') . ' + WHERE group_legend > ' . self::GROUP_DISABLED . ' + AND group_legend' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND group_legend' . (($move_up) ? ' < ' : ' > ') . $current_value; + $this->db->sql_query($sql); + + // Because there might be fewer groups above/below the group than we wanted to move, + // we use the number of changed groups, to update the group. + $delta = (int) $this->db->sql_affectedrows(); + + if ($delta) + { + // And now finally, when we moved some other groups and built a gap, + // we can move the desired group to it. + $sql = 'UPDATE ' . GROUPS_TABLE . ' + SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . ' + WHERE group_id = ' . (int) $group_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Error + * + * {@inheritDoc} + */ + public function error($message) + { + trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); + } + + /** + * Get group type language var + * + * @param int $group_type group_type from the groups-table + * @return string name of the language variable for the given group-type. + */ + static public function group_type_language($group_type) + { + switch ($group_type) + { + case GROUP_OPEN: + return 'GROUP_REQUEST'; + case GROUP_CLOSED: + return 'GROUP_CLOSED'; + case GROUP_HIDDEN: + return 'GROUP_HIDDEN'; + case GROUP_SPECIAL: + return 'GROUP_SPECIAL'; + case GROUP_FREE: + return 'GROUP_OPEN'; + } + } +} diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php new file mode 100644 index 0000000000..60e07f650e --- /dev/null +++ b/phpBB/includes/groupposition/teampage.php @@ -0,0 +1,548 @@ +adm_back_link = $adm_back_link; + $this->db = $db; + $this->user = $user; + } + + /** + * Returns the teampage position for a given group, if the group exists. + * + * {@inheritDoc} + */ + public function get_group_value($group_id) + { + $sql = 'SELECT g.group_id, t.teampage_position + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = ' . (int) $group_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return (int) $row['teampage_position']; + } + + /** + * Returns the row for a given group, if the group exists. + * + * @param int $group_id group_id of the group to be selected + * @return array Data row of the group + */ + public function get_group_values($group_id) + { + $sql = 'SELECT * + FROM ' . GROUPS_TABLE . ' g + LEFT JOIN ' . TEAMPAGE_TABLE . ' t + ON (t.group_id = g.group_id) + WHERE g.group_id = ' . (int) $group_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return $row; + } + + /** + * Returns the teampage position for a given teampage item, if the item exists. + * + * @param int $teampage_id Teampage_id of the selected item + * @return int Teampage position of the item + */ + public function get_teampage_value($teampage_id) + { + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $current_value = $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + if ($current_value === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return (int) $current_value; + } + + /** + * Returns the teampage row for a given teampage item, if the item exists. + * + * @param int $teampage_id Teampage_id of the selected item + * @return array Teampage row of the item + */ + public function get_teampage_values($teampage_id) + { + $sql = 'SELECT teampage_position, teampage_parent + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + if ($row === false) + { + // Group not found. + $this->error('NO_GROUP'); + } + + return $row; + } + + + /** + * Get number of items displayed + * + * {@inheritDoc} + */ + public function get_group_count() + { + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $group_count = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + return $group_count; + } + + /** + * Adds a group by group_id + * + * {@inheritDoc} + */ + public function add_group($group_id) + { + $this->add_group_teampage($group_id, self::NO_PARENT); + } + + /** + * Adds a group by group_id + * + * @param int $group_id group_id of the group to be added + * @param int $parent_id Teampage ID of the parent item + * @return null + */ + public function add_group_teampage($group_id, $parent_id) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value == self::GROUP_DISABLED) + { + if ($parent_id != self::NO_PARENT) + { + // Get value of last child from this parent and add group there + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $parent_id . ' + OR teampage_id = ' . (int) $parent_id . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position + 1 + WHERE teampage_position > ' . $new_position; + $this->db->sql_query($sql); + + } + else + { + // Add group at the end + $new_position = $this->get_group_count(); + } + + $sql_ary = array( + 'group_id' => $group_id, + 'teampage_position' => $new_position + 1, + 'teampage_parent' => $parent_id, + ); + + $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + } + } + + /** + * Adds a new category + * + * @param string $category_name Name of the category to be added + * @return null + */ + public function add_category_teampage($category_name) + { + $num_entries = $this->get_group_count(); + + $sql_ary = array( + 'group_id' => 0, + 'teampage_position' => $num_entries + 1, + 'teampage_parent' => 0, + 'teampage_name' => $category_name, + ); + + $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); + } + + /** + * Deletes a group from the list and closes the gap in the position list. + * + * {@inheritDoc} + */ + public function delete_group($group_id, $skip_group = false) + { + $current_value = $this->get_group_value($group_id); + + if ($current_value != self::GROUP_DISABLED) + { + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position - 1 + WHERE teampage_position > ' . $current_value; + $this->db->sql_query($sql); + + $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' + WHERE group_id = ' . $group_id; + $this->db->sql_query($sql); + } + } + + /** + * Deletes an item from the list and closes the gap in the position list. + * + * @param int $teampage_id teampage_id of the item to be deleted + * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. + * @return null + */ + public function delete_teampage($teampage_id, $skip_group = false) + { + $current_value = $this->get_teampage_value($teampage_id); + + if ($current_value != self::GROUP_DISABLED) + { + $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . $teampage_id . ' + OR teampage_parent = ' . $teampage_id; + $this->db->sql_query($sql); + + $delta = (int) $this->db->sql_affectedrows(); + + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position - ' . $delta . ' + WHERE teampage_position > ' . $current_value; + $this->db->sql_query($sql); + } + } + + /** + * Moves a group up by group_id + * + * {@inheritDoc} + */ + public function move_up($group_id) + { + $this->move($group_id, 1); + } + + /** + * Moves an item up by teampage_id + * + * @param int $group_id group_id of the group to be moved + * @return null + */ + public function move_up_teampage($teampage_id) + { + $this->move_teampage($teampage_id, 1); + } + + /** + * Moves a group down by group_id + * + * {@inheritDoc} + */ + public function move_down($group_id) + { + $this->move($group_id, -1); + } + + /** + * Movesan item down by teampage_id + * + * @param int $group_id group_id of the group to be moved + * @return null + */ + public function move_down_teampage($teampage_id) + { + $this->move_teampage($teampage_id, -1); + } + + /** + * Moves a group up/down + * + * {@inheritDoc} + */ + public function move($group_id, $delta) + { + if (!is_int($delta) || !$delta) + { + return; + } + + $move_up = ($delta > 0) ? true : false; + $data = $this->get_group_values($group_id); + + $current_value = (int) $data['teampage_position']; + if ($current_value != self::GROUP_DISABLED) + { + $this->db->sql_transaction('begin'); + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // If we move items down, we need to grab the one sibling more, + // so we do not ignore the children of the previous sibling. + // We will remove the additional sibling later on. + $delta = abs($delta) + 1; + } + + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $data['teampage_parent'] . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); + $result = $this->db->sql_query_limit($sql, $delta); + + // Reset the delta, as we recalculate the new real delta + $delta = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $delta = $current_value - $row['teampage_position']; + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // Remove the additional sibling we added previously + $delta++; + } + } + $this->db->sql_freeresult($result); + + if ($delta) + { + // First we move all items between our current value and the target value up/down 1, + // so we have a gap for our item to move. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position' . (($move_up) ? ' + 1' : ' - 1') . ' + WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value; + $this->db->sql_query($sql); + + // And now finally, when we moved some other items and built a gap, + // we can move the desired item to it. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . ' + WHERE group_id = ' . (int) $group_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Moves an item up/down + * + * @param int $teampage_id teampage_id of the item to be moved + * @param int $delta number of steps: + * - positive = move up + * - negative = move down + * @return null + */ + public function move_teampage($teampage_id, $delta) + { + if (!is_int($delta) || !$delta) + { + return; + } + + $move_up = ($delta > 0) ? true : false; + $data = $this->get_teampage_values($teampage_id); + + $current_value = (int) $data['teampage_position']; + if ($current_value != self::GROUP_DISABLED) + { + $this->db->sql_transaction('begin'); + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + { + // If we move items down, we need to grab the one sibling more, + // so we do not ignore the children of the previous sibling. + // We will remove the additional sibling later on. + $delta = abs($delta) + 1; + } + + $sql = 'SELECT teampage_id, teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $data['teampage_parent'] . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); + $result = $this->db->sql_query_limit($sql, $delta); + + $sibling_count = 0; + $sibling_limit = $delta; + + // Reset the delta, as we recalculate the new real delta + $delta = 0; + while ($row = $this->db->sql_fetchrow($result)) + { + $sibling_count++; + $delta = $current_value - $row['teampage_position']; + + // Remove the additional sibling we added previously + // But only, if we included it, this is not be the case + // when we reached the end of our list + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit) + { + $delta++; + } + } + $this->db->sql_freeresult($result); + + if ($delta) + { + $sql = 'SELECT COUNT(teampage_id) as num_items + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id; + $result = $this->db->sql_query($sql); + $num_items = (int) $this->db->sql_fetchfield('num_items'); + $this->db->sql_freeresult($result); + + // First we move all items between our current value and the target value up/down 1, + // so we have a gap for our item to move. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position' . (($move_up) ? ' + ' : ' - ') . $num_items . ' + WHERE teampage_position' . (($move_up) ? ' >= ' : ' <= ') . ($current_value - $delta) . ' + AND teampage_position' . (($move_up) ? ' < ' : ' > ') . $current_value . ' + AND NOT (teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id . ')'; + $this->db->sql_query($sql); + + $delta = (!$move_up && $data['teampage_parent'] == self::NO_PARENT) ? (abs($delta) - ($num_items - 1)) : abs($delta); + + // And now finally, when we moved some other items and built a gap, + // we can move the desired item to it. + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . $delta . ' + WHERE teampage_id = ' . (int) $teampage_id . ' + OR teampage_parent = ' . (int) $teampage_id; + $this->db->sql_query($sql); + } + + $this->db->sql_transaction('commit'); + } + } + + /** + * Error + * + * {@inheritDoc} + */ + public function error($message) + { + trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); + } + + /** + * Get group type language var + * + * @param int $group_type group_type from the groups-table + * @return string name of the language variable for the given group-type. + */ + static public function group_type_language($group_type) + { + switch ($group_type) + { + case GROUP_OPEN: + return 'GROUP_REQUEST'; + case GROUP_CLOSED: + return 'GROUP_CLOSED'; + case GROUP_HIDDEN: + return 'GROUP_HIDDEN'; + case GROUP_SPECIAL: + return 'GROUP_SPECIAL'; + case GROUP_FREE: + return 'GROUP_OPEN'; + } + } +} -- cgit v1.2.1 From 53cb148d70b8ab89f8f8e6fba98a63f290ebf21b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 13 Nov 2012 15:29:54 +0100 Subject: [ticket/10411] Fix comment in interface and some problems in teampage Category names on the teampage can not be empty. Also fixing a problem with the delta when moving a category. PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 4 +-- phpBB/includes/groupposition/teampage.php | 47 +++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index b5d8a6b097..9eadb049c8 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -47,10 +47,10 @@ interface phpbb_groupposition_interface public function add_group($group_id); /** - * Deletes a group by setting the field to self::GROUP_DISABLED and closing the gap in the list. + * Deletes a group by group_id * * @param int $group_id group_id of the group to be deleted - * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. + * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. * @return null */ public function delete_group($group_id, $skip_group = false); diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 60e07f650e..374d33e987 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -204,21 +204,32 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface { if ($parent_id != self::NO_PARENT) { - // Get value of last child from this parent and add group there - $sql = 'SELECT teampage_position + // Check, whether the given parent is a category + $sql = 'SELECT teampage_id FROM ' . TEAMPAGE_TABLE . ' - WHERE teampage_parent = ' . (int) $parent_id . ' - OR teampage_id = ' . (int) $parent_id . ' - ORDER BY teampage_position DESC'; + WHERE group_id = 0 + AND teampage_id = ' . (int) $parent_id; $result = $this->db->sql_query_limit($sql, 1); - $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $parent_is_category = (bool) $this->db->sql_fetchfield('teampage_id'); $this->db->sql_freeresult($result); - $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' - SET teampage_position = teampage_position + 1 - WHERE teampage_position > ' . $new_position; - $this->db->sql_query($sql); - + if ($parent_is_category) + { + // Get value of last child from this parent and add group there + $sql = 'SELECT teampage_position + FROM ' . TEAMPAGE_TABLE . ' + WHERE teampage_parent = ' . (int) $parent_id . ' + OR teampage_id = ' . (int) $parent_id . ' + ORDER BY teampage_position DESC'; + $result = $this->db->sql_query_limit($sql, 1); + $new_position = (int) $this->db->sql_fetchfield('teampage_position'); + $this->db->sql_freeresult($result); + + $sql = 'UPDATE ' . TEAMPAGE_TABLE . ' + SET teampage_position = teampage_position + 1 + WHERE teampage_position > ' . $new_position; + $this->db->sql_query($sql); + } } else { @@ -245,13 +256,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function add_category_teampage($category_name) { + if ($category_name === '') + { + return; + } + $num_entries = $this->get_group_count(); $sql_ary = array( 'group_id' => 0, 'teampage_position' => $num_entries + 1, 'teampage_parent' => 0, - 'teampage_name' => $category_name, + 'teampage_name' => truncate_string($category_name, 255, 255), ); $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); @@ -384,12 +400,17 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface ORDER BY teampage_position' . (($move_up) ? ' DESC' : ' ASC'); $result = $this->db->sql_query_limit($sql, $delta); + $sibling_count = 0; + $sibling_limit = $delta; + // Reset the delta, as we recalculate the new real delta $delta = 0; while ($row = $this->db->sql_fetchrow($result)) { + $sibling_count++; $delta = $current_value - $row['teampage_position']; - if (!$move_up && $data['teampage_parent'] == self::NO_PARENT) + + if (!$move_up && $data['teampage_parent'] == self::NO_PARENT && $sibling_count == $sibling_limit) { // Remove the additional sibling we added previously $delta++; -- cgit v1.2.1 From 79eea0ccac1bc6dd5d39b4d47e973ef522cf7781 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 15:31:16 +0100 Subject: [ticket/10411] Use DIC to get the groupposition classes PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 8 ------ phpBB/includes/groupposition/legend.php | 25 ++++++++++++----- phpBB/includes/groupposition/teampage.php | 44 +++++++++++++++++++++++++----- 3 files changed, 55 insertions(+), 22 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 9eadb049c8..749ad61071 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -81,12 +81,4 @@ interface phpbb_groupposition_interface * @return null */ public function move($group_id, $delta); - - /** - * Error - * - * @param string $message Error message to display - * @return null - */ - public function error($message); } diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 4bd4d43ece..4dcf31ff06 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -31,12 +31,14 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface const GROUP_DISABLED = 0; /** - * phpbb-database object + * Database object + * @var dbal */ private $db = null; /** - * phpbb-user object + * User object + * @var phpbb_user */ private $user = null; @@ -48,16 +50,25 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface /** * Constructor * - * @param phpbb_dbal $db Database object - * @param string $adm_back_link Return URL to use after an error occured + * @param dbal $db Database object + * @param phpbb_user $user User object */ - public function __construct($db, phpbb_user $user, $adm_back_link = '') + public function __construct(dbal $db, phpbb_user $user) { - $this->adm_back_link = $adm_back_link; $this->db = $db; $this->user = $user; } + /** + * Set the back link for error messages + * + * @param string $adm_back_link Return URL to use after an error occured + */ + public function set_admin_back_link($adm_back_link) + { + $this->adm_back_link = $adm_back_link; + } + /** * Returns the group_legend for a given group, if the group exists. * @@ -221,7 +232,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface * * {@inheritDoc} */ - public function error($message) + private function error($message) { trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); } diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 374d33e987..ab23dd0420 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -35,15 +35,23 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface const NO_PARENT = 0; /** - * phpbb-database object + * Database object + * @var dbal */ private $db = null; /** - * phpbb-user object + * User object + * @var phpbb_user */ private $user = null; + /** + * Cache object + * @var phpbb_cache_driver_interface + */ + private $cache = null; + /** * URI for the adm_back_link when there was an error. */ @@ -52,14 +60,24 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Constructor * - * @param phpbb_dbal $db Database object - * @param string $adm_back_link Return URL to use after an error occured + * @param dbal $db Database object + * @param phpbb_user $user User object */ - public function __construct($db, phpbb_user $user, $adm_back_link = '') + public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { - $this->adm_back_link = $adm_back_link; $this->db = $db; $this->user = $user; + $this->cache = $cache; + } + + /** + * Set the back link for error messages + * + * @param string $adm_back_link Return URL to use after an error occured + */ + public function set_admin_back_link($adm_back_link) + { + $this->adm_back_link = $adm_back_link; } /** @@ -246,6 +264,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -272,6 +292,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -294,6 +316,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE group_id = ' . $group_id; $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -321,6 +345,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -438,6 +464,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_transaction('commit'); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -532,6 +560,8 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_transaction('commit'); } + + $this->cache->destroy('sql', TEAMPAGE_TABLE); } /** @@ -539,7 +569,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * {@inheritDoc} */ - public function error($message) + private function error($message) { trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); } -- cgit v1.2.1 From 59bb498de7025a54c28f0442d994ab1d23e1cce7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Nov 2012 19:03:24 +0100 Subject: [ticket/10411] Fix docs and remove empty sql array parts PHPBB3-10411 --- phpBB/includes/groupposition/teampage.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index ab23dd0420..a189d5def9 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -60,8 +60,9 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object + * @param dbal $db Database object + * @param phpbb_user $user User object + * @param phpbb_cache_driver_interface $cache Cache object */ public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { -- cgit v1.2.1 From 46b75f4cf925ee0da852beeb6c4932e4fcb37992 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 15 Jan 2013 13:20:35 +0100 Subject: [ticket/10411] Add a comment why we left join the group table We left join the group table because we want to check that the group does exist there aswell. PHPBB3-10411 --- phpBB/includes/groupposition/teampage.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index a189d5def9..2c488dd8a9 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -88,6 +88,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_value($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT g.group_id, t.teampage_position FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t @@ -114,6 +115,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function get_group_values($group_id) { + // The join is required to ensure that the group itself exists $sql = 'SELECT * FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . TEAMPAGE_TABLE . ' t -- cgit v1.2.1 From b0dc5925b91cb0447046e8a7f089c6675e4be95c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:29:04 +0100 Subject: [ticket/10411] Fix typehinting and change private to protected PHPBB3-10411 --- phpBB/includes/groupposition/legend.php | 14 +++++++------- phpBB/includes/groupposition/teampage.php | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 4dcf31ff06..51f2510e85 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -32,28 +32,28 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object - * @param phpbb_user $user User object + * @param phpbb_db_driver $db Database object + * @param phpbb_user $user User object */ - public function __construct(dbal $db, phpbb_user $user) + public function __construct(phpbb_db_driver $db, phpbb_user $user) { $this->db = $db; $this->user = $user; diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 2c488dd8a9..f13e171134 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -36,35 +36,35 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface /** * Database object - * @var dbal + * @var phpbb_db_driver */ - private $db = null; + protected $db; /** * User object * @var phpbb_user */ - private $user = null; + protected $user; /** * Cache object * @var phpbb_cache_driver_interface */ - private $cache = null; + protected $cache; /** * URI for the adm_back_link when there was an error. */ - private $adm_back_link = ''; + protected $adm_back_link = ''; /** * Constructor * - * @param dbal $db Database object + * @param phpbb_db_driver $db Database object * @param phpbb_user $user User object * @param phpbb_cache_driver_interface $cache Cache object */ - public function __construct(dbal $db, phpbb_user $user, phpbb_cache_driver_interface $cache) + public function __construct(phpbb_db_driver $db, phpbb_user $user, phpbb_cache_driver_interface $cache) { $this->db = $db; $this->user = $user; -- cgit v1.2.1 From 1d7b082a6fa05d5760ef15ef8bf78cd3a1d204cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 20:58:12 +0100 Subject: [ticket/10411] Add return value to move functions PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 6 ++--- phpBB/includes/groupposition/legend.php | 15 +++++++++---- phpBB/includes/groupposition/teampage.php | 36 +++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 18 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 749ad61071..6fb16134e0 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -59,7 +59,7 @@ interface phpbb_groupposition_interface * Moves a group up by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up($group_id); @@ -67,7 +67,7 @@ interface phpbb_groupposition_interface * Moves a group down by group_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down($group_id); @@ -78,7 +78,7 @@ interface phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move($group_id, $delta); } diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 51f2510e85..9b69f9d2b3 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -168,7 +168,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** @@ -178,7 +178,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** @@ -188,9 +188,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -221,10 +222,16 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface SET group_legend = group_legend ' . (($move_up) ? ' - ' : ' + ') . $delta . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + + return true; } $this->db->sql_transaction('commit'); } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index f13e171134..cbdf06ebaf 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -359,18 +359,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_up($group_id) { - $this->move($group_id, 1); + return $this->move($group_id, 1); } /** * Moves an item up by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_up_teampage($teampage_id) { - $this->move_teampage($teampage_id, 1); + return $this->move_teampage($teampage_id, 1); } /** @@ -380,18 +380,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move_down($group_id) { - $this->move($group_id, -1); + return $this->move($group_id, -1); } /** * Movesan item down by teampage_id * * @param int $group_id group_id of the group to be moved - * @return null + * @return bool True if the group was moved successfully */ public function move_down_teampage($teampage_id) { - $this->move_teampage($teampage_id, -1); + return $this->move_teampage($teampage_id, -1); } /** @@ -401,9 +401,10 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function move($group_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -463,12 +464,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position ' . (($move_up) ? ' - ' : ' + ') . abs($delta) . ' WHERE group_id = ' . (int) $group_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -478,13 +485,14 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return null + * @return bool True if the group was moved successfully */ public function move_teampage($teampage_id, $delta) { - if (!is_int($delta) || !$delta) + $delta = (int) $delta; + if (!$delta) { - return; + return false; } $move_up = ($delta > 0) ? true : false; @@ -559,12 +567,18 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface WHERE teampage_id = ' . (int) $teampage_id . ' OR teampage_parent = ' . (int) $teampage_id; $this->db->sql_query($sql); + + $this->db->sql_transaction('commit'); + $this->cache->destroy('sql', TEAMPAGE_TABLE); + + return true; } $this->db->sql_transaction('commit'); } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** -- cgit v1.2.1 From 41eea66da975a3b4140d8f4dc3f6931ea84916db Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 25 Feb 2013 21:24:52 +0100 Subject: [ticket/10411] Add return values to add/delete function PHPBB3-10411 --- phpBB/includes/groupposition/interface.php | 4 ++-- phpBB/includes/groupposition/legend.php | 7 +++++++ phpBB/includes/groupposition/teampage.php | 23 ++++++++++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/interface.php b/phpBB/includes/groupposition/interface.php index 6fb16134e0..eacc04e1a4 100644 --- a/phpBB/includes/groupposition/interface.php +++ b/phpBB/includes/groupposition/interface.php @@ -42,7 +42,7 @@ interface phpbb_groupposition_interface * Addes a group by group_id * * @param int $group_id group_id of the group to be added - * @return null + * @return bool True if the group was added successfully */ public function add_group($group_id); @@ -51,7 +51,7 @@ interface phpbb_groupposition_interface * * @param int $group_id group_id of the group to be deleted * @param bool $skip_group Skip setting the value for this group, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the group was deleted successfully */ public function delete_group($group_id, $skip_group = false); diff --git a/phpBB/includes/groupposition/legend.php b/phpBB/includes/groupposition/legend.php index 9b69f9d2b3..8f115a8b1e 100644 --- a/phpBB/includes/groupposition/legend.php +++ b/phpBB/includes/groupposition/legend.php @@ -128,7 +128,10 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface WHERE group_legend = ' . self::GROUP_DISABLED . ' AND group_id = ' . (int) $group_id; $this->db->sql_query($sql); + return true; } + + return false; } /** @@ -158,7 +161,11 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface } $this->db->sql_transaction('commit'); + + return true; } + + return false; } /** diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index cbdf06ebaf..3be8ef2774 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -207,7 +207,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ public function add_group($group_id) { - $this->add_group_teampage($group_id, self::NO_PARENT); + return $this->add_group_teampage($group_id, self::NO_PARENT); } /** @@ -215,7 +215,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $group_id group_id of the group to be added * @param int $parent_id Teampage ID of the parent item - * @return null + * @return bool True if the group was added successfully */ public function add_group_teampage($group_id, $parent_id) { @@ -266,22 +266,26 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'INSERT INTO ' . TEAMPAGE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** * Adds a new category * * @param string $category_name Name of the category to be added - * @return null + * @return bool True if the category was added successfully */ public function add_category_teampage($category_name) { if ($category_name === '') { - return; + return false; } $num_entries = $this->get_group_count(); @@ -297,6 +301,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->db->sql_query($sql); $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } /** @@ -318,9 +323,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $sql = 'DELETE FROM ' . TEAMPAGE_TABLE . ' WHERE group_id = ' . $group_id; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** @@ -328,7 +337,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface * * @param int $teampage_id teampage_id of the item to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return null + * @return bool True if the item was deleted successfully */ public function delete_teampage($teampage_id, $skip_group = false) { @@ -347,9 +356,13 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface SET teampage_position = teampage_position - ' . $delta . ' WHERE teampage_position > ' . $current_value; $this->db->sql_query($sql); + + $this->cache->destroy('sql', TEAMPAGE_TABLE); + return true; } $this->cache->destroy('sql', TEAMPAGE_TABLE); + return false; } /** -- cgit v1.2.1 From e0df5934485df0eee22141d1c5ded3e432119b20 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 26 Feb 2013 16:52:53 +0100 Subject: [ticket/10411] Throw exceptions instead of using trigger_error() PHPBB3-10411 --- phpBB/includes/groupposition/exception.php | 23 +++++++++++++++++++++ phpBB/includes/groupposition/legend.php | 27 +----------------------- phpBB/includes/groupposition/teampage.php | 33 ++++-------------------------- 3 files changed, 28 insertions(+), 55 deletions(-) create mode 100644 phpBB/includes/groupposition/exception.php (limited to 'phpBB/includes/groupposition') diff --git a/phpBB/includes/groupposition/exception.php b/phpBB/includes/groupposition/exception.php new file mode 100644 index 0000000000..e4ff09c703 --- /dev/null +++ b/phpBB/includes/groupposition/exception.php @@ -0,0 +1,23 @@ +user = $user; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the group_legend for a given group, if the group exists. * @@ -86,7 +71,7 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -241,16 +226,6 @@ class phpbb_groupposition_legend implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * diff --git a/phpBB/includes/groupposition/teampage.php b/phpBB/includes/groupposition/teampage.php index 3be8ef2774..7c758199e7 100644 --- a/phpBB/includes/groupposition/teampage.php +++ b/phpBB/includes/groupposition/teampage.php @@ -52,11 +52,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface */ protected $cache; - /** - * URI for the adm_back_link when there was an error. - */ - protected $adm_back_link = ''; - /** * Constructor * @@ -71,16 +66,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface $this->cache = $cache; } - /** - * Set the back link for error messages - * - * @param string $adm_back_link Return URL to use after an error occured - */ - public function set_admin_back_link($adm_back_link) - { - $this->adm_back_link = $adm_back_link; - } - /** * Returns the teampage position for a given group, if the group exists. * @@ -101,7 +86,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $row['teampage_position']; @@ -128,7 +113,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -152,7 +137,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($current_value === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return (int) $current_value; @@ -176,7 +161,7 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface if ($row === false) { // Group not found. - $this->error('NO_GROUP'); + throw new phpbb_groupposition_exception('NO_GROUP'); } return $row; @@ -594,16 +579,6 @@ class phpbb_groupposition_teampage implements phpbb_groupposition_interface return false; } - /** - * Error - * - * {@inheritDoc} - */ - private function error($message) - { - trigger_error($this->user->lang[$message] . (($this->adm_back_link) ? adm_back_link($this->adm_back_link) : ''), E_USER_WARNING); - } - /** * Get group type language var * -- cgit v1.2.1