ILIAS  Release_3_10_x_branch Revision 61812
 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)." ";
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->start,IL_CAL_DATETIME,'UTC');
78  $info['start'] = $date->getUnixTime();
79  $date = new ilDateTime($row->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 start > NOW() ".
111  "AND event_id IN (".implode(',',ilUtil::quoteArray($obj_ids)).") ".
112  "ORDER BY start LIMIT 1";
113  $res = $ilDB->query($query);
114  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
115  {
116  $event_id = $row->event_id;
117  }
118  return isset($event_id) ? $event_id : 0;
119  }
120 
129  public static function lookupLastSessionByCourse($a_ref_id)
130  {
131  global $tree,$ilDB;
132 
133  $sessions = $tree->getChildsByType($a_ref_id,'sess');
134  $obj_ids = array();
135  foreach($sessions as $tree_data)
136  {
137  $obj_ids[] = $tree_data['obj_id'];
138  }
139  if(!count($obj_ids))
140  {
141  return false;
142  }
143  $query = "SELECT event_id FROM event_appointment ".
144  "WHERE start < NOW() ".
145  "AND event_id IN (".implode(',',ilUtil::quoteArray($obj_ids)).") ".
146  "ORDER BY start DESC LIMIT 1";
147  $res = $ilDB->query($query);
148  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
149  {
150  $event_id = $row->event_id;
151  }
152  return isset($event_id) ? $event_id : 0;
153  }
154 
155  // Interface methods
163  public function isFullday()
164  {
165  return $this->enabledFullTime();
166  }
167 
175  public function getStart()
176  {
177  return $this->start ? $this->start : $this->start = new ilDateTime(date('Y-m-d').' 08:00:00',IL_CAL_DATETIME);
178  }
179 
186  public function setStart($a_start)
187  {
188  $this->start = $a_start;
189  }
190 
197  public function getEnd()
198  {
199  return $this->end ? $this->end : $this->end = new ilDateTime(date('Y-m-d').' 16:00:00',IL_CAL_DATETIME);
200  }
201 
209  public function setEnd($a_end)
210  {
211  $this->end = $a_end;
212  }
213 
214  function setAppointmentId($a_appointment_id)
215  {
216  $this->appointment_id = $a_appointment_id;
217  }
218  function getAppointmentId()
219  {
220  return $this->appointment_id;
221  }
222 
223  function setSessionId($a_session_id)
224  {
225  $this->session_id = $a_session_id;
226  }
227  function getSessionId()
228  {
229  return $this->session_id;
230  }
231 
232  function setStartingTime($a_starting_time)
233  {
234  $this->starting_time = $a_starting_time;
235  $this->start = new ilDateTime($this->starting_time,IL_CAL_UNIX);
236 
237  }
238  function getStartingTime()
239  {
240  return isset($this->starting_time) ? $this->starting_time : mktime(8,0,0,date('n',time()),date('d',time()),date('Y',time()));
241  }
242 
243  function setEndingTime($a_ending_time)
244  {
245  $this->ending_time = $a_ending_time;
246  $this->end = new ilDateTime($this->ending_time,IL_CAL_UNIX);
247  }
248  function getEndingTime()
249  {
250  return isset($this->ending_time) ? $this->ending_time : mktime(16,0,0,date('n',time()),date('d',time()),date('Y',time()));
251  }
252 
253  function toggleFullTime($a_status)
254  {
255  $this->fulltime = $a_status;
256  }
257  function enabledFullTime()
258  {
259  return $this->fulltime;
260  }
261 
262  function formatTime()
263  {
265  }
266 
268  {
269  global $ilUser,$lng;
270 
271  $start = date($this->lng->txt('lang_timeformat_no_sec'),$start);
272  $end = date($this->lng->txt('lang_timeformat_no_sec'),$end);
273 
274  return $start.' - '. $end;
275  }
276 
277  function _appointmentToString($start,$end,$fulltime)
278  {
279  global $lng;
280 
281  if($fulltime)
282  {
285  new ilDate($end,IL_CAL_UNIX)).' ('.$lng->txt('event_full_time_info').')';
286  }
287  else
288  {
292  }
293  }
294 
296  {
298  }
299 
307  public function cloneObject($new_id)
308  {
309  $new_app = new ilSessionAppointment();
310  $new_app->setSessionId($new_id);
311  $new_app->setStartingTime($this->getStartingTime());
312  $new_app->setEndingTime($this->getEndingTime());
313  $new_app->toggleFullTime($this->isFullday());
314  $new_app->create();
315  return $new_app;
316  }
317 
318  function create()
319  {
320  global $ilDB;
321 
322  if(!$this->getSessionId())
323  {
324  return false;
325  }
326  $query = "INSERT INTO event_appointment ".
327  "SET event_id = ".$ilDB->quote($this->getSessionId()).", ".
328  "start = ".$ilDB->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC')).", ".
329  "end = ".$ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC')).", ".
330  "fulltime = ".$ilDB->quote($this->enabledFullTime())." ";
331 
332  $this->appointment_id = $ilDB->getLastInsertId();
333 
334  $this->db->query($query);
335 
336 
337  return true;
338  }
339 
340  function update()
341  {
342  global $ilDB;
343 
344  if(!$this->getSessionId())
345  {
346  return false;
347  }
348  $query = "UPDATE event_appointment ".
349  "SET event_id = ".$ilDB->quote($this->getSessionId()).", ".
350  "start = ".$ilDB->quote($this->getStart()->get(IL_CAL_DATETIME,'','UTC')).", ".
351  "end = ".$ilDB->quote($this->getEnd()->get(IL_CAL_DATETIME,'','UTC')).", ".
352  "fulltime = ".$ilDB->quote($this->enabledFullTime())." ".
353  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId())." ";
354 
355  $this->db->query($query);
356  return true;
357  }
358 
359  function delete()
360  {
362  }
363 
364  function _delete($a_appointment_id)
365  {
366  global $ilDB;
367 
368  $query = "DELETE FROM event_appointment ".
369  "WHERE appointment_id = ".$ilDB->quote($a_appointment_id)." ";
370  $this->db->query($query);
371 
372  return true;
373  }
374 
375  function _deleteBySession($a_event_id)
376  {
377  global $ilDB;
378 
379  $query = "DELETE FROM event_appointment ".
380  "WHERE event_id = ".$ilDB->quote($a_event_id)." ";
381  $ilDB->query($query);
382 
383  return true;
384  }
385 
386  function _readAppointmentsBySession($a_event_id)
387  {
388  global $ilDB;
389 
390  $query = "SELECT * FROM event_appointment ".
391  "WHERE event_id = ".$ilDB->quote($a_event_id)." ".
392  "ORDER BY starting_time";
393 
394  $res = $ilDB->query($query);
395  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
396  {
397  $appointments[] =& new ilSessionAppointment($row->appointment_id);
398  }
399  return is_array($appointments) ? $appointments : array();
400  }
401 
402  function validate()
403  {
404  if($this->starting_time > $this->ending_time)
405  {
406  $this->ilErr->appendMessage($this->lng->txt('event_etime_smaller_stime'));
407  return false;
408  }
409  return true;
410  }
411 
412  // PRIVATE
413  function __read()
414  {
415  global $ilDB;
416 
417  if(!$this->getAppointmentId())
418  {
419  return null;
420  }
421 
422  $query = "SELECT * FROM event_appointment ".
423  "WHERE appointment_id = ".$ilDB->quote($this->getAppointmentId())." ";
424  $res = $this->db->query($query);
425  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
426  {
427  $this->setSessionId($row->event_id);
428  $this->toggleFullTime($row->fulltime);
429 
430  if($this->isFullday())
431  {
432  $this->start = new ilDate($row->start,IL_CAL_DATETIME);
433  $this->end = new ilDate($row->end,IL_CAL_DATETIME);
434  }
435  else
436  {
437  $this->start = new ilDateTime($row->start,IL_CAL_DATETIME,'UTC');
438  $this->end = new ilDateTime($row->end,IL_CAL_DATETIME,'UTC');
439  }
440  $this->starting_time = $this->start->getUnixTime();
441  $this->ending_time = $this->end->getUnixTime();
442  }
443  return true;
444  }
445 
446 }
447 ?>