Shortcut for pagination appending.
This commit is contained in:
parent
5e1d36abac
commit
b8687406b8
18 changed files with 42 additions and 72 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
|
@ -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(...));
|
||||
|
|
Loading…
Reference in a new issue