ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSessionDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
14 {
21  public function getSupportedVersions($a_entity)
22  {
23  switch ($a_entity)
24  {
25  case "sess":
26  return array("4.1.0");
27 
28  case "sess_item":
29  return array("4.1.0");
30 
31  }
32  }
33 
40  function getXmlNamespace($a_entity, $a_target_release)
41  {
42  return "http://www.ilias.de/xml/Modules/Session/".$a_entity;
43  }
44 
51  protected function getTypes($a_entity, $a_version)
52  {
53  if ($a_entity == "sess")
54  {
55  switch ($a_version)
56  {
57  case "4.1.0":
58  return array(
59  "Id" => "integer",
60  "Title" => "text",
61  "Description" => "text",
62  "Location" => "text",
63  "TutorName" => "text",
64  "TutorEmail" => "text",
65  "TutorPhone" => "text",
66  "Details" => "text",
67  "Registration" => "integer",
68  "EventStart" => "text",
69  "EventEnd" => "text",
70  "StartingTime" => "integer",
71  "EndingTime" => "integer",
72  "Fulltime" => "integer"
73  );
74  }
75  }
76 
77  if ($a_entity == "sess_item")
78  {
79  switch ($a_version)
80  {
81  case "4.1.0":
82  return array(
83  "SessionId" => "integer",
84  "ItemId" => "text",
85  );
86  }
87  }
88 
89  }
90 
97  function readData($a_entity, $a_version, $a_ids, $a_field = "")
98  {
99  global $ilDB;
100 
101  if (!is_array($a_ids))
102  {
103  $a_ids = array($a_ids);
104  }
105 
106  if ($a_entity == "sess")
107  {
108  switch ($a_version)
109  {
110  case "4.1.0":
111  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, od.description description, ".
112  " location, tutor_name, tutor_email, tutor_phone, details, registration, ".
113  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime ".
114  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) ".
115  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) ".
116  "WHERE ".
117  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
118  break;
119  }
120  }
121 
122  if ($a_entity == "sess_item")
123  {
124  switch ($a_version)
125  {
126  case "4.1.0":
127  $this->getDirectDataFromQuery($q = "SELECT event_id session_id, item_id ".
128  " FROM event_items ".
129  "WHERE ".
130  $ilDB->in("event_id", $a_ids, false, "integer"));
131  break;
132  }
133  }
134 
135  }
136 
143  function getXmlRecord($a_entity, $a_version, $a_set)
144  {
145  if ($a_entity == "sess")
146  {
147  // convert server dates to utc
148  if(!$a_set["Fulltime"])
149  {
150  $start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
151  $a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
152  $end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
153  $a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
154  }
155  }
156  if ($a_entity == "sess_item")
157  {
158  // make ref id an object id
159  $a_set["ItemId"] = ilObject::_lookupObjId($a_set["ItemId"]);
160  }
161  return $a_set;
162  }
163 
164 
165 
169  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
170  {
171  switch ($a_entity)
172  {
173  case "sess":
174  return array (
175  "sess_item" => array("ids" => $a_rec["Id"])
176  );
177  }
178 
179  return false;
180  }
181 
182 
189  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
190  {
191  switch ($a_entity)
192  {
193  case "sess":
194  include_once("./Modules/Session/classes/class.ilObjSession.php");
195  include_once("./Modules/Session/classes/class.ilSessionAppointment.php");
196 
197  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
198  {
199  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
200  }
201  else
202  {
203  $newObj = new ilObjSession();
204  $newObj->setType("sess");
205  $newObj->create(true);
206  }
207  $newObj->setTitle($a_rec["Title"]);
208  $newObj->setDescription($a_rec["Description"]);
209  $newObj->setLocation($a_rec["Location"]);
210  $newObj->setName($a_rec["TutorName"]);
211  $newObj->setPhone($a_rec["TutorPhone"]);
212  $newObj->setEmail($a_rec["TutorEmail"]);
213  $newObj->setDetails($a_rec["Details"]);
214  $newObj->enableRegistration($a_rec["Registration"]);
215  $newObj->update();
216 
217  $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
218  $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
219 //echo "<br>".$start->get(IL_CAL_UNIX);
220 //echo "<br>".$start->get(IL_CAL_DATETIME);
221  $app = new ilSessionAppointment();
222  $app->setStart($a_rec["EventStart"]);
223  $app->setEnd($a_rec["EventEnd"]);
224  $app->setStartingTime($start->get(IL_CAL_UNIX));
225  $app->setEndingTime($end->get(IL_CAL_UNIX));
226  $app->toggleFullTime($a_rec["Fulltime"]);
227  $app->setSessionId($newObj->getId());
228  $app->create();
229 
230  //$newObj->setAppointments(array($app));
231  //$newObj->update();
232 
233  $this->current_obj = $newObj;
234  $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId());
235 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
236  break;
237 
238  case "sess_item":
239 
240  if($obj_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['ItemId']))
241  {
242  $ref_id = current(ilObject::_getAllReferences($obj_id));
243  include_once './Modules/Session/classes/class.ilEventItems.php';
244  $evi = new ilEventItems($this->current_obj->getId());
245  $evi->addItem($ref_id);
246  $evi->update();
247  }
248  break;
249  }
250  }
251 }
252 ?>