67 lines
1.9 KiB
PHP
67 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Model;
|
|
|
|
class CalendarEvent extends Model {
|
|
public $id;
|
|
public $title;
|
|
public $region;
|
|
public $content;
|
|
public $starts;
|
|
public $ends;
|
|
public $images;
|
|
public $podcast;
|
|
public $video;
|
|
public $keywords;
|
|
public $url;
|
|
public $metadata;
|
|
|
|
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 = "/agenda/{$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 = isset($this->images) && 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>';
|
|
}
|
|
}
|