Add support for blogs

This commit is contained in:
2020-03-22 19:45:04 +01:00
parent 22acca0e05
commit 507ad08488
3 changed files with 50 additions and 7 deletions

View File

@@ -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]);
}

View File

@@ -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' );

23
common/classes/Blog.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace Model;
class Blog extends Model {
public $id;
public $title;
public $description;
public $news_category;
public $start_date;
public $end_date;
public $is_active;
public $url;
public function __construct($data, $images = null, $podcast = null) {
parent::__construct($data);
parent::ConvertToDateTime($this->start_date);
parent::ConvertToDateTime($this->end_date);
$this->url = "/blog/{$this->id}/" . parent::url_slug($this->title);
}
}