ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  var $ilErr;
18  var $ilDB;
19  var $tree;
20  var $lng;
21 
22  protected $start = null;
23  protected $end = null;
24 
25  var $starting_time = null;
26  var $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  {
60  $info['fullday'] = $row->fulltime;
61 
62  $date = new ilDateTime($row->e_start,IL_CAL_DATETIME,'UTC');
63  $info['start'] = $date->getUnixTime();
64  $date = new ilDateTime($row->e_end,IL_CAL_DATETIME,'UTC');
65  $info['end'] = $date->getUnixTime();
66 
67  return $info;
68  }
69  return array();
70  }
71 
80  public static function lookupNextSessionByCourse($a_ref_id)
81  {
82  global $tree,$ilDB;
83 
84 
85  $sessions = $tree->getChildsByType($a_ref_id,'sess');
86  $obj_ids = array();
87  foreach($sessions as $tree_data)
88  {
89  $obj_ids[] = $tree_data['obj_id'];
90  }
91  if(!count($obj_ids))
92  {
93  return false;
94  }
95 
96  // Try to read the next sessions within the next 24 hours
97  $now = new ilDate(time(),IL_CAL_UNIX);
98  $tomorrow = clone $now;
99  $tomorrow->increment(IL_CAL_DAY,2);
100 
101  $query = "SELECT event_id FROM event_appointment ".
102  "WHERE e_start > ".$ilDB->quote($now->get(IL_CAL_DATE,'timestamp')).' '.
103  "AND e_start < ".$ilDB->quote($tomorrow->get(IL_CAL_DATE,'timestamp')).' '.
104  "AND ".$ilDB->in('event_id',$obj_ids,false,'integer').' '.
105  "ORDER BY e_start ";
106 
107  $event_ids = array();
108 
109  $res = $ilDB->query($query);
110  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
111  {
112  $event_ids[] = $row->event_id;
113  }
114 
115  if(count($event_ids))
116  {
117  return $event_ids;
118  }
119 
120  // Alternativ: get next event.
121  $query = "SELECT event_id FROM event_appointment ".
122  "WHERE e_start > ".$ilDB->now()." ".
123  "AND ".$ilDB->in('event_id',$obj_ids,false,'integer')." ".
124  "ORDER BY e_start ";
125  $ilDB->setLimit(1);
126  $res = $ilDB->query($query);
127  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
128  {
129  $event_id = $row->event_id;
130  }
131  return isset($event_id) ? array($event_id) : array();
132  }
133 
142  public static function lookupLastSessionByCourse($a_ref_id)
143  {
144  global $tree,$ilDB;
145 
146  $sessions = $tree->getChildsByType($a_ref_id,'sess');
147  $obj_ids = array();
148  foreach($sessions as $tree_data)
149  {
150  $obj_ids[] = $tree_data['obj_id'];
151  }
152  if(!count($obj_ids))
153  {
154  return false;
155  }
156  $query = "SELECT event_id FROM event_appointment ".
157  "WHERE e_start < ".$ilDB->now()." ".
158  "AND ".$ilDB->in('event_id',$obj_ids,false,'integer')." ".
159  "ORDER BY e_start DESC ";
160  $ilDB->setLimit(1);
161  $res = $ilDB->query($query);
162  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
163  {
164  $event_id = $row->event_id;
165  }
166  return isset($event_id) ? $event_id : 0;
167  }
168 
169  // Interface methods
177  public function isFullday()
178  {
179  return $this->enabledFullTime();
180  }
181 
189  public function getStart()
190  {
191  return $this->start ? $this->start : $this->start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
192  }
193 
200  public function setStart($a_start)
201  {
202  $this->start = $a_start;
203  }
204 
211  public function getEnd()
212  {
213  return $this->end ? $this->end : $this->end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
214  }
215 
223  public function setEnd($a_end)
224  {
225  $this->end = $a_end;
226  }
227 
228  function setAppointmentId($a_appointment_id)
229  {
230  $this->appointment_id = $a_appointment_id;
231  }
232  function getAppointmentId()
233  {
234  return $this->appointment_id;
235  }
236 
237  function setSessionId($a_session_id)
238  {
239  $this->session_id = $a_session_id;
240  }
241  function getSessionId()
242  {
243  return $this->session_id;
244  }
245 
246  function setStartingTime($a_starting_time)
247  {
248  $this->starting_time = $a_starting_time;
249  $this->start = new ilDateTime($this->starting_time,IL_CAL_UNIX);
250 
251  }
252  function getStartingTime()
253  {
254  return isset($this->starting_time) ? $this->starting_time : mktime(8,0,0,date('n',time()),date('d',time()),date('Y',time()));
255  }
256 
257  function setEndingTime($a_ending_time)
258  {
259  $this->ending_time = $a_ending_time;
260  $this->end = new ilDateTime($this->ending_time,IL_CAL_UNIX);
261  }
262  function getEndingTime()
263  {
264  return isset($this->ending_time) ? $this->ending_time : mktime(16,0,0,date('n',time()),date('d',time()),date('Y',time()));
265  }
266 
267  function toggleFullTime($a_status)
268  {
269  $this->fulltime = $a_status;
270  }
271  function enabledFullTime()
272  {
273  return $this->fulltime;
274  }
275 
276  function formatTime()
277  {
279  }
280 
282  {
283  global $ilUser,$lng;
284 
285  $start = date($this->lng->txt('lang_timeformat_no_sec'),$start);
286  $end = date($this->lng->txt('lang_timeformat_no_sec'),$end);
287 
288  return $start.' - '. $end;
289  }
290 
291  public static function _appointmentToString($start,$end,$fulltime)
292  {
293  global $lng;
294 
295  if($fulltime)
296  {
299  #new ilDate($end,IL_CAL_UNIX)).' ('.$lng->txt('event_full_time_info').')';
300  new ilDate($end,IL_CAL_UNIX));
301  }
302  else
303  {
307  }
308  }
309 
311  {
313  }
314 
322  public function cloneObject($new_id)
323  {
324  $new_app = new ilSessionAppointment();
325  $new_app->setSessionId($new_id);
326  $new_app->setStartingTime($this->getStartingTime());
327  $new_app->setEndingTime($this->getEndingTime());
328  $new_app->toggleFullTime($this->isFullday());
329  $new_app->create();
330  return $new_app;
331  }
332 
333  function create()
334  {
335  global $ilDB;
336 
337  if(!$this->getSessionId())
338  {
339  return false;
340  }
341  $next_id = $ilDB->nextId('event_appointment');
342  $query = "INSERT INTO event_appointment (appointment_id,event_id,e_start,e_end,fulltime) ".
343  "VALUES( ".
344  $ilDB->quote($next_id,'integer').", ".
345  $ilDB->quote($this->getSessionId() ,'integer').", ".
346  $ilDB->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC') ,'timestamp').", ".
347  $ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC') ,'timestamp').", ".
348  $ilDB->quote($this->enabledFullTime() ,'integer')." ".
349  ")";
350  $this->appointment_id = $next_id;
351  $res = $ilDB->manipulate($query);
352 
353  return true;
354  }
355 
356  function update()
357  {
358  global $ilDB;
359 
360  if(!$this->getSessionId())
361  {
362  return false;
363  }
364  $query = "UPDATE event_appointment ".
365  "SET event_id = ".$ilDB->quote($this->getSessionId() ,'integer').", ".
366  "e_start = ".$ilDB->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC') ,'timestamp').", ".
367  "e_end = ".$ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'), 'timestamp').", ".
368  "fulltime = ".$ilDB->quote($this->enabledFullTime() ,'integer')." ".
369  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId() ,'integer')." ";
370  $res = $ilDB->manipulate($query);
371  return true;
372  }
373 
374  function delete()
375  {
377  }
378 
379  public static function _delete($a_appointment_id)
380  {
381  global $ilDB;
382 
383  $query = "DELETE FROM event_appointment ".
384  "WHERE appointment_id = ".$ilDB->quote($a_appointment_id ,'integer')." ";
385  $res = $ilDB->manipulate($query);
386 
387  return true;
388  }
389 
390  public static function _deleteBySession($a_event_id)
391  {
392  global $ilDB;
393 
394  $query = "DELETE FROM event_appointment ".
395  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
396  $res = $ilDB->manipulate($query);
397 
398  return true;
399  }
400 
401  public static function _readAppointmentsBySession($a_event_id)
402  {
403  global $ilDB;
404 
405  $query = "SELECT * FROM event_appointment ".
406  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
407  "ORDER BY starting_time";
408 
409  $res = $ilDB->query($query);
410  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
411  {
412  $appointments[] = new ilSessionAppointment($row->appointment_id);
413  }
414  return is_array($appointments) ? $appointments : array();
415  }
416 
417  function validate()
418  {
419  if($this->starting_time > $this->ending_time)
420  {
421  $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
422  return false;
423  }
424  return true;
425  }
426 
427  // PRIVATE
428  function __read()
429  {
430  global $ilDB;
431 
432  if(!$this->getAppointmentId())
433  {
434  return null;
435  }
436 
437  $query = "SELECT * FROM event_appointment ".
438  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId() ,'integer')." ";
439  $res = $this->db->query($query);
440  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
441  {
442  $this->setSessionId($row->event_id);
443  $this->toggleFullTime($row->fulltime);
444 
445  if($this->isFullday())
446  {
447  $this->start = new ilDate($row->e_start,IL_CAL_DATETIME);
448  $this->end = new ilDate($row->e_end,IL_CAL_DATETIME);
449  }
450  else
451  {
452  $this->start = new ilDateTime($row->e_start,IL_CAL_DATETIME,'UTC');
453  $this->end = new ilDateTime($row->e_end,IL_CAL_DATETIME,'UTC');
454  }
455  $this->starting_time = $this->start->getUnixTime();
456  $this->ending_time = $this->end->getUnixTime();
457  }
458  return true;
459  }
460 
461 }
462 ?>
const IL_CAL_DATETIME
static _delete($a_appointment_id)
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
const IL_CAL_UNIX
const IL_CAL_DAY
$info
Definition: example_052.php:80
static _deleteBySession($a_event_id)
Class for single dates.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static _appointmentToString($start, $end, $fulltime)
Date and time handling
$ilUser
Definition: imgupload.php:18
cloneObject($new_id)
clone appointment
Create styles array
The data for the language used.
static lookupLastSessionByCourse($a_ref_id)
public
const IL_CAL_DATE
__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.
static lookupNextSessionByCourse($a_ref_id)
public
class ilSessionAppointment