Skip to content

Commit

Permalink
fix: handled some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 26, 2023
1 parent 6055ba0 commit 003b149
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion phpmyfaq/show.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
]
);
} else {
$selectedCategoryId = 0;
try {
$faqSession->userTracking('show_all_categories', 0);
} catch (Exception) {
Expand All @@ -129,7 +130,7 @@
'categoryDescription' => '',
'categoryFaqsHeader' => '',
'categorySubsHeader' => '',
'categoryContent' => $categoryHelper->renderCategoryTree(),
'categoryContent' => $categoryHelper->renderCategoryTree($selectedCategoryId),
'subCategoryContent' => $subCategoryContent,
'categoryLevelUp' => '',
]
Expand Down
10 changes: 4 additions & 6 deletions phpmyfaq/src/phpMyFAQ/Category/CategoryRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,17 @@ public function getCategoryTree(): array
);
} else {
$query .= sprintf(
'AND ( fdg.group_id IN (%s) OR (fdu.user_id = %d OR fdg.group_id IN (%s)) )
AND ( fcg.group_id IN (%s) OR (fcu.user_id = %d OR fcg.group_id IN (%s)) )',
implode(', ', $this->category->getGroups()),
'AND ( fdu.user_id = %d OR fdg.group_id IN (%s) )
AND ( fcu.user_id = %d OR fcg.group_id IN (%s) )',
$this->category->getUser(),
implode(', ', $this->category->getGroups()),
implode(', ', $this->category->getGroups()),
$this->category->getUser(),
implode(', ', $this->category->getGroups())
);
}
}

if (strlen((string) $this->config->getLanguage()->getLanguage()) > 0) {
if (strlen($this->config->getLanguage()->getLanguage()) > 0) {
$query .= sprintf(
" AND fd.lang = '%s'",
$this->config->getLanguage()->getLanguage()
Expand Down Expand Up @@ -237,7 +235,7 @@ public function getNumberOfFaqsPerCategory(bool $categoryRestriction = false, bo
}

/**
* Calculates the aggregated numbers of FAQs for a given category
* Calculates the aggregated numbers of FAQs
*/
public function getAggregatedFaqNumbers(array $categories, int $parentId = 0): array
{
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/src/phpMyFAQ/Helper/CategoryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function renderCategoryTree(int $parentId = 0): string
$categoryRelation = new CategoryRelation($this->config, $this->Category);
$categoryRelation->setGroups($this->Category->getGroups());
$categoriesWithNumbers = $categoryRelation->getCategoryTree();
$aggregatedNumbers = $categoryRelation->getAggregatedFaqNumbers($categoriesWithNumbers);
$aggregatedNumbers = $categoryRelation->getAggregatedFaqNumbers($categoriesWithNumbers, $parentId);

return sprintf(
'<ul class="pmf-category-overview">%s</ul>',
Expand Down

0 comments on commit 003b149

Please sign in to comment.