Shortcut for pagination appending.

This commit is contained in:
Pachira 2024-12-19 02:27:28 +00:00
parent 5e1d36abac
commit b8687406b8
18 changed files with 42 additions and 72 deletions

View file

@ -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();

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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();

View file

@ -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();

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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();

View file

@ -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();

View file

@ -1,6 +1,7 @@
<?php
namespace Misuzu;
use Index\Db\DbStatement;
use Index\Http\HttpRequest;
final class Pagination {
@ -27,6 +28,11 @@ final class Pagination {
get => (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,

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));

View file

@ -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(...));