ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSessionAppointment.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
6include_once('./Services/Calendar/classes/class.ilDate.php');
16{
17 public $ilErr;
18 public $ilDB;
19 public $tree;
20 public $lng;
21
22 protected $start = null;
23 protected $end = null;
24
25 public $starting_time = null;
26 public $ending_time = null;
27
32 public function __construct($a_appointment_id = null)
33 {
34 global $DIC;
35
36 $ilErr = $DIC['ilErr'];
37 $ilDB = $DIC['ilDB'];
38 $lng = $DIC['lng'];
39 $tree = $DIC['tree'];
40
41 $this->ilErr = $ilErr;
42 $this->db = $ilDB;
43 $this->lng = $lng;
44
45 $this->appointment_id = $a_appointment_id;
46 $this->__read();
47 }
48
56 public static function _lookupAppointment($a_obj_id)
57 {
58 global $DIC;
59
60 $ilDB = $DIC['ilDB'];
61
62 $query = "SELECT * FROM event_appointment " .
63 "WHERE event_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
64 $res = $ilDB->query($query);
65 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
66 $info['fullday'] = $row->fulltime;
67
68 $date = new ilDateTime($row->e_start, IL_CAL_DATETIME, 'UTC');
69 $info['start'] = $date->getUnixTime();
70 $date = new ilDateTime($row->e_end, IL_CAL_DATETIME, 'UTC');
71 $info['end'] = $date->getUnixTime();
72
73 return $info;
74 }
75 return array();
76 }
77
86 public static function lookupNextSessionByCourse($a_ref_id)
87 {
88 global $DIC;
89
90 $tree = $DIC['tree'];
91 $ilDB = $DIC['ilDB'];
92
93
94 $sessions = $tree->getChildsByType($a_ref_id, 'sess');
95 $obj_ids = array();
96 foreach ($sessions as $tree_data) {
97 $obj_ids[] = $tree_data['obj_id'];
98 }
99 if (!count($obj_ids)) {
100 return false;
101 }
102
103 // Try to read the next sessions within the next 24 hours
104 $now = new ilDate(time(), IL_CAL_UNIX);
105 $tomorrow = clone $now;
106 $tomorrow->increment(IL_CAL_DAY, 2);
107
108 $query = "SELECT event_id FROM event_appointment " .
109 "WHERE e_start > " . $ilDB->quote($now->get(IL_CAL_DATE, 'timestamp')) . ' ' .
110 "AND e_start < " . $ilDB->quote($tomorrow->get(IL_CAL_DATE, 'timestamp')) . ' ' .
111 "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . ' ' .
112 "ORDER BY e_start ";
113
114 $event_ids = array();
115
116 $res = $ilDB->query($query);
117 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118 $event_ids[] = $row->event_id;
119 }
120
121 if (count($event_ids)) {
122 return $event_ids;
123 }
124
125 // Alternativ: get next event.
126 $query = "SELECT event_id FROM event_appointment " .
127 "WHERE e_start > " . $ilDB->now() . " " .
128 "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . " " .
129 "ORDER BY e_start ";
130 $ilDB->setLimit(1);
131 $res = $ilDB->query($query);
132 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
133 $event_id = $row->event_id;
134 }
135 return isset($event_id) ? array($event_id) : array();
136 }
137
146 public static function lookupLastSessionByCourse($a_ref_id)
147 {
148 global $DIC;
149
150 $tree = $DIC['tree'];
151 $ilDB = $DIC['ilDB'];
152
153 $sessions = $tree->getChildsByType($a_ref_id, 'sess');
154 $obj_ids = array();
155 foreach ($sessions as $tree_data) {
156 $obj_ids[] = $tree_data['obj_id'];
157 }
158 if (!count($obj_ids)) {
159 return false;
160 }
161 $query = "SELECT event_id FROM event_appointment " .
162 "WHERE e_start < " . $ilDB->now() . " " .
163 "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . " " .
164 "ORDER BY e_start DESC ";
165 $ilDB->setLimit(1);
166 $res = $ilDB->query($query);
167 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
168 $event_id = $row->event_id;
169 }
170 return isset($event_id) ? $event_id : 0;
171 }
172
173 // Interface methods
181 public function isFullday()
182 {
183 return $this->enabledFullTime();
184 }
185
193 public function getStart()
194 {
195 return $this->start ? $this->start : $this->start = new ilDateTime(date('Y-m-d') . ' 08:00:00', IL_CAL_DATETIME);
196 }
197
204 public function setStart($a_start)
205 {
206 $this->start = $a_start;
207 }
208
215 public function getEnd()
216 {
217 return $this->end ? $this->end : $this->end = new ilDateTime(date('Y-m-d') . ' 16:00:00', IL_CAL_DATETIME);
218 }
219
227 public function setEnd($a_end)
228 {
229 $this->end = $a_end;
230 }
231
232 public function setAppointmentId($a_appointment_id)
233 {
234 $this->appointment_id = $a_appointment_id;
235 }
236 public function getAppointmentId()
237 {
238 return $this->appointment_id;
239 }
240
241 public function setSessionId($a_session_id)
242 {
243 $this->session_id = $a_session_id;
244 }
245 public function getSessionId()
246 {
247 return $this->session_id;
248 }
249
250 public function setStartingTime($a_starting_time)
251 {
252 $this->starting_time = $a_starting_time;
253 $this->start = new ilDateTime($this->starting_time, IL_CAL_UNIX);
254 }
255 public function getStartingTime()
256 {
257 return isset($this->starting_time) ? $this->starting_time : mktime(8, 0, 0, date('n', time()), date('d', time()), date('Y', time()));
258 }
259
260 public function setEndingTime($a_ending_time)
261 {
262 $this->ending_time = $a_ending_time;
263 $this->end = new ilDateTime($this->ending_time, IL_CAL_UNIX);
264 }
265 public function getEndingTime()
266 {
267 return isset($this->ending_time) ? $this->ending_time : mktime(16, 0, 0, date('n', time()), date('d', time()), date('Y', time()));
268 }
269
270 public function toggleFullTime($a_status)
271 {
272 $this->fulltime = $a_status;
273 }
274 public function enabledFullTime()
275 {
276 return $this->fulltime;
277 }
278
279 public function formatTime()
280 {
282 }
283
284 public function _timeToString($start, $end)
285 {
286 global $DIC;
287
288 $ilUser = $DIC['ilUser'];
289 $lng = $DIC['lng'];
290
291 $start = date($this->lng->txt('lang_timeformat_no_sec'), $start);
292 $end = date($this->lng->txt('lang_timeformat_no_sec'), $end);
293
294 return $start . ' - ' . $end;
295 }
296
297 public static function _appointmentToString($start, $end, $fulltime)
298 {
299 global $DIC;
300
301 $lng = $DIC['lng'];
302
303 if ($fulltime) {
306 #new ilDate($end,IL_CAL_UNIX)).' ('.$lng->txt('event_full_time_info').')';
308 );
309 } else {
313 );
314 }
315 }
316
317 public function appointmentToString()
318 {
320 }
321
329 public function cloneObject($new_id)
330 {
331 $new_app = new ilSessionAppointment();
332 $new_app->setSessionId($new_id);
333 $new_app->setStartingTime($this->getStartingTime());
334 $new_app->setEndingTime($this->getEndingTime());
335 $new_app->toggleFullTime($this->isFullday());
336 $new_app->create();
337 return $new_app;
338 }
339
340 public function create()
341 {
342 global $DIC;
343
344 $ilDB = $DIC['ilDB'];
345
346 if (!$this->getSessionId()) {
347 return false;
348 }
349 $next_id = $ilDB->nextId('event_appointment');
350 $query = "INSERT INTO event_appointment (appointment_id,event_id,e_start,e_end,fulltime) " .
351 "VALUES( " .
352 $ilDB->quote($next_id, 'integer') . ", " .
353 $ilDB->quote($this->getSessionId(), 'integer') . ", " .
354 $ilDB->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
355 $ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
356 $ilDB->quote($this->enabledFullTime(), 'integer') . " " .
357 ")";
358 $this->appointment_id = $next_id;
359 $res = $ilDB->manipulate($query);
360
361 return true;
362 }
363
364 public function update()
365 {
366 global $DIC;
367
368 $ilDB = $DIC['ilDB'];
369
370 if (!$this->getSessionId()) {
371 return false;
372 }
373 $query = "UPDATE event_appointment " .
374 "SET event_id = " . $ilDB->quote($this->getSessionId(), 'integer') . ", " .
375 "e_start = " . $ilDB->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
376 "e_end = " . $ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
377 "fulltime = " . $ilDB->quote($this->enabledFullTime(), 'integer') . " " .
378 "WHERE appointment_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . " ";
379 $res = $ilDB->manipulate($query);
380 return true;
381 }
382
383 public function delete()
384 {
386 }
387
388 public static function _delete($a_appointment_id)
389 {
390 global $DIC;
391
392 $ilDB = $DIC['ilDB'];
393
394 $query = "DELETE FROM event_appointment " .
395 "WHERE appointment_id = " . $ilDB->quote($a_appointment_id, 'integer') . " ";
396 $res = $ilDB->manipulate($query);
397
398 return true;
399 }
400
401 public static function _deleteBySession($a_event_id)
402 {
403 global $DIC;
404
405 $ilDB = $DIC['ilDB'];
406
407 $query = "DELETE FROM event_appointment " .
408 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
409 $res = $ilDB->manipulate($query);
410
411 return true;
412 }
413
414 public static function _readAppointmentsBySession($a_event_id)
415 {
416 global $DIC;
417
418 $ilDB = $DIC['ilDB'];
419
420 $query = "SELECT * FROM event_appointment " .
421 "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
422 "ORDER BY starting_time";
423
424 $res = $ilDB->query($query);
425 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
426 $appointments[] = new ilSessionAppointment($row->appointment_id);
427 }
428 return is_array($appointments) ? $appointments : array();
429 }
430
431 public function validate()
432 {
433 if ($this->starting_time > $this->ending_time) {
434 $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
435 return false;
436 }
437 return true;
438 }
439
440 // PRIVATE
441 public function __read()
442 {
443 global $DIC;
444
445 $ilDB = $DIC['ilDB'];
446
447 if (!$this->getAppointmentId()) {
448 return null;
449 }
450
451 $query = "SELECT * FROM event_appointment " .
452 "WHERE appointment_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . " ";
453 $res = $this->db->query($query);
454 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
455 $this->setSessionId($row->event_id);
456 $this->toggleFullTime($row->fulltime);
457
458 if ($this->isFullday()) {
459 $this->start = new ilDate($row->e_start, IL_CAL_DATETIME);
460 $this->end = new ilDate($row->e_end, IL_CAL_DATETIME);
461 } else {
462 $this->start = new ilDateTime($row->e_start, IL_CAL_DATETIME, 'UTC');
463 $this->end = new ilDateTime($row->e_end, IL_CAL_DATETIME, 'UTC');
464 }
465 $this->starting_time = $this->start->getUnixTime();
466 $this->ending_time = $this->end->getUnixTime();
467 }
468 return true;
469 }
470}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const IL_CAL_DAY
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Class for single dates.
class ilSessionAppointment
cloneObject($new_id)
clone appointment
static _readAppointmentsBySession($a_event_id)
static lookupLastSessionByCourse($a_ref_id)
@access public
static _delete($a_appointment_id)
__construct($a_appointment_id=null)
Consructor.
static _lookupAppointment($a_obj_id)
lookup appointment
static _appointmentToString($start, $end, $fulltime)
static _deleteBySession($a_event_id)
static lookupNextSessionByCourse($a_ref_id)
@access public
$query
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46