Agenda toegevoegd (/agenda/overzicht/{week,maand,alles} en /agenda/details/:id)
This commit is contained in:
40
common/classes/CalendarEvent.php
Normal file
40
common/classes/CalendarEvent.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
class CalendarEvent extends Model {
|
||||
public $id;
|
||||
public $title;
|
||||
public $region;
|
||||
public $content;
|
||||
public $starts;
|
||||
public $ends;
|
||||
public $images;
|
||||
public $url;
|
||||
|
||||
public function __construct($data, $images = null) {
|
||||
parent::__construct($data);
|
||||
parent::ConvertToDateTime($this->starts);
|
||||
parent::ConvertToDateTime($this->ends);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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>';
|
||||
}
|
||||
}
|
||||
@@ -36,14 +36,25 @@ class Model {
|
||||
}
|
||||
|
||||
public function url_slug($text) {
|
||||
// Alles naar kleine letter
|
||||
$text = strtolower($text);
|
||||
|
||||
// Vervang accent-tekens door niet-geaccentueerde versies
|
||||
// $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);
|
||||
|
||||
// Verwijder alle woorden van 3 letters, behalve BEL (BEL-combinatie etc)
|
||||
$text = preg_replace('/\b(?!bel)([a-z]{1,3})\b/u', '', $text);
|
||||
|
||||
// Vervang alles dat niet een woord-karakter is (letter, cijfer), een streepje of spatie
|
||||
$text = preg_replace('/[^\w_\-\s]/', '', $text);
|
||||
|
||||
// Reeksen van één of meer spaties / streepjes vervangen door een enkel streepje
|
||||
$text = preg_replace('/[\-\s]+/', '-', $text);
|
||||
|
||||
// Verwijder alle witruimte / streepjes aan begin en eind
|
||||
return trim(strtolower($text), '-');
|
||||
}
|
||||
}
|
||||
|
||||
19
common/classes/NewsImage.php
Normal file
19
common/classes/NewsImage.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,33 +2,8 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
require "NewsImage.php";
|
||||
require "NewsSource.php";
|
||||
|
||||
class NewsItem extends Model {
|
||||
public $id;
|
||||
|
||||
15
common/classes/NewsSource.php
Normal file
15
common/classes/NewsSource.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user