nieuws/overzicht[/aantal/pagina] toegevoegd
This commit is contained in:
@@ -3,21 +3,29 @@
|
||||
namespace Model;
|
||||
|
||||
class Model {
|
||||
protected function ConvertToDateTime(&$field) {
|
||||
if($field) {
|
||||
$field = new DateTime($field);
|
||||
if($field === false || $field->getTimestamp() == 0) {
|
||||
$field = null;
|
||||
}
|
||||
protected function ConvertToDateTime(&$field) {
|
||||
if($field) {
|
||||
$field = new \DateTime($field);
|
||||
if($field === false || $field->getTimestamp() == 0) {
|
||||
$field = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct($data) {
|
||||
$class = get_class($this);
|
||||
foreach($data as $key => $val) {
|
||||
if(property_exists($class, $key)) {
|
||||
$this->$key = $val;
|
||||
}
|
||||
public function __construct($data) {
|
||||
$class = get_class($this);
|
||||
foreach($data as $key => $val) {
|
||||
if(property_exists($class, $key)) {
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function url_slug($text) {
|
||||
$text = strtolower($text);
|
||||
$text = preg_replace('/\b([a-z]{1,3})\b/u', '', $text);
|
||||
$text = preg_replace('/[^\w_\+\s]/', '', $text);
|
||||
$text = preg_replace('/\s+/', '-', $text);
|
||||
return trim(strtolower($text), '-');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,65 @@
|
||||
|
||||
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 $url;
|
||||
public $title;
|
||||
|
||||
public function __construct($data, $urlPrefix = '/') {
|
||||
parent::__construct($data);
|
||||
if($this->url) { $this->url = $urlPrefix . $this->url; }
|
||||
}
|
||||
}
|
||||
|
||||
class NewsItem extends Model {
|
||||
public $id;
|
||||
public $title;
|
||||
public $content;
|
||||
public $published;
|
||||
public $edited;
|
||||
public $images;
|
||||
public $edited;
|
||||
public $keywords;
|
||||
|
||||
public function __construct($data) {
|
||||
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->image = new stdClass();
|
||||
//$this->image->url = "";
|
||||
//$this->image->title = $this->title;
|
||||
$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;
|
||||
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user