NewsItem kan direct gedeserialiseerd worden vanuit API JSON

This commit is contained in:
2017-06-07 01:17:43 +02:00
parent ad7e82e01d
commit 3f726e884d
2 changed files with 20 additions and 7 deletions

View File

@@ -19,9 +19,8 @@ class NewsImage extends Model {
public $url;
public $title;
public function __construct($data, $urlPrefix = '/') {
parent::__construct($data);
if($this->url) { $this->url = $urlPrefix . $this->url; }
public function getUrl() {
return '/img/news/' . $this->url;
}
}
@@ -52,8 +51,8 @@ class NewsItem extends Model {
$this->source = $data->source ? new \Model\NewsSource($data->source, $data->source_url, $data->showsource) : null;
$this->keywords = trim($data->keywords) ? explode(' ', $data->keywords) : null;
$this->podcast = $data->podcast ? $data->podcast : null;
if($images) {
if($images = $images ?? $data->images) {
$this->images = [];
foreach($images as $image) {
$this->images[] = new NewsImage($image, '/img/news/');