From 96dd42044af0ded9f1cdb3e024410c23c9360f4c Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 16 Feb 2022 15:34:47 +0000 Subject: [PATCH] Fix Pagination::getOffset() and allow percent signs in $condition for loadSORMCollection() fixes #683 --- lib/classes/Pagination.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/classes/Pagination.php b/lib/classes/Pagination.php index 28755757a87..77105df8a8d 100644 --- a/lib/classes/Pagination.php +++ b/lib/classes/Pagination.php @@ -43,13 +43,13 @@ class Pagination $this->current_page = $current_page; $this->per_page = $per_page; + $this->current_page = min( + $this->current_page, + $this->getPageCount() - 1 + ); + if ($this->current_page < 0) { $this->current_page = 0; - } else { - $this->current_page = min( - $this->current_page, - $this->getPageCount() - 1 - ); } } @@ -206,11 +206,7 @@ class Pagination throw new RuntimeException('No valid SORM class given'); } - $sql = sprintf( - "{$condition} LIMIT %u, %u", - $this->getOffset(), - $this->getPerPage() - ); + $sql = "{$condition} LIMIT {$this->getOffset()}, {$this->getPerPage()}"; return SimpleORMapCollection::createFromArray( $sorm_class::findBySQL($sql, $parameters) -- GitLab