aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-11-14 15:31:16 +0100
committerJoas Schilling <nickvergessen@gmx.de>2012-11-14 15:31:16 +0100
commit79eea0ccac1bc6dd5d39b4d47e973ef522cf7781 (patch)
tree4457c2a25c9759ee3a04637aff616516295291f2 /phpBB
parenteac1c46588d3121a050bda42690444c8888c40dd (diff)
downloadforums-79eea0ccac1bc6dd5d39b4d47e973ef522cf7781.tar
forums-79eea0ccac1bc6dd5d39b4d47e973ef522cf7781.tar.gz
forums-79eea0ccac1bc6dd5d39b4d47e973ef522cf7781.tar.bz2
forums-79eea0ccac1bc6dd5d39b4d47e973ef522cf7781.tar.xz
forums-79eea0ccac1bc6dd5d39b4d47e973ef522cf7781.zip
[ticket/10411] Use DIC to get the groupposition classes
PHPBB3-10411
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/config/services.yml13
-rw-r--r--phpBB/includes/acp/acp_groups.php14
-rw-r--r--phpBB/includes/functions_user.php16
-rw-r--r--phpBB/includes/groupposition/interface.php8
-rw-r--r--phpBB/includes/groupposition/legend.php25
-rw-r--r--phpBB/includes/groupposition/teampage.php44
6 files changed, 82 insertions, 38 deletions
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml
index 42bb473e66..eccdbc7631 100644
--- a/phpBB/config/services.yml
+++ b/phpBB/config/services.yml
@@ -91,6 +91,19 @@ services:
- .%core.php_ext%
- @cache.driver
+ groupposition.legend:
+ class: phpbb_groupposition_legend
+ arguments:
+ - @dbal.conn
+ - @user
+
+ groupposition.teampage:
+ class: phpbb_groupposition_teampage
+ arguments:
+ - @dbal.conn
+ - @user
+ - @cache.driver
+
request:
class: phpbb_request
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php
index 59f84f8c48..e0ce456a62 100644
--- a/phpBB/includes/acp/acp_groups.php
+++ b/phpBB/includes/acp/acp_groups.php
@@ -830,13 +830,12 @@ class acp_groups
// Invalid mode
trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
- else if ($field == 'legend')
- {
- $group_position = new phpbb_groupposition_legend($db, $user, $this->u_action);
- }
- else if ($field == 'teampage')
+ else if ($field)
{
- $group_position = new phpbb_groupposition_teampage($db, $user, $this->u_action);
+ global $phpbb_container;
+
+ $group_position = $phpbb_container->get('groupposition.' . $field);
+ $group_position->set_admin_back_link($this->u_action);
}
if ($field == 'teampage')
@@ -863,9 +862,6 @@ class acp_groups
$group_position->move_down_teampage($teampage_id);
break;
}
-
- global $cache;
- $cache->destroy('sql', TEAMPAGE_TABLE);
}
else if ($field == 'legend')
{
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index 2a38010f2b..3005f5efda 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -2602,8 +2602,10 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
$current_legend = phpbb_groupposition_legend::GROUP_DISABLED;
$current_teampage = phpbb_groupposition_teampage::GROUP_DISABLED;
- $legend = new phpbb_groupposition_legend($db, $user, '');
- $teampage = new phpbb_groupposition_teampage($db, $user, '');
+ global $phpbb_container;
+
+ $legend = $phpbb_container->get('groupposition.legend');
+ $teampage = $phpbb_container->get('groupposition.teampage');
if ($group_id)
{
$current_legend = $legend->get_group_value($group_id);
@@ -2623,7 +2625,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
$group_attributes['group_legend'] = $current_legend;
}
}
- else if ($group_id && ($current_legend > phpbb_groupposition_legend::GROUP_DISABLED))
+ else if ($group_id && ($current_legend != phpbb_groupposition_legend::GROUP_DISABLED))
{
// Group is removed from the legend
$legend->delete_group($group_id, true);
@@ -2746,7 +2748,7 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow
$teampage->add_group($group_id);
}
}
- else if ($group_id && ($current_teampage > phpbb_groupposition_teampage::GROUP_DISABLED))
+ else if ($group_id && ($current_teampage != phpbb_groupposition_teampage::GROUP_DISABLED))
{
$teampage->delete_group($group_id);
}
@@ -2833,7 +2835,7 @@ function avatar_remove_db($avatar_name)
*/
function group_delete($group_id, $group_name = false)
{
- global $db, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher;
+ global $db, $user, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_container;
if (!$group_name)
{
@@ -2875,11 +2877,11 @@ function group_delete($group_id, $group_name = false)
while ($start);
// Delete group from legend and teampage
- $legend = new phpbb_groupposition_legend($db, $user, '');
+ $legend = $phpbb_container->get('groupposition.legend');
$legend->delete_group($group_id);
unset($legend);
- $teampage = new phpbb_groupposition_teampage($db, $user, '');
+ $teampage = $phpbb_container->get('groupposition.teampage');
$teampage->delete_group($group_id);
unset($teampage);
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,17 +50,26 @@ 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.
*
* {@inheritDoc}
@@ -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,16 +35,24 @@ 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.
*/
private $adm_back_link = '';
@@ -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);
}