1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Anax\Events;
|
4
|
|
|
|
5
|
|
|
/**
|
6
|
|
|
* A controller for Events.
|
7
|
|
|
*
|
8
|
|
|
*/
|
9
|
|
|
class EventController implements \Anax\DI\IInjectionAware
|
10
|
|
|
{
|
11
|
|
|
use \Anax\DI\TInjectable;
|
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* View the calendar.
|
16
|
|
|
*
|
17
|
|
|
* @return void
|
18
|
|
|
*/
|
19
|
|
|
public function initialize()
|
20
|
|
|
{
|
21
|
|
|
$this->events = new \Anax\Events\Event();
|
|
|
|
|
22
|
|
|
$this->events->setDI($this->di);
|
|
|
|
|
23
|
|
|
}
|
24
|
|
|
|
25
|
|
|
/**
|
26
|
|
|
* Initialize the controller.
|
27
|
|
|
*
|
28
|
|
|
* @return void
|
29
|
|
|
*/
|
30
|
|
|
|
31
|
|
|
public function viewAction(){
|
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->initialize();
|
34
|
|
|
$calendar = new \Anax\Calendar\CCalendar();
|
35
|
|
|
$calendar->getValues();
|
36
|
|
|
$calendar->generateCalenderData();
|
37
|
|
|
$month = $calendar->getMonthNumber();
|
38
|
|
|
$year = $calendar->getYear();
|
39
|
|
|
|
40
|
|
|
$date = $this->dispatcher->getParam('date');
|
|
|
|
|
41
|
|
|
$_GET = array();
|
42
|
|
|
$currentDate = $year ."-". $month ."-". sprintf('%02s',$date);
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
$events = $this->events->findEventsOfDay($currentDate);
|
46
|
|
|
$eventCount = $this->events->getEventCountPerDayOfMonth($month);
|
47
|
|
|
|
48
|
|
|
$form = new \Mos\HTMLForm\CForm();
|
49
|
|
|
|
50
|
|
|
$form = $form->create([], [
|
51
|
|
|
'title' => [
|
52
|
|
|
'type' => 'text',
|
53
|
|
|
'label' => 'Title',
|
54
|
|
|
'required' => true,
|
55
|
|
|
'validation' => ['not_empty'],
|
56
|
|
|
],
|
57
|
|
|
'time' => [
|
58
|
|
|
'type' => 'date',
|
59
|
|
|
'label' => 'Date for event',
|
60
|
|
|
'required' => true,
|
61
|
|
|
'validation' => ['not_empty'],
|
62
|
|
|
],
|
63
|
|
|
'content' => [
|
64
|
|
|
'type' => 'textarea',
|
65
|
|
|
'label' => 'Content',
|
66
|
|
|
'required' => true,
|
67
|
|
|
'validation' => ['not_empty'],
|
68
|
|
|
],
|
69
|
|
|
'submit' => [
|
70
|
|
|
'type' => 'submit',
|
71
|
|
|
'callback' => function($form) {
|
72
|
|
|
$form->saveInSession = true;
|
73
|
|
|
return true;
|
74
|
|
|
}
|
75
|
|
|
],
|
76
|
|
|
]);
|
77
|
|
|
|
78
|
|
|
// Check the status of the form
|
79
|
|
|
$status = $form->check();
|
80
|
|
|
|
81
|
|
View Code Duplication |
if ($status === true) {
|
|
|
|
|
82
|
|
|
|
83
|
|
|
$this->dispatcher->forward([
|
|
|
|
|
84
|
|
|
'controller' => 'event',
|
85
|
|
|
'action' => 'add',
|
86
|
|
|
]);
|
87
|
|
|
|
88
|
|
|
} else if ($status === false) {
|
89
|
|
|
|
90
|
|
|
var_dump('Check method returned false');
|
|
|
|
|
91
|
|
|
die;
|
|
|
|
|
92
|
|
|
}
|
93
|
|
|
|
94
|
|
|
$this->views->add('calendar/calendar', [
|
|
|
|
|
95
|
|
|
'content' => $calendar->printResponsiveCalendar($eventCount),
|
96
|
|
|
'form' => $form->getHTML(),
|
97
|
|
|
'events' => $events,
|
98
|
|
|
]);
|
99
|
|
|
|
100
|
|
|
}
|
101
|
|
|
|
102
|
|
|
public function addAction(){
|
103
|
|
|
|
104
|
|
|
$now = gmdate('Y-m-d H:i:s');
|
105
|
|
|
|
106
|
|
|
$calendar = new \Anax\Calendar\CCalendar();
|
107
|
|
|
$calendar->getValues();
|
108
|
|
|
$calendar->generateCalenderData();
|
109
|
|
|
$month = $calendar->getMonth();
|
110
|
|
|
$year = $calendar->getYear();
|
111
|
|
|
$day = $this->request->getPost('time');
|
|
|
|
|
112
|
|
|
|
113
|
|
|
$this->events->save([
|
114
|
|
|
'id' => $this->request->getPost('id'),
|
|
|
|
|
115
|
|
|
'title' => $this->request->getPost('title'),
|
|
|
|
|
116
|
|
|
'showdate' => $this->request->getPost('time'),
|
|
|
|
|
117
|
|
|
'content' => $this->request->getPost('content'),
|
|
|
|
|
118
|
|
|
'created' => $now,
|
119
|
|
|
]);
|
120
|
|
|
$redirect = "calendar?month=$month&year=$year&date=$day";
|
121
|
|
|
$url = $this->url->create($redirect);
|
|
|
|
|
122
|
|
|
$this->response->redirect($url);
|
|
|
|
|
123
|
|
|
|
124
|
|
|
}
|
125
|
|
|
|
126
|
|
|
public function findEventsAction()
|
127
|
|
|
{
|
128
|
|
|
|
129
|
|
|
$this->initialize();
|
130
|
|
|
|
131
|
|
|
$reslut = $this->events->findEventsOfDay();
|
132
|
|
|
|
133
|
|
|
$this->views->add('calendar/calendar', [
|
|
|
|
|
134
|
|
|
'events' => $reslut,
|
135
|
|
|
]);
|
136
|
|
|
|
137
|
|
|
$url = $this->url->create('calendar');
|
|
|
|
|
138
|
|
|
$this->response->redirect($url);
|
|
|
|
|
139
|
|
|
|
140
|
|
|
|
141
|
|
|
}
|
142
|
|
|
public function deleteAction($id = null)
|
143
|
|
|
{
|
144
|
|
|
$this->initialize();
|
145
|
|
|
|
146
|
|
|
if (!isset($id)) {
|
147
|
|
|
die("Missing id");
|
|
|
|
|
148
|
|
|
}
|
149
|
|
|
|
150
|
|
|
$this->events->delete($id);
|
151
|
|
|
|
152
|
|
|
$url = $this->url->create('calendar');
|
|
|
|
|
153
|
|
|
$this->response->redirect($url);
|
|
|
|
|
154
|
|
|
}
|
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function idAction($id = null)
|
158
|
|
|
{
|
159
|
|
|
$this->initialize();
|
160
|
|
|
|
161
|
|
|
$event = $this->events->find($id);
|
162
|
|
|
|
163
|
|
|
$form = new \Mos\HTMLForm\CForm();
|
164
|
|
|
|
165
|
|
|
$form = $form->create([], [
|
166
|
|
|
'id' => [
|
167
|
|
|
'type' => 'hidden',
|
168
|
|
|
'required' => true,
|
169
|
|
|
'validation' => ['not_empty'],
|
170
|
|
|
'value' => $id
|
171
|
|
|
],
|
172
|
|
|
'title' => [
|
173
|
|
|
'class' => 'form-control',
|
174
|
|
|
'type' => 'text',
|
175
|
|
|
'label' => 'Title',
|
176
|
|
|
'value' => $event->title,
|
177
|
|
|
'required' => true,
|
178
|
|
|
'validation' => ['not_empty'],
|
179
|
|
|
],
|
180
|
|
|
'time' => [
|
181
|
|
|
'class' => 'form-control',
|
182
|
|
|
'type' => 'date',
|
183
|
|
|
'label' => 'Date for event',
|
184
|
|
|
'value' => $event->showdate,
|
185
|
|
|
'required' => true,
|
186
|
|
|
'validation' => ['not_empty'],
|
187
|
|
|
],
|
188
|
|
|
'content' => [
|
189
|
|
|
'class' => 'form-control',
|
190
|
|
|
'type' => 'textarea',
|
191
|
|
|
'label' => 'Content',
|
192
|
|
|
'value' => $event->content,
|
193
|
|
|
'required' => true,
|
194
|
|
|
'validation' => ['not_empty'],
|
195
|
|
|
],
|
196
|
|
|
'submit' => [
|
197
|
|
|
'class' => 'btn btn-default',
|
198
|
|
|
'type' => 'submit',
|
199
|
|
|
'value' => 'Update',
|
200
|
|
|
'callback' => function($form) {
|
201
|
|
|
$form->saveInSession = true;
|
202
|
|
|
return true;
|
203
|
|
|
}
|
204
|
|
|
],
|
205
|
|
|
]);
|
206
|
|
|
|
207
|
|
|
// Check the status of the form
|
208
|
|
|
$status = $form->check();
|
209
|
|
|
|
210
|
|
|
if ($status === true) {
|
211
|
|
|
|
212
|
|
|
$this->dispatcher->forward([
|
|
|
|
|
213
|
|
|
'controller' => 'event',
|
214
|
|
|
'action' => 'add',
|
215
|
|
|
'params' => ['id' => $id],
|
216
|
|
|
]);
|
217
|
|
|
|
218
|
|
|
} else if ($status === false) {
|
219
|
|
|
|
220
|
|
|
var_dump('Check method returned false');
|
|
|
|
|
221
|
|
|
die;
|
|
|
|
|
222
|
|
|
}
|
223
|
|
|
|
224
|
|
|
$this->theme->setTitle("View event with id");
|
|
|
|
|
225
|
|
|
$this->views->add('calendar/view', [
|
|
|
|
|
226
|
|
|
'event' => $event,
|
227
|
|
|
'form' => $form->getHTML()
|
228
|
|
|
]);
|
229
|
|
|
}
|
230
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: