File: D:/HostingSpaces/SBogers64/klimroosbudel.nl/wwwroot/app/models/m_agenda.class.php
<?php
/**
* m_news.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 11/02/14
*/
class Agenda_Model extends Site_Model
{
public function __construct()
{
parent::__construct();
}
/*
* Get News data
*/
public function get()
{
// Set name
$this->set('_name', strtolower('agenda'));
$this->set('_pageId', 1);
// Get data
$data = $this->getTableData(['date', 'ASC']);
return $data;
}
/*
* Create output
*/
public function create($thisYear = null)
{
$output = '';
// Filter by month
$months = [];
foreach ($this->get() as $item) {
$year = date('Y', $item['date']);
if ($thisYear == null) {
$thisYear = date('Y');
}
if ($year == $thisYear) {
$month = date('n', $item['date']);
$months[$month][] = $item;
}
}
$names = ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'];
// Get output by month
for ($i = 1; $i <= 12; $i++) {
$nr = str_pad($i, 2, 0, STR_PAD_LEFT);
if (($thisYear == date('Y') && $i >= date('n')) ||
($thisYear > date('Y'))
) {
// Start month list
$output .= '<div class="col g3';
if ($i % 3 == 0 && $i != 1) {
$output .= ' last';
}
$output .= '">';
$output .= '<h2 class="agenda_title">'.$names[$i - 1].' <span class="month_nr">'.$nr.'</span></h2>';
if (isset($months[$i])) {
$output .= '<ul class="agenda_item">';
foreach ($months[$i] as $item) {
$day = date('d', $item['date']);
$output .= '<li><span class="date">'.$day.'</span><span>'.$item['title'].'</span><span class="clear"></span></li>';
}
$output .= '</ul>';
}
$output .= '</div>';
}
if ($i % 3 == 0 && $i != 1) {
$output .= '<div class="clear"></div>';
}
}
return $output;
}
}