-
Notifications
You must be signed in to change notification settings - Fork 0
/
FullCalendar.php
executable file
·241 lines (238 loc) · 6.95 KB
/
FullCalendar.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
/**
* FullCalendar Nodule Class
*
* NOLOH Nodule Wrapper of Adam Shaw's FullCalendar
* http://arshaw.com/fullcalendar/
*
* Licensed Under MIT License
* http://www.opensource.org/licenses/mit-license.html
*/
class FullCalendar extends Panel
{
private static $CalendarPath = 'fullcalendar-1.5.3';
/**
* Types of Calendar Views
*/
const Month = 'month', Week = 'week', BasicWeek = 'basicWeek',
BasicDay = 'basicDay', AgendaWeek = 'agendaWeek', AgendaDay = 'agendaDay';
/**
* Information pertaining to an event that was triggered on the Calendar
*
* @var mixed
*/
public static $Data;
/**
* Synched Event Data
* @var mixed
*/
private $EventData;
/**
* Array holder for Configuration options
*
* @var array(arrays)
*/
private $Config;
/**
* ArrayList of Events.
*
* @var ImplicitArrayList
*/
private $Events;
/**
* Constructor
*
* @param self::Month|self::Week|self::BasicWeek|self::BasicDay|self::AgendaWeek|self::AgendaDay|array(types) $type
* @param integer $left
* @param integer $top
* @param mixed $width
* @param mixed $height
* @return Highcharts
*/
function __construct($type=self::Month, $left=0, $top=0, $width=900, $height=707)
{
parent::Panel($left, $top, $width, $height);
$this->Events = new ImplicitArrayList($this, 'AddEvent', 'RemoveEventAt', 'ClearEvents');
$this->SetDefaults();
$this->SetType($type);
}
/**
* Sets the defaults of this tinyMCE instance
*/
private function SetDefaults()
{
$this->Config = array();
$this->Config['dayClick'] = ClientScript::Raw("function(date, allDay){_NSet('$this', '_NEventData', '{\"date\" : \"' + date + '\", \"allDay\" : ' + allDay + ', \"rand\" : ' + Math.random() + '}'); if(_N('$this').DayClick){_N('$this').DayClick()}}");
$this->Config['eventClick'] = ClientScript::Raw("function(calEvent){_NSet('$this', '_NEventData', JSON.stringify(calEvent, function(k,v){return k == 'source'?Math.random():v})); if(_N('$this').EventClick){_N('$this').EventClick()}}");
$this->SetHeaderTemplate();
}
/**
* Set a FullCalendar configuration option. See {@link http://arshaw.com/fullcalendar/docs/} for all options.
*
* @param array(arrays)|string $option
* @param mixed $value
*/
function SetConfig($option, $value=null)
{
if(is_array($option) && !$value)
{
$this->Config = $option;
}
else
$this->Config[$option] = $value;
// $this->Refresh();
}
function GetConfig() {return $this->Config;}
/**
* Re-renders the FullCalendar instance. In most cases there is no need to call manually.
*/
function Refresh($firstTime=false)
{
if(!$firstTime && $this->ShowStatus == Component::Shown)
{
ClientScript::RaceQueue($this, 'jQuery.fullCalendar', "\$('#{$this}').fullCalendar", array('destroy'));
}
elseif($this->ShowStatus != Component::Shown)
return;
ClientScript::RaceQueue($this, 'jQuery.fullCalendar', "\$('#{$this}').fullCalendar", array($this->Config));
}
public function GetEvents() {return $this->Events;}
/**
* Returns the Event associated with a Calendar day being clicked
* @return Event
*/
function GetDayClick()
{
return $this->GetEvent('DayClick');
}
/**
* Sets the Event associated with a Calendar day being clicked
* @param Event $event
*/
function SetDayClick($event)
{
return $this->SetEvent($event, 'DayClick');
}
/**
* Returns the Event associated with a Calendar's Event being clicked
* @return Event
*/
function GetEventClick()
{
return $this->GetEvent('EventClick');
}
/**
* Sets the Event associated with a Calendar's Event being clicked
* @param Event $event
*/
function SetEventClick($event)
{
return $this->SetEvent($event, 'EventClick');
}
/**
* Called by Events ImplicitArrayList when adding an event
*
* @param array|FullCalendarEvent $event
*/
function AddEvent($event)
{
if(is_array($event))
$event = new FullCalendarEvent($event);
if(!$event instanceof FullCalendarEvent)
throw new Exception('Event must be an arrray or FullCalendarEvent object');
if($this->ShowStatus == Component::Shown)
{
ClientScript::RaceQueue($this, 'jQuery.fullCalendar', "\$('#{$this}').fullCalendar", array('addEventSource', array($event->Properties)));
}
else
{
$this->Config['events'][] = $event->Properties;
}
$this->Events->Add($event, true);
}
/**
* Called by Events ImplicitArrayList when Clearing an Events
*
* @param array|FullCalendarEvent $event
*/
function ClearEvents()
{
if($this->ShowStatus == Component::Shown)
{
ClientScript::RaceQueue($this, 'jQuery.fullCalendar', "\$('#{$this}').fullCalendar", array('removeEvents'));
}
$this->Events->Clear(true);
}
/**
* Sets the type of Calendar, whether it's month, week, day, agenda, etc.
* If an array of types are passed in buttons will be added for each type
* with the default being the first specified type
*
* @param self::Month|self::Week|self::BasicWeek|self::BasicDay|self::AgendaWeek|self::AgendaDay|array(types) $type
*/
function SetType($type)
{
if(is_array($type))
{
$right = implode(',', $type);
$this->Config['defaultView'] = $type[0];
if(isset($this->Config['header']['right']))
$right = ', ' . $right;
$this->Config['header']['right'] .= $right;
}
else
{
$right = $type;
$this->Config['defaultView'] = $type;
}
$this->Refresh();
}
/**
* @ignore
*/
public function Set_NEventData($data)
{
$this->EventData = json_decode($data, true);
self::$Data = $this->EventData;
}
/**
* Sets the Header Template
*/
function SetHeaderTemplate($left = 'title', $center = '', $right = 'today prev,next')
{
$this->Config['header']['left'] = $left;
$this->Config['header']['center'] = $center;
$this->Config['header']['right'] = $right;
$this->Refresh();
}
/**
* Do not call manually! Override of default Show(). Triggers when FullCalendar instance is initially shown.
*/
function Show()
{
parent::Show();
$relativePath = System::GetRelativePath(getcwd(), dirname(__FILE__));
//Add FullCalendar CSS
WebPage::That()->CSSFiles->Add($relativePath . '/Vendor/' . self::$CalendarPath . '/fullcalendar/fullcalendar.css');
//Add FullCalendar script files
ClientScript::AddSource($relativePath . 'Vendor/' . self::$CalendarPath . '/jquery/' . 'jquery-1.7.2.min.js', false);
ClientScript::AddSource($relativePath . 'Vendor/' . self::$CalendarPath . '/jquery/' . 'jquery-1.7.2.min.js', false);
ClientScript::RaceAddSource('jQuery', $relativePath . 'Vendor/' . self::$CalendarPath . '/fullcalendar/' . 'fullcalendar.min.js');
$this->Refresh(true);
}
/**
* Generic function handler to handle for native non-handled FullCalendar calls.
* For example: ChangeView(), Prev(), Next(), PrevYear(), NextYear(), Today(), GoToDate(), IncrementDate(), GetDate()
*
* @param string $name Name of method you wish to call
* @param mixed $args Method arguments
*/
function __call($name, $args)
{
if($this->HasMethod($name))
parent::__call($name, $args);
else
ClientScript::RaceQueue($this, 'jQuery.fullCalendar', "\$('#{$this}').fullCalendar." . lcfirst($name) , $args);
}
}
?>