forked from Public/pics
Pass builder function for custom pagination link generation.
This makes pagination for GenericTables work properly again.
This commit is contained in:
parent
cba42a9129
commit
681af07985
@ -118,6 +118,7 @@ class GenericTable
|
||||
'base_url' => $this->base_url,
|
||||
'index_class' => $options['index_class'] ?? '',
|
||||
'items_per_page' => $this->items_per_page,
|
||||
'linkBuilder' => [$this, 'getLink'],
|
||||
'recordCount' => $this->recordCount,
|
||||
'sort_direction' => $this->sort_direction,
|
||||
'sort_order' => $this->sort_order,
|
||||
|
@ -12,6 +12,7 @@ class PageIndex
|
||||
protected $current_page = 1;
|
||||
protected $index_class = 'pagination';
|
||||
protected $items_per_page = 0;
|
||||
private $linkBuilder;
|
||||
protected $needsPageIndex = false;
|
||||
protected $num_pages = 1;
|
||||
protected $page_index = [];
|
||||
@ -32,7 +33,7 @@ class PageIndex
|
||||
$this->$key = $options[$key];
|
||||
}
|
||||
|
||||
static $optionalKeys = ['index_class', 'page_slug', 'sort_direction', 'sort_order', 'start'];
|
||||
static $optionalKeys = ['index_class', 'linkBuilder', 'page_slug', 'sort_direction', 'sort_order', 'start'];
|
||||
foreach ($optionalKeys as $key)
|
||||
if (isset($options[$key]))
|
||||
$this->$key = $options[$key];
|
||||
@ -40,6 +41,14 @@ class PageIndex
|
||||
$this->generatePageIndex();
|
||||
}
|
||||
|
||||
private function buildLink($start = null, $order = null, $dir = null)
|
||||
{
|
||||
if (isset($this->linkBuilder))
|
||||
return call_user_func($this->linkBuilder, $start, $order, $dir);
|
||||
else
|
||||
return $this->getLink($start, $order, $dir);
|
||||
}
|
||||
|
||||
protected function generatePageIndex()
|
||||
{
|
||||
/*
|
||||
@ -80,7 +89,7 @@ class PageIndex
|
||||
$this->page_index[$p] = [
|
||||
'index' => $p,
|
||||
'is_selected' => $this->current_page == $p,
|
||||
'href'=> $this->getLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
'href'=> $this->buildLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
];
|
||||
|
||||
// The center of the page index.
|
||||
@ -93,7 +102,7 @@ class PageIndex
|
||||
$this->page_index[$center] = [
|
||||
'index' => $center,
|
||||
'is_selected' => $this->current_page == $center,
|
||||
'href'=> $this->getLink(($center - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
'href'=> $this->buildLink(($center - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
];
|
||||
}
|
||||
|
||||
@ -106,7 +115,7 @@ class PageIndex
|
||||
$this->page_index[$p] = [
|
||||
'index' => $p,
|
||||
'is_selected' => $this->current_page == $p,
|
||||
'href'=> $this->getLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
'href'=> $this->buildLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
];
|
||||
|
||||
// The center of the page index.
|
||||
@ -119,7 +128,7 @@ class PageIndex
|
||||
$this->page_index[$center] = [
|
||||
'index' => $center,
|
||||
'is_selected' => $this->current_page == $center,
|
||||
'href'=> $this->getLink(($center - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
'href'=> $this->buildLink(($center - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
];
|
||||
}
|
||||
|
||||
@ -132,7 +141,7 @@ class PageIndex
|
||||
$this->page_index[$p] = [
|
||||
'index' => $p,
|
||||
'is_selected' => $this->current_page == $p,
|
||||
'href'=> $this->getLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
'href'=> $this->buildLink(($p - 1) * $this->items_per_page, $this->sort_order, $this->sort_direction),
|
||||
];
|
||||
|
||||
// Previous page?
|
||||
@ -169,11 +178,6 @@ class PageIndex
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getArray()
|
||||
{
|
||||
return $this->page_index;
|
||||
}
|
||||
|
||||
public function getPageIndex()
|
||||
{
|
||||
return $this->page_index;
|
||||
|
Loading…
Reference in New Issue
Block a user