diff --git a/api/app/Http/Controllers/PodcastController.php b/api/app/Http/Controllers/PodcastController.php index 007ce10..55e44ca 100644 --- a/api/app/Http/Controllers/PodcastController.php +++ b/api/app/Http/Controllers/PodcastController.php @@ -68,6 +68,38 @@ QUERY; return response()->json(new \Model\Podcast($podcasts[0])); } + public function findpodcast(Request $request, $query) { + $page = (int)$request->get('pagina', 1); + if($page <= 0) { + return abort(400); + } + + $query = strip_tags(urldecode($query)); + $searchRange = [ + (new \DateTimeImmutable())->setDate(date('Y') + 1 - $page, 1, 1), + (new \DateTimeImmutable())->setDate(date('Y') + 2 - $page, 1, 1)]; + + $podcasts = app('db')->select(self::$BASE_SQL + . ' AND `podcast_meta`.`creationdt` >= :startRange AND `podcast_meta`.`creationdt` <= :endRange' + . ' AND MATCH(`podcast_meta`.`title`, `podcast_meta`.`content`) AGAINST(:query IN BOOLEAN MODE)' + . ' ORDER BY `creationdt` DESC' + . ' LIMIT 0, 20', [ + 'startRange' => $searchRange[0]->format('Y-m-d'), + 'endRange' => $searchRange[1]->format('Y-m-d'), + 'query' => $query + ]); + + $result = array(); + foreach($podcasts as $podcast) { + $model = new \Model\Podcast($podcast); + $model->title = \Helpers::HighlightQuery($query, $model->title); + $model->content = \Helpers::HighlightQuery($query, $model->content); + $result[] = $model; + } + + return response()->json(['page' => $page, 'podcasts' => $result]); + } + private function getPodcastList(Request $request, $filter, $params) { $count = (int)$request->get('aantal', 15); diff --git a/api/routes/web.php b/api/routes/web.php index 954b731..ecfeada 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -29,6 +29,7 @@ $app->get('agenda/populair', 'NewsController@popularCalendar' ); $app->get('podcast/overzicht', 'PodcastController@overview' ); $app->get('podcast/details/{id:\d+}', 'PodcastController@details' ); +$app->get('podcast/zoeken/{query}', 'PodcastController@findpodcast' ); $app->get('podcast/programma/{id:\d+}', 'PodcastController@program' ); $app->get('podcast/download/{id:\d+}/{title}', 'PodcastController@download' ); $app->get('podcast/stream/{id:\d+}/{title}', 'PodcastController@stream' );