diff --git a/api/app/Http/Controllers/NewsController.php b/api/app/Http/Controllers/NewsController.php index 3a58de2..57cbfa4 100644 --- a/api/app/Http/Controllers/NewsController.php +++ b/api/app/Http/Controllers/NewsController.php @@ -11,6 +11,8 @@ class NewsController extends Controller private static $CALENDAR_CATEGORY = 42; private static $EXTERNAL_NEWS_CATEGORY = 44; private static $BLOG_CATEGORY = 45; + private static $JOBS_CATEGORY = 46; + private static $FEATIMG_CATEGORY = 47; private static $WEBSITE_TARGET = 1; private static $TV_TARGET = 2; @@ -188,6 +190,62 @@ QUERY; return response()->json($result); } + + /** + * Vacatures ophalen + */ + public function jobslist(Request $request) { + $today = new \DateTime('today'); + $vacatures = app('db')->select(self::$BASE_SQL + . ' AND (`news`.`enddt` = 0 OR `news`.`enddt` >= :today) ' + . ' ORDER BY `news`.`startdt` ASC, `news`.`enddt` ASC', ['target' => self::$WEBSITE_TARGET, 'category' => self::$JOBS_CATEGORY, 'secondarycategory' => 0, 'today' => $today]); + + $result = array(); + foreach($vacatures as $vacature) { + // Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :) + $vacature->content = $vacature->content; + $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $vacature->id]); + $result[] = new \Model\JobOpening($vacature, $pictures); + } + + return response()->json(['jobs' => $result]); + } + + /** + * Beelden ophalen + */ + public function featuredimages(Request $request) { + $today = new \DateTime('today'); + $items = app('db')->select(self::$BASE_SQL + . ' AND (`news`.`enddt` = 0 OR `news`.`enddt` >= :today) ' + . ' ORDER BY `news`.`startdt` ASC, `news`.`enddt` ASC', ['target' => self::$WEBSITE_TARGET, 'category' => self::$FEATIMG_CATEGORY, 'secondarycategory' => 0, 'today' => $today]); + + $result = array(); + foreach($items as $item) { + // Note: content is stored in the database with an additional addslashes() - don't ask why, just remove it :) + $item->content = $item->content; + $pictures = app('db')->select(self::$LOAD_IMAGES, ['newsId' => $item->id]); + $result[] = new \Model\NewsItem($item, $pictures); + } + + return response()->json(['items' => $result]); + } + + /** + * Specifiek nieuwsbericht ophalen + */ + public function jobsitem($id) { + $item = $this->itemFromCategory(self::$JOBS_CATEGORY, $id); + if(!$item) { + return abort(404); + } + + $data = array( + 'item' => new \Model\JobOpening($item['data'], $item['images'], null)); + + return response()->json($data); + } + /** * Blogitems ophalen */ diff --git a/api/routes/web.php b/api/routes/web.php index edf6479..cb6d8c4 100644 --- a/api/routes/web.php +++ b/api/routes/web.php @@ -35,6 +35,11 @@ $app->get('agenda/overzicht[/week]', 'NewsController@calendarlist' ); $app->get('agenda/item/{id:\d+}', 'NewsController@calendaritem' ); $app->get('agenda/populair', 'NewsController@popularCalendar' ); +$app->get('vacatures/overzicht', 'NewsController@jobslist' ); +$app->get('vacatures/details/{id:\d+}', 'NewsController@jobsitem' ); + +$app->get('beelden/overzicht', 'NewsController@featuredimages' ); + $app->get('blog/overzicht', 'NewsController@bloglist'); $app->get('blog/overzicht/{id:\d+}', 'NewsController@blogitemlist'); diff --git a/common/classes/JobOpening.php b/common/classes/JobOpening.php new file mode 100644 index 0000000..b1d9147 --- /dev/null +++ b/common/classes/JobOpening.php @@ -0,0 +1,61 @@ +starts); + parent::ConvertToDateTime($this->ends); + + $this->keywords = null; + if(isset($data->keywords)) { + if(is_array($data->keywords)) { + $this->keywords = $data->keywords; + } else if(trim($data->keywords)) { + $this->keywords = explode(' ', $data->keywords); + } + } + + 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 + : (isset($data->images) ? $data->images : null); + if($images) { + $this->images = []; + foreach($images as $image) { + $this->images[] = new NewsImage($image, '/img/news/'); + } + } + + $this->url = "/vacatures/{$this->id}/" . parent::url_slug($this->title); + $this->metadata = (new MetaData()) + ->set('title', $this->title) + ->set('description', strip_tags($this->excerpt())) + ->set('image', isset($this->images) && count($this->images) ? $this->images[0]->url : null ) + ->set('audio', isset($this->podcast) ? $this->podcast->url : null) + ; + } + + public function excerpt() { + $hasImages = count($this->images) > 0; + $maxLength = $hasImages ? 200 : 500; + return '

' . + substr($this->content, 0, $maxLength) . + (strlen($this->content) > $maxLength ? '...' : '') . + '

'; + } +}