LinkPager   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 27
c 2
b 0
f 0
dl 0
loc 55
ccs 0
cts 36
cp 0
rs 10
wmc 11

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderPageButton() 0 16 4
B renderPageButtons() 0 27 7
1
<?php
2
/**
3
 * Hyde Theme for hiqdev/yii2-thememanager
4
 *
5
 * @link      https://github.com/hiqdev/yii2-theme-hyde
6
 * @package   yii2-theme-hyde
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\themes\hyde\widgets;
12
13
use yii\helpers\ArrayHelper;
14
use yii\helpers\Html;
15
16
class LinkPager extends \yii\widgets\LinkPager
17
{
18
    /** {@inheritdoc} */
19
    public $prevPageCssClass = 'pagination-item newer';
20
21
    /** {@inheritdoc} */
22
    public $nextPageCssClass = 'pagination-item older';
23
24
    /** {@inheritdoc} */
25
    public function renderPageButtons()
26
    {
27
        $pageCount = $this->pagination->getPageCount();
28
        if ($pageCount < 2 && $this->hideOnSinglePage) {
29
            return '';
30
        }
31
32
        $buttons = [];
33
        $currentPage = $this->pagination->getPage();
34
35
        // prev page
36
        if ($this->prevPageLabel !== false) {
37
            if (($page = $currentPage - 1) < 0) {
38
                $page = 0;
39
            }
40
            $buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false);
41
        }
42
43
        // next page
44
        if ($this->nextPageLabel !== false) {
45
            if (($page = $currentPage + 1) >= $pageCount - 1) {
46
                $page = $pageCount - 1;
47
            }
48
            $buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false);
49
        }
50
51
        return Html::tag('div', implode("\n", $buttons), $this->options);
52
    }
53
54
    /** {@inheritdoc} */
55
    protected function renderPageButton($label, $page, $class, $disabled, $active)
56
    {
57
        $options = ['class' => empty($class) ? $this->pageCssClass : $class];
58
        if ($active) {
59
            Html::addCssClass($options, $this->activePageCssClass);
60
        }
61
        if ($disabled) {
62
            Html::addCssClass($options, $this->disabledPageCssClass);
63
            $tag = ArrayHelper::remove($this->disabledListItemSubTagOptions, 'tag', 'span');
64
65
            return Html::tag($tag, $label, $options);
66
        }
67
        $linkOptions = $this->linkOptions;
68
        $linkOptions['data-page'] = $page;
69
70
        return Html::a($label, $this->pagination->createUrl($page), $options);
71
    }
72
}
73