ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSessionAppointment.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('./Services/Calendar/interfaces/interface.ilDatePeriod.php');
25 include_once('./Services/Calendar/classes/class.ilDate.php');
35 {
36  var $ilErr;
37  var $ilDB;
38  var $tree;
39  var $lng;
40 
41  protected $start = null;
42  protected $end = null;
43 
44  var $starting_time = null;
45  var $ending_time = null;
46 
47  function ilSessionAppointment($a_appointment_id = null)
48  {
49  global $ilErr,$ilDB,$lng,$tree;
50 
51  $this->ilErr =& $ilErr;
52  $this->db =& $ilDB;
53  $this->lng =& $lng;
54 
55  $this->appointment_id = $a_appointment_id;
56  $this->__read();
57  }
58 
66  public static function _lookupAppointment($a_obj_id)
67  {
68  global $ilDB;
69 
70  $query = "SELECT * FROM event_appointment ".
71  "WHERE event_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
72  $res = $ilDB->query($query);
73  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
74  {
75  $info['fullday'] = $row->fulltime;
76 
77  $date = new ilDateTime($row->e_start,IL_CAL_DATETIME,'UTC');
78  $info['start'] = $date->getUnixTime();
79  $date = new ilDateTime($row->e_end,IL_CAL_DATETIME,'UTC');
80  $info['end'] = $date->getUnixTime();
81 
82  return $info;
83  }
84  return array();
85  }
86 
95  public static function lookupNextSessionByCourse($a_ref_id)
96  {
97  global $tree,$ilDB;
98 
99  $sessions = $tree->getChildsByType($a_ref_id,'sess');
100  $obj_ids = array();
101  foreach($sessions as $tree_data)
102  {
103  $obj_ids[] = $tree_data['obj_id'];
104  }
105  if(!count($obj_ids))
106  {
107  return false;
108  }
109  $query = "SELECT event_id FROM event_appointment ".
110  "WHERE e_start > ".$ilDB->now()." ".
111  "AND ".$ilDB->in('event_id',$obj_ids,false,'integer')." ".
112  "ORDER BY e_start ";
113  $ilDB->setLimit(1);
114  $res = $ilDB->query($query);
115  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
116  {
117  $event_id = $row->event_id;
118  }
119  return isset($event_id) ? $event_id : 0;
120  }
121 
130  public static function lookupLastSessionByCourse($a_ref_id)
131  {
132  global $tree,$ilDB;
133 
134  $sessions = $tree->getChildsByType($a_ref_id,'sess');
135  $obj_ids = array();
136  foreach($sessions as $tree_data)
137  {
138  $obj_ids[] = $tree_data['obj_id'];
139  }
140  if(!count($obj_ids))
141  {
142  return false;
143  }
144  $query = "SELECT event_id FROM event_appointment ".
145  "WHERE e_start < ".$ilDB->now()." ".
146  "AND ".$ilDB->in('event_id',$obj_ids,false,'integer')." ".
147  "ORDER BY e_start DESC ";
148  $ilDB->setLimit(1);
149  $res = $ilDB->query($query);
150  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
151  {
152  $event_id = $row->event_id;
153  }
154  return isset($event_id) ? $event_id : 0;
155  }
156 
157  // Interface methods
165  public function isFullday()
166  {
167  return $this->enabledFullTime();
168  }
169 
177  public function getStart()
178  {
179  return $this->start ? $this->start : $this->start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
180  }
181 
188  public function setStart($a_start)
189  {
190  $this->start = $a_start;
191  }
192 
199  public function getEnd()
200  {
201  return $this->end ? $this->end : $this->end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
202  }
203 
211  public function setEnd($a_end)
212  {
213  $this->end = $a_end;
214  }
215 
216  function setAppointmentId($a_appointment_id)
217  {
218  $this->appointment_id = $a_appointment_id;
219  }
220  function getAppointmentId()
221  {
222  return $this->appointment_id;
223  }
224 
225  function setSessionId($a_session_id)
226  {
227  $this->session_id = $a_session_id;
228  }
229  function getSessionId()
230  {
231  return $this->session_id;
232  }
233 
234  function setStartingTime($a_starting_time)
235  {
236  $this->starting_time = $a_starting_time;
237  $this->start = new ilDateTime($this->starting_time,IL_CAL_UNIX);
238 
239  }
240  function getStartingTime()
241  {
242  return isset($this->starting_time) ? $this->starting_time : mktime(8,0,0,date('n',time()),date('d',time()),date('Y',time()));
243  }
244 
245  function setEndingTime($a_ending_time)
246  {
247  $this->ending_time = $a_ending_time;
248  $this->end = new ilDateTime($this->ending_time,IL_CAL_UNIX);
249  }
250  function getEndingTime()
251  {
252  return isset($this->ending_time) ? $this->ending_time : mktime(16,0,0,date('n',time()),date('d',time()),date('Y',time()));
253  }
254 
255  function toggleFullTime($a_status)
256  {
257  $this->fulltime = $a_status;
258  }
259  function enabledFullTime()
260  {
261  return $this->fulltime;
262  }
263 
264  function formatTime()
265  {
267  }
268 
270  {
271  global $ilUser,$lng;
272 
273  $start = date($this->lng->txt('lang_timeformat_no_sec'),$start);
274  $end = date($this->lng->txt('lang_timeformat_no_sec'),$end);
275 
276  return $start.' - '. $end;
277  }
278 
279  public static function _appointmentToString($start,$end,$fulltime)
280  {
281  global $lng;
282 
283  if($fulltime)
284  {
287  #new ilDate($end,IL_CAL_UNIX)).' ('.$lng->txt('event_full_time_info').')';
288  new ilDate($end,IL_CAL_UNIX));
289  }
290  else
291  {
295  }
296  }
297 
299  {
301  }
302 
310  public function cloneObject($new_id)
311  {
312  $new_app = new ilSessionAppointment();
313  $new_app->setSessionId($new_id);
314  $new_app->setStartingTime($this->getStartingTime());
315  $new_app->setEndingTime($this->getEndingTime());
316  $new_app->toggleFullTime($this->isFullday());
317  $new_app->create();
318  return $new_app;
319  }
320 
321  function create()
322  {
323  global $ilDB;
324 
325  if(!$this->getSessionId())
326  {
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  function update()
345  {
346  global $ilDB;
347 
348  if(!$this->getSessionId())
349  {
350  return false;
351  }
352  $query = "UPDATE event_appointment ".
353  "SET event_id = ".$ilDB->quote($this->getSessionId() ,'integer').", ".
354  "e_start = ".$ilDB->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC') ,'timestamp').", ".
355  "e_end = ".$ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC'), 'timestamp').", ".
356  "fulltime = ".$ilDB->quote($this->enabledFullTime() ,'integer')." ".
357  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId() ,'integer')." ";
358  $res = $ilDB->manipulate($query);
359  return true;
360  }
361 
362  function delete()
363  {
365  }
366 
367  function _delete($a_appointment_id)
368  {
369  global $ilDB;
370 
371  $query = "DELETE FROM event_appointment ".
372  "WHERE appointment_id = ".$ilDB->quote($a_appointment_id ,'integer')." ";
373  $res = $ilDB->manipulate($query);
374 
375  return true;
376  }
377 
378  function _deleteBySession($a_event_id)
379  {
380  global $ilDB;
381 
382  $query = "DELETE FROM event_appointment ".
383  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ";
384  $res = $ilDB->manipulate($query);
385 
386  return true;
387  }
388 
389  function _readAppointmentsBySession($a_event_id)
390  {
391  global $ilDB;
392 
393  $query = "SELECT * FROM event_appointment ".
394  "WHERE event_id = ".$ilDB->quote($a_event_id ,'integer')." ".
395  "ORDER BY starting_time";
396 
397  $res = $ilDB->query($query);
398  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
399  {
400  $appointments[] =& new ilSessionAppointment($row->appointment_id);
401  }
402  return is_array($appointments) ? $appointments : array();
403  }
404 
405  function validate()
406  {
407  if($this->starting_time > $this->ending_time)
408  {
409  $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
410  return false;
411  }
412  return true;
413  }
414 
415  // PRIVATE
416  function __read()
417  {
418  global $ilDB;
419 
420  if(!$this->getAppointmentId())
421  {
422  return null;
423  }
424 
425  $query = "SELECT * FROM event_appointment ".
426  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId() ,'integer')." ";
427  $res = $this->db->query($query);
428  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
429  {
430  $this->setSessionId($row->event_id);
431  $this->toggleFullTime($row->fulltime);
432 
433  if($this->isFullday())
434  {
435  $this->start = new ilDate($row->e_start,IL_CAL_DATETIME);
436  $this->end = new ilDate($row->e_end,IL_CAL_DATETIME);
437  }
438  else
439  {
440  $this->start = new ilDateTime($row->e_start,IL_CAL_DATETIME,'UTC');
441  $this->end = new ilDateTime($row->e_end,IL_CAL_DATETIME,'UTC');
442  }
443  $this->starting_time = $this->start->getUnixTime();
444  $this->ending_time = $this->end->getUnixTime();
445  }
446  return true;
447  }
448 
449 }
450 ?>