Skip to content

Commit b4fe1b5

Browse files
author
Fredrick Peter
committed
Pagination Display Error Fix
1 parent 210cf30 commit b4fe1b5

File tree

5 files changed

+39
-40
lines changed

5 files changed

+39
-40
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Prior to installing `php-orm-database` get the [Composer](https://getcomposer.or
108108
**Step 1** — update your `composer.json`:
109109
```composer.json
110110
"require": {
111-
"peterson/php-orm-database": "^3.1.7"
111+
"peterson/php-orm-database": "^3.1.8"
112112
}
113113
```
114114

@@ -483,7 +483,6 @@ $db->tableExist('users');
483483
| toArray() | `array` Convert items to array |
484484
| toObject() | `object` Convert items to object |
485485
| toJson() | `string` Convert items to json |
486-
| getQuery() | `object` Get Query information |
487486
| toSql() | `string` Sql Query String without execution |
488487

489488

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"extra": {
4040
"branch-alias": {
41-
"dev-main": "3.1.7-dev"
41+
"dev-main": "3.1.8-dev"
4242
}
4343
},
4444
"minimum-stability": "stable",

src/Collections/Collection.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ public function has($key)
125125
*/
126126
public function links(?array $options = [])
127127
{
128-
if(self::$check_paginate){
129-
if(self::$pagination){
130-
self::$pagination->links($options);
131-
}
128+
if(self::$pagination){
129+
self::$pagination->links($options);
132130
}
133131
}
134132

@@ -140,10 +138,8 @@ public function links(?array $options = [])
140138
*/
141139
public function showing(?array $options = [])
142140
{
143-
if(self::$check_paginate){
144-
if(self::$pagination){
145-
self::$pagination->showing($options);
146-
}
141+
if(self::$pagination){
142+
self::$pagination->showing($options);
147143
}
148144
}
149145

@@ -155,8 +151,8 @@ public function showing(?array $options = [])
155151
*/
156152
public function numbers(mixed $key = 0)
157153
{
158-
$key = (int) $key + 1;
159154
if(self::$check_paginate){
155+
$key = (int) $key + 1;
160156
$pagination = $this->getPagination();
161157
return ($pagination->offset + $key);
162158
}

src/Collections/CollectionMapper.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,28 @@
1111

1212
class CollectionMapper implements IteratorAggregate, ArrayAccess
1313
{
14+
/**
15+
* Items attributes
16+
* @var mixed
17+
*/
1418
private $attributes;
15-
private $getQuery;
19+
20+
/**
21+
* Array index key
22+
* @var mixed
23+
*/
1624
private $key;
17-
static private $check_paginate = false;
25+
26+
/**
27+
* If pagination is true
28+
* @var bool
29+
*/
30+
static private $is_paginate = false;
31+
32+
/**
33+
* Pagination Instance
34+
* @var mixed
35+
*/
1836
static private $pagination;
1937

2038
/**
@@ -24,14 +42,13 @@ class CollectionMapper implements IteratorAggregate, ArrayAccess
2442
*/
2543
public function __construct($items = [], mixed $key = 0, ?bool $check_paginate = false, mixed $pagination = null)
2644
{
27-
$this->attributes = $this->convertOnInit($items);
28-
$this->getQuery = get_query();
45+
$this->attributes = $this->convertOnInit($items);
2946
$this->key = ((int) $key + 1);
3047

3148
// if pagination request is `true`
3249
if($check_paginate){
33-
self::$check_paginate = $check_paginate;
34-
self::$pagination = $pagination->pagination ?? null;
50+
self::$is_paginate = $check_paginate;
51+
self::$pagination = $pagination->pagination ?? null;
3552
}
3653
}
3754

@@ -108,7 +125,7 @@ public function __isset($key)
108125
*/
109126
public function getPagination()
110127
{
111-
if(self::$check_paginate){
128+
if(self::$is_paginate){
112129
$pagination = self::$pagination;
113130
return (object) [
114131
'limit' => (int) $pagination->limit,
@@ -128,7 +145,7 @@ public function getPagination()
128145
*/
129146
public function numbers()
130147
{
131-
if(self::$check_paginate){
148+
if(self::$is_paginate){
132149
$pagination = $this->getPagination();
133150
return ($pagination->offset + $this->key);
134151
}
@@ -218,16 +235,6 @@ public function toJson()
218235
return json_encode( $this->attributes );
219236
}
220237

221-
/**
222-
* Get database query
223-
*
224-
* @return array
225-
*/
226-
public function getQuery()
227-
{
228-
return $this->getQuery;
229-
}
230-
231238
/**
232239
* Convert data to an array on Initializaiton
233240
* @param mixed $items

src/Collections/Traits/CollectionTrait.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ protected function wrapArrayIntoCollectionMappers(mixed $items)
135135

136136
if (is_array($items) && count($items) > 0) {
137137
return array_map(function ($item, $key){
138+
139+
// dd(
140+
// self::$pagination_data,
141+
// $this->items,
142+
// self::$pagination
143+
// );
144+
138145
return new CollectionMapper($item, $key, self::$check_paginate, self::$pagination);
139146
}, $items, array_keys($items));
140147
}
@@ -266,16 +273,6 @@ public function toJson()
266273
{
267274
return json_encode($this->getItemsData());
268275
}
269-
270-
/**
271-
* Get database query
272-
*
273-
* @return array
274-
*/
275-
public function getQuery()
276-
{
277-
return get_query();
278-
}
279276

280277
/**
281278
* Check if items is an array

0 commit comments

Comments
 (0)