PaginatorAbstract   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 105
c 0
b 0
f 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setCurrentPageNumber() 0 4 1
A getCurrentPageNumber() 0 4 1
A setItemNumberPerPage() 0 4 1
A getItemNumberPerPage() 0 4 1
A setTotalItemCount() 0 4 1
A getTotalItemCount() 0 4 1
A getOffset() 0 4 1
A paginate() 0 6 1
A getPagesCount() 0 4 1
A setPageRange() 0 4 1
A getPageRange() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of gpupo/search
5
 *
6
 * (c) Gilmar Pupo <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gpupo\Search\Paginator;
13
14
/**
15
 * Componente de paginacao de resultados da Busca.
16
 *
17
 * Não gerencia os itens de resultados, mas apenas os números de limite e offset
18
 * de uma query Sphinx Search
19
 *
20
 * Usado como referencia o Knp Pager component.
21
 */
22
abstract class PaginatorAbstract
23
{
24
    protected $range = 5;
25
    protected $currentPageNumber;
26
    protected $numItemsPerPage;
27
    protected $totalCount;
28
29
    public function setCurrentPageNumber($pageNumber)
30
    {
31
        $this->currentPageNumber = $pageNumber;
32
    }
33
34
    /**
35
     * Get currently used page number.
36
     *
37
     * @return int
38
     */
39
    public function getCurrentPageNumber()
40
    {
41
        return $this->currentPageNumber;
42
    }
43
44
    public function setItemNumberPerPage($numItemsPerPage)
45
    {
46
        $this->numItemsPerPage = $numItemsPerPage;
47
    }
48
49
    /**
50
     * Get number of items per page.
51
     *
52
     * @return int
53
     */
54
    public function getItemNumberPerPage()
55
    {
56
        return $this->numItemsPerPage;
57
    }
58
59
    public function setTotalItemCount($numTotal)
60
    {
61
        $this->totalCount = $numTotal;
62
    }
63
64
    /**
65
     * Get total item number available.
66
     *
67
     * @return int
68
     */
69
    public function getTotalItemCount()
70
    {
71
        return $this->totalCount;
72
    }
73
74
    /**
75
     * Offsets the result list by the number of places set by the count;.
76
     *
77
     * This would be used for pagination through results, where if you have 20
78
     * results per 'page', the second page would begin at offset 20, the third
79
     * page at offset 40, etc.
80
     *
81
     * @return int
82
     */
83
    public function getOffset()
84
    {
85
        return abs($this->getCurrentPageNumber() - 1) * $this->getItemNumberPerPage();
86
    }
87
88
    /**
89
     * Processa os valors de resultado.
90
     *
91
     * @param int $numTotal
92
     * @param int $page
93
     * @param int $limit
94
     */
95
    public function paginate($numTotal, $page, $limit = 10)
96
    {
97
        $this->setTotalItemCount($numTotal);
98
        $this->setCurrentPageNumber($page);
99
        $this->setItemNumberPerPage($limit);
100
    }
101
102
    public function getPagesCount()
103
    {
104
        return intval(ceil($this->getTotalItemCount() / $this->getItemNumberPerPage()));
105
    }
106
107
    /**
108
     * Pagination page range.
109
     *
110
     * @param int $range
111
     */
112
    public function setPageRange($range)
113
    {
114
        $this->range = intval(abs($range));
115
    }
116
117
    /**
118
     * Pagination page range.
119
     *
120
     * @return int
121
     */
122
    public function getPageRange()
123
    {
124
        return $this->range;
125
    }
126
}
127