1
0
Fork 0
mirror of https://github.com/Oreolek/kangana.git synced 2024-06-16 23:11:07 +03:00

Fixed #11: pagination display

This commit is contained in:
Alexander Yakovlev 2016-11-10 13:32:09 +07:00
parent 37a3274689
commit 0ea30dc1d2
4 changed files with 30 additions and 25 deletions

View file

@ -37,10 +37,15 @@ class Controller_Client extends Controller_Layout {
->clients
->filter_by_page($this->request->param('page'))
->find_all();
$this->template->item_count = $group
->clients
->count_all();
} else {
$this->template->items = ORM::factory('Client')
->filter_by_page($this->request->param('page'))
->find_all();
$this->template->item_count = ORM::factory('Client')
->count_all();
}
}

View file

@ -40,7 +40,6 @@ class View_Index extends View_Layout {
{
return I18n::translate('No objects found to show');
};
$items = $this->filter_items();
foreach ($this->items as $item)
{
array_push($result, $this->show_item($item));

View file

@ -13,9 +13,13 @@ class View_Layout {
public $errors;
/**
* Items to show
* Items to show filtered list
**/
public $items = NULL;
/**
* How many items there are
*/
public $item_count = 0;
/**
* Pagination controls
@ -23,14 +27,27 @@ class View_Layout {
public function get_paging()
{
$current_page = $this->get_current_page();
$item_count = count($this->items);
$item_count = $this->item_count;
$page_size = Kohana::$config->load('common.page_size');
$page_count = ceil($item_count / $page_size);
if ($page_count === 1.0)
return '';
$i = 1;
$output = '';
while ($i <= $page_count)
$i = $current_page - 10;
if ($i < 1)
{
$i = 1;
}
$max = $page_count;
if ($max > $current_page + 10)
{
$max = $current_page + 10;
}
if ($i > 1)
{
$output .= '<span>…</span>&nbsp;';
}
while ($i <= $max)
{
$output .= '<a href="'.Route::url('default', array('controller' => Request::current()->controller(), 'action' => Request::current()->action(), 'page' => $i)).'"';
if ($i == $current_page)
@ -40,28 +57,13 @@ class View_Layout {
$output .= '>'.$i.'</a>';
$i++;
}
if ($max < $page_count)
{
$output .= '&nbsp;<span>…</span>';
}
return $output;
}
/**
* Filters $this->items to only current page.
**/
protected function filter_items()
{
$current_page = $this->get_current_page();
$page_size = Kohana::$config->load('common.page_size');
$item_count = count($this->items);
if ($item_count > $page_size)
{
$page_count = ceil($item_count / $page_size);
return array_slice($this->items->as_array(), ($current_page - 1) * $page_size, $page_size);
}
else
{
return $this->items;
}
}
/**
* Pagination: calculate current page
**/

View file

@ -9,7 +9,6 @@
{{{.}}}
</div>
{{/content}}
{{{get_paging}}}
<table class="table">
<thead>
<tr>