From d6a90d8144fe88c39bc00cd7ace7ed2786fe9bfc Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 7 Jun 2017 01:23:32 +0200 Subject: [PATCH] NewsItem images: file / url --- api/app/Http/Controllers/NewsController.php | 2 +- common/classes/NewsItem.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 02b201f..1250952 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -24,7 +24,7 @@ SELECT `news`.`id`, `content`.`title`, `content`.`content`, `news`.`podcast` QUERY; private static $LOAD_IMAGES = - 'SELECT `id`, `file` AS `url`, `description` AS `title` FROM `news_pictures` WHERE `news` = ? AND `active` = 1'; + 'SELECT `id`, `file`, `description` AS `title` FROM `news_pictures` WHERE `news` = ? AND `active` = 1'; /** * Create a new controller instance. diff --git a/common/classes/NewsItem.php b/common/classes/NewsItem.php index 9061acb..a587f52 100644 --- a/common/classes/NewsItem.php +++ b/common/classes/NewsItem.php @@ -16,11 +16,17 @@ class NewsSource { class NewsImage extends Model { public $id; - public $url; public $title; + public $url; - public function getUrl() { - return '/img/news/' . $this->url; + public function __construct($data, $urlPrefix = '/') { + parent::__construct($data); + + // Deserialisatie van JSON heeft url in data, + // lezen uit database heeft file en (als het goed is) urlPrefix + if(isset($data->file)) { + $this->url = $urlPrefix . $data->file; + } } }