ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarRegistration.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  private $appointment_id = 0;
16 
17  private $registered = array();
18 
23  public function __construct($a_appointment_id)
24  {
25  $this->appointment_id = $a_appointment_id;
26 
27  $this->read();
28  }
29 
35  public static function deleteByUser($a_usr_id)
36  {
37  global $ilDB;
38 
39  $query = "DELETE FROM cal_registrations ".
40  "WHERE usr_id = ".$ilDB->quote($a_usr_id,'integer');
41  $ilDB->manipulate($query);
42  }
43 
44  public static function deleteByAppointment($a_cal_id)
45  {
46  global $ilDB;
47 
48  $query = "DELETE FROM cal_registrations ".
49  "WHERE cal_id = ".$ilDB->quote($a_cal_id,'integer');
50  $ilDB->manipulate($query);
51  }
52 
57  public function getAppointmentId()
58  {
59  return $this->appointment_id;
60  }
61 
66  public function getRegisteredUsers()
67  {
68  foreach($this->registered as $reg_data)
69  {
70  if($reg_data['usr_id'] == $a_usr_id)
71  {
72  if($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX))
73  {
74  return true;
75  }
76  }
77  }
78  return (array) $this->registered;
79  }
80 
86  public function isRegistered($a_usr_id,ilDateTime $start, ilDateTime $end)
87  {
88  foreach($this->registered as $reg_data)
89  {
90  if($reg_data['usr_id'] == $a_usr_id)
91  {
92  if($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX))
93  {
94  return true;
95  }
96  }
97  }
98  }
99 
105  public function register($a_usr_id,ilDateTime $start, ilDateTime $end)
106  {
107  global $ilDB;
108 
109  $this->unregister($a_usr_id,$start,$end);
110 
111  $query = "INSERT INTO cal_registrations (cal_id,usr_id,dstart,dend) ".
112  "VALUES ( ".
113  $ilDB->quote($this->getAppointmentId(),'integer').", ".
114  $ilDB->quote($a_usr_id,'integer').", ".
115  $ilDB->quote($start->get(IL_CAL_UNIX),'integer').", ".
116  $ilDB->quote($end->get(IL_CAL_UNIX),'integer').
117  ")";
118  $ilDB->manipulate($query);
119 
120  $this->registered[] = $a_usr_id;
121  return true;
122  }
123 
129  public function unregister($a_usr_id,ilDateTime $start, ilDateTime $end)
130  {
131  global $ilDB;
132 
133  $query = "DELETE FROM cal_registrations ".
134  "WHERE cal_id = ".$ilDB->quote($this->getAppointmentId(),'integer').' '.
135  "AND usr_id = ".$ilDB->quote($a_usr_id,'integer').' '.
136  "AND dstart = ".$ilDB->quote($start->get(IL_CAL_UNIX),'integer').' '.
137  "AND dend = ".$ilDB->quote($end->get(IL_CAL_UNIX),'integer');
138  $res = $ilDB->manipulate($query);
139  }
140 
141 
146  protected function read()
147  {
148  global $ilDB;
149 
150  if(!$this->getAppointmentId())
151  {
152  return false;
153  }
154 
155  $query = "SELECT * FROM cal_registrations WHERE cal_id = ".$ilDB->quote($this->getAppointmentId(),'integer');
156  $res = $ilDB->query($query);
157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
158  {
159  $this->registered[] = array(
160  'usr_id'=> $row->usr_id,
161  'dstart' =>$row->dstart,
162  'dend' => $row->dend
163  );
164  }
165  }
166 }
167 ?>