Skip to content

Commit 437ed1a

Browse files
committed
fix: backport fix for #3579
1 parent ea8f508 commit 437ed1a

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

phpmyfaq/search.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@
148148
}
149149
}
150150

151-
$searchResults = $faq->renderFaqsByFaqIds($recordIds);
152151
$numOfResults = count($recordIds);
152+
153+
// Apply pagination to record IDs for tag search
154+
$confPerPage = $faqConfig->get('records.numberOfRecordsPerPage');
155+
$first = ($page - 1) * $confPerPage;
156+
$paginatedRecordIds = array_slice($recordIds, $first, $confPerPage);
157+
158+
$searchResults = $faq->renderFaqsByFaqIds($paginatedRecordIds, 'fd.id', 'ASC', false);
153159
}
154160
} else {
155161
$searchResults = [];

phpmyfaq/src/phpMyFAQ/Faq.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,15 @@ public function renderFaqsByCategoryId(int $categoryId, string $orderBy = 'id',
458458
* @param int[] $faqIds Array of record ids
459459
* @param string $orderBy Order by
460460
* @param string $sortBy Sort by
461+
* @param bool $usePagination Whether to use internal pagination
461462
* @throws CommonMarkException
462463
*/
463-
public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', string $sortBy = 'ASC'): array
464-
{
464+
public function renderFaqsByFaqIds(
465+
array $faqIds,
466+
string $orderBy = 'fd.id',
467+
string $sortBy = 'ASC',
468+
bool $usePagination = true
469+
): array {
465470
$records = implode(', ', $faqIds);
466471
$page = Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1);
467472

@@ -530,21 +535,20 @@ public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', str
530535
$num = $this->configuration->getDb()->numRows($result);
531536
$numberPerPage = $this->configuration->get('records.numberOfRecordsPerPage');
532537

533-
if ($page == 1) {
534-
$first = 0;
535-
} else {
536-
$first = ($page * $numberPerPage) - $numberPerPage;
537-
}
538+
$first = $usePagination && $page > 1 ? ($page * $numberPerPage) - $numberPerPage : 0;
538539

539540
$searchResults = [];
540541
if ($num > 0) {
541542
$counter = 0;
542543
$displayedCounter = 0;
543544
$lastFaqId = 0;
544545
$faqHelper = new FaqHelper($this->configuration);
545-
while (($row = $this->configuration->getDb()->fetchObject($result)) && $displayedCounter < $numberPerPage) {
546+
while (
547+
($row = $this->configuration->getDb()->fetchObject($result)) &&
548+
(!$usePagination || $displayedCounter < $numberPerPage)
549+
) {
546550
++$counter;
547-
if ($counter <= $first) {
551+
if ($usePagination && $counter <= $first) {
548552
continue;
549553
}
550554

0 commit comments

Comments
 (0)