From 355c29301d7fdccf550c8109e76f9b1ca5af266d Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 21 Jul 2024 08:39:54 -0700 Subject: [PATCH 1/3] Add pagination to the pages list in ACP Signed-off-by: Matt Friedman fix Signed-off-by: Matt Friedman fix Signed-off-by: Matt Friedman --- adm/style/manage_pages.html | 12 ++++++++++++ controller/admin_controller.php | 10 +++++++++- operators/page.php | 33 ++++++++++++++++++++++++++------- operators/page_interface.php | 24 +++++++++++++++++------- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/adm/style/manage_pages.html b/adm/style/manage_pages.html index 48a00ba..33555df 100644 --- a/adm/style/manage_pages.html +++ b/adm/style/manage_pages.html @@ -152,6 +152,12 @@

{{ lang('ACP_PAGES_MANAGE') }}

+ {% if pagination %} + + {% endif %} + @@ -193,6 +199,12 @@

{{ lang('ACP_PAGES_MANAGE') }}

+ {% if pagination %} + + {% endif %} +
diff --git a/controller/admin_controller.php b/controller/admin_controller.php index ef51a2c..c9765b2 100644 --- a/controller/admin_controller.php +++ b/controller/admin_controller.php @@ -97,8 +97,14 @@ public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\ */ public function display_pages() { + /* @var $pagination \phpbb\pagination */ + $pagination = $this->container->get('pagination'); + $start = $this->request->variable('start', 0); + $total = $this->page_operator->get_total_pages(); + $limit = 25; + // Grab all the pages from the db - $entities = $this->page_operator->get_pages(); + $entities = $this->page_operator->get_pages($limit, $start); // Process each page entity for display /* @var $entity \phpbb\pages\entity\page */ @@ -121,6 +127,8 @@ public function display_pages() )); } + $pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $total, $limit, $start); + // Set output vars for display in the template $this->template->assign_vars(array( 'U_ACTION' => $this->u_action, diff --git a/operators/page.php b/operators/page.php index ea5beda..7f21eb6 100644 --- a/operators/page.php +++ b/operators/page.php @@ -67,12 +67,14 @@ public function __construct(\phpbb\cache\driver\driver_interface $cache, Contain } /** - * Get all pages - * - * @return array Array of page data entities - * @access public - */ - public function get_pages() + * Get all pages + * + * @param int $limit + * @param int $start + * @return array Array of page data entities + * @access public + */ + public function get_pages($limit = 0, $start = 0) { $entities = array(); @@ -80,7 +82,7 @@ public function get_pages() $sql = 'SELECT * FROM ' . $this->pages_table . ' ORDER BY page_order ASC, page_id ASC'; - $result = $this->db->sql_query($sql); + $result = $this->db->sql_query_limit($sql, $limit, $start); while ($row = $this->db->sql_fetchrow($result)) { @@ -367,6 +369,23 @@ public function get_link_locations() return $rows; } + /** + * Get the total number of pages + * + * @return int + * @access public + */ + public function get_total_pages() + { + $sql = 'SELECT COUNT(*) AS pages + FROM ' . $this->pages_table; + $result = $this->db->sql_query($sql); + $pages = $this->db->sql_fetchfield('pages'); + $this->db->sql_freeresult($result); + + return (int) $pages; + } + /** * Check if a page identifier exists in the database * diff --git a/operators/page_interface.php b/operators/page_interface.php index 634b2e6..16c611d 100644 --- a/operators/page_interface.php +++ b/operators/page_interface.php @@ -13,17 +13,19 @@ /** * Interface for our pages operator * -* This describes all of the methods we'll have for working with a set of pages +* This describes all the methods we'll have for working with a set of pages */ interface page_interface { /** - * Get all pages - * - * @return array Array of page data entities - * @access public - */ - public function get_pages(); + * Get all pages + * + * @param int $limit + * @param int $start + * @return array Array of page data entities + * @access public + */ + public function get_pages($limit = 0, $start = 0); /** * Add a page @@ -108,4 +110,12 @@ public function insert_page_links($page_id, $link_ids); * @access public */ public function get_link_locations(); + + /** + * Get the total number of pages + * + * @return int + * @access public + */ + public function get_total_pages(); } From 7f27b657f5924c6eb3d1bee6425c5574e0b15701 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 21 Jul 2024 08:48:24 -0700 Subject: [PATCH 2/3] Update tests Signed-off-by: Matt Friedman --- .github/workflows/tests.yml | 4 ++ .../page_operator_get_pages_test.php | 59 +++++++++++++------ .../page_operator_get_total_pages_test.php | 22 +++++++ 3 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 tests/operators/page_operator_get_total_pages_test.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4379c66..7c69307 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -127,6 +127,8 @@ jobs: db: "mysql:5.7" - php: '8.3' db: "mysql:5.7" + - php: '8.4' + db: "mysql:5.7" name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }} @@ -270,6 +272,8 @@ jobs: db: "postgres:14" - php: '8.3' db: "postgres:14" + - php: '8.4' + db: "postgres:14" name: PHP ${{ matrix.php }} - ${{ matrix.db }} diff --git a/tests/operators/page_operator_get_pages_test.php b/tests/operators/page_operator_get_pages_test.php index b7de4b0..2c12c56 100644 --- a/tests/operators/page_operator_get_pages_test.php +++ b/tests/operators/page_operator_get_pages_test.php @@ -19,10 +19,12 @@ class page_operator_get_pages_test extends page_operator_base */ public function get_pages_test_data() { - return array( - array( - array( - array( + return [ + [ + 0, + 0, + [ + [ 'page_id' => 1, 'page_order' => 1, 'page_description' => 'description_1', @@ -34,8 +36,8 @@ public function get_pages_test_data() 'page_display_to_guests' => 1, 'page_title_switch' => 0, 'page_icon_font' => 'foo-1', - ), - array( + ], + [ 'page_id' => 2, 'page_order' => 2, 'page_description' => 'description_2', @@ -47,8 +49,8 @@ public function get_pages_test_data() 'page_display_to_guests' => 1, 'page_title_switch' => 0, 'page_icon_font' => '', - ), - array( + ], + [ 'page_id' => 3, 'page_order' => 3, 'page_description' => 'description_3', @@ -60,8 +62,8 @@ public function get_pages_test_data() 'page_display_to_guests' => 0, 'page_title_switch' => 0, 'page_icon_font' => '', - ), - array( + ], + [ 'page_id' => 4, 'page_order' => 4, 'page_description' => 'description_4', @@ -73,10 +75,29 @@ public function get_pages_test_data() 'page_display_to_guests' => 0, 'page_title_switch' => 0, 'page_icon_font' => '', - ), - ), - ), - ); + ], + ], + ], + [ + 2, + 1, + [ + [ + 'page_id' => 3, + 'page_order' => 3, + 'page_description' => 'description_3', + 'page_description_display' => 0, + 'page_route' => 'page_3', + 'page_title' => 'title_3', + 'page_content' => 'message_3', + 'page_display' => 1, + 'page_display_to_guests' => 0, + 'page_title_switch' => 0, + 'page_icon_font' => '', + ], + ], + ], + ]; } /** @@ -84,16 +105,16 @@ public function get_pages_test_data() * * @dataProvider get_pages_test_data */ - public function test_get_pages($expected) + public function test_get_pages($start, $limit, $expected) { - // Setup the operator class + // Set up the operator class $operator = $this->get_page_operator(); // Grab the page data as an array of entities - $entities = $operator->get_pages(); + $entities = $operator->get_pages($limit, $start); // Map the fields to the getters - $map = array( + $map = [ 'page_id' => 'get_id', 'page_order' => 'get_order', 'page_description' => 'get_description', @@ -105,7 +126,7 @@ public function test_get_pages($expected) 'page_display_to_guests' => 'get_page_display_to_guests', 'page_title_switch' => 'get_page_title_switch', 'page_icon_font' => 'get_icon_font', - ); + ]; // Test through each entity in the array of entities $i = 0; diff --git a/tests/operators/page_operator_get_total_pages_test.php b/tests/operators/page_operator_get_total_pages_test.php new file mode 100644 index 0000000..99940b4 --- /dev/null +++ b/tests/operators/page_operator_get_total_pages_test.php @@ -0,0 +1,22 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +*/ + +namespace phpbb\pages\tests\operators; + +class page_operator_get_total_pages_test extends page_operator_base +{ + public function test_get_total_pages() + { + // Set up the operator class + $operator = $this->get_page_operator(); + + self::assertEquals(4, $operator->get_total_pages()); + } +} From 88773df0e270d3c23be4d003eb7150ece6396f8b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sun, 21 Jul 2024 08:48:31 -0700 Subject: [PATCH 3/3] Update composer Signed-off-by: Matt Friedman --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 844b99e..5fd907e 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "composer/installers": "~1.0" }, "require-dev": { - "phing/phing": "2.4.*" + "phing/phing": "~2.4" }, "extra": { "display-name": "Pages",