From bc356917cfdc91d8514c8d61b72b575603426857 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Wed, 3 Oct 2018 16:28:18 +0200 Subject: [PATCH] Add pagination for PIP GUI entry list See #2545 --- .../templates/devtoolsProjectPipEntryList.tpl | 43 ++++++++++- .../DevtoolsProjectPipEntryListPage.class.php | 77 ++++++++++++++++++- .../pip/DevtoolsPipEntryList.class.php | 13 +++- .../pip/IDevtoolsPipEntryList.class.php | 12 ++- 4 files changed, 141 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl b/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl index 705a42684f..7067bef227 100644 --- a/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl +++ b/wcfsetup/install/files/acp/templates/devtoolsProjectPipEntryList.tpl @@ -32,6 +32,14 @@ +{hascontent} +
+ {content} + {pages print=true assign=pagesLinks controller="DevtoolsProjectPipEntryList" id=$project->projectID link="$linkParameters&pageNo=%d"} + {/content} +
+{/hascontent} + {if !$entryList->getEntries()|empty}
@@ -44,7 +52,7 @@ - {foreach from=$entryList->getEntries() key=identifier item=entry} + {foreach from=$entryList->getEntries($startIndex, $itemsPerPage) key=identifier item=entry} {foreach from=$entryList->getKeys() key=key item=languageItem} @@ -55,6 +63,39 @@
+ + {else}

{lang}wcf.global.noItems{/lang}

{/if} diff --git a/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php b/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php index f3ddfbd600..eaecf818e8 100644 --- a/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/DevtoolsProjectPipEntryListPage.class.php @@ -23,12 +23,42 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { */ public $activeMenuItem = 'wcf.acp.menu.link.devtools.project.list'; + /** + * indicates the range of the listed items + * @var integer + */ + public $endIndex = 0; + + /** + * pip entry list + * @var IDevtoolsPipEntryList + */ + public $entryList; + /** * type of the listed pip entries * @var string */ public $entryType; + /** + * number of items shown per page + * @var integer + */ + public $itemsPerPage = 100; + + /** + * number of all items + * @var integer + */ + public $items = 0; + + /** + * pagination link parameters + * @var string + */ + public $linkParameters = ''; + /** * @inheritDoc */ @@ -39,6 +69,18 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { */ public $neededPermissions = ['admin.configuration.package.canInstallPackage']; + /** + * current page number + * @var integer + */ + public $pageNo = 0; + + /** + * number of all pages + * @var integer + */ + public $pages = 0; + /** * name of the requested pip * @var string @@ -63,6 +105,12 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { */ public $projectID = 0; + /** + * indicates the range of the listed items + * @var integer + */ + public $startIndex = 0; + /** * @inheritDoc */ @@ -106,6 +154,13 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { else if (!empty($this->pipObject->getPip()->getEntryTypes())) { throw new IllegalLinkException(); } + + if (isset($_REQUEST['pageNo'])) $this->pageNo = intval($_REQUEST['pageNo']); + + $this->linkParameters = 'pip=' . $this->pip; + if ($this->entryType !== null) { + $this->linkParameters .= '&entryType=' . $this->entryType; + } } /** @@ -116,6 +171,19 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { /** @var IDevtoolsPipEntryList entryList */ $this->entryList = $this->pipObject->getPip()->getEntryList(); + + $this->items = count($this->entryList->getEntries()); + $this->pages = intval(ceil($this->items / $this->itemsPerPage)); + + // correct active page number + if ($this->pageNo > $this->pages) $this->pageNo = $this->pages; + if ($this->pageNo < 1) $this->pageNo = 1; + + // calculate start and end index + $this->startIndex = ($this->pageNo - 1) * $this->itemsPerPage; + $this->endIndex = $this->startIndex + $this->itemsPerPage; + $this->startIndex++; + if ($this->endIndex > $this->items) $this->endIndex = $this->items; } /** @@ -125,10 +193,17 @@ class DevtoolsProjectPipEntryListPage extends AbstractPage { parent::assignVariables(); WCF::getTPL()->assign([ + 'endIndex' => $this->endIndex, 'entryList' => $this->entryList, 'entryType' => $this->entryType, + 'items' => $this->items, + 'itemsPerPage' => $this->itemsPerPage, + 'linkParameters' => $this->linkParameters, + 'pageNo' => $this->pageNo, + 'pages' => $this->pages, 'pip' => $this->pip, - 'project' => $this->project + 'project' => $this->project, + 'startIndex' => $this->startIndex ]); } } diff --git a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php index 110c221b7e..2d54cc6a51 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/DevtoolsPipEntryList.class.php @@ -55,7 +55,11 @@ class DevtoolsPipEntryList implements IDevtoolsPipEntryList { /** * @inheritDoc */ - public function getEntries() { + public function getEntries($startIndex = null, $entryCount = null) { + if ($startIndex !== null && $entryCount !== null) { + return array_slice($this->entries, $startIndex, $entryCount); + } + return $this->entries; } @@ -70,6 +74,13 @@ class DevtoolsPipEntryList implements IDevtoolsPipEntryList { return $this->keys; } + /** + * @inheritDoc + */ + public function hasEntry($id) { + return isset($this->entries[$id]); + } + /** * @inheritDoc */ diff --git a/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php b/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php index 815cb9a749..ddfd95d112 100644 --- a/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php +++ b/wcfsetup/install/files/lib/system/devtools/pip/IDevtoolsPipEntryList.class.php @@ -25,9 +25,11 @@ interface IDevtoolsPipEntryList { /** * Returns all entries in the list. * + * @param int $startIndex + * @param int $entryCount * @return array */ - public function getEntries(); + public function getEntries($startIndex = null, $entryCount = null); /** * Returns the expected keys of the entries that can be used to display the @@ -41,6 +43,14 @@ interface IDevtoolsPipEntryList { */ public function getKeys(); + /** + * Returns true if an entry with the given entry identifier exists. + * + * @param string $id unique entry identifier + * @return bool + */ + public function hasEntry($id); + /** * Sets the keys of the entries that can be used to display the entry list * as a table. -- 2.20.1