-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarControl.php
70 lines (54 loc) · 1.6 KB
/
CalendarControl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Description of CalendarControl
*
* @author Honza
*/
class CalendarControl extends Control {
/** @var int */
public $month;
/** @var int */
public $year;
protected function createTemplate() {
$template = parent::createTemplate();
$template->setFile(dirname(__FILE__) . "/calendar.phtml");
return $template;
}
public function setTemplateFile($filename) {
$this->getTemplate()->setFile($filename);
}
/**
* Render calendar
*/
public function render($mont = null, $year = null) {
if ($month === null) {
$month = $this->month ? $this->month : (int) date("n");
}
$this->setTemplate();
if ($year === null) {
$year = $this->year ? $this->year : (int) date("Y");
}
$template = $this->createTemplate();
$template->setFile();
$timestamp = mktime(0, 0, 0, $this->month, 1, $this->year);
// current date
$template->currentDay = date("j");
$template->currentMonth = date("n");
$template->currentYear = date("Y");
// days
$template->day = date("j", $timestamp);
$template->firstDay = date("N", $timestamp) - 1;
$template->daysInMonth = date("t", $timestamp);
// month
$template->month = $this->month;
$template->prevMonth = $this->month === 1 ? 12 : $this->month - 1;
$template->nextMonth = $this->month === 12 ? 1 : $this->month + 1;
// year
$template->year = $this->year;
$template->prevYear = $this->month === 1 ? $this->year - 1 : $this->year;
$template->nextYear = $this->month === 12 ? $this->year + 1 : $this->year;
// events
$template->events = $this->model->events->getMonthList($this->month, $this->year);
$template->render();
}
}