From 2ecc79c714f0bc09b884ed26236c64c318f43b5a Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 11 Nov 2022 15:50:38 +0100 Subject: [PATCH] Controllers: Add option for archived blog searching --- app/controllers/BlogController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/controllers/BlogController.php b/app/controllers/BlogController.php index 579261b..0402845 100644 --- a/app/controllers/BlogController.php +++ b/app/controllers/BlogController.php @@ -8,8 +8,9 @@ class BlogController extends PageController { public function indexAction(): void { + $archived = $this->router->request()->param('archived', 0); $query = $this->router->request()->param('search', ''); - $posts = $this->search($query); + $posts = $this->search($query, $archived); $this->defineHelpers(); @@ -21,8 +22,9 @@ class BlogController extends PageController { public function searchAction(): void { + $archived = $this->router->request()->param('archived', 0); $query = $this->router->request()->param('query', ''); - $posts = $this->search($query); + $posts = $this->search($query, $archived); $this->defineHelpers(); @@ -32,7 +34,7 @@ class BlogController extends PageController { //-------------------------------------// - private function search(string $query): ?array + private function search(string $query = '', int $archived = 0): ?array { return BlogModel::selectAll( 'blog_post.*, media.filename, media.extension, page.page, section.section, log.created_at', ' @@ -40,11 +42,14 @@ class BlogController extends PageController { LEFT JOIN page ON blog_post.page_id = page.id LEFT JOIN section ON page.section_id = section.id LEFT JOIN log ON blog_post.log_id = log.id - WHERE blog_post.archived = 0 AND + WHERE blog_post.archived = :archived AND (blog_post.content LIKE :query OR blog_post.title LIKE :query OR blog_post.tag LIKE :query) - ', [[':query', "%$query%", \PDO::PARAM_STR]]); + ', [ + [':archived', "$archived", \PDO::PARAM_INT], + [':query', "%$query%", \PDO::PARAM_STR] + ]); } private function defineHelpers(): void