Skip to content

Commit 3a44f8f

Browse files
committed
Merge branch 'master' into dev/4.0
Signed-off-by: Matt Friedman <maf675@gmail.com> # Conflicts: # .github/workflows/tests.yml
2 parents 8e7bea5 + c02be0a commit 3a44f8f

File tree

8 files changed

+133
-35
lines changed

8 files changed

+133
-35
lines changed

.github/workflows/tests.yml

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ jobs:
127127
db: "mysql:5.7"
128128
- php: '8.3'
129129
db: "mariadb:10.2"
130+
- php: '8.4'
131+
db: "mysql:8.0"
132+
- php: '8.4'
133+
db: "mariadb:10.3"
130134

131135
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
132136

@@ -264,6 +268,8 @@ jobs:
264268
db: "postgres:9.5"
265269
- php: '8.3'
266270
db: "postgres:9.5"
271+
- php: '8.4'
272+
db: "postgres:9.5"
267273

268274
name: PHP ${{ matrix.php }} - ${{ matrix.db }}
269275

adm/style/manage_pages.html

+12
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ <h1>{{ lang('ACP_PAGES_MANAGE') }}</h1>
152152
</fieldset>
153153
</form>
154154

155+
{% if pagination %}
156+
<div class="pagination top-pagination">
157+
{% include 'pagination.html' %}
158+
</div>
159+
{% endif %}
160+
155161
<table class="table1 zebra-table fixed-width-table">
156162
<thead>
157163
<tr>
@@ -193,6 +199,12 @@ <h1>{{ lang('ACP_PAGES_MANAGE') }}</h1>
193199
</tbody>
194200
</table>
195201

202+
{% if pagination %}
203+
<div class="pagination">
204+
{% include 'pagination.html' %}
205+
</div>
206+
{% endif %}
207+
196208
<form id="pages_add_page" method="post" action="{{ U_ACTION }}">
197209
<fieldset class="quick">
198210
<input class="button2" type="submit" name="addpage" value="{{ lang('ACP_PAGES_CREATE_PAGE') }}" />

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"composer/installers": "~1.0"
5454
},
5555
"require-dev": {
56-
"phing/phing": "2.4.*"
56+
"phing/phing": "~2.4"
5757
},
5858
"extra": {
5959
"display-name": "Pages",

controller/admin_controller.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,14 @@ public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\
9797
*/
9898
public function display_pages()
9999
{
100+
/* @var $pagination \phpbb\pagination */
101+
$pagination = $this->container->get('pagination');
102+
$start = $this->request->variable('start', 0);
103+
$total = $this->page_operator->get_total_pages();
104+
$limit = 25;
105+
100106
// Grab all the pages from the db
101-
$entities = $this->page_operator->get_pages();
107+
$entities = $this->page_operator->get_pages($limit, $start);
102108

103109
// Process each page entity for display
104110
/* @var $entity \phpbb\pages\entity\page */
@@ -121,6 +127,8 @@ public function display_pages()
121127
));
122128
}
123129

