Skip to content

Commit

Permalink
feat: added possibility to filter for inactive and new FAQs, closes #494
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 26, 2024
1 parent 0e59969 commit 6428ac6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 8 deletions.
12 changes: 10 additions & 2 deletions phpmyfaq/admin/assets/src/api/faqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@
* @since 2023-12-27
*/

export const fetchAllFaqsByCategory = async (categoryId) => {
export const fetchAllFaqsByCategory = async (categoryId, onlyInactive, onlyNew) => {
try {
const response = await fetch(`./api/faqs/${categoryId}`, {
const currentUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
const url = new URL(`${currentUrl}api/faqs/${categoryId}`);
if (onlyInactive) {
url.searchParams.set('only-inactive', onlyInactive);
}
if (onlyNew) {
url.searchParams.set('only-new', onlyNew);
}
const response = await fetch(url.toString(), {
method: 'GET',
cache: 'no-cache',
headers: {
Expand Down
9 changes: 7 additions & 2 deletions phpmyfaq/admin/assets/src/content/faqs.overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
*/

import { deleteFaq, fetchAllFaqsByCategory, fetchCategoryTranslations } from '../api';
import { addElement } from '../../../../assets/src/utils';
import { pushNotification } from '../utils';
import { addElement } from '../../../../assets/src/utils';

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

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

category.addEventListener('shown.bs.collapse', async () => {
const faqs = await fetchAllFaqsByCategory(categoryId);
const onlyInactive = filterForInactive.checked;
const onlyNew = filterForNew.checked;

const faqs = await fetchAllFaqsByCategory(categoryId, onlyInactive, onlyNew);
await populateCategoryTable(categoryId, faqs.faqs);
const deleteFaqButtons = document.querySelectorAll('.pmf-button-delete-faq');
const toggleStickyAllFaqs = document.querySelectorAll('.pmf-admin-faqs-all-sticky');
Expand Down
3 changes: 2 additions & 1 deletion phpmyfaq/admin/faqs.overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
exit();
}

$request = Request::createFromGlobals();
$faqConfig = Configuration::getConfigurationInstance();
$user = CurrentUser::getCurrentUser($faqConfig);

Expand All @@ -53,6 +52,8 @@

$templateVars = [
'msgHeaderFAQOverview' => Translation::get('ad_entry_aor'),
'msgOnlyInactiveFAQs' => Translation::get('msgOnlyInactiveFAQs'),
'msgOnlyNewFAQs' => Translation::get('msgOnlyNewFAQs'),
'msgSearch' => Translation::get('ad_menu_searchfaqs'),
'csrfTokenSearch' => Token::getInstance()->getTokenInput('edit-faq'),
'errorNoRecords' => Translation::get('err_noArticles'),
Expand Down
16 changes: 16 additions & 0 deletions phpmyfaq/assets/templates/admin/content/faq.overview.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
<i aria-hidden="true" class="bi bi-list-alt"></i>
{{ msgHeaderFAQOverview }}
</h1>
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-inactive">
<label class="form-check-label" for="pmf-checkbox-filter-inactive">
{{ msgOnlyInactiveFAQs }}
</label>
</div>
</div>
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-new">
<label class="form-check-label" for="pmf-checkbox-filter-new">
{{ msgOnlyNewFAQs }}
</label>
</div>
</div>
<div class="pmf-faq-overview-search col-4">
<form name="pmf-faq-search-autocomplete" id="pmf-faq-search-autocomplete" action="?action=faq-overview"
method="post" role="form">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ public function listByCategory(Request $request): JsonResponse

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

$faq = new Faq(Configuration::getConfigurationInstance());
$onlyInactive = Filter::filterVar($request->query->get('only-inactive'), FILTER_VALIDATE_BOOLEAN, false);
$onlyNew = Filter::filterVar($request->query->get('only-new'), FILTER_VALIDATE_BOOLEAN, false);

$faq = new Faq($this->configuration);

return $this->json(
[
'faqs' => $faq->getAllFaqsByCategory($categoryId),
'faqs' => $faq->getAllFaqsByCategory($categoryId, $onlyInactive, $onlyNew),
],
Response::HTTP_OK
);
Expand Down
6 changes: 5 additions & 1 deletion phpmyfaq/src/phpMyFAQ/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function getAllAvailableFaqsByCategoryId(
return $faqData;
}

public function getAllFaqsByCategory(int $categoryId): array
public function getAllFaqsByCategory(int $categoryId, bool $onlyInactive = false, bool $onlyNew = false): array
{
$faqData = [];

Expand Down Expand Up @@ -291,6 +291,8 @@ public function getAllFaqsByCategory(int $categoryId): array
fcr.category_id = %d
AND
fd.lang = '%s'
%s
%s
ORDER BY
fd.id ASC",
Database::getTablePrefix(),
Expand All @@ -300,6 +302,8 @@ public function getAllFaqsByCategory(int $categoryId): array
Database::getTablePrefix(),
$categoryId,
$this->configuration->getLanguage()->getLanguage(),
$onlyInactive ? "AND fd.active = 'no'" : '',
$onlyNew ? sprintf("AND fd.created > '%s'", date('Y-m-d H:i:s', strtotime('-1 month'))) : ''
);

$result = $this->configuration->getDb()->query($query);
Expand Down
4 changes: 4 additions & 0 deletions phpmyfaq/translations/language_de.php
Original file line number Diff line number Diff line change
Expand Up @@ -1395,4 +1395,8 @@
$PMF_LANG['msgExportSessionsFrom'] = 'Von';
$PMF_LANG['msgExportSessionsTo'] = 'Bis';

// added v4.0.0-alpha.2 - 2024-03-26 by Thorsten
$PMF_LANG['msgOnlyInactiveFAQs'] = 'Nur inaktive FAQs';
$PMF_LANG['msgOnlyNewFAQs'] = 'Nur neue FAQs';

return $PMF_LANG;
4 changes: 4 additions & 0 deletions phpmyfaq/translations/language_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -1415,4 +1415,8 @@
$PMF_LANG['msgExportSessionsFrom'] = 'From';
$PMF_LANG['msgExportSessionsTo'] = 'To';

// added v4.0.0-alpha.2 - 2024-03-26 by Thorsten
$PMF_LANG['msgOnlyInactiveFAQs'] = 'Only inactive FAQs';
$PMF_LANG['msgOnlyNewFAQs'] = 'Only new FAQs';

return $PMF_LANG;

0 comments on commit 6428ac6

Please sign in to comment.