Nieuws filter op regio
This commit is contained in:
@@ -13,7 +13,7 @@ SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast` AS
|
||||
`news`.`creationdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`,
|
||||
`news`.`startdt` AS `starts`, `news`.`enddt` AS `ends`,
|
||||
`content`.`showsource` AS `showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`,
|
||||
`themes`.`title` AS `theme`, `themes`.`thumbnail` AS `theme_thumbnail`, `regions`.`title` AS `region`
|
||||
`themes`.`title` AS `theme`, `themes`.`thumbnail` AS `theme_thumbnail`, `regions`.`title` AS `region`, `regions`.`slug` as `region_slug`
|
||||
FROM `news`
|
||||
LEFT JOIN `news_target_content` AS `content` ON `content`.`news` = `news`.`id`
|
||||
LEFT JOIN `news_regions` AS `regions` ON `regions`.`id` = `news`.`region`
|
||||
@@ -38,17 +38,28 @@ QUERY;
|
||||
/**
|
||||
* Lijst van alle nieuwsberichten
|
||||
*/
|
||||
public function newslist(Request $request) {
|
||||
public function newslist(Request $request, $filter = null) {
|
||||
$count = (int)$request->get('aantal', 15);
|
||||
$page = (int)$request->get('pagina', 1);
|
||||
if($count <= 0 || $page <= 0) {
|
||||
return abort(400);
|
||||
}
|
||||
}
|
||||
|
||||
$filterSql = "";
|
||||
$params = ['category' => self::$NEWS_CATEGORY];
|
||||
if($filter) {
|
||||
foreach($filter as $field => $value) {
|
||||
$paramName = preg_replace('/[^A-Za-z0-9]/', '', $field);
|
||||
$filterSql .= " AND $field = :$paramName";
|
||||
$params[$paramName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$start = ($page - 1) * $count;
|
||||
$newsItems = app('db')->select(self::$BASE_SQL
|
||||
$newsItems = app('db')->select(self::$BASE_SQL
|
||||
. $filterSql
|
||||
. ' ORDER BY `published` DESC'
|
||||
. ' LIMIT ' . (int)$start . ', ' . (int)$count, ['category' => self::$NEWS_CATEGORY]);
|
||||
. ' LIMIT ' . (int)$start . ', ' . (int)$count, $params);
|
||||
|
||||
$result = array();
|
||||
foreach($newsItems as $newsItem) {
|
||||
@@ -61,6 +72,10 @@ QUERY;
|
||||
return response()->json(['page' => $page, 'count' => $count, 'news' => $result]);
|
||||
}
|
||||
|
||||
public function regionlist(Request $request, $region) {
|
||||
return $this->newslist($request, ['`regions`.`slug`' => $region]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Agendaberichten ophalen
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,7 @@ $app->get('/', function () use ($app) {
|
||||
});
|
||||
|
||||
$app->get('nieuws/overzicht', 'NewsController@newslist' );
|
||||
$app->get('nieuws/regio/{region:[a-z0-9]+}', 'NewsController@regionlist' );
|
||||
$app->get('nieuws/populair', 'NewsController@popularNews' );
|
||||
$app->get('nieuws/bericht/{id:\d+}', 'NewsController@newsitem' );
|
||||
$app->get('nieuws/regionieuws', 'PodcastController@latestNews' );
|
||||
|
||||
Reference in New Issue
Block a user