130+
$pagination->generate_template_pagination($this->u_action, 'pagination', 'start', $total, $limit, $start);
131+
124132
// Set output vars for display in the template
125133
$this->template->assign_vars(array(
126134
'U_ACTION' => $this->u_action,

operators/page.php

+26-7
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,22 @@ public function __construct(\phpbb\cache\driver\driver_interface $cache, Contain
6767
}
6868

6969
/**
70-
* Get all pages
71-
*
72-
* @return array Array of page data entities
73-
* @access public
74-
*/
75-
public function get_pages()
70+
* Get all pages
71+
*
72+
* @param int $limit
73+
* @param int $start
74+
* @return array Array of page data entities
75+
* @access public
76+
*/
77+
public function get_pages($limit = 0, $start = 0)
7678
{
7779
$entities = array();
7880

7981
// Load all page data from the database
8082
$sql = 'SELECT *
8183
FROM ' . $this->pages_table . '
8284
ORDER BY page_order ASC, page_id ASC';
83-
$result = $this->db->sql_query($sql);
85+
$result = $this->db->sql_query_limit($sql, $limit, $start);
8486

8587
while ($row = $this->db->sql_fetchrow($result))
8688
{
@@ -367,6 +369,23 @@ public function get_link_locations()
367369
return $rows;
368370
}
369371

372+
/**
373+
* Get the total number of pages
374+
*
375+
* @return int
376+
* @access public
377+
*/
378+
public function get_total_pages()
379+
{
380+
$sql = 'SELECT COUNT(*) AS pages
381+
FROM ' . $this->pages_table;
382+
$result = $this->db->sql_query($sql);
383+
$pages = $this->db->sql_fetchfield('pages');
384+
$this->db->sql_freeresult($result);
385+
386+
return (int) $pages;
387+
}
388+
370389
/**
371390
* Check if a page identifier exists in the database
372391
*

operators/page_interface.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
/**
1414
* Interface for our pages operator
1515
*
16-
* This describes all of the methods we'll have for working with a set of pages
16+
* This describes all the methods we'll have for working with a set of pages
1717
*/
1818
interface page_interface
1919
{
2020
/**
21-
* Get all pages
22-
*
23-
* @return array Array of page data entities
24-
* @access public
25-
*/
26-
public function get_pages();
21+
* Get all pages
22+
*
23+
* @param int $limit
24+
* @param int $start
25+
* @return array Array of page data entities
26+
* @access public
27+
*/
28+
public function get_pages($limit = 0, $start = 0);
2729

2830
/**
2931
* Add a page
@@ -108,4 +110,12 @@ public function insert_page_links($page_id, $link_ids);
108110
* @access public
109111
*/
110112
public function get_link_locations();
113+
114+
/**
115+
* Get the total number of pages
116+
*
117+
* @return int
118+
* @access public
119+
*/
120+
public function get_total_pages();
111121
}

tests/operators/page_operator_get_pages_test.php

+40-19
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class page_operator_get_pages_test extends page_operator_base
1919
*/
2020
public function get_pages_test_data()
2121
{
22-
return array(
23-
array(
24-
array(
25-
array(
22+
return [
23+
[
24+
0,
25+
0,
26+
[
27+
[
2628
'page_id' => 1,
2729
'page_order' => 1,
2830
'page_description' => 'description_1',
@@ -34,8 +36,8 @@ public function get_pages_test_data()
3436
'page_display_to_guests' => 1,
3537
'page_title_switch' => 0,
3638
'page_icon_font' => 'foo-1',
37-
),
38-
array(
39+
],
40+
[
3941
'page_id' => 2,
4042
'page_order' => 2,
4143
'page_description' => 'description_2',
@@ -47,8 +49,8 @@ public function get_pages_test_data()
4749
'page_display_to_guests' => 1,
4850
'page_title_switch' => 0,
4951
'page_icon_font' => '',
50-
),
51-
array(
52+
],
53+
[
5254
'page_id' => 3,
5355
'page_order' => 3,
5456
'page_description' => 'description_3',
@@ -60,8 +62,8 @@ public function get_pages_test_data()
6062
'page_display_to_guests' => 0,
6163
'page_title_switch' => 0,
6264
'page_icon_font' => '',
63-
),
64-
array(
65+
],
66+
[
6567
'page_id' => 4,
6668
'page_order' => 4,
6769
'page_description' => 'description_4',
@@ -73,27 +75,46 @@ public function get_pages_test_data()
7375
'page_display_to_guests' => 0,
7476
'page_title_switch' => 0,
7577
'page_icon_font' => '',
76-
),
77-
),
78-
),
79-
);
78+
],
79+
],
80+
],
81+
[
82+
2,
83+
1,
84+
[
85+
[
86+
'page_id' => 3,
87+
'page_order' => 3,
88+
'page_description' => 'description_3',
89+
'page_description_display' => 0,
90+
'page_route' => 'page_3',
91+
'page_title' => 'title_3',
92+
'page_content' => 'message_3',
93+
'page_display' => 1,
94+
'page_display_to_guests' => 0,
95+
'page_title_switch' => 0,
96+
'page_icon_font' => '',
97+
],
98+
],
99+
],
100+
];
80101
}
81102

82103
/**
83104
* Test getting pages from the database
84105
*
85106
* @dataProvider get_pages_test_data
86107
*/
87-
public function test_get_pages($expected)
108+
public function test_get_pages($start, $limit, $expected)
88109
{
89-
// Setup the operator class
110+
// Set up the operator class
90111
$operator = $this->get_page_operator();
91112

92113
// Grab the page data as an array of entities
93-
$entities = $operator->get_pages();
114+
$entities = $operator->get_pages($limit, $start);
94115

95116
// Map the fields to the getters
96-
$map = array(
117+
$map = [
97118
'page_id' => 'get_id',
98119
'page_order' => 'get_order',
99120
'page_description' => 'get_description',
@@ -105,7 +126,7 @@ public function test_get_pages($expected)
105126
'page_display_to_guests' => 'get_page_display_to_guests',
106127
'page_title_switch' => 'get_page_title_switch',
107128
'page_icon_font' => 'get_icon_font',
108-
);
129+
];
109130

110131
// Test through each entity in the array of entities
111132
$i = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
*
4+
* Pages extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2024 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\pages\tests\operators;
12+
13+
class page_operator_get_total_pages_test extends page_operator_base
14+
{
15+
public function test_get_total_pages()
16+
{
17+
// Set up the operator class
18+
$operator = $this->get_page_operator();
19+
20+
self::assertEquals(4, $operator->get_total_pages());
21+
}
22+
}

0 commit comments

Comments
 (0)