aboutsummaryrefslogtreecommitdiffstats
path: root/core/namespace/ORM/Repository.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 19:05:55 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 19:05:55 +0200
commit6342c9a87509fddb3b3ec9046b111bdc2090bc00 (patch)
tree2bf38072b08d66f54f19b5b29dab5397814fe02f /core/namespace/ORM/Repository.php
parentf2d9607438670550661fe423eaf26bc24f22bc9e (diff)
downloadblog-6342c9a87509fddb3b3ec9046b111bdc2090bc00.tar.gz
blog-6342c9a87509fddb3b3ec9046b111bdc2090bc00.tar.xz
blog-6342c9a87509fddb3b3ec9046b111bdc2090bc00.zip
Add LIMIT and OFFSET parameters for search method
Diffstat (limited to 'core/namespace/ORM/Repository.php')
-rw-r--r--core/namespace/ORM/Repository.php10
1 files changed, 7 insertions, 3 deletions
diff --git a/core/namespace/ORM/Repository.php b/core/namespace/ORM/Repository.php
index a1efa3c..b2778f4 100644
--- a/core/namespace/ORM/Repository.php
+++ b/core/namespace/ORM/Repository.php
@@ -261,7 +261,7 @@ abstract class Repository {
#===============================================================================
# Get entities based on search query
#===============================================================================
- public function search(string $search, array $filter = []): array {
+ public function search(string $search, array $filter = [], int $limit = NULL, int $offset = 0): array {
if($search === '*') {
return $this->getAll([], NULL, 20);
}
@@ -281,11 +281,15 @@ abstract class Repository {
$params[] = $filter['day'];
}
+ if($limit) {
+ $limit = "LIMIT $offset,$limit";
+ }
+
$dateparts = implode(' ', $extend ?? []);
$query = 'SELECT * FROM %s WHERE %s MATCH(name, body)
- AGAINST(? IN BOOLEAN MODE) LIMIT 20';
- $query = sprintf($query, static::getTableName(), $dateparts);
+ AGAINST(? IN BOOLEAN MODE) %s';
+ $query = sprintf($query, static::getTableName(), $dateparts, $limit ?? 'LIMIT 20');
$Statement = $this->Database->prepare($query);
$Statement->execute(array_merge($params ?? [], [$search]));