[ticket/216] Use get_move_module_data() for acquiring module data for moving
This will get rid of a query code that was duplicated over 4 methods in portal_module. B3P-216
This commit is contained in:
@@ -829,6 +829,24 @@ class portal_module
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module_data required for moving it
|
||||
*
|
||||
* @param int $module_id ID of the module that should be moved
|
||||
* @return array|null Module_data or empty if not successful
|
||||
*/
|
||||
public function get_move_module_data($module_id)
|
||||
{
|
||||
$sql = 'SELECT module_order, module_column, module_classname
|
||||
FROM ' . PORTAL_MODULES_TABLE . '
|
||||
WHERE module_id = ' . (int) $module_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$module_data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $module_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move module up one row
|
||||
*
|
||||
@@ -836,12 +854,7 @@ class portal_module
|
||||
*/
|
||||
public function move_module_up($module_id)
|
||||
{
|
||||
$sql = 'SELECT module_order, module_column
|
||||
FROM ' . PORTAL_MODULES_TABLE . '
|
||||
WHERE module_id = ' . (int) $module_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$module_data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
$module_data = $this->get_move_module_data($module_id);
|
||||
|
||||
if (($module_data !== false) && ($module_data['module_order'] > 1))
|
||||
{
|
||||
@@ -876,12 +889,7 @@ class portal_module
|
||||
*/
|
||||
protected function move_module_down($module_id)
|
||||
{
|
||||
$sql = 'SELECT module_order, module_column
|
||||
FROM ' . PORTAL_MODULES_TABLE . '
|
||||
WHERE module_id = ' . (int) $module_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$module_data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
$module_data = $this->get_move_module_data($module_id);
|
||||
|
||||
if ($module_data !== false)
|
||||
{
|
||||
@@ -915,12 +923,7 @@ class portal_module
|
||||
*/
|
||||
protected function move_module_left($module_id)
|
||||
{
|
||||
$sql = 'SELECT module_order, module_column, module_classname
|
||||
FROM ' . PORTAL_MODULES_TABLE . '
|
||||
WHERE module_id = ' . (int) $module_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$module_data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
$module_data = $this->get_move_module_data($module_id);
|
||||
|
||||
if (!isset($this->modules[$module_data['module_classname']]))
|
||||
{
|
||||
@@ -1023,12 +1026,7 @@ class portal_module
|
||||
*/
|
||||
protected function move_module_right($module_id)
|
||||
{
|
||||
$sql = 'SELECT module_order, module_column, module_classname
|
||||
FROM ' . PORTAL_MODULES_TABLE . '
|
||||
WHERE module_id = ' . (int) $module_id;
|
||||
$result = $this->db->sql_query_limit($sql, 1);
|
||||
$module_data = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
$module_data = $this->get_move_module_data($module_id);
|
||||
|
||||
if (!isset($this->modules[$module_data['module_classname']]))
|
||||
{
|
||||
|
||||
@@ -49,6 +49,16 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/modules.xml');
|
||||
}
|
||||
|
||||
public function test_get_move_module_data()
|
||||
{
|
||||
$module_data = $this->portal_module->get_move_module_data(1);
|
||||
$this->assertEquals(array(
|
||||
'module_order' => 1,
|
||||
'module_column' => 2,
|
||||
'module_classname' => '\board3\portal\modules\clock',
|
||||
), $module_data);
|
||||
}
|
||||
|
||||
public function test_move_module_up()
|
||||
{
|
||||
self::$redirected = false;
|
||||
|
||||
Reference in New Issue
Block a user