KumbiaPHP/KumbiaPHP

View on GitHub
core/views/partials/paginators/digg.phtml

Summary

Maintainability
Test Coverage
<?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 - 2023 KumbiaPHP Team (http://www.kumbiaphp.com)
 * @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;
}

$half = floor($show / 2);

//Calculando el inicio de paginador centrado
if ($page->current <= $half) {
    $start = 1;
} elseif (($page->total - $page->current) < $half) {
    $start = $page->total - $show + 1;
    if ($start < 1) {
        $start = 1;
    }

} else {
    $start = $page->current - $half;
}
$last = false;
if ($start == $page->total) {
    if ($start - 1 > 0) {
        $start -= 1;
    }

    $last = true;
}
?>

<div class="paginator">
    <?php if ($page->prev == 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->prev) {
    echo Html::link("$url/$page->prev/", 'Anterior', 'title="Ir a la pág. anterior" class="nextprev" 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->current == 1 ? "<strong>1</strong>" : Html::link("$url/", '1');
}?>

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

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

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

    <?php if ($page->next) {
    echo Html::link("$url/$page->next/", 'Siguiente', 'title="Ir a la pág. siguiente" class="nextprev" rel="next"');
}
?>
</div>