Skip to content

Commit 355c293

Browse files
committed
Add pagination to the pages list in ACP
Signed-off-by: Matt Friedman <maf675@gmail.com> fix Signed-off-by: Matt Friedman <maf675@gmail.com> fix Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent 5797775 commit 355c293

4 files changed

Lines changed: 64 additions & 15 deletions

File tree

adm/style/manage_pages.html

Lines changed: 12 additions & 0 deletions
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') }}" />

controller/admin_controller.php

Lines changed: 9 additions & 1 deletion
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

Lines changed: 26 additions & 7 deletions
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

Lines changed: 17 additions & 7 deletions
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
}

0 commit comments

Comments
 (0)