ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
6 include_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 $ilErr,$ilDB,$lng,$tree;
35 
36  $this->ilErr = $ilErr;
37  $this->db = $ilDB;
38  $this->lng = $lng;
39 
40  $this->appointment_id = $a_appointment_id;
41  $this->__read();
42  }
43 
51  public static function _lookupAppointment($a_obj_id)
52  {
53  global $ilDB;
54 
55  $query = "SELECT * FROM event_appointment " .
56  "WHERE event_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
57  $res = $ilDB->query($query);
58  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
59  $info['fullday'] = $row->fulltime;
60 
61  $date = new ilDateTime($row->e_start, IL_CAL_DATETIME, 'UTC');
62  $info['start'] = $date->getUnixTime();
63  $date = new ilDateTime($row->e_end, IL_CAL_DATETIME, 'UTC');
64  $info['end'] = $date->getUnixTime();
65 
66  return $info;
67  }
68  return array();
69  }
70 
79  public static function lookupNextSessionByCourse($a_ref_id)
80  {
81  global $tree,$ilDB;
82 
83 
84  $sessions = $tree->getChildsByType($a_ref_id, 'sess');
85  $obj_ids = array();
86  foreach ($sessions as $tree_data) {
87  $obj_ids[] = $tree_data['obj_id'];
88  }
89  if (!count($obj_ids)) {
90  return false;
91  }
92 
93  // Try to read the next sessions within the next 24 hours
94  $now = new ilDate(time(), IL_CAL_UNIX);
95  $tomorrow = clone $now;
96  $tomorrow->increment(IL_CAL_DAY, 2);
97 
98  $query = "SELECT event_id FROM event_appointment " .
99  "WHERE e_start > " . $ilDB->quote($now->get(IL_CAL_DATE, 'timestamp')) . ' ' .
100  "AND e_start < " . $ilDB->quote($tomorrow->get(IL_CAL_DATE, 'timestamp')) . ' ' .
101  "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . ' ' .
102  "ORDER BY e_start ";
103 
104  $event_ids = array();
105 
106  $res = $ilDB->query($query);
107  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
108  $event_ids[] = $row->event_id;
109  }
110 
111  if (count($event_ids)) {
112  return $event_ids;
113  }
114 
115  // Alternativ: get next event.
116  $query = "SELECT event_id FROM event_appointment " .
117  "WHERE e_start > " . $ilDB->now() . " " .
118  "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . " " .
119  "ORDER BY e_start ";
120  $ilDB->setLimit(1);
121  $res = $ilDB->query($query);
122  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
123  $event_id = $row->event_id;
124  }
125  return isset($event_id) ? array($event_id) : array();
126  }
127 
136  public static function lookupLastSessionByCourse($a_ref_id)
137  {
138  global $tree,$ilDB;
139 
140  $sessions = $tree->getChildsByType($a_ref_id, 'sess');
141  $obj_ids = array();
142  foreach ($sessions as $tree_data) {
143  $obj_ids[] = $tree_data['obj_id'];
144  }
145  if (!count($obj_ids)) {
146  return false;
147  }
148  $query = "SELECT event_id FROM event_appointment " .
149  "WHERE e_start < " . $ilDB->now() . " " .
150  "AND " . $ilDB->in('event_id', $obj_ids, false, 'integer') . " " .
151  "ORDER BY e_start DESC ";
152  $ilDB->setLimit(1);
153  $res = $ilDB->query($query);
154  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
155  $event_id = $row->event_id;
156  }
157  return isset($event_id) ? $event_id : 0;
158  }
159 
160  // Interface methods
168  public function isFullday()
169  {
170  return $this->enabledFullTime();
171  }
172 
180  public function getStart()
181  {
182  return $this->start ? $this->start : $this->start = new ilDateTime(date('Y-m-d') . ' 08:00:00', IL_CAL_DATETIME);
183  }
184 
191  public function setStart($a_start)
192  {
193  $this->start = $a_start;
194  }
195 
202  public function getEnd()
203  {
204  return $this->end ? $this->end : $this->end = new ilDateTime(date('Y-m-d') . ' 16:00:00', IL_CAL_DATETIME);
205  }
206 
214  public function setEnd($a_end)
215  {
216  $this->end = $a_end;
217  }
218 
219  public function setAppointmentId($a_appointment_id)
220  {
221  $this->appointment_id = $a_appointment_id;
222  }
223  public function getAppointmentId()
224  {
225  return $this->appointment_id;
226  }
227 
228  public function setSessionId($a_session_id)
229  {
230  $this->session_id = $a_session_id;
231  }
232  public function getSessionId()
233  {
234  return $this->session_id;
235  }
236 
237  public function setStartingTime($a_starting_time)
238  {
239  $this->starting_time = $a_starting_time;
240  $this->start = new ilDateTime($this->starting_time, IL_CAL_UNIX);
241  }
242  public function getStartingTime()
243  {
244  return isset($this->starting_time) ? $this->starting_time : mktime(8, 0, 0, date('n', time()), date('d', time()), date('Y', time()));
245  }
246 
247  public function setEndingTime($a_ending_time)
248  {
249  $this->ending_time = $a_ending_time;
250  $this->end = new ilDateTime($this->ending_time, IL_CAL_UNIX);
251  }
252  public function getEndingTime()
253  {
254  return isset($this->ending_time) ? $this->ending_time : mktime(16, 0, 0, date('n', time()), date('d', time()), date('Y', time()));
255  }
256 
257  public function toggleFullTime($a_status)
258  {
259  $this->fulltime = $a_status;
260  }
261  public function enabledFullTime()
262  {
263  return $this->fulltime;
264  }
265 
266  public function formatTime()
267  {
269  }
270 
271  public function _timeToString($start, $end)
272  {
273  global $ilUser,$lng;
274 
275  $start = date($this->lng->txt('lang_timeformat_no_sec'), $start);
276  $end = date($this->lng->txt('lang_timeformat_no_sec'), $end);
277 
278  return $start . ' - ' . $end;
279  }
280 
281  public static function _appointmentToString($start, $end, $fulltime)
282  {
283  global $lng;
284 
285  if ($fulltime) {
287  new ilDate($start, IL_CAL_UNIX),
288  #new ilDate($end,IL_CAL_UNIX)).' ('.$lng->txt('event_full_time_info').')';
289  new ilDate($end, IL_CAL_UNIX)
290  );
291  } else {
295  );
296  }
297  }
298 
299  public function appointmentToString()
300  {
302  }
303 
311  public function cloneObject($new_id)
312  {
313  $new_app = new ilSessionAppointment();
314  $new_app->setSessionId($new_id);
315  $new_app->setStartingTime($this->getStartingTime());
316  $new_app->setEndingTime($this->getEndingTime());
317  $new_app->toggleFullTime($this->isFullday());
318  $new_app->create();
319  return $new_app;
320  }
321 
322  public function create()
323  {
324  global $ilDB;
325 
326  if (!$this->getSessionId()) {
327  return false;
328  }
329  $next_id = $ilDB->nextId('event_appointment');
330  $query = "INSERT INTO event_appointment (appointment_id,event_id,e_start,e_end,fulltime) " .
331  "VALUES( " .
332  $ilDB->quote($next_id, 'integer') . ", " .
333  $ilDB->quote($this->getSessionId(), 'integer') . ", " .
334  $ilDB->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
335  $ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
336  $ilDB->quote($this->enabledFullTime(), 'integer') . " " .
337  ")";
338  $this->appointment_id = $next_id;
339  $res = $ilDB->manipulate($query);
340 
341  return true;
342  }
343 
344  public function update()
345  {
346  global $ilDB;
347 
348  if (!$this->getSessionId()) {
349  return false;
350  }
351  $query = "UPDATE event_appointment " .
352  "SET event_id = " . $ilDB->quote($this->getSessionId(), 'integer') . ", " .
353  "e_start = " . $ilDB->quote($this->getStart()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
354  "e_end = " . $ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME, '', 'UTC'), 'timestamp') . ", " .
355  "fulltime = " . $ilDB->quote($this->enabledFullTime(), 'integer') . " " .
356  "WHERE appointment_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . " ";
357  $res = $ilDB->manipulate($query);
358  return true;
359  }
360 
361  public function delete()
362  {
364  }
365 
366  public static function _delete($a_appointment_id)
367  {
368  global $ilDB;
369 
370  $query = "DELETE FROM event_appointment " .
371  "WHERE appointment_id = " . $ilDB->quote($a_appointment_id, 'integer') . " ";
372  $res = $ilDB->manipulate($query);
373 
374  return true;
375  }
376 
377  public static function _deleteBySession($a_event_id)
378  {
379  global $ilDB;
380 
381  $query = "DELETE FROM event_appointment " .
382  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " ";
383  $res = $ilDB->manipulate($query);
384 
385  return true;
386  }
387 
388  public static function _readAppointmentsBySession($a_event_id)
389  {
390  global $ilDB;
391 
392  $query = "SELECT * FROM event_appointment " .
393  "WHERE event_id = " . $ilDB->quote($a_event_id, 'integer') . " " .
394  "ORDER BY starting_time";
395 
396  $res = $ilDB->query($query);
397  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
398  $appointments[] = new ilSessionAppointment($row->appointment_id);
399  }
400  return is_array($appointments) ? $appointments : array();
401  }
402 
403  public function validate()
404  {
405  if ($this->starting_time > $this->ending_time) {
406  $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
407  return false;
408  }
409  return true;
410  }
411 
412  // PRIVATE
413  public function __read()
414  {
415  global $ilDB;
416 
417  if (!$this->getAppointmentId()) {
418  return null;
419  }
420 
421  $query = "SELECT * FROM event_appointment " .
422  "WHERE appointment_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . " ";
423  $res = $this->db->query($query);
424  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
425  $this->setSessionId($row->event_id);
426  $this->toggleFullTime($row->fulltime);
427 
428  if ($this->isFullday()) {
429  $this->start = new ilDate($row->e_start, IL_CAL_DATETIME);
430  $this->end = new ilDate($row->e_end, IL_CAL_DATETIME);
431  } else {
432  $this->start = new ilDateTime($row->e_start, IL_CAL_DATETIME, 'UTC');
433  $this->end = new ilDateTime($row->e_end, IL_CAL_DATETIME, 'UTC');
434  }
435  $this->starting_time = $this->start->getUnixTime();
436  $this->ending_time = $this->end->getUnixTime();
437  }
438  return true;
439  }
440 }
const IL_CAL_DATETIME
static _delete($a_appointment_id)
const IL_CAL_UNIX
const IL_CAL_DAY
static _deleteBySession($a_event_id)
Class for single dates.
foreach($_POST as $key=> $value) $res
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static _appointmentToString($start, $end, $fulltime)
Date and time handling
$ilUser
Definition: imgupload.php:18
$query
cloneObject($new_id)
clone appointment
Create styles array
The data for the language used.
static lookupLastSessionByCourse($a_ref_id)
public
const IL_CAL_DATE
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
__construct($a_appointment_id=null)
Consructor.
static _lookupAppointment($a_obj_id)
lookup appointment
static _readAppointmentsBySession($a_event_id)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$info
Definition: index.php:5
static lookupNextSessionByCourse($a_ref_id)
public
class ilSessionAppointment