Completed
Push — master ( 11bc17...602c99 )
by Klochok
03:34
created

LinkPager::renderPageButton()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 9.2
cc 4
eloc 11
nc 8
nop 5
crap 20
1
<?php
2
3
namespace hiqdev\themes\hyde\widgets;
4
5
use yii\helpers\ArrayHelper;
6
use yii\helpers\Html;
7
8
class LinkPager extends \yii\widgets\LinkPager
9
{
10
    /** @inheritdoc */
11
    public $prevPageCssClass = 'pagination-item newer';
12
13
    /** @inheritdoc */
14
    public $nextPageCssClass = 'pagination-item older';
15
16
    /** @inheritdoc */
17
    public function renderPageButtons()
18
    {
19
        $pageCount = $this->pagination->getPageCount();
20
        if ($pageCount < 2 && $this->hideOnSinglePage) {
21
            return '';
22
        }
23
24
        $buttons = [];
25
        $currentPage = $this->pagination->getPage();
26
27
        // prev page
28
        if ($this->prevPageLabel !== false) {
29
            if (($page = $currentPage - 1) < 0) {
30
                $page = 0;
31
            }
32
            $buttons[] = $this->renderPageButton($this->prevPageLabel, $page, $this->prevPageCssClass, $currentPage <= 0, false);
33
        }
34
35
        // next page
36
        if ($this->nextPageLabel !== false) {
37
            if (($page = $currentPage + 1) >= $pageCount - 1) {
38
                $page = $pageCount - 1;
39
            }
40
            $buttons[] = $this->renderPageButton($this->nextPageLabel, $page, $this->nextPageCssClass, $currentPage >= $pageCount - 1, false);
41
        }
42
43
        return Html::tag('div', implode("\n", $buttons), $this->options);
44
    }
45
46
    /** @inheritdoc */
47
    protected function renderPageButton($label, $page, $class, $disabled, $active)
48
    {
49
        $options = ['class' => empty($class) ? $this->pageCssClass : $class];
50
        if ($active) {
51
            Html::addCssClass($options, $this->activePageCssClass);
52
        }
53
        if ($disabled) {
54
            Html::addCssClass($options, $this->disabledPageCssClass);
55
            $tag = ArrayHelper::remove($this->disabledListItemSubTagOptions, 'tag', 'span');
0 ignored issues
show
Bug introduced by
The property disabledListItemSubTagOptions does not seem to exist. Did you mean options?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
56
57
            return Html::tag($tag, $label, $options);
58
        }
59
        $linkOptions = $this->linkOptions;
60
        $linkOptions['data-page'] = $page;
61
62
        return Html::a($label, $this->pagination->createUrl($page), $options);
63
    }
64
}
65
66