Fragment terugluisteren toegevoegd aan nieuws en agenda

This commit is contained in:
2017-09-01 19:20:46 +02:00
parent cbfd38e1ea
commit ec122e1d9a
4 changed files with 35 additions and 16 deletions

View File

@@ -9,11 +9,10 @@ ini_set('display_errors', true);
class NewsController extends Controller class NewsController extends Controller
{ {
// TODO: Include podcast
private static $NEWS_CATEGORY = 1; private static $NEWS_CATEGORY = 1;
private static $CALENDAR_CATEGORY = 42; private static $CALENDAR_CATEGORY = 42;
private static $BASE_SQL = <<<QUERY private static $BASE_SQL = <<<QUERY
SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast`, `news`.`video`, `news`.`keywords`, `news`.`titlewithdate`, SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast` AS `podcast_id`, `news`.`video`, `news`.`keywords`, `news`.`titlewithdate`,
`news`.`creationdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`, `news`.`creationdt` AS `published`, `content`.`creator`, `content`.`editingdt` AS `edited`, `content`.`editor`,
`news`.`startdt` AS `starts`, `news`.`enddt` AS `ends`, `news`.`startdt` AS `starts`, `news`.`enddt` AS `ends`,
`content`.`showsource` AS `showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`, `content`.`showsource` AS `showsource`, `sources`.`title` AS `source`, `sources`.`url` AS `source_url`,
@@ -90,7 +89,7 @@ QUERY;
*/ */
public function newsitem($id) { public function newsitem($id) {
$item = $this->itemFromCategory(self::$NEWS_CATEGORY, $id); $item = $this->itemFromCategory(self::$NEWS_CATEGORY, $id);
return $item ? response()->json(new \Model\NewsItem($item['data'], $item['images'])) : abort(404); return $item ? response()->json(new \Model\NewsItem($item['data'], $item['images'], $item['podcast'])) : abort(404);
} }
/** /**
@@ -98,7 +97,7 @@ QUERY;
*/ */
public function calendaritem($id) { public function calendaritem($id) {
$item = $this->itemFromCategory(self::$CALENDAR_CATEGORY, $id); $item = $this->itemFromCategory(self::$CALENDAR_CATEGORY, $id);
return $item ? response()->json(new \Model\CalendarEvent($item['data'], $item['images'])) : abort(404); return $item ? response()->json(new \Model\CalendarEvent($item['data'], $item['images'], $item['podcast'])) : abort(404);
} }
private function itemFromCategory($category, $id) { private function itemFromCategory($category, $id) {
@@ -112,7 +111,14 @@ QUERY;
// Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :) // Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :)
$newsItem[0]->content = stripslashes($newsItem[0]->content); $newsItem[0]->content = stripslashes($newsItem[0]->content);
$images = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]); $images = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]);
return ['data' => $newsItem[0], 'images' => $images]; $podcast = null;
if($newsItem[0]->podcast_id > 0)
{
$podcast = app('db')->select(PodcastController::$BASE_SQL . ' AND `podcast`.`id` = :podcastId', ['podcastId' => $newsItem[0]->podcast_id]);
$podcast = count($podcast) ? $podcast[0] : null;
}
return ['data' => $newsItem[0], 'images' => $images, 'podcast' => $podcast];
} }
} }
} }

View File

@@ -11,7 +11,7 @@ ini_set('display_errors', true);
class PodcastController extends Controller class PodcastController extends Controller
{ {
// TODO: Include program // TODO: Include program
private static $BASE_SQL = <<<QUERY public static $BASE_SQL = <<<QUERY
SELECT `podcast`.`id`, `podcast`.`soundfilename`, SELECT `podcast`.`id`, `podcast`.`soundfilename`,
`podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`, `podcast_meta`.`creationdt` AS `created`, `podcast_meta`.`title`, `podcast_meta`.`content`, `podcast_meta`.`program`,
`programs`.`longname` AS `program_name`, `programs`.`description` AS `program_description` `programs`.`longname` AS `program_name`, `programs`.`description` AS `program_description`

View File

@@ -14,7 +14,7 @@ class CalendarEvent extends Model {
public $keywords; public $keywords;
public $url; public $url;
public function __construct($data, $images = null) { public function __construct($data, $images = null, $podcast = null) {
parent::__construct($data); parent::__construct($data);
parent::ConvertToDateTime($this->starts); parent::ConvertToDateTime($this->starts);
parent::ConvertToDateTime($this->ends); parent::ConvertToDateTime($this->ends);
@@ -28,7 +28,12 @@ class CalendarEvent extends Model {
} }
} }
$this->podcast = isset($data->podcast) && $data->podcast ? $data->podcast : null; if($podcast)
{
$this->podcast = new \Model\Podcast($podcast);
} else if(isset($data->podcast) && $data->podcast) {
$this->podcast = new \Model\Podcast($data->podcast);
}
$images = ($images != null) ? $images $images = ($images != null) ? $images
: (isset($data->images) ? $data->images : null); : (isset($data->images) ? $data->images : null);

View File

@@ -17,14 +17,14 @@ class NewsItem extends Model {
public $category; public $category;
public $theme; public $theme;
public $region; public $region;
public $podcast; public $podcast;
public $images; public $images;
public $video; public $video;
public $url; public $url;
public function __construct($data, $images = null) { public function __construct($data, $images = null, $podcast = null) {
parent::__construct($data); parent::__construct($data);
parent::ConvertToDateTime($this->published); parent::ConvertToDateTime($this->published);
parent::ConvertToDateTime($this->edited); parent::ConvertToDateTime($this->edited);
@@ -35,11 +35,21 @@ class NewsItem extends Model {
} }
$this->source = null; $this->source = null;
if(is_object($data->source)) if(isset($data->source))
{ {
$this->source = new \Model\NewsSource($data->source->title, $data->source->url, $data->source->url); if(is_object($data->source))
} else if($data->source) { {
$this->source = new \Model\NewsSource($data->source, $data->source_url, $data->showsource); $this->source = new \Model\NewsSource($data->source->title, $data->source->url, $data->source->show);
} else if($data->source) {
$this->source = new \Model\NewsSource($data->source, $data->source_url, $data->showsource);
}
}
if($podcast)
{
$this->podcast = new \Model\Podcast($podcast);
} else if(isset($data->podcast) && $data->podcast) {
$this->podcast = new \Model\Podcast($data->podcast);
} }
$this->keywords = null; $this->keywords = null;
@@ -49,8 +59,6 @@ class NewsItem extends Model {
$this->keywords = explode(' ', $data->keywords); $this->keywords = explode(' ', $data->keywords);
} }
$this->podcast = $data->podcast ? $data->podcast : null;
$images = ($images != null) ? $images $images = ($images != null) ? $images
: (isset($data->images) ? $data->images : null); : (isset($data->images) ? $data->images : null);
if($images) { if($images) {