From 16c79dea35b309a44b821232e522207bcdfe2cbf Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 29 Nov 2014 12:53:44 +0100 Subject: [PATCH] [ticket/416] Use only one method for moving module vertically B3P-416 --- acp/portal_module.php | 4 ++-- portal/modules/manager.php | 33 ++++++++--------------------- tests/unit/acp/move_module_test.php | 8 +++---- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/acp/portal_module.php b/acp/portal_module.php index 3b8e669a..569e8ef2 100644 --- a/acp/portal_module.php +++ b/acp/portal_module.php @@ -403,11 +403,11 @@ class portal_module if ($action == 'move_up') { - $this->modules_manager->move_module_up($module_id); + $this->modules_manager->move_module_vertical($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); } else if ($action == 'move_down') { - $this->modules_manager->move_module_down($module_id); + $this->modules_manager->move_module_vertical($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); } else if($action == 'move_right') { diff --git a/portal/modules/manager.php b/portal/modules/manager.php index 8f1881e9..b2a9a46d 100644 --- a/portal/modules/manager.php +++ b/portal/modules/manager.php @@ -235,39 +235,24 @@ class manager } /** - * Move module up one row + * Move module vertically * - * @param int $module_id ID of the module that should be moved + * @param int $module_id Module ID + * @param int $direction Direction of move, either -1 for up or 1 for down */ - public function move_module_up($module_id) + public function move_module_vertical($module_id, $direction) { - $updated = false; $module_data = $this->get_move_module_data($module_id); - if (($module_data !== false) && ($module_data['module_order'] > 1)) + if ($module_data === false || ($direction == database_handler::MOVE_DIRECTION_UP && $module_data['module_order'] <= 1) || + ($direction == database_handler::MOVE_DIRECTION_DOWN && $this->get_last_module_order($module_data['module_column']) == $module_data['module_order'])) { - $updated = $this->database_handler->move_module_vertical($module_id, $module_data, database_handler::MOVE_DIRECTION_UP, 1); + $this->handle_after_move(false, true); } - - $this->handle_after_move($updated, true); - } - - /** - * Move module down one row - * - * @param int $module_id ID of the module that should be moved - */ - public function move_module_down($module_id) - { - $updated = false; - $module_data = $this->get_move_module_data($module_id); - - if ($module_data !== false && $this->get_last_module_order($module_data['module_column']) != $module_data['module_order']) + else { - $updated = $this->database_handler->move_module_vertical($module_id, $module_data, database_handler::MOVE_DIRECTION_DOWN, 1); + $this->handle_after_move($this->database_handler->move_module_vertical($module_id, $module_data, $direction, 1), true); } - - $this->handle_after_move($updated, true); } /** diff --git a/tests/unit/acp/move_module_test.php b/tests/unit/acp/move_module_test.php index 86423d33..cde8ceb7 100644 --- a/tests/unit/acp/move_module_test.php +++ b/tests/unit/acp/move_module_test.php @@ -132,24 +132,24 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data public function test_move_module_up() { self::$redirected = false; - $this->modules_manager->move_module_up(2); + $this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); $this->assertTrue(self::$redirected); $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW'); self::$redirected = false; - $this->modules_manager->move_module_up(2); + $this->modules_manager->move_module_vertical(2, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); $this->assertFalse(self::$redirected); } public function test_move_module_down() { self::$redirected = false; - $this->modules_manager->move_module_down(3); + $this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); $this->assertTrue(self::$redirected); $this->setExpectedTriggerError(E_USER_NOTICE, 'UNABLE_TO_MOVE_ROW'); self::$redirected = false; - $this->modules_manager->move_module_down(3); + $this->modules_manager->move_module_vertical(3, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); $this->assertFalse(self::$redirected); }