Skip to content

Commit 6428ac6

Browse files
committed
feat: added possibility to filter for inactive and new FAQs, closes #494
1 parent 0e59969 commit 6428ac6

File tree

8 files changed

+53
-8
lines changed

8 files changed

+53
-8
lines changed

phpmyfaq/admin/assets/src/api/faqs.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313
* @since 2023-12-27
1414
*/
1515

16-
export const fetchAllFaqsByCategory = async (categoryId) => {
16+
export const fetchAllFaqsByCategory = async (categoryId, onlyInactive, onlyNew) => {
1717
try {
18-
const response = await fetch(`./api/faqs/${categoryId}`, {
18+
const currentUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
19+
const url = new URL(`${currentUrl}api/faqs/${categoryId}`);
20+
if (onlyInactive) {
21+
url.searchParams.set('only-inactive', onlyInactive);
22+
}
23+
if (onlyNew) {
24+
url.searchParams.set('only-new', onlyNew);
25+
}
26+
const response = await fetch(url.toString(), {
1927
method: 'GET',
2028
cache: 'no-cache',
2129
headers: {

phpmyfaq/admin/assets/src/content/faqs.overview.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
*/
1515

1616
import { deleteFaq, fetchAllFaqsByCategory, fetchCategoryTranslations } from '../api';
17-
import { addElement } from '../../../../assets/src/utils';
1817
import { pushNotification } from '../utils';
18+
import { addElement } from '../../../../assets/src/utils';
1919

2020
export const handleFaqOverview = async () => {
2121
const collapsedCategories = document.querySelectorAll('.accordion-collapse');
22+
const filterForInactive = document.getElementById('pmf-checkbox-filter-inactive');
23+
const filterForNew = document.getElementById('pmf-checkbox-filter-new');
2224

2325
if (collapsedCategories) {
2426
collapsedCategories.forEach((category) => {
@@ -30,7 +32,10 @@ export const handleFaqOverview = async () => {
3032
});
3133

3234
category.addEventListener('shown.bs.collapse', async () => {
33-
const faqs = await fetchAllFaqsByCategory(categoryId);
35+
const onlyInactive = filterForInactive.checked;
36+
const onlyNew = filterForNew.checked;
37+
38+
const faqs = await fetchAllFaqsByCategory(categoryId, onlyInactive, onlyNew);
3439
await populateCategoryTable(categoryId, faqs.faqs);
3540
const deleteFaqButtons = document.querySelectorAll('.pmf-button-delete-faq');
3641
const toggleStickyAllFaqs = document.querySelectorAll('.pmf-admin-faqs-all-sticky');

phpmyfaq/admin/faqs.overview.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
exit();
3232
}
3333

34-
$request = Request::createFromGlobals();
3534
$faqConfig = Configuration::getConfigurationInstance();
3635
$user = CurrentUser::getCurrentUser($faqConfig);
3736

@@ -53,6 +52,8 @@
5352

5453
$templateVars = [
5554
'msgHeaderFAQOverview' => Translation::get('ad_entry_aor'),
55+
'msgOnlyInactiveFAQs' => Translation::get('msgOnlyInactiveFAQs'),
56+
'msgOnlyNewFAQs' => Translation::get('msgOnlyNewFAQs'),
5657
'msgSearch' => Translation::get('ad_menu_searchfaqs'),
5758
'csrfTokenSearch' => Token::getInstance()->getTokenInput('edit-faq'),
5859
'errorNoRecords' => Translation::get('err_noArticles'),

phpmyfaq/assets/templates/admin/content/faq.overview.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
<i aria-hidden="true" class="bi bi-list-alt"></i>
44
{{ msgHeaderFAQOverview }}
55
</h1>
6+
<div class="col-2">
7+
<div class="form-check">
8+
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-inactive">
9+
<label class="form-check-label" for="pmf-checkbox-filter-inactive">
10+
{{ msgOnlyInactiveFAQs }}
11+
</label>
12+
</div>
13+
</div>
14+
<div class="col-2">
15+
<div class="form-check">
16+
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-new">
17+
<label class="form-check-label" for="pmf-checkbox-filter-new">
18+
{{ msgOnlyNewFAQs }}
19+
</label>
20+
</div>
21+
</div>
622
<div class="pmf-faq-overview-search col-4">
723
<form name="pmf-faq-search-autocomplete" id="pmf-faq-search-autocomplete" action="?action=faq-overview"
824
method="post" role="form">

phpmyfaq/src/phpMyFAQ/Controller/Administration/FaqController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ public function listByCategory(Request $request): JsonResponse
7373

7474
$categoryId = Filter::filterVar($request->get('categoryId'), FILTER_VALIDATE_INT);
7575

76-
$faq = new Faq(Configuration::getConfigurationInstance());
76+
$onlyInactive = Filter::filterVar($request->query->get('only-inactive'), FILTER_VALIDATE_BOOLEAN, false);
77+
$onlyNew = Filter::filterVar($request->query->get('only-new'), FILTER_VALIDATE_BOOLEAN, false);
78+
79+
$faq = new Faq($this->configuration);
7780

7881
return $this->json(
7982
[
80-
'faqs' => $faq->getAllFaqsByCategory($categoryId),
83+
'faqs' => $faq->getAllFaqsByCategory($categoryId, $onlyInactive, $onlyNew),
8184
],
8285
Response::HTTP_OK
8386
);

phpmyfaq/src/phpMyFAQ/Faq.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function getAllAvailableFaqsByCategoryId(
248248
return $faqData;
249249
}
250250

251-
public function getAllFaqsByCategory(int $categoryId): array
251+
public function getAllFaqsByCategory(int $categoryId, bool $onlyInactive = false, bool $onlyNew = false): array
252252
{
253253
$faqData = [];
254254

@@ -291,6 +291,8 @@ public function getAllFaqsByCategory(int $categoryId): array
291291
fcr.category_id = %d
292292
AND
293293
fd.lang = '%s'
294+
%s
295+
%s
294296
ORDER BY
295297
fd.id ASC",
296298
Database::getTablePrefix(),
@@ -300,6 +302,8 @@ public function getAllFaqsByCategory(int $categoryId): array
300302
Database::getTablePrefix(),
301303
$categoryId,
302304
$this->configuration->getLanguage()->getLanguage(),
305+
$onlyInactive ? "AND fd.active = 'no'" : '',
306+
$onlyNew ? sprintf("AND fd.created > '%s'", date('Y-m-d H:i:s', strtotime('-1 month'))) : ''
303307
);
304308

305309
$result = $this->configuration->getDb()->query($query);

phpmyfaq/translations/language_de.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,4 +1395,8 @@
13951395
$PMF_LANG['msgExportSessionsFrom'] = 'Von';
13961396
$PMF_LANG['msgExportSessionsTo'] = 'Bis';
13971397

1398+
// added v4.0.0-alpha.2 - 2024-03-26 by Thorsten
1399+
$PMF_LANG['msgOnlyInactiveFAQs'] = 'Nur inaktive FAQs';
1400+
$PMF_LANG['msgOnlyNewFAQs'] = 'Nur neue FAQs';
1401+
13981402
return $PMF_LANG;

phpmyfaq/translations/language_en.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,4 +1415,8 @@
14151415
$PMF_LANG['msgExportSessionsFrom'] = 'From';
14161416
$PMF_LANG['msgExportSessionsTo'] = 'To';
14171417

1418+
// added v4.0.0-alpha.2 - 2024-03-26 by Thorsten
1419+
$PMF_LANG['msgOnlyInactiveFAQs'] = 'Only inactive FAQs';
1420+
$PMF_LANG['msgOnlyNewFAQs'] = 'Only new FAQs';
1421+
14181422
return $PMF_LANG;

0 commit comments

Comments
 (0)