Completed
Push — master ( ebad6a...a5b5d2 )
by
unknown
02:11
created

DLpaginateReversed::getPageQuery()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 5
nop 1
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Class DLpaginate
5
 */
6
class DLpaginateReversed extends DLpaginate
7
{
8
    /**
9
     * @param $page
10
     * @return int|mixed
11
     */
12
    protected function getPageQuery($page)
13
    {
14
        switch ($this->mode) {
15
            case 'offset':
16
                $display = isset($this->modeConfig['display']) ? $this->modeConfig['display'] : 0;
17
                $out = $display * ($this->total_pages - $page) - $this->modeConfig['offset'];
18
                break;
19
            case 'back':
20
            case 'pages':
21
            default:
22
                $out = $page;
23
                break;
24
        }
25
26
        return $out;
27
    }
28
29
    /**
30
     * @param $tpl
31
     * @param $num
32
     * @return mixed
33
     */
34
    protected function renderItemTPL($tpl, $num)
35
    {
36
        $_num = $this->total_pages + 1 - $num;
37
        return str_replace(array('[+num+]', '[+link+]'), array($_num, $this->get_pagenum_link($_num)), $tpl);
38
    }
39
40
    /**
41
     * @param $id
42
     * @return mixed|string
43
     */
44
    public function get_pagenum_link($id)
45
    {
46
        $flag = (strpos($this->target, '?') === false);
47
        $value = $this->getPageQuery($id);
48
        if ($flag && !empty($this->urlF)) {
49
            $out = str_replace($this->urlF, $value, $this->target);
50
        } else {
51
            $out = $this->target;
52
            if ($id > 0 && $id < $this->total_pages) {
53
                $out .= ($flag ? "?" : "&") . $this->parameterName . "=" . $value;
54
            }
55
        }
56
57
        return $out;
58
    }
59
}
60