From 2602532d34291ceb733bf8c53b09350b122c848b Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Fri, 5 Jul 2019 23:48:24 +0200 Subject: [PATCH] Added live blog --- api/app/Http/Controllers/NewsController.php | 38 +++++++++++++++++++++ api/routes/web.php | 2 ++ 2 files changed, 40 insertions(+) diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 9b17934..2c83d33 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -8,6 +8,8 @@ class NewsController extends Controller { private static $NEWS_CATEGORY = 1; private static $CALENDAR_CATEGORY = 42; + private static $BLOG_CATEGORY = 45; + private static $BASE_SQL = <<json($result); } + /** + * Blogitems ophalen + */ + public function bloglist(Request $request, $from, $to) { + $count = (int)$request->get('aantal', 15); + $page = (int)$request->get('pagina', 1); + if($count <= 0 || $page <= 0) { + return abort(400); + } + + $startIndex = ($page - 1) * $count; + $start = new \DateTime($from); + $end = new \DateTime($to); + $blogItems = app('db')->select($sql = self::$BASE_SQL + . ' AND `news`.`startdt` >= :start AND `news`.`startdt` <= :end ' + . ' ORDER BY `news`.`startdt` DESC' + . ' LIMIT ' . (int)$startIndex . ', ' . (int)$count, + ['category' => self::$BLOG_CATEGORY, 'start' => $from, 'end' => $to]); + + $result = array(); + foreach($blogItems as $blogItem) { + // Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :) + $blogItem->content = $blogItem->content; + $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $blogItem->id]); + if($blogItem->podcast_id > 0) + { + $podcast = app('db')->select(PodcastController::$BASE_SQL . ' AND `podcast`.`id` = :podcastId', ['podcastId' => $blogItem->podcast_id]); + $podcast = count($podcast) ? $podcast[0] : null; + } + + $result[] = new \Model\NewsItem($blogItem, $pictures, $podcast); + } + + return response()->json(['page' => $page, 'count' => $count, 'items' => $result]); + } + /** * Populaire berichten ophalen diff --git a/api/routes/web.php b/api/routes/web.php index a71a34c..849b337 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -27,6 +27,8 @@ $app->get('agenda/overzicht[/week]', 'NewsController@calendarlist' ); $app->get('agenda/item/{id:\d+}', 'NewsController@calendaritem' ); $app->get('agenda/populair', 'NewsController@popularCalendar' ); +$app->get('blog/overzicht/{from:\d\d\d\d-\d\d?-\d\d?}/{to:\d\d\d\d-\d\d?-\d\d?}', 'NewsController@bloglist' ); + $app->get('podcast/overzicht', 'PodcastController@overview' ); $app->get('podcast/details/{id:\d+}', 'PodcastController@details' ); $app->get('podcast/zoeken/{query}', 'PodcastController@findpodcast' );