Skip to content

Commit e319bc5

Browse files
author
Fredrick Peter
committed
Pagination on Select Update...
1 parent 0bfca45 commit e319bc5

File tree

16 files changed

+514
-561
lines changed

16 files changed

+514
-561
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ was pretty tough. So i decided to create a much more easier way of communicating
3939
* [Count](#count)
4040
* [Paginate](#paginate)
4141
* [Exist](#exists)
42-
* [Table Exist](#table-exist)
42+
* [Table Exists](#table-exists)
4343
* [Asset](#Asset)
4444
* [Asset config](#asset-config)
4545
* [Asset Cache](#asset-cache)
@@ -151,8 +151,7 @@ $db = new DB();
151151
| By default you don't need to define any path again |
152152
| Files you'll see `.env` `.gitignore` `.htaccess` `.user.ini` `php.ini` `init.php` |
153153
| The below code should be called before using the database model |
154-
| It's important to install vendor in your project root [dir] |
155-
| When done running the code first time, Then remove code and include `init.php` file |
154+
| When done running the code first time, Then remove code and include `init.php` file anywhere in your project |
156155

157156
```
158157
use builder\Database\EnvAutoLoad;
@@ -245,8 +244,6 @@ $db->table('users')->insert([
245244
```
246245

247246
### Insert Or Ignore
248-
<details><summary>Read more...</summary>
249-
250247
- Same as `insert()` method
251248
- It returns an object of created data or `false` on error
252249

@@ -256,7 +253,6 @@ $db->table('users')->insertOrIgnore([
256253
'first_name' => 'Alfred',
257254
]);
258255
```
259-
</details>
260256

261257
### Update
262258
- Takes one parameter as assoc array `column_name => value`
@@ -271,8 +267,6 @@ $db->table('users')
271267
```
272268

273269
### Update Or Ignore
274-
<details><summary>Read more...</summary>
275-
276270
- Same as `update()` method
277271
- Returns an `int` numbers of affected rows or `0` on error
278272

@@ -283,7 +277,6 @@ $db->table('users')
283277
'first_name' => 'Alfred C.',
284278
]);
285279
```
286-
</details>
287280

288281
### Delete
289282
- Returns an `int`
@@ -405,7 +398,7 @@ $db->table('post')
405398
| count() | int |
406399
| paginate() | array of objects |
407400
| exists() | boolean `true` \| `false` |
408-
| tableExist() | boolean `true` \| `false` |
401+
| tableExists() | boolean `true` \| `false` |
409402

410403
### GET
411404
```
@@ -496,10 +489,10 @@ $db->table('users')
496489
->exists();
497490
```
498491

499-
### Table Exist
492+
### Table Exists
500493
- Takes param as `string` `$table_name`
501494
```
502-
$db->tableExist('users');
495+
$db->tableExists('users');
503496
```
504497

505498
## Asset
@@ -658,6 +651,7 @@ config_pagination([
658651
```
659652

660653
<details><summary>Read more...</summary>
654+
661655
- 2 Can also be called using the `$db->configPagination` method
662656
```
663657
$db->configPagination([

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=7.2",
19+
"php": "^7.2",
2020
"vlucas/phpdotenv": "^5.3",
2121
"yidas/pagination": "^1.0",
22-
"symfony/var-dumper": "^6.2.8",
22+
"symfony/var-dumper": "^4.0 || ^5.0 || ^6.0",
2323
"ezyang/htmlpurifier": "^4.16.0"
2424
},
25+
"config": {
26+
"platform": {
27+
"php": "7.2"
28+
}
29+
},
2530
"autoload": {
2631
"files": [
2732
"src/helpers.php"

src/Asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static public function asset(?string $asset = null)
3333
$assetPath = ASSET_BASE_DIRECTORY;
3434

3535
// trim
36-
$asset = trim($asset, '/');
36+
$asset = trim((string) $asset, '/');
3737

3838
$file_domain = "{$assetPath['domain']}/{$asset}";
3939

src/Capsule/Manager.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ static public function findCharset(?string $charset = null)
262262
*/
263263
static public function replaceWhiteSpace(?string $string = null)
264264
{
265-
return preg_replace(self::$regex_whitespace, " ", $string);
265+
return trim(preg_replace(
266+
self::$regex_whitespace,
267+
" ",
268+
$string
269+
));
266270
}
267271

268272
/**
@@ -533,15 +537,22 @@ static public function configIncrementOperator($column = null, $count = 1, $para
533537
* Trim empty strings from an array value
534538
*
535539
* @param array $param
540+
* @param bool $indent
536541
*
537542
* @return array
538543
*/
539-
static public function arrayWalkerTrim(?array $param = [])
544+
static public function arrayWalkerTrim(?array $param = [], ?bool $indent = false)
540545
{
541-
array_walk($param, function(&$value, $index){
546+
array_walk($param, function(&$value, $index) use($indent){
542547
if(!empty($value)){
543548
if(is_string($value)){
549+
// trim
544550
$value = trim($value);
551+
552+
// if indentation of value is allowed
553+
if($indent){
554+
$value = "`$value`";
555+
}
545556
}
546557
}
547558
});

src/Collections/Collection.php

Lines changed: 11 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
use Traversable;
1818
use ArrayIterator;
1919
use IteratorAggregate;
20+
use builder\Database\Collections\CollectionProperty;
21+
use builder\Database\Collections\Traits\RelatedTrait;
2022
use builder\Database\Collections\Traits\CollectionTrait;
2123

2224

23-
class Collection implements IteratorAggregate, ArrayAccess
25+
class Collection extends CollectionProperty implements IteratorAggregate, ArrayAccess
2426
{
25-
use CollectionTrait;
27+
use CollectionTrait, RelatedTrait;
2628

2729
/**
2830
* The items contained in the collection.
2931
*
3032
* @var array
3133
*/
3234
protected $items = [];
33-
35+
36+
3437
/**
3538
* Create a new collection.
3639
*
@@ -56,66 +59,11 @@ public function __construct($items = [])
5659
*/
5760
public function getIterator() : Traversable
5861
{
59-
// Automatically wrap Mappers into an array
60-
$items = $this->wrapArrayIntoCollectionMappers($this->items);
61-
62-
return new ArrayIterator($items);
63-
}
64-
65-
/**
66-
* Determine if an item exists at an offset.
67-
*
68-
* @param mixed $offset
69-
* @return bool
70-
*/
71-
public function offsetExists($offset): bool
72-
{
73-
return isset($this->items[$offset]);
74-
}
75-
76-
/**
77-
* Get an item at a given offset.
78-
*
79-
* @param mixed $offset
80-
* @return mixed
81-
*/
82-
public function offsetGet($offset): mixed
83-
{
84-
return $this->__get($offset);
85-
}
86-
87-
/**
88-
* Set the item at a given offset.
89-
*
90-
* @param mixed $offset
91-
* @param mixed $value
92-
* @return void
93-
*/
94-
public function offsetSet($offset, $value): void
95-
{
96-
$this->__set($offset, $value);
97-
}
98-
99-
/**
100-
* Unset the item at a given offset.
101-
*
102-
* @param mixed $offset
103-
* @return void
104-
*/
105-
public function offsetUnset($offset): void
106-
{
107-
unset($this->items[$offset]);
108-
}
109-
110-
/**
111-
* Determine if the collection has a given key.
112-
*
113-
* @param mixed $key
114-
* @return bool
115-
*/
116-
public function has($key)
117-
{
118-
return array_key_exists($key, $this->items);
62+
// On interation (foreach)
63+
// Wrap items into instance of CollectionMapper
64+
return new ArrayIterator(
65+
$this->wrapArrayIntoCollectionMappers($this->items)
66+
);
11967
}
12068

12169
/**
@@ -161,42 +109,4 @@ public function numbers(mixed $key = 0)
161109
return $key;
162110
}
163111

164-
/**
165-
* Check if an item exists in the collection.
166-
*
167-
* @param string $key
168-
* @return bool
169-
*/
170-
public function __isset($key)
171-
{
172-
return isset($this->items[$key]);
173-
}
174-
175-
/**
176-
* Dynamically access collection items.
177-
*
178-
* @param string $key
179-
* @return mixed
180-
*/
181-
public function __get($key)
182-
{
183-
// Convert data to array
184-
$unasignedItems = $this->toArray();
185-
return $unasignedItems[$key]
186-
?? $unasignedItems[0][$key]
187-
?? null;
188-
}
189-
190-
/**
191-
* Dynamically set an item in the collection.
192-
*
193-
* @param string $key
194-
* @param mixed $value
195-
* @return void
196-
*/
197-
public function __set($key, $value)
198-
{
199-
$this->items[$key] = $value;
200-
}
201-
202112
}

0 commit comments

Comments
 (0)