Passed
Push — 1.0.0-dev ( ceb5d8...dc6bfa )
by nguereza
02:28
created
core/libraries/Pagination.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 25
 	*/
26 26
 
27
-    class Pagination{
27
+    class Pagination {
28 28
         
29 29
 		/**
30 30
          * The list of loaded config
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
          * Create an instance of pagination
43 43
          * @param array $overwriteConfig the list of configuration to overwrite the defined configuration in config_pagination.php
44 44
          */
45
-        public function __construct($overwriteConfig = array()){
46
-            if (file_exists(CONFIG_PATH . 'config_pagination.php')){
45
+        public function __construct($overwriteConfig = array()) {
46
+            if (file_exists(CONFIG_PATH . 'config_pagination.php')) {
47 47
                 $config = array();
48 48
                 require_once CONFIG_PATH . 'config_pagination.php';
49
-                if (empty($config) || ! is_array($config)){
49
+                if (empty($config) || !is_array($config)) {
50 50
                     show_error('No configuration found in ' . CONFIG_PATH . 'config_pagination.php');
51 51
                 }
52
-				else{
53
-					if (! empty($overwriteConfig)){
52
+				else {
53
+					if (!empty($overwriteConfig)) {
54 54
 						$config = array_merge($config, $overwriteConfig);
55 55
 					}
56 56
 					$this->config = $config;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 					unset($config);
60 60
 				}
61 61
             }
62
-            else{
62
+            else {
63 63
                 show_error('Unable to find the pagination configuration file');
64 64
             }
65 65
         }
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
          * config_pagination.php
71 71
          * @param array $config the configuration to overwrite
72 72
          */
73
-        public function setConfig(array $config = array()){
74
-            if (! empty($config)){
73
+        public function setConfig(array $config = array()) {
74
+            if (!empty($config)) {
75 75
                 $this->config = array_merge($this->config, $config);
76 76
                 Config::setAll($config);
77 77
             }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
          * 
83 83
          * @return array
84 84
          */
85
-        public function getConfig(){
85
+        public function getConfig() {
86 86
             return $this->config;
87 87
         }
88 88
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
          * Return the value of the pagination query string
91 91
          * @return string
92 92
          */
93
-        public function getPaginationQueryString(){
93
+        public function getPaginationQueryString() {
94 94
             return $this->paginationQueryString;
95 95
         }
96 96
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
          * @param string $paginationQueryString the new value
100 100
          * @return object
101 101
          */
102
-        public function setPaginationQueryString($paginationQueryString){
102
+        public function setPaginationQueryString($paginationQueryString) {
103 103
             $this->paginationQueryString = $paginationQueryString;
104 104
             return $this;
105 105
         }
@@ -112,25 +112,25 @@  discard block
 block discarded – undo
112 112
          * 
113 113
          * @return object
114 114
          */
115
-        public function determinePaginationQueryStringValue(){
115
+        public function determinePaginationQueryStringValue() {
116 116
             $pageQueryName = $this->config['page_query_string_name'];
117 117
             $queryString = Url::queryString();
118 118
             $currentUrl = Url::current();
119 119
             $query = '';
120
-             if ($queryString == ''){
120
+             if ($queryString == '') {
121 121
                 $query = '?' . $pageQueryName . '=';
122 122
             }
123
-            else{
123
+            else {
124 124
                 $tab = explode($pageQueryName . '=', $queryString);
125 125
                 $nb = count($tab);
126
-                if ($nb == 1){
126
+                if ($nb == 1) {
127 127
                     $query = '?' . $queryString . '&' . $pageQueryName . '=';
128 128
                 }
129
-                else{
130
-                    if ($tab[0] == ''){
129
+                else {
130
+                    if ($tab[0] == '') {
131 131
                         $query = '?' . $pageQueryName . '=';
132 132
                     }
133
-                    else{
133
+                    else {
134 134
                         $query = '?' . $tab[0] . '' . $pageQueryName . '=';
135 135
                     }
136 136
                 }
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
          * 
149 149
          * @return string the pagination link
150 150
          */
151
-        public function getLink($totalRows, $currentPageNumber){
151
+        public function getLink($totalRows, $currentPageNumber) {
152 152
             $numberOfLink = $this->config['nb_link'];
153 153
 			$numberOfRowPerPage = $this->config['pagination_per_page'];
154
-            if (empty($this->paginationQueryString)){
154
+            if (empty($this->paginationQueryString)) {
155 155
                 //determine the pagination query string value
156 156
                 $this->determinePaginationQueryStringValue();
157 157
             }
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             $numberOfLink = (int) $numberOfLink;
163 163
             $numberOfRowPerPage = (int) $numberOfRowPerPage;
164 164
 			
165
-            if ($currentPageNumber <= 0){
165
+            if ($currentPageNumber <= 0) {
166 166
 				$currentPageNumber = 1;
167 167
 			}
168 168
             if ($numberOfPage <= 1 || $numberOfLink <= 0 || $numberOfRowPerPage <= 0) {
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
             $start = null;
172 172
             $end   = null;
173 173
             $begin = null;
174
-            if ($numberOfLink % 2 == 0){
174
+            if ($numberOfLink % 2 == 0) {
175 175
                 $start = $currentPageNumber - ($numberOfLink / 2) + 1;
176 176
                 $end = $currentPageNumber + ($numberOfLink / 2);
177 177
             }
178
-            else{
178
+            else {
179 179
                 $start = $currentPageNumber - floor($numberOfLink / 2);
180 180
                 $end = $currentPageNumber + floor($numberOfLink / 2);
181 181
             }
182
-            if ($start <= 1){
182
+            if ($start <= 1) {
183 183
                 $begin = 1;
184 184
                 $end = $numberOfLink;
185 185
             }
186
-            else if ($start > 1 && $end < $numberOfPage){
186
+            else if ($start > 1 && $end < $numberOfPage) {
187 187
                 $begin = $start;
188 188
                 $end = $end;
189 189
             }
190
-            else{
190
+            else {
191 191
                 $begin = ($numberOfPage - $numberOfLink) + 1;
192 192
                 $end = $numberOfPage;
193 193
             }
194
-            if ($numberOfPage <= $numberOfLink){
194
+            if ($numberOfPage <= $numberOfLink) {
195 195
                 $begin = 1;
196 196
                 $end = $numberOfPage;
197 197
             }
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
             $end = (int) $end;
200 200
 
201 201
             //**
202
-            if ($currentPageNumber == 1){
202
+            if ($currentPageNumber == 1) {
203 203
                 $navbar .= $this->buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber);
204 204
             }
205 205
             ///////////
206
-            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage){
206
+            else if ($currentPageNumber > 1 && $currentPageNumber < $numberOfPage) {
207 207
                 $navbar .= $this->buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber);
208 208
             }
209
-            else if ($currentPageNumber == $numberOfPage){
209
+            else if ($currentPageNumber == $numberOfPage) {
210 210
                $navbar .= $this->buildPaginationLinkForLastPage($begin, $end, $currentPageNumber);
211 211
             }
212 212
             $navbar = $this->config['pagination_open'] . $navbar . $this->config['pagination_close'];
@@ -220,14 +220,14 @@  discard block
 block discarded – undo
220 220
          * @param  int $currentPageNumber the pagination current page number
221 221
          * @return string                    
222 222
          */
223
-        protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber){
223
+        protected function buildPaginationLinkForFirstPage($begin, $end, $currentPageNumber) {
224 224
             $navbar = null;
225 225
             $query = $this->paginationQueryString;
226
-            for($i = $begin; $i <= $end; $i++){
227
-                if ($i == $currentPageNumber){
226
+            for ($i = $begin; $i <= $end; $i++) {
227
+                if ($i == $currentPageNumber) {
228 228
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
229 229
                 }
230
-                else{
230
+                else {
231 231
                     $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '" ' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
232 232
                 }
233 233
             }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
          * @param  int $currentPageNumber the pagination current page number
243 243
          * @return string                    
244 244
          */
245
-        protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber){
245
+        protected function buildPaginationLinkForMiddlePage($begin, $end, $currentPageNumber) {
246 246
             $navbar = null;
247 247
             $query = $this->paginationQueryString;
248 248
             $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
249
-            for($i = $begin; $i <= $end; $i++){
250
-                if ($i == $currentPageNumber){
249
+            for ($i = $begin; $i <= $end; $i++) {
250
+                if ($i == $currentPageNumber) {
251 251
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
252 252
                 }
253
-                else{
254
-                    $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i .'</a>' . $this->config['digit_close'];
253
+                else {
254
+                    $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
255 255
                 }
256 256
             }
257
-            $navbar .= $this->config['next_open']."<a href='$query".($currentPageNumber + 1)."'>".$this->config['next_text']."</a>".$this->config['next_close'];
257
+            $navbar .= $this->config['next_open'] . "<a href='$query" . ($currentPageNumber + 1) . "'>" . $this->config['next_text'] . "</a>" . $this->config['next_close'];
258 258
             return $navbar;
259 259
         }
260 260
 
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
          * @param  int $currentPageNumber the pagination current page number
266 266
          * @return string                    
267 267
          */
268
-        protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber){
268
+        protected function buildPaginationLinkForLastPage($begin, $end, $currentPageNumber) {
269 269
             $navbar = null;
270 270
             $query = $this->paginationQueryString;
271 271
             $navbar .= $this->config['previous_open'] . '<a href="' . $query . ($currentPageNumber - 1) . '">' . $this->config['previous_text'] . '</a>' . $this->config['previous_close'];
272
-            for($i = $begin; $i <= $end; $i++){
273
-                if ($i == $currentPageNumber){
272
+            for ($i = $begin; $i <= $end; $i++) {
273
+                if ($i == $currentPageNumber) {
274 274
                     $navbar .= $this->config['active_link_open'] . $currentPageNumber . $this->config['active_link_close'];
275 275
                 }
276
-                else{
276
+                else {
277 277
                     $navbar .= $this->config['digit_open'] . '<a href="' . $query . $i . '"' . attributes_to_string($this->config['attributes']) . '>' . $i . '</a>' . $this->config['digit_close'];
278 278
                 }
279 279
             }
Please login to merge, or discard this patch.