Skip to content

Commit

Permalink
pagination param update
Browse files Browse the repository at this point in the history
  • Loading branch information
tamedevelopers committed Jul 4, 2024
1 parent 9764361 commit ebdf3c0
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/Schema/Pagination/Yidas/PaginationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ public function setPerPage($perPage)
*/
public function createUrl($page, $perPage = null)
{
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);

// Add or reset page parameter
$params[$this->pageParam] = (int) $page;

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

// request url
$requestUri = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);

// merge main params
$mainParams = array_merge($params, $this->params);

// Build URL
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(array_merge($params, $this->params));
$url = "//{$_SERVER['HTTP_HOST']}{$requestUri}?" . http_build_query(
array_merge($this->getDefaultURLParams($mainParams), $mainParams)
);

return $url;
}
Expand Down Expand Up @@ -248,5 +254,32 @@ private function convertToIntegers()
$this->pageCount = (int) $this->pageCount;
$this->totalCount = (int) $this->totalCount;
}

/**
* Get Default Url Params
*
* @param mixed $mainParams
* @return array
*/
private function getDefaultURLParams($mainParams = [])
{
// get Query
$REQUEST_URI = parse_url($_SERVER["REQUEST_URI"]);

// get request query
$REQUEST_URI = isset($REQUEST_URI['query']) ? $REQUEST_URI['query'] : "";

// Parse the query string into an associative array
parse_str($REQUEST_URI, $query_params);

// remove keys assisnged to pagination
foreach($query_params as $key => $param){
if(in_array($key, array_keys($mainParams))){
unset($query_params[$key]);
}
}

return is_array($query_params) ? $query_params : [];
}

}

0 comments on commit ebdf3c0

Please sign in to comment.