From 0d594a204da0795dce235334b2c8b34b57c240a5 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Wed, 6 Nov 2019 11:32:01 +0100 Subject: [PATCH 01/11] Pagination fix API com_config now return correct links for pagination. Similarly, fixed JsonApiView.php. In JsonApiView I added model->setState because 'start' and 'limit' weren't populated and they always got default values (0 and 20) showing the first 20 records. I don't know if there's a better solution than this one... --- .../View/Application/JsonapiView.php | 67 ++++++++------- .../com_config/View/Component/JsonapiView.php | 67 ++++++++------- libraries/src/MVC/View/JsonApiView.php | 83 +++++++++++-------- 3 files changed, 128 insertions(+), 89 deletions(-) diff --git a/api/components/com_config/View/Application/JsonapiView.php b/api/components/com_config/View/Application/JsonapiView.php index d8f9fe008910d..bfd69a090330b 100644 --- a/api/components/com_config/View/Application/JsonapiView.php +++ b/api/components/com_config/View/Application/JsonapiView.php @@ -58,38 +58,49 @@ public function displayList(array $items = null) $items = array_splice($items, $offset, $limit); - $firstPage = clone $currentUrl; - $firstPageQuery = $currentPageQuery; - $firstPageQuery['offset'] = 0; - $firstPage->setVar('page', $firstPageQuery); - - $nextPage = clone $currentUrl; - $nextPageQuery = $currentPageQuery; - $nextOffset = $currentPageQuery['offset'] + $limit; - $nextPageQuery['offset'] = ($nextOffset > ($totalPagesAvailable * $limit)) ? $totalPagesAvailable - $limit : $nextOffset; - $nextPage->setVar('page', $nextPageQuery); - - $previousPage = clone $currentUrl; - $previousPageQuery = $currentPageQuery; - $previousOffset = $currentPageQuery['offset'] - $limit; - $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; - $previousPage->setVar('page', $previousPageQuery); - - $lastPage = clone $currentUrl; - $lastPageQuery = $currentPageQuery; - $lastPageQuery['offset'] = $totalPagesAvailable - $limit; - $lastPage->setVar('page', $lastPageQuery); + $this->document->addMeta('total-pages', $totalPagesAvailable) + ->addLink('self', (string) $currentUrl); + + // Check for first and previous pages + if ($offset > 0) + { + $firstPage = clone $currentUrl; + $firstPageQuery = $currentPageQuery; + $firstPageQuery['offset'] = 0; + $firstPage->setVar('page', $firstPageQuery); + + $previousPage = clone $currentUrl; + $previousPageQuery = $currentPageQuery; + $previousOffset = $currentPageQuery['offset'] - $limit; + $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; + $previousPage->setVar('page', $previousPageQuery); + + $this->document->addLink('first', (string) $firstPage) + ->addLink('previous', (string) $previousPage); + } + + // Check for next and last pages + if ($offset + $limit < $totalItemsCount) + { + $nextPage = clone $currentUrl; + $nextPageQuery = $currentPageQuery; + $nextOffset = $currentPageQuery['offset'] + $limit; + $nextPageQuery['offset'] = ($nextOffset > ($totalPagesAvailable * $limit)) ? $totalPagesAvailable - $limit : $nextOffset; + $nextPage->setVar('page', $nextPageQuery); + + $lastPage = clone $currentUrl; + $lastPageQuery = $currentPageQuery; + $lastPageQuery['offset'] = ($totalPagesAvailable - 1) * $limit; + $lastPage->setVar('page', $lastPageQuery); + + $this->document->addLink('next', (string) $nextPage) + ->addLink('last', (string) $lastPage); + } $collection = (new Collection($items, new JoomlaSerializer($this->type))); // Set the data into the document and render it - $this->document->addMeta('total-pages', $totalPagesAvailable) - ->setData($collection) - ->addLink('self', (string) $currentUrl) - ->addLink('first', (string) $firstPage) - ->addLink('next', (string) $nextPage) - ->addLink('previous', (string) $previousPage) - ->addLink('last', (string) $lastPage); + $this->document->setData($collection); return $this->document->render(); } diff --git a/api/components/com_config/View/Component/JsonapiView.php b/api/components/com_config/View/Component/JsonapiView.php index 983ecce21a1ea..7d6903b9ad940 100644 --- a/api/components/com_config/View/Component/JsonapiView.php +++ b/api/components/com_config/View/Component/JsonapiView.php @@ -74,38 +74,49 @@ public function displayList(array $items = null) $items = array_splice($items, $offset, $limit); - $firstPage = clone $currentUrl; - $firstPageQuery = $currentPageQuery; - $firstPageQuery['offset'] = 0; - $firstPage->setVar('page', $firstPageQuery); - - $nextPage = clone $currentUrl; - $nextPageQuery = $currentPageQuery; - $nextOffset = $currentPageQuery['offset'] + $limit; - $nextPageQuery['offset'] = ($nextOffset > ($totalPagesAvailable * $limit)) ? $totalPagesAvailable - $limit : $nextOffset; - $nextPage->setVar('page', $nextPageQuery); - - $previousPage = clone $currentUrl; - $previousPageQuery = $currentPageQuery; - $previousOffset = $currentPageQuery['offset'] - $limit; - $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; - $previousPage->setVar('page', $previousPageQuery); - - $lastPage = clone $currentUrl; - $lastPageQuery = $currentPageQuery; - $lastPageQuery['offset'] = $totalPagesAvailable - $limit; - $lastPage->setVar('page', $lastPageQuery); + $this->document->addMeta('total-pages', $totalPagesAvailable) + ->addLink('self', (string) $currentUrl); + + // Check for first and previous pages + if ($offset > 0) + { + $firstPage = clone $currentUrl; + $firstPageQuery = $currentPageQuery; + $firstPageQuery['offset'] = 0; + $firstPage->setVar('page', $firstPageQuery); + + $previousPage = clone $currentUrl; + $previousPageQuery = $currentPageQuery; + $previousOffset = $currentPageQuery['offset'] - $limit; + $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; + $previousPage->setVar('page', $previousPageQuery); + + $this->document->addLink('first', (string) $firstPage) + ->addLink('previous', (string) $previousPage); + } + + // Check for next and last pages + if ($offset + $limit < $totalItemsCount) + { + $nextPage = clone $currentUrl; + $nextPageQuery = $currentPageQuery; + $nextOffset = $currentPageQuery['offset'] + $limit; + $nextPageQuery['offset'] = ($nextOffset > ($totalPagesAvailable * $limit)) ? $totalPagesAvailable - $limit : $nextOffset; + $nextPage->setVar('page', $nextPageQuery); + + $lastPage = clone $currentUrl; + $lastPageQuery = $currentPageQuery; + $lastPageQuery['offset'] = $totalPagesAvailable - $limit; + $lastPage->setVar('page', $lastPageQuery); + + $this->document->addLink('next', (string) $nextPage) + ->addLink('last', (string) $lastPage); + } $collection = (new Collection($items, new JoomlaSerializer($this->type))); // Set the data into the document and render it - $this->document->addMeta('total-pages', $totalPagesAvailable) - ->setData($collection) - ->addLink('self', (string) $currentUrl) - ->addLink('first', (string) $firstPage) - ->addLink('next', (string) $nextPage) - ->addLink('previous', (string) $previousPage) - ->addLink('last', (string) $lastPage); + $this->document->setData($collection); return $this->document->render(); } diff --git a/libraries/src/MVC/View/JsonApiView.php b/libraries/src/MVC/View/JsonApiView.php index 0d4028ece4a18..51a57047e5f9c 100644 --- a/libraries/src/MVC/View/JsonApiView.php +++ b/libraries/src/MVC/View/JsonApiView.php @@ -112,6 +112,15 @@ public function displayList(array $items = null) /** @var \Joomla\CMS\MVC\Model\ListModel $model */ $model = $this->getModel(); + // Get page query + $currentUrl = Uri::getInstance(); + $currentPageDefaultInformation = ['offset' => 0, 'limit' => 20]; + $currentPageQuery = $currentUrl->getVar('page', $currentPageDefaultInformation); + + // Set model start and limit params + $model->setState('list.start', $currentPageQuery['offset']); + $model->setState('list.limit', $currentPageQuery['limit']); + if ($items === null) { $items = []; @@ -136,44 +145,52 @@ public function displayList(array $items = null) } // Set up links for pagination - $currentUrl = Uri::getInstance(); - $currentPageDefaultInformation = array('offset' => $pagination->limitstart, 'limit' => $pagination->limit); - $currentPageQuery = $currentUrl->getVar('page', $currentPageDefaultInformation); - $totalPagesAvailable = ($pagination->pagesTotal * $pagination->limit); - - $firstPage = clone $currentUrl; - $firstPageQuery = $currentPageQuery; - $firstPageQuery['offset'] = 0; - $firstPage->setVar('page', $firstPageQuery); - - $nextPage = clone $currentUrl; - $nextPageQuery = $currentPageQuery; - $nextOffset = $currentPageQuery['offset'] + $pagination->limit; - $nextPageQuery['offset'] = ($nextOffset > ($totalPagesAvailable * $pagination->limit)) ? $totalPagesAvailable - $pagination->limit : $nextOffset; - $nextPage->setVar('page', $nextPageQuery); - - $previousPage = clone $currentUrl; - $previousPageQuery = $currentPageQuery; - $previousOffset = $currentPageQuery['offset'] - $pagination->limit; - $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; - $previousPage->setVar('page', $previousPageQuery); - - $lastPage = clone $currentUrl; - $lastPageQuery = $currentPageQuery; - $lastPageQuery['offset'] = $totalPagesAvailable - $pagination->limit; - $lastPage->setVar('page', $lastPageQuery); + $totalItemsCount = ($pagination->pagesTotal * $pagination->limit); + + $this->document->addMeta('total-pages', $pagination->pagesTotal) + ->addLink('self', (string) $currentUrl); + + // Check for first and previous pages + if ($pagination->limitstart > 0) + { + $firstPage = clone $currentUrl; + $firstPageQuery = $currentPageQuery; + $firstPageQuery['offset'] = 0; + $firstPage->setVar('page', $firstPageQuery); + + $previousPage = clone $currentUrl; + $previousPageQuery = $currentPageQuery; + $previousOffset = $currentPageQuery['offset'] - $pagination->limit; + $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; + $previousPage->setVar('page', $previousPageQuery); + + $this->document->addLink('first', (string) $firstPage) + ->addLink('previous', (string) $previousPage); + } + + // Check for next and last pages + if ($pagination->limitstart + $pagination->limit < $totalItemsCount) + { + $nextPage = clone $currentUrl; + $nextPageQuery = $currentPageQuery; + $nextOffset = $currentPageQuery['offset'] + $pagination->limit; + $nextPageQuery['offset'] = ($nextOffset > ($pagination->pagesTotal * $pagination->limit)) ? $pagination->pagesTotal - $pagination->limit : $nextOffset; + $nextPage->setVar('page', $nextPageQuery); + + $lastPage = clone $currentUrl; + $lastPageQuery = $currentPageQuery; + $lastPageQuery['offset'] = ($pagination->pagesTotal - 1) * $pagination->limit; + $lastPage->setVar('page', $lastPageQuery); + + $this->document->addLink('next', (string) $nextPage) + ->addLink('last', (string) $lastPage); + } $collection = (new Collection($items, $this->serializer)) ->fields([$this->type => $this->fieldsToRenderList]); // Set the data into the document and render it - $this->document->addMeta('total-pages', $pagination->pagesTotal) - ->setData($collection) - ->addLink('self', (string) $currentUrl) - ->addLink('first', (string) $firstPage) - ->addLink('next', (string) $nextPage) - ->addLink('previous', (string) $previousPage) - ->addLink('last', (string) $lastPage); + $this->document->setData($collection); return $this->document->render(); } From 0f8ea37ee3e449b8c5cdca4a9d708d38eae3b860 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Wed, 6 Nov 2019 13:35:16 +0100 Subject: [PATCH 02/11] Code standard fixes --- api/components/com_config/View/Application/JsonapiView.php | 4 ++-- api/components/com_config/View/Component/JsonapiView.php | 4 ++-- libraries/src/MVC/View/JsonApiView.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/components/com_config/View/Application/JsonapiView.php b/api/components/com_config/View/Application/JsonapiView.php index bfd69a090330b..7e339a055fcff 100644 --- a/api/components/com_config/View/Application/JsonapiView.php +++ b/api/components/com_config/View/Application/JsonapiView.php @@ -76,7 +76,7 @@ public function displayList(array $items = null) $previousPage->setVar('page', $previousPageQuery); $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + ->addLink('previous', (string) $previousPage); } // Check for next and last pages @@ -94,7 +94,7 @@ public function displayList(array $items = null) $lastPage->setVar('page', $lastPageQuery); $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + ->addLink('last', (string) $lastPage); } $collection = (new Collection($items, new JoomlaSerializer($this->type))); diff --git a/api/components/com_config/View/Component/JsonapiView.php b/api/components/com_config/View/Component/JsonapiView.php index 7d6903b9ad940..59dec65f4ca11 100644 --- a/api/components/com_config/View/Component/JsonapiView.php +++ b/api/components/com_config/View/Component/JsonapiView.php @@ -92,7 +92,7 @@ public function displayList(array $items = null) $previousPage->setVar('page', $previousPageQuery); $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + ->addLink('previous', (string) $previousPage); } // Check for next and last pages @@ -110,7 +110,7 @@ public function displayList(array $items = null) $lastPage->setVar('page', $lastPageQuery); $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + ->addLink('last', (string) $lastPage); } $collection = (new Collection($items, new JoomlaSerializer($this->type))); diff --git a/libraries/src/MVC/View/JsonApiView.php b/libraries/src/MVC/View/JsonApiView.php index 51a57047e5f9c..12b19b71cb0e4 100644 --- a/libraries/src/MVC/View/JsonApiView.php +++ b/libraries/src/MVC/View/JsonApiView.php @@ -165,7 +165,7 @@ public function displayList(array $items = null) $previousPage->setVar('page', $previousPageQuery); $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + ->addLink('previous', (string) $previousPage); } // Check for next and last pages @@ -183,7 +183,7 @@ public function displayList(array $items = null) $lastPage->setVar('page', $lastPageQuery); $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + ->addLink('last', (string) $lastPage); } $collection = (new Collection($items, $this->serializer)) From 90c6acff1506dbd5cd15f08c0bc7d4188b06f8fb Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Fri, 8 Nov 2019 12:14:02 +0100 Subject: [PATCH 03/11] Updated ApiController.php displayList() pagination --- libraries/src/MVC/Controller/ApiController.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/src/MVC/Controller/ApiController.php b/libraries/src/MVC/Controller/ApiController.php index da023b29eb77b..166d2a3e15850 100644 --- a/libraries/src/MVC/Controller/ApiController.php +++ b/libraries/src/MVC/Controller/ApiController.php @@ -199,7 +199,6 @@ public function displayList() { // Assemble pagination information (using recommended JsonApi pagination notation for offset strategy) $paginationInfo = $this->input->get('page', [], 'array'); - $internalPaginationMapping = []; if (\array_key_exists('offset', $paginationInfo)) { @@ -208,11 +207,9 @@ public function displayList() if (\array_key_exists('limit', $paginationInfo)) { - $internalPaginationMapping['limit'] = $paginationInfo['limit']; + $this->input->set('limit', $paginationInfo['limit']); } - $this->input->set('list', $internalPaginationMapping); - $viewType = $this->app->getDocument()->getType(); $viewName = $this->input->get('view', $this->default_view); $viewLayout = $this->input->get('layout', 'default', 'string'); @@ -253,11 +250,20 @@ public function displayList() // Push the model into the view (as default) $view->setModel($model, true); + if ($this->input->getInt('limitstart', null)) + { + $model->setState('list.start', $this->input->get('limitstart')); + } + /** * Sanity check we don't have too much data being requested as regularly in html we automatically set it back to * the last page of data. If there isn't a limit start then set */ - if (!$this->input->getInt('limit', null)) + if ($this->input->getInt('limit', null)) + { + $model->setState('list.limit', $this->input->get('limit')); + } + else { $model->setState('list.limit', $this->itemsPerPage); } From ca331aaea8141c3feb65522031c3faa5bd5c1df9 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Fri, 8 Nov 2019 14:38:49 +0100 Subject: [PATCH 04/11] Update JsonApiView.php Removed $model->setState from the view, everything seems to work... ToDo: square brackets encoding? --- libraries/src/MVC/View/JsonApiView.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/src/MVC/View/JsonApiView.php b/libraries/src/MVC/View/JsonApiView.php index 12b19b71cb0e4..2a47fa1574fca 100644 --- a/libraries/src/MVC/View/JsonApiView.php +++ b/libraries/src/MVC/View/JsonApiView.php @@ -117,10 +117,6 @@ public function displayList(array $items = null) $currentPageDefaultInformation = ['offset' => 0, 'limit' => 20]; $currentPageQuery = $currentUrl->getVar('page', $currentPageDefaultInformation); - // Set model start and limit params - $model->setState('list.start', $currentPageQuery['offset']); - $model->setState('list.limit', $currentPageQuery['limit']); - if ($items === null) { $items = []; From 933f80f1347dc336a4e0c836634c292f042751e6 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Wed, 13 Nov 2019 15:47:22 +0100 Subject: [PATCH 05/11] Square bracket encoding in pagination links I introduced the method "queryEncode" to encode square brackets in pagination links. AbstractURI->toString() returns unencoded brackets, so I had to find a workaround, but I'm not sure it's the cleanest way to do this. The method is defined as protected in Joomla\CMS\MVC\View\JsonApiView so that it can be used by other extending classes, like com_config api views. Fixed an error in com_config component view pagination (L109). --- .../View/Application/JsonapiView.php | 8 +++---- .../com_config/View/Component/JsonapiView.php | 10 ++++---- libraries/src/MVC/View/JsonApiView.php | 23 +++++++++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/api/components/com_config/View/Application/JsonapiView.php b/api/components/com_config/View/Application/JsonapiView.php index 7e339a055fcff..7f57489941fe4 100644 --- a/api/components/com_config/View/Application/JsonapiView.php +++ b/api/components/com_config/View/Application/JsonapiView.php @@ -75,8 +75,8 @@ public function displayList(array $items = null) $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; $previousPage->setVar('page', $previousPageQuery); - $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + $this->document->addLink('first', $this->queryEncode((string) $firstPage)) + ->addLink('previous', $this->queryEncode((string) $previousPage)); } // Check for next and last pages @@ -93,8 +93,8 @@ public function displayList(array $items = null) $lastPageQuery['offset'] = ($totalPagesAvailable - 1) * $limit; $lastPage->setVar('page', $lastPageQuery); - $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + $this->document->addLink('next', $this->queryEncode((string) $nextPage)) + ->addLink('last', $this->queryEncode((string) $lastPage)); } $collection = (new Collection($items, new JoomlaSerializer($this->type))); diff --git a/api/components/com_config/View/Component/JsonapiView.php b/api/components/com_config/View/Component/JsonapiView.php index 59dec65f4ca11..776ef6f846367 100644 --- a/api/components/com_config/View/Component/JsonapiView.php +++ b/api/components/com_config/View/Component/JsonapiView.php @@ -91,8 +91,8 @@ public function displayList(array $items = null) $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; $previousPage->setVar('page', $previousPageQuery); - $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + $this->document->addLink('first', $this->queryEncode((string) $firstPage)) + ->addLink('previous', $this->queryEncode((string) $previousPage)); } // Check for next and last pages @@ -106,11 +106,11 @@ public function displayList(array $items = null) $lastPage = clone $currentUrl; $lastPageQuery = $currentPageQuery; - $lastPageQuery['offset'] = $totalPagesAvailable - $limit; + $lastPageQuery['offset'] = ($totalPagesAvailable - 1) * $limit; $lastPage->setVar('page', $lastPageQuery); - $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + $this->document->addLink('next', $this->queryEncode((string) $nextPage)) + ->addLink('last', $this->queryEncode((string) $lastPage)); } $collection = (new Collection($items, new JoomlaSerializer($this->type))); diff --git a/libraries/src/MVC/View/JsonApiView.php b/libraries/src/MVC/View/JsonApiView.php index 2a47fa1574fca..0c635e9468bed 100644 --- a/libraries/src/MVC/View/JsonApiView.php +++ b/libraries/src/MVC/View/JsonApiView.php @@ -160,8 +160,8 @@ public function displayList(array $items = null) $previousPageQuery['offset'] = $previousOffset >= 0 ? $previousOffset : 0; $previousPage->setVar('page', $previousPageQuery); - $this->document->addLink('first', (string) $firstPage) - ->addLink('previous', (string) $previousPage); + $this->document->addLink('first', $this->queryEncode((string) $firstPage)) + ->addLink('previous', $this->queryEncode((string) $previousPage)); } // Check for next and last pages @@ -178,8 +178,8 @@ public function displayList(array $items = null) $lastPageQuery['offset'] = ($pagination->pagesTotal - 1) * $pagination->limit; $lastPage->setVar('page', $lastPageQuery); - $this->document->addLink('next', (string) $nextPage) - ->addLink('last', (string) $lastPage); + $this->document->addLink('next', $this->queryEncode((string) $nextPage)) + ->addLink('last', $this->queryEncode((string) $lastPage)); } $collection = (new Collection($items, $this->serializer)) @@ -252,4 +252,19 @@ protected function prepareItem($item) { return $item; } + + /** + * Encode square brackets in the URI query, according to JSON API specification. + * + * @param string $query The URI query + * + * @return string + * + * @since 4.0.0 + */ + protected function queryEncode($query) + { + return str_replace(array('[', ']'), array('%5B', '%5D'), $query); + } + } From f5f01b18b98735b9183fd6c0161448331167eac6 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Fri, 20 Mar 2020 19:06:40 +0100 Subject: [PATCH 06/11] Update JsonapiView.php --- api/components/com_config/View/Application/JsonapiView.php | 1 - 1 file changed, 1 deletion(-) diff --git a/api/components/com_config/View/Application/JsonapiView.php b/api/components/com_config/View/Application/JsonapiView.php index 7f57489941fe4..6444674c71ca3 100644 --- a/api/components/com_config/View/Application/JsonapiView.php +++ b/api/components/com_config/View/Application/JsonapiView.php @@ -117,7 +117,6 @@ public function displayList(array $items = null) protected function prepareItem($item) { $item->id = ExtensionHelper::getExtensionRecord('files_joomla')->extension_id; - return $item; } } From 32d57cf5865a898cecc4f16e797c432a14574c64 Mon Sep 17 00:00:00 2001 From: stefanoel <56836583+stefanoel@users.noreply.github.com> Date: Fri, 20 Mar 2020 19:12:57 +0100 Subject: [PATCH 07/11] Update libraries/src/MVC/View/JsonApiView.php Co-Authored-By: Quy --- libraries/src/MVC/View/JsonApiView.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/src/MVC/View/JsonApiView.php b/libraries/src/MVC/View/JsonApiView.php index 0c635e9468bed..268ed4e8a1a38 100644 --- a/libraries/src/MVC/View/JsonApiView.php +++ b/libraries/src/MVC/View/JsonApiView.php @@ -266,5 +266,4 @@ protected function queryEncode($query) { return str_replace(array('[', ']'), array('%5B', '%5D'), $query); } - } From 9b096b34d76818b0ab349af605c76c1df82eef94 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sat, 21 Mar 2020 00:34:37 +0000 Subject: [PATCH 08/11] Update api/components/com_config/View/Application/JsonapiView.php Co-Authored-By: Quy --- api/components/com_config/View/Application/JsonapiView.php | 1 + 1 file changed, 1 insertion(+) diff --git a/api/components/com_config/View/Application/JsonapiView.php b/api/components/com_config/View/Application/JsonapiView.php index 6444674c71ca3..7f57489941fe4 100644 --- a/api/components/com_config/View/Application/JsonapiView.php +++ b/api/components/com_config/View/Application/JsonapiView.php @@ -117,6 +117,7 @@ public function displayList(array $items = null) protected function prepareItem($item) { $item->id = ExtensionHelper::getExtensionRecord('files_joomla')->extension_id; + return $item; } } From bc1b63b6764b8216b59a7f89e0bd9f1e26bfd925 Mon Sep 17 00:00:00 2001 From: Richard Fath Date: Tue, 24 Mar 2020 11:33:55 +0100 Subject: [PATCH 09/11] Add back removed line from conflicts solving --- libraries/src/MVC/Controller/ApiController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/src/MVC/Controller/ApiController.php b/libraries/src/MVC/Controller/ApiController.php index 48d81cb2f8e73..57abcd54ec109 100644 --- a/libraries/src/MVC/Controller/ApiController.php +++ b/libraries/src/MVC/Controller/ApiController.php @@ -209,6 +209,8 @@ public function displayList() if (\array_key_exists('limit', $paginationInfo)) { $this->modelState->set($this->context . '.list.limit', $paginationInfo['limit']); + + $this->input->set('limit', $paginationInfo['limit']); } $viewType = $this->app->getDocument()->getType(); From 6dec7cc68909c1c5962bc2337861878d0cbf9be5 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Tue, 24 Mar 2020 11:30:40 +0000 Subject: [PATCH 10/11] Fix up the code to latest version --- libraries/src/MVC/Controller/ApiController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/src/MVC/Controller/ApiController.php b/libraries/src/MVC/Controller/ApiController.php index 57abcd54ec109..d41f6e4884ffd 100644 --- a/libraries/src/MVC/Controller/ApiController.php +++ b/libraries/src/MVC/Controller/ApiController.php @@ -206,11 +206,12 @@ public function displayList() $this->modelState->set($this->context . '.limitstart', $paginationInfo['offset']); } + $limit = null + if (\array_key_exists('limit', $paginationInfo)) { - $this->modelState->set($this->context . '.list.limit', $paginationInfo['limit']); - - $this->input->set('limit', $paginationInfo['limit']); + $limit = $paginationInfo['limit']; + $this->modelState->set($this->context . '.list.limit', $limit); } $viewType = $this->app->getDocument()->getType(); @@ -254,9 +255,9 @@ public function displayList() * Sanity check we don't have too much data being requested as regularly in html we automatically set it back to * the last page of data. If there isn't a limit start then set */ - if ($this->input->getInt('limit', null)) + if ($limit) { - $model->setState('list.limit', $this->input->get('limit')); + $model->setState('list.limit', $limit); } else { From c42d6414c52516969590a36deb1f9a118a565022 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Tue, 24 Mar 2020 11:34:53 +0000 Subject: [PATCH 11/11] More fixes --- libraries/src/MVC/Controller/ApiController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/src/MVC/Controller/ApiController.php b/libraries/src/MVC/Controller/ApiController.php index d41f6e4884ffd..b3b9580ad08a2 100644 --- a/libraries/src/MVC/Controller/ApiController.php +++ b/libraries/src/MVC/Controller/ApiController.php @@ -200,14 +200,15 @@ public function displayList() { // Assemble pagination information (using recommended JsonApi pagination notation for offset strategy) $paginationInfo = $this->input->get('page', [], 'array'); + $limit = null; + $offset = null; if (\array_key_exists('offset', $paginationInfo)) { - $this->modelState->set($this->context . '.limitstart', $paginationInfo['offset']); + $offset = $paginationInfo['offset']; + $this->modelState->set($this->context . '.limitstart', $offset); } - $limit = null - if (\array_key_exists('limit', $paginationInfo)) { $limit = $paginationInfo['limit']; @@ -246,9 +247,9 @@ public function displayList() // Push the model into the view (as default) $view->setModel($model, true); - if ($this->input->getInt('limitstart', null)) + if ($offset) { - $model->setState('list.start', $this->input->get('limitstart')); + $model->setState('list.start', $offset); } /** @@ -264,7 +265,7 @@ public function displayList() $model->setState('list.limit', $this->itemsPerPage); } - if ($this->input->getInt('limitstart', 0) > $model->getTotal()) + if (!is_null($offset) && $offset > $model->getTotal()) { throw new Exception\ResourceNotFound; }