Skip to content

Commit

Permalink
Merge pull request #22 from joanhey/paginators
Browse files Browse the repository at this point in the history
Paginators
  • Loading branch information
joanhey authored Jun 27, 2020
2 parents 31baaba + 2a823c9 commit 3018eb8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 48 deletions.
67 changes: 67 additions & 0 deletions app/views/_shared/partials/paginators/classic.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* KumbiaPHP web & app Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.
*
* Paginador "digg" para aplicaciones
*
* Parametros del paginador:
* page: objeto obtenido al invocar al paginador
* show: numero de paginas que se mostraran en el paginador
* url: url para la accion que efectua la paginacion, por defecto "module/controller/page/"
* y se envia por parametro el numero de pagina
*
* @category Kumbia
* @package Partials
* @subpackage Paginators
*
* @copyright Copyright (c) 2005 - 2020 KumbiaPHP Team (http://www.kumbiaphp.com)
* @license https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE New BSD License
*/

$url = $url ?? Router::get('controller_path');
$show = $how ?? 6;
$half = floor($show / 2);

$pagetotal = $page->totalPages();
$prev = $page->prevPage();
$next = $page->nextPage();
$page = $page->page();
// Calculando el inicio de paginador centrado
if ($page <= $half) {
$start = 1;
} elseif (($pagetotal - $page) < $half) {
$start = $pagetotal - $show + 1;
if ($start < 1) {
$start = 1;
}
} else {
$start = $page - $half;
}

if ($pagetotal > 1) : ?>
<nav class="paginator">
<?php
if ($page === 2) {
echo Html::link("$url/", _('Prev'), 'rel="prev"'); // Se coloca el enlace sin número de página para la pagina 1
} elseif ($page > 2) {
echo Html::link("$url/page/$prev", _('Prev'), 'rel="prev"');
} ?>
<?php if ($start === 1) { //se coloca el link sin número de página para la página 1
$start = 2;
$show -= 1;
echo $page === 1 ? "<strong>1</strong>" : Html::link("$url/", '1', 'rel="first"');
} ?>
<?php for ($i = $start; $i <= $pagetotal && $i < ($start + $show); $i++) : ?>
<?= $i === $page ? "<strong>$i</strong>" : Html::link("$url/page/$i", $i) ?>
<?php endfor ?>
<?php if ($next) {
echo Html::link("$url/page/$next", _('Next'), 'rel="next"');
} ?>
</nav>
<?php endif ?>
<?php //count($data), ' - ', $data->count(), ' items.' ?>
84 changes: 37 additions & 47 deletions app/views/_shared/partials/paginators/digg.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* KumbiaPHP web & app Framework
*
Expand All @@ -23,17 +24,8 @@
* @license https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE New BSD License
*/

if (!isset($url)) {
extract(Router::get());
$url = "$controller/page";
if ($module) {
$url = "$module/$url";
}
}

if (!isset($show)) {
$show = 10;
}
$url = $url ?? Router::get('controller_path') . '/page';
$show = $show ?? 10;

$half = floor($show / 2);

Expand All @@ -45,12 +37,11 @@ if ($page->page() <= $half) {
if ($start < 1) {
$start = 1;
}

} else {
$start = $page->page() - $half;
}
$last = false;
if ($start == $page->totalPages()) {
if ($start === $page->totalPages()) {
if ($start - 1 > 0) {
$start -= 1;
}
Expand All @@ -59,44 +50,43 @@ if ($start == $page->totalPages()) {
}
?>

<div class="paginator">
<?php if ($page->prevPage() == 1) {
echo Html::link("$url/", 'Anterior', 'title="Ir a la pág. anterior" class="nextprev" rel="prev"');
}
//se coloca el link sin número de página para la página 1
elseif ($page->prevPage()) {
echo Html::link("$url/$page->prevPage()/", 'Anterior', 'title="Ir a la pág. anterior" class="nextprev" rel="prev"');
}
?>
<nav class="paginator">
<?php if ($page->prevPage() === 1) {
echo Html::link("$url/", _('Prev'), 'rel="prev"');
}
//se coloca el link sin número de página para la página 1
elseif ($page->prevPage()) {
echo Html::link("$url/$page->prevPage()/", _('Prev'), 'rel="prev"');
}
?>

<?php if ($start == 1) { //se coloca el link sin número de página para la página 1
$start = 2;
$show -= 1;
echo $page->page() == 1 ? "<strong>1</strong>" : Html::link("$url/", '1');
}?>
<?php if ($start === 1) { //se coloca el link sin número de página para la página 1
$start = 2;
$show -= 1;
echo $page->page() === 1 ? "<strong>1</strong>" : Html::link("$url/", '1');
} ?>

<?php for ($i = $start; $i <= $page->totalPages() && $i < ($start + $show); $i++): ?>
<?=$i == $page->page() ? "<strong>$i</strong>" : Html::link("$url/$i/", $i, "title=\"Ir a la pág. $i\"");?>
<?php endfor;?>
<?php for ($i = $start; $i <= $page->totalPages() && $i < ($start + $show); $i++) : ?>
<?= $i === $page->page() ? "<strong>$i</strong>" : Html::link("$url/$i/", $i ) ?>
<?php endfor ?>

<?php if ($page->totalPages() > $i): ?>
<?php if ($page->totalPages() > ($i + 1)): ?>
<?php if ($page->totalPages() > $i) : ?>
<?php if ($page->totalPages() > ($i + 1)) : ?>
...
<?php endif?>
<?php endif ?>

<?php $i = $page->totalPages() - 1;?>
<?=Html::link("$url/$i/", $i)?>
<?=Html::link("$url/{$page->totalPages()}/", $page->totalPages())?>
<?php elseif ($i == $page->totalPages()): ?>
<?php if ($last): ?>
<?="<strong>$i</strong>"?>
<?php else: ?>
<?=Html::link("$url/$i/", $i)?>
<?php endif;?>
<?php endif;?>
<?php $i = $page->totalPages() - 1 ?>
<?= Html::link("$url/$i/", $i) ?>
<?= Html::link("$url/{$page->totalPages()}/", $page->totalPages()) ?>
<?php elseif ($i === $page->totalPages()) : ?>
<?php if ($last) : ?>
<?= "<strong>$i</strong>" ?>
<?php else : ?>
<?= Html::link("$url/$i/", $i) ?>
<?php endif ?>
<?php endif ?>

<?php if ($page->nextPage()) {
echo Html::link("$url/{$page->nextPage()}/", 'Siguiente', 'title="Ir a la pág. siguiente" class="nextprev" rel="next"');
}
?>
</div>
echo Html::link("$url/{$page->nextPage()}/", _('Next'), 'rel="next"');
} ?>
</nav>
2 changes: 1 addition & 1 deletion app/views/_shared/scaffolds/lite/page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<?php endforeach ?>
</tbody>
</table>
<?php View::partial('paginators/digg', false, ['page' => $data, 'url' => Router::get('controller_path') . '/page']) ?>
<?php View::partial('paginators/digg', false, ['page' => $data]) ?>

<?php else : // If there are no items
?>
Expand Down

0 comments on commit 3018eb8

Please sign in to comment.