Completed
Branch master (b7ffcb)
by Tomas Norre
17:57
created

PaginationView   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 9
lcom 2
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 10 1
A getCurrentOffset() 0 4 1
A getPerPage() 0 4 1
A setCurrentOffset() 0 4 1
A setPerPage() 0 4 1
A getTotalItemCount() 0 4 1
A setTotalItemCount() 0 4 1
A getTotalPagesCount() 0 4 1
A getLabelForPageOffset() 0 4 1
1
<?php
2
namespace AOE\Crawler\Backend\View;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2017 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30
/**
31
 * Class PaginationView
32
 *
33
 * @package AOE\Crawler\Backend\View
34
 */
35
class PaginationView
36
{
37
38
    /**
39
     * @var string template path
40
     */
41
    protected $template = 'EXT:crawler/template/pagination.php';
42
43
    /**
44
     * @var int $perpage number of items perPage
45
     */
46
    protected $perPage;
47
48
    /**
49
     * @var int $currentOffset current offset
50
     */
51
    protected $currentOffset;
52
53
    /**
54
     * @var int $totalItemCount number of total item
55
     */
56
    protected $totalItemCount;
57
58
    /**
59
     * @var string $baseUrl
60
     */
61
    protected $baseUrl;
62
63
    /**
64
     * Method to render the view.
65
     *
66
     * @return string html content
67
     */
68
    public function render()
69
    {
70
        ob_start();
71
        $this->template = GeneralUtility::getFileAbsFileName($this->template);
72
        include($this->template);
73
        $content = ob_get_contents();
74
        ob_end_clean();
75
76
        return $content;
77
    }
78
79
    /**
80
     * Returns the currently configured offset-
81
     * @return int
82
     */
83
    public function getCurrentOffset()
84
    {
85
        return $this->currentOffset;
86
    }
87
88
    /**
89
     * Method to read the number of items per page
90
     *
91
     * @return int
92
     */
93
    public function getPerPage()
94
    {
95
        return $this->perPage;
96
    }
97
98
    /**
99
     * Method to set the current offset from start
100
     *
101
     * @param int $currentOffset
102
     */
103
    public function setCurrentOffset($currentOffset)
104
    {
105
        $this->currentOffset = $currentOffset;
106
    }
107
108
    /**
109
     * Number of items per page.
110
     *
111
     * @param int $perPage
112
     */
113
    public function setPerPage($perPage)
114
    {
115
        $this->perPage = $perPage;
116
    }
117
118
    /**
119
     * returns the total number of items
120
     * @return int
121
     */
122
    public function getTotalItemCount()
123
    {
124
        return $this->totalItemCount;
125
    }
126
127
    /**
128
     * Method to set the total number of items in the pagination
129
     *
130
     * @param int $totalItemCount
131
     */
132
    public function setTotalItemCount($totalItemCount)
133
    {
134
        $this->totalItemCount = $totalItemCount;
135
    }
136
137
    /**
138
     * Returns the total number of pages needed to  display all content which
139
     * is paginatable
140
     *
141
     * @return float
142
     */
143
    public function getTotalPagesCount()
144
    {
145
        return ceil($this->getTotalItemCount() / $this->getPerPage());
146
    }
147
148
    /**
149
     * This method is used to caluclate the label for a pageoffset,
150
     * in normal cases its the internal offset + 1
151
     *
152
     * @param int $pageoffset
153
     * @return int
154
     */
155
    protected function getLabelForPageOffset($pageoffset)
156
    {
157
        return $pageoffset + 1;
158
    }
159
}
160