57 lines
2.2 KiB
PHP
57 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', true);
|
|
|
|
class NewsController extends Controller
|
|
{
|
|
// TODO: Include podcast
|
|
private static $BASE_SQL = <<<QUERY
|
|
SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast`, `news`.`video`, `news`.`keywords`, `news`.`titlewithdate`,
|
|
`content`.`publishingdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`,
|
|
`content`.`showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`,
|
|
`categories`.`title` AS `category`, `themes`.`title` AS `theme`, `themes`.`thumbnail` AS `theme_thumbnail`, `regions`.`title` AS `region`
|
|
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`
|
|
LEFT JOIN `news_sources` AS `sources` ON `sources`.`id` = `news`.`source`
|
|
LEFT JOIN `news_categories` AS `categories` ON `categories`.`id` = `news`.`category`
|
|
LEFT JOIN `news_themes` AS `themes` ON `themes`.`id` = `news`.`theme`
|
|
WHERE `content`.`target` = 1 AND `news`.`active` = 1 AND `content`.`active` = 1
|
|
ORDER BY `content`.`publishingdt` DESC
|
|
QUERY;
|
|
|
|
private static $LOAD_IMAGES =
|
|
'SELECT `id`, `file` AS `url`, `description` AS `title` FROM `news_pictures` WHERE `news` = ? AND `active` = 1';
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Lijst van alle nieuwsberichten
|
|
*/
|
|
public function list(int $count = 10, int $page = 1) {
|
|
if((int)$count <= 0) { $count = 10; }
|
|
if((int)$page <= 0) { $page = 1; }
|
|
$start = ($page - 1) * $count;
|
|
$newsItems = app('db')->select(self::$BASE_SQL . 'LIMIT ' . (int)$start . ', ' . (int)$count);
|
|
|
|
$result = array();
|
|
foreach($newsItems as $newsItem) {
|
|
$pictures = app('db')->select(self::$LOAD_IMAGES, [$newsItem->id]);
|
|
$result[] = new \Model\NewsItem($newsItem, $pictures);
|
|
}
|
|
|
|
return response()->json(['page' => $page, 'count' => $count, 'news' => $result]);
|
|
}
|
|
}
|