8000 Pagination desteği eklendi · InitPHP/Database@10f857e · GitHub
[go: up one dir, main page]

Skip to content

Commit 10f857e

Browse files
committed
Pagination desteği eklendi
1 parent a4173dc commit 10f857e

22 files changed

+277
-24
lines changed

src/Database.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

1414
namespace InitPHP\Database;
1515

16+
use InitPHP\Database\Utils\Pagination;
1617
use \InitPHP\Database\Exceptions\{WritableException,
1718
ReadableException,
1819
UpdatableException,
@@ -467,6 +468,30 @@ public function createBatch(array $set)
467468
return $res->numRows() > 0;
468469
}
469470

471+
/**
472+
* QueryBuilder resetlemeden SELECT cümlesi kurar ve satır sayısını döndürür.
473+
*
474+
* @return int
475+
*/
476+
public function count(): int
477+
{
478+
$this->_deleteFieldBuild(false);
479+
$res = $this->query($this->_readQuery());
480+
481+
return $res->numRows();
482+
}
483+
484+
public function pagination(int $page = 1, int $per_page_limit = 10, string $link = '?page={page}'): Pagination
485+
{
486+
$total_row = $this->count();
487+
$this->offset(($page - 1) * $per_page_limit)
488+
->limit($per_page_limit);
489+
$res = $this->query($this->_readQuery());
490+
$this->reset();
491+
492+
return new Pagination($res, $page, $per_page_limit, $total_row, $link);
493+
}
494+
470495
/**
471496
* @param array $selector
472497
* @param array $conditions

src/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/ConnectionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/DeletableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/ModelCallbacksException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/ModelException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/ModelRelationsException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/ReadableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/SQLQueryExecuteException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

src/Exceptions/UpdatableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Muhammet ŞAFAK <info@muhammetsafak.com.tr>
88
* @copyright Copyright © 2022 Muhammet ŞAFAK
99
* @license ./LICENSE MIT
10-
* @version 2.0.5
10+
* @version 2.0.6
1111
* @link https://www.muhammetsafak.com.tr
1212
*/
1313

0 commit comments

Comments
 (0)
0