From a6e78ef9e3d64ccc6e1f36c82fe94c73ad5b1585 Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Fri, 28 Feb 2020 11:14:18 +0100 Subject: [PATCH] Small changes from dev --- api/app/Http/Controllers/NewsController.php | 51 +++++++++++---------- api/routes/web.php | 1 + 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 2ef9a59..6299229 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -1,16 +1,13 @@ EXTERNAL_NEWS_API = env('EXTERNAL_NEWS_API', '//'); + } + + /** + * RSS-feed van alle podcasts + */ + public function rss(Request $request) { + $page = (int)$request->get('page', 1); + if($page <= 0) { + return abort(400); + } + + $podcasts = $this->retrieveNewsItems($page, $count = 20, $filter = null, $params = []); + $view = view('rss.news')->with('news', $podcasts)->with('url', $request->url())->with('page', $page); + return response($view)->header('Content-Type', 'application/xml'); } /** @@ -50,7 +60,12 @@ QUERY; if($count <= 0 || $page <= 0) { return abort(400); } + + $result = $this->retrieveNewsItems($page, $count, $filter, []); + return response()->json(['page' => $page, 'count' => $count, 'news' => $result]); + } + public function retrieveNewsItems($page, $count, $filter, $params) { $filterSql = ""; $params = ['category' => self::$NEWS_CATEGORY, 'secondarycategory' => self::$EXTERNAL_NEWS_CATEGORY]; if($filter) { @@ -75,7 +90,7 @@ QUERY; $result[] = new \Model\NewsItem($newsItem, $pictures); } - return response()->json(['page' => $page, 'count' => $count, 'news' => $result]); + return $result; } public function regionlist(Request $request, $region) { @@ -88,24 +103,19 @@ QUERY; public function findnews(Request $request, $query) { $page = (int)$request->get('pagina', 1); + $count = (int)$request->get('aantal', 15); if($page <= 0) { return abort(400); } - + + $start = ($page - 1) * $count; $query = strip_tags(urldecode($query)); - $searchRange = [ - (new \DateTimeImmutable())->setDate(date('Y') + 1 - $page, 1, 1), - (new \DateTimeImmutable())->setDate(date('Y') + 2 - $page, 1, 1)]; - - $newsItems = app('db')->select(self::$BASE_SQL - . ' AND `news`.`creationdt` >= :startRange AND `news`.`creationdt` <= :endRange' - . ' AND MATCH(`content`.`title`, `content`.`content`) AGAINST(:query IN BOOLEAN MODE)' + $newsItems = app('db')->select($s=self::$BASE_SQL + . ' AND MATCH(`content`.`title`, `content`.`content`) AGAINST(:query IN NATURAL LANGUAGE MODE)' . ' ORDER BY COALESCE(`news`.`pubupdatedt`, `news`.`creationdt`) DESC' - . ' LIMIT 0, 20', [ + . ' LIMIT ' . $start . ', ' . $count, [ 'category' => self::$NEWS_CATEGORY, 'secondarycategory' => self::$EXTERNAL_NEWS_CATEGORY, - 'startRange' => $searchRange[0]->format('Y-m-d'), - 'endRange' => $searchRange[1]->format('Y-m-d'), 'query' => $query ]); @@ -243,13 +253,6 @@ QUERY $data = array('version' => 1, 'news' => new \Model\NewsItem($item['data'], $item['images'], $item['podcast'])); - if($externalId = (int)$item['data']->external_id) { - $externalSource = json_decode(file_get_contents($this->EXTERNAL_NEWS_API . 'news?source=api&externalid=' . (int)$externalId)); - if($externalSource) { - $data['version'] = 2; - $data['source'] = $externalSource->news; - } - } return response()->json($data); } diff --git a/api/routes/web.php b/api/routes/web.php index 2f0c436..5f346f2 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -17,6 +17,7 @@ $app->get('/', function () use ($app) { }); $app->get( 'rss/podcasts', 'PodcastController@rss' ); +$app->get( 'rss/nieuws', 'NewsController@rss' ); $app->get( 'menu/special', 'MenuController@special' );