From 8b30298ca6156e62d813e3a1ab80591e98758e0a Mon Sep 17 00:00:00 2001 From: Mischa Spelt Date: Wed, 26 Jul 2017 00:07:52 +0200 Subject: [PATCH] Changes for frontend --- .hgignore | 3 ++- api/app/Http/Controllers/NewsController.php | 8 ++++---- common/classes/NewsItem.php | 10 ++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.hgignore b/.hgignore index a5b0290..f79da44 100644 --- a/.hgignore +++ b/.hgignore @@ -1,4 +1,5 @@ syntax: glob .env -api/storage/logs +api/storage +*.orig diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 8d23970..fcd1705 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -63,16 +63,16 @@ QUERY; /** * Specifiek bericht ophalen */ - public function item(int $id) { + public function item($id) { $newsItem = app('db')->select(self::$BASE_SQL . ' AND `news`.`id` = :id LIMIT 0, 1', - ['id' => $id]); + ['id' => (int)$id]); if(count($newsItem) != 1) { return abort(404); } else { - $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]); - return response()->json(new \Model\NewsItem($newsItem[0])); + $images = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $id]); + return response()->json(new \Model\NewsItem($newsItem[0], $images)); } } } diff --git a/common/classes/NewsItem.php b/common/classes/NewsItem.php index afcbaea..69979fb 100644 --- a/common/classes/NewsItem.php +++ b/common/classes/NewsItem.php @@ -29,8 +29,14 @@ class NewsItem extends Model { parent::ConvertToDateTime($this->published); parent::ConvertToDateTime($this->edited); - $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->source = null; + if($data->source) + { + $data->source = is_object($data->source) + ? new \Model\NewsSource($data->source->title, $data->source->url, $data->source->url) + : new \Model\NewsSource($data->source, $data->source_url, $data->showsource); + } + $this->keywords = !is_array($data->keywords) && trim($data->keywords) ? explode(' ', $data->keywords) : null; $this->podcast = $data->podcast ? $data->podcast : null; $images = ($images != null) ? $images