Lumen opgezet met eenvoudige modelklasse

This commit is contained in:
2017-06-05 15:36:05 +02:00
commit ebecdcc485
4297 changed files with 495115 additions and 0 deletions

23
common/classes/Model.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace Model;
class Model {
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;
}
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Model;
class NewsItem extends Model {
public $id;
public $title;
public $content;
public $published;
public $edited;
public $images;
public function __construct($data) {
parent::__construct($data);
parent::ConvertToDateTime($this->published);
parent::ConvertToDateTime($this->edited);
//$this->image = new stdClass();
//$this->image->url = "";
//$this->image->title = $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>';
}
}