Skip to content

Commit ebdf3c0

Browse files
pagination param update
1 parent 9764361 commit ebdf3c0

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/Schema/Pagination/Yidas/PaginationLoader.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ public function setPerPage($perPage)
181181
*/
182182
public function createUrl($page, $perPage = null)
183183
{
184-
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
185-
186184
// Add or reset page parameter
187185
$params[$this->pageParam] = (int) $page;
188186

@@ -194,8 +192,16 @@ public function createUrl($page, $perPage = null)
194192
// Verify $this->params
195193
$this->params = is_array($this->params) ? $this->params : [];
196194

195+
// request url
196+
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
197+
198+
// merge main params
199+
$mainParams = array_merge($params, $this->params);
200+
197201
// Build URL
198-
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(array_merge($params, $this->params));
202+
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(
203+
array_merge($this->getDefaultURLParams($mainParams), $mainParams)
204+
);
199205

200206
return $url;
201207
}
@@ -248,5 +254,32 @@ private function convertToIntegers()
248254
$this->pageCount = (int) $this->pageCount;
249255
$this->totalCount = (int) $this->totalCount;
250256
}
257+
258+
/**
259+
* Get Default Url Params
260+
*
261+
* @param mixed $mainParams
262+
* @return array
263+
*/
264+
private function getDefaultURLParams($mainParams = [])
265+
{
266+
// get Query
267+
$REQUEST_URI = parse_url($_SERVER["REQUEST_URI"]);
268+
269+
// get request query
270+
$REQUEST_URI = isset($REQUEST_URI['query']) ? $REQUEST_URI['query'] : "";
271+
272+
// Parse the query string into an associative array
273+
parse_str($REQUEST_URI, $query_params);
274+
275+
// remove keys assisnged to pagination
276+
foreach($query_params as $key => $param){
277+
if(in_array($key, array_keys($mainParams))){
278+
unset($query_params[$key]);
279+
}
280+
}
281+
282+
return is_array($query_params) ? $query_params : [];
283+
}
251284

252285
}

0 commit comments

Comments
 (0)