diff --git a/src/AuditLog/AuditLog.php b/src/AuditLog/AuditLog.php index cbef494..7fc89ec 100644 --- a/src/AuditLog/AuditLog.php +++ b/src/AuditLog/AuditLog.php @@ -84,10 +84,8 @@ class AuditLog { $stmt->nextParameter($userInfo); if($hasRemoteAddr) $stmt->nextParameter($remoteAddr); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); diff --git a/src/Auth/LoginAttempts.php b/src/Auth/LoginAttempts.php index be73e25..5995760 100644 --- a/src/Auth/LoginAttempts.php +++ b/src/Auth/LoginAttempts.php @@ -109,10 +109,8 @@ class LoginAttempts { $stmt->nextParameter($remoteAddr); if($hasTimeRange) $stmt->nextParameter($timeRange); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(LoginAttemptInfo::fromResult(...)); diff --git a/src/Auth/Sessions.php b/src/Auth/Sessions.php index f79f884..68da552 100644 --- a/src/Auth/Sessions.php +++ b/src/Auth/Sessions.php @@ -75,10 +75,8 @@ class Sessions { $stmt = $this->cache->get($query); if($hasUserInfo) $stmt->nextParameter($userInfo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(SessionInfo::fromResult(...)); diff --git a/src/Changelog/Changelog.php b/src/Changelog/Changelog.php index a703e62..65492a2 100644 --- a/src/Changelog/Changelog.php +++ b/src/Changelog/Changelog.php @@ -163,10 +163,8 @@ class Changelog { if($hasTags) foreach($tags as $tag) $stmt->nextParameter((string)$tag); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); diff --git a/src/Comments/Comments.php b/src/Comments/Comments.php index 56c30d0..a2cbd1e 100644 --- a/src/Comments/Comments.php +++ b/src/Comments/Comments.php @@ -63,10 +63,8 @@ class Comments { if($hasOwner) $stmt->nextParameter($owner); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); diff --git a/src/Counters/Counters.php b/src/Counters/Counters.php index 68df5a6..3143d74 100644 --- a/src/Counters/Counters.php +++ b/src/Counters/Counters.php @@ -39,10 +39,8 @@ class Counters { $query .= ' LIMIT ? OFFSET ?'; $stmt = $this->cache->get($query); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(CounterInfo::fromResult(...)); diff --git a/src/Forum/ForumCategories.php b/src/Forum/ForumCategories.php index 4daa7d5..0214b6a 100644 --- a/src/Forum/ForumCategories.php +++ b/src/Forum/ForumCategories.php @@ -151,10 +151,8 @@ class ForumCategories { } if($hasType) $stmt->nextParameter($type); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); $cats = $stmt->getResult()->getIterator(ForumCategoryInfo::fromResult(...)); diff --git a/src/Forum/ForumPosts.php b/src/Forum/ForumPosts.php index 94dec2b..0df7e38 100644 --- a/src/Forum/ForumPosts.php +++ b/src/Forum/ForumPosts.php @@ -183,10 +183,8 @@ class ForumPosts { $stmt->nextParameter($newerThanDays); if($hasSearchQuery) $stmt->nextParameter($searchQuery); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(ForumPostInfo::fromResult(...)); diff --git a/src/Forum/ForumTopicRedirects.php b/src/Forum/ForumTopicRedirects.php index 8a5415d..f6196d5 100644 --- a/src/Forum/ForumTopicRedirects.php +++ b/src/Forum/ForumTopicRedirects.php @@ -54,10 +54,8 @@ class ForumTopicRedirects { $stmt = $this->cache->get($query); if($hasUserInfo) $stmt->nextParameter($userInfo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(ForumTopicRedirectInfo::fromResult(...)); diff --git a/src/Forum/ForumTopics.php b/src/Forum/ForumTopics.php index 0a58205..bbfdacf 100644 --- a/src/Forum/ForumTopics.php +++ b/src/Forum/ForumTopics.php @@ -190,10 +190,8 @@ class ForumTopics { $stmt->nextParameter($afterTopicId); if($hasSearchQuery) $stmt->nextParameter($searchQuery); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(ForumTopicInfo::fromResult(...)); diff --git a/src/Messages/MessagesDatabase.php b/src/Messages/MessagesDatabase.php index 6869e78..62c86e1 100644 --- a/src/Messages/MessagesDatabase.php +++ b/src/Messages/MessagesDatabase.php @@ -146,10 +146,8 @@ class MessagesDatabase { $stmt->nextParameter($repliesFor instanceof MessageInfo ? $repliesFor->id : $repliesFor); if($hasReplyTo) $stmt->nextParameter($replyTo instanceof MessageInfo ? $replyTo->replyToId : $replyTo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); diff --git a/src/News/News.php b/src/News/News.php index a1fc22b..5f07ec1 100644 --- a/src/News/News.php +++ b/src/News/News.php @@ -52,10 +52,8 @@ class News { $query .= ' LIMIT ? OFFSET ?'; $stmt = $this->cache->get($query); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); @@ -256,10 +254,8 @@ class News { $stmt->nextParameter($categoryInfo); if($hasSearchQuery) $stmt->nextParameter($searchQuery); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); diff --git a/src/Pagination.php b/src/Pagination.php index 4b7ba18..0e7edc2 100644 --- a/src/Pagination.php +++ b/src/Pagination.php @@ -1,6 +1,7 @@ (int)floor($this->offset / $this->range) + 1; } + public function addToStatement(DbStatement $stmt): void { + $stmt->nextParameter($this->range); + $stmt->nextParameter($this->offset); + } + public static function fromPage( int $count, int $page, diff --git a/src/Users/Bans.php b/src/Users/Bans.php index 7ad0240..78bc7cd 100644 --- a/src/Users/Bans.php +++ b/src/Users/Bans.php @@ -92,10 +92,8 @@ class Bans { $stmt = $this->cache->get($query); if($hasUserInfo) $stmt->nextParameter($userInfo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(BanInfo::fromResult(...)); diff --git a/src/Users/ModNotes.php b/src/Users/ModNotes.php index f7ffc0d..2e07c6d 100644 --- a/src/Users/ModNotes.php +++ b/src/Users/ModNotes.php @@ -84,10 +84,8 @@ class ModNotes { $stmt->nextParameter($userInfo); if($hasAuthorInfo) $stmt->nextParameter($authorInfo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(ModNoteInfo::fromResult(...)); diff --git a/src/Users/Roles.php b/src/Users/Roles.php index fb8db21..cd99635 100644 --- a/src/Users/Roles.php +++ b/src/Users/Roles.php @@ -84,10 +84,8 @@ class Roles { $stmt = $this->cache->get($query); if($hasUserInfo) $stmt->nextParameter($userInfo); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(RoleInfo::fromResult(...)); diff --git a/src/Users/Users.php b/src/Users/Users.php index 68be1b7..f33f3b5 100644 --- a/src/Users/Users.php +++ b/src/Users/Users.php @@ -204,10 +204,8 @@ class Users { $stmt->nextParameter($birthdate->format('%-m-d')); if($hasSearchQuery) $stmt->nextParameter($searchQuery); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(UserInfo::fromResult(...)); diff --git a/src/Users/Warnings.php b/src/Users/Warnings.php index 6182967..32a860c 100644 --- a/src/Users/Warnings.php +++ b/src/Users/Warnings.php @@ -100,10 +100,8 @@ class Warnings { $stmt->nextParameter($userInfo); if($hasBacklog) $stmt->nextParameter($backlog); - if($hasPagination) { - $stmt->nextParameter($pagination->range); - $stmt->nextParameter($pagination->offset); - } + if($hasPagination) + $pagination->addToStatement($stmt); $stmt->execute(); return $stmt->getResult()->getIterator(WarningInfo::fromResult(...));