diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php
index ad66977ad..f026df4e7 100644
--- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php
+++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalCategoryController.php
@@ -38,6 +38,7 @@
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
+use Illuminate\Database\Eloquent\Builder;
use AidingApp\KnowledgeBase\Models\KnowledgeBaseCategory;
use AidingApp\Portal\DataTransferObjects\KnowledgeBaseCategoryData;
@@ -74,6 +75,12 @@ public function show(KnowledgeBaseCategory $category): JsonResponse
'articles' => $category->knowledgeBaseItems()
->with('tags')
->public()
+ ->when(request()->get('filter') === 'featured', function (Builder $query) {
+ $query->where('is_featured', true);
+ })
+ ->when(request()->get('filter') === 'most-viewed', function (Builder $query) {
+ $query->where('portal_view_count', '>', 0)->orderBy('portal_view_count', 'desc');
+ })
->paginate(5)
->through(function ($category) {
$category->name = $category->title;
diff --git a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php
index 6eb587e35..a899a8f56 100644
--- a/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php
+++ b/app-modules/portal/src/Http/Controllers/KnowledgeManagementPortal/KnowledgeManagementPortalSearchController.php
@@ -69,6 +69,12 @@ public function get(Request $request): KnowledgeManagementSearchData
->with('tags')
->when($search->isNotEmpty(), fn (Builder $query) => $query->tap(new SearchBy('title', $search)))
->when($tags->isNotEmpty(), fn (Builder $query) => $query->whereHas('tags', fn (Builder $query) => $query->whereIn('id', $tags)))
+ ->when($request->get('filter') === 'featured', function (Builder $query) {
+ $query->where('is_featured', true);
+ })
+ ->when($request->get('filter') === 'most-viewed', function (Builder $query) {
+ $query->where('portal_view_count', '>', 0)->orderBy('portal_view_count', 'desc');
+ })
->paginate(5)
->through(function (KnowledgeBaseItem $article) {
return [
diff --git a/portals/knowledge-management/src/Components/FilterComponent.vue b/portals/knowledge-management/src/Components/FilterComponent.vue
new file mode 100644
index 000000000..6a33acb7e
--- /dev/null
+++ b/portals/knowledge-management/src/Components/FilterComponent.vue
@@ -0,0 +1,85 @@
+
+
+
+
+
+
diff --git a/portals/knowledge-management/src/Components/SearchResults.vue b/portals/knowledge-management/src/Components/SearchResults.vue
index 65098e9ab..dd3322315 100644
--- a/portals/knowledge-management/src/Components/SearchResults.vue
+++ b/portals/knowledge-management/src/Components/SearchResults.vue
@@ -37,9 +37,10 @@
import { ChevronRightIcon, XMarkIcon } from '@heroicons/vue/20/solid';
import Tags from './Tags.vue';
import Article from './Article.vue';
+ import FilterComponent from './FilterComponent.vue';
import Pagination from './Pagination.vue';
- const emit = defineEmits(['fetchNextPage', 'fetchPreviousPage', 'fetchPage']);
+ const emit = defineEmits(['fetchNextPage', 'fetchPreviousPage', 'fetchPage', 'change-filter']);
defineProps({
searchQuery: {
@@ -54,6 +55,10 @@
type: Boolean,
required: true,
},
+ selectedFilter: {
+ type: String,
+ default: '',
+ },
currentPage: {
type: Number,
required: true,
@@ -75,6 +80,11 @@
required: true,
},
});
+
+ const updateFilter = (value) => {
+ emit('change-filter', value);
+ };
+
function fetchNextPage() {
emit('fetchNextPage');
}
@@ -96,6 +106,7 @@
Search results: {{ searchQuery }}
+