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

[ticket/10411] Use DIC to get the groupposition classes

PHPBB3-10411
This commit is contained in:
Joas Schilling
2012-11-14 15:31:16 +01:00
parent eac1c46588
commit 79eea0ccac
8 changed files with 97 additions and 53 deletions

View File

@@ -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')
else if ($field)
{
$group_position = new phpbb_groupposition_legend($db, $user, $this->u_action);
}
else if ($field == 'teampage')
{
$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')
{

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}