Vacatures en beelden toegevoegd

This commit is contained in:
2021-10-05 20:06:11 +02:00
parent d194572073
commit 34bae091bf
3 changed files with 124 additions and 0 deletions

View File

@@ -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
*/

View File

@@ -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');

View File

@@ -0,0 +1,61 @@
<?php
namespace Model;
class JobOpening extends Model {
public $id;
public $title;
public $content;
public $starts;
public $ends;
public $images;
public $url;
public function __construct($data, $images = null, $podcast = null) {
parent::__construct($data);
parent::ConvertToDateTime($this->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 '<p class="news-excerpt ' . ($hasImages ? 'short' : 'long') . '">' .
substr($this->content, 0, $maxLength) .
(strlen($this->content) > $maxLength ? '...' : '') .
'</p>';
}
}