Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion phpmyfaq/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,14 @@
}
}

$searchResults = $faq->renderFaqsByFaqIds($recordIds);
$numOfResults = count($recordIds);

// Apply pagination to record IDs for tag search
$confPerPage = $faqConfig->get('records.numberOfRecordsPerPage');
$first = ($page - 1) * $confPerPage;
$paginatedRecordIds = array_slice($recordIds, $first, $confPerPage);

$searchResults = $faq->renderFaqsByFaqIds($paginatedRecordIds, 'fd.id', 'ASC', false);
}
} else {
$searchResults = [];
Expand Down
18 changes: 13 additions & 5 deletions phpmyfaq/src/phpMyFAQ/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,16 @@ public function renderFaqsByCategoryId(int $categoryId, string $orderBy = 'id',
* @param int[] $faqIds Array of record ids
* @param string $orderBy Order by
* @param string $sortBy Sort by
* @param bool $usePagination Whether to use internal pagination
* @throws CommonMarkException
* @todo this method needs to be refactored, parts of it should be moved to a Twig template
*/
public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', string $sortBy = 'ASC'): array
{
public function renderFaqsByFaqIds(
array $faqIds,
string $orderBy = 'fd.id',
string $sortBy = 'ASC',
bool $usePagination = true
): array {
$records = implode(', ', $faqIds);
$page = Filter::filterInput(INPUT_GET, 'seite', FILTER_VALIDATE_INT, 1);

Expand Down Expand Up @@ -533,17 +538,20 @@ public function renderFaqsByFaqIds(array $faqIds, string $orderBy = 'fd.id', str
$num = $this->configuration->getDb()->numRows($result);
$numberPerPage = $this->configuration->get('records.numberOfRecordsPerPage');

$first = $page == 1 ? 0 : ($page * $numberPerPage) - $numberPerPage;
$first = $usePagination && $page > 1 ? ($page * $numberPerPage) - $numberPerPage : 0;

$searchResults = [];
if ($num > 0) {
$counter = 0;
$displayedCounter = 0;
$lastFaqId = 0;
$faqHelper = new FaqHelper($this->configuration);
while (($row = $this->configuration->getDb()->fetchObject($result)) && $displayedCounter < $numberPerPage) {
while (
($row = $this->configuration->getDb()->fetchObject($result)) &&
(!$usePagination || $displayedCounter < $numberPerPage)
) {
++$counter;
if ($counter <= $first) {
if ($usePagination && $counter <= $first) {
continue;
}

Expand Down