50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Model;
|
|
|
|
class Model {
|
|
protected function ConvertToDateTime(&$field) {
|
|
if($field) {
|
|
// PHP7 JSON-encodes to {date: "", "timezone_type": ..., "timezone": "UTC" }
|
|
// In that case $field will be an object
|
|
if(is_object($field)) {
|
|
$field = ($field->timezone)
|
|
? new \DateTime($field->date, new \DateTimeZone($field->timezone))
|
|
: (new \DateTime($field->date));
|
|
} else {
|
|
// If $field is not an object, assume it's a plain, valid, string
|
|
$field = new \DateTime($field);
|
|
}
|
|
|
|
if($field === false || $field->getTimestamp() == 0) {
|
|
// If field had data but is invalid DateTime or is 0000-00-00 00:00, set it to null.
|
|
$field = null;
|
|
} else {
|
|
// If valid, return local timezone
|
|
$field->setTimezone(new \DateTimeZone("Europe/Amsterdam"));
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $text);
|
|
$search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
|
|
$replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");
|
|
$text = str_replace($search, $replace, $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), '-');
|
|
}
|
|
}
|