public function paging($params)
{
$params = parse_params($params);
$pages_count = 1;
$base_url = false;
$paging_param = 'current_page';
$keyword_param = 'keyword_param';
$class = 'pagination';
$li_class = '';
if (isset($params['num'])) {
$pages_count = $params['num'];
}
if (isset($params['num'])) {
$pages_count = $params['num'];
}
$limit = false;
if (isset($params['limit'])) {
$limit = intval($params['limit']);
}
if (isset($params['class'])) {
$class = $params['class'];
}
if (isset($params['li_class'])) {
$li_class = $params['li_class'];
}
if (isset($params['paging_param'])) {
$paging_param = $params['paging_param'];
}
$current_page_from_url = $this->app->url_manager->param($paging_param);
if (isset($params['current_page'])) {
$current_page_from_url = $params['current_page'];
} elseif (isset($params['curent_page'])) {
$current_page_from_url = $params['curent_page'];
}
$data = $this->paging_links($base_url, $pages_count, $paging_param, $keyword_param);
if (is_array($data)) {
$to_print = "<div class='{$class}-holder' ><ul class='{$class}'>";
$paging_items = array();
$active_item = 1;
foreach ($data as $key => $value) {
$skip = false;
$act_class = '';
if ($current_page_from_url != false) {
if (intval($current_page_from_url) == intval($key)) {
$act_class = ' active ';
$active_item = $key;
}
}
$item_to_print = '';
$item_to_print .= "<li class=\"{$li_class} {$act_class}\" data-page-number=\"{$key}\">";
$item_to_print .= "<a class=\"{$act_class}\" href=\"{$value}\" data-page-number=\"{$key}\">{$key}</a> ";
$item_to_print .= '</li>';
$paging_items[$key] = $item_to_print;
}
if ($limit != false and count($paging_items) > $limit) {
$limited_paging = array();
$limited_paging_begin = array();
foreach ($paging_items as $key => $paging_item) {
if ($key == $active_item) {
$steps = $steps2 = floor($limit / 2);
for ($i = 1; $i <= $steps; ++$i) {
if (isset($paging_items[$key - $i])) {
$limited_paging_begin[$key - $i] = $paging_items[$key - $i];
// $steps2--;
} else {
++$steps2;
}
}
$limited_paging[$key] = $paging_item;
for ($i = 1; $i <= $steps2; ++$i) {
if (isset($paging_items[$key + $i])) {
$limited_paging[$key + $i] = $paging_items[$key + $i];
}
}
}
}
$prev_link = '#';
$next_link = '#';
if (isset($data[$active_item - 1])) {
$prev_link = $data[$active_item - 1];
$limited_paging_begin[] = '<li class="mw-previous-page-item"><a data-page-number="' . ($active_item - 1) . '" href="' . $prev_link . '">«</a></li>';
}
$limited_paging_begin = array_reverse($limited_paging_begin);
$limited_paging = array_merge($limited_paging_begin, $limited_paging);
if (isset($data[$active_item + 1])) {
$next_link = $data[$active_item + 1];
$limited_paging[] = '<li class="mw-next-page-item"><a data-page-number="' . ($active_item + 1) . '" href="' . $next_link . '">»</a></li>';
}
if (count($limited_paging) > 2) {
$paging_items = $limited_paging;
}
}
$to_print .= implode("\n", $paging_items);
$to_print .= '</ul></div>';
return $to_print;
}
}