diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 8a22957..6b462b1 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -159,7 +159,28 @@ QUERY; /** * Blogitems ophalen */ - public function bloglist(Request $request, $from, $to) { + public function bloglist() { + $blogs = app('db')->select( 'SELECT id, title, description, news_category, start_date, end_date, is_active ' + . ' FROM liveblog ORDER BY is_active DESC' ); + $result = array(); + foreach($blogs as $blog) { + $result[] = new \Model\Blog($blog); + } + + return response()->json($result); + } + + /** + * Blogitems ophalen + */ + public function blogitemlist(Request $request, $id) { + $blog_data = app('db')->select('SELECT id, title, description, news_category, start_date, end_date, is_active ' + . ' FROM liveblog WHERE id = :id', ['id' => (int)$id]); + if(count($blog_data) != 1) { + return abort(400); + } + + $blog = new \Model\Blog($blog_data[0]); $count = (int)$request->get('aantal', 15); $page = (int)$request->get('pagina', 1); if($count <= 0 || $page <= 0) { @@ -167,13 +188,11 @@ QUERY; } $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 ' + . ' AND `news`.`startdt` >= :start AND `news`.`startdt` <= :end' . ' ORDER BY `news`.`startdt` DESC' . ' LIMIT ' . (int)$startIndex . ', ' . (int)$count, - ['category' => self::$BLOG_CATEGORY, 'secondarycategory' => 0, 'start' => $from, 'end' => $to]); + ['category' => $blog->news_category, 'secondarycategory' => 0, 'start' => $blog->start_date, 'end' => $blog->end_date]); $result = array(); foreach($blogItems as $blogItem) { @@ -193,7 +212,7 @@ QUERY; $result[] = new \Model\NewsItem($blogItem, $pictures, $podcast); } - return response()->json(['page' => $page, 'count' => $count, 'items' => $result]); + return response()->json(['page' => $page, 'count' => $count, 'blog' => $blog, 'items' => $result]); } diff --git a/api/routes/web.php b/api/routes/web.php index bc800c6..475ecec 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -33,7 +33,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('blog/overzicht', 'NewsController@bloglist'); +$app->get('blog/overzicht/{id:\d+}', 'NewsController@blogitemlist'); $app->get('podcast/overzicht', 'PodcastController@overview' ); $app->get('podcast/details/{id:\d+}', 'PodcastController@details' ); diff --git a/common/classes/Blog.php b/common/classes/Blog.php new file mode 100644 index 0000000..8da4ab7 --- /dev/null +++ b/common/classes/Blog.php @@ -0,0 +1,23 @@ +start_date); + parent::ConvertToDateTime($this->end_date); + + $this->url = "/blog/{$this->id}/" . parent::url_slug($this->title); + } +}