86 lines
2.1 KiB
PHP
86 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Model;
|
|
|
|
class NewsSource {
|
|
public $title;
|
|
public $url;
|
|
public $show;
|
|
|
|
public function __construct($title, $url, $show) {
|
|
$this->title = $title;
|
|
$this->url = $url;
|
|
$this->show = $show;
|
|
}
|
|
}
|
|
|
|
class NewsImage extends Model {
|
|
public $id;
|
|
public $title;
|
|
public $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;
|
|
}
|
|
}
|
|
}
|
|
|
|
class NewsItem extends Model {
|
|
public $id;
|
|
public $title;
|
|
public $content;
|
|
public $published;
|
|
public $edited;
|
|
public $keywords;
|
|
|
|
public $source;
|
|
public $category;
|
|
public $theme;
|
|
public $region;
|
|
|
|
public $podcast;
|
|
public $images;
|
|
public $video;
|
|
|
|
public $url;
|
|
|
|
public function __construct($data, $images = null) {
|
|
parent::__construct($data);
|
|
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->podcast = $data->podcast ? $data->podcast : null;
|
|
|
|
$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 = "/nieuws/{$this->id}/" . parent::url_slug($this->title);
|
|
}
|
|
|
|
public function detailsUrl() {
|
|
return "/{$this->id}/" . urlencode($this->title);
|
|
}
|
|
|
|
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>';
|
|
}
|
|
}
|