ILIAS  Release_4_4_x_branch Revision 61816
 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()
22  {
23  return array("4.1.0");
24  }
25 
32  function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Modules/Session/".$a_entity;
35  }
36 
43  protected function getTypes($a_entity, $a_version)
44  {
45  if ($a_entity == "sess")
46  {
47  switch ($a_version)
48  {
49  case "4.1.0":
50  return array(
51  "Id" => "integer",
52  "Title" => "text",
53  "Description" => "text",
54  "Location" => "text",
55  "TutorName" => "text",
56  "TutorEmail" => "text",
57  "TutorPhone" => "text",
58  "Details" => "text",
59  "Registration" => "integer",
60  "EventStart" => "text",
61  "EventEnd" => "text",
62  "StartingTime" => "integer",
63  "EndingTime" => "integer",
64  "Fulltime" => "integer"
65  );
66  }
67  }
68 
69  if ($a_entity == "sess_item")
70  {
71  switch ($a_version)
72  {
73  case "4.1.0":
74  return array(
75  "SessionId" => "integer",
76  "ItemId" => "text",
77  );
78  }
79  }
80 
81  }
82 
89  function readData($a_entity, $a_version, $a_ids, $a_field = "")
90  {
91  global $ilDB;
92 
93  if (!is_array($a_ids))
94  {
95  $a_ids = array($a_ids);
96  }
97 
98  if ($a_entity == "sess")
99  {
100  switch ($a_version)
101  {
102  case "4.1.0":
103  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, od.description description, ".
104  " location, tutor_name, tutor_email, tutor_phone, details, registration, ".
105  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime ".
106  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) ".
107  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) ".
108  "WHERE ".
109  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
110  break;
111  }
112  }
113 
114  if ($a_entity == "sess_item")
115  {
116  switch ($a_version)
117  {
118  case "4.1.0":
119  $this->getDirectDataFromQuery($q = "SELECT event_id session_id, item_id ".
120  " FROM event_items ".
121  "WHERE ".
122  $ilDB->in("event_id", $a_ids, false, "integer"));
123  break;
124  }
125  }
126 
127  }
128 
135  function getXmlRecord($a_entity, $a_version, $a_set)
136  {
137  if ($a_entity == "sess")
138  {
139  // convert server dates to utc
140  if(!$a_set["Fulltime"])
141  {
142  // nothing has to be done here, since the dates are already stored in UTC
143  #$start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
144  #$a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
145  #$end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
146  #$a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
147  }
148  }
149  if ($a_entity == "sess_item")
150  {
151  // make ref id an object id
152  $a_set["ItemId"] = ilObject::_lookupObjId($a_set["ItemId"]);
153  }
154  return $a_set;
155  }
156 
157 
158 
162  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
163  {
164  switch ($a_entity)
165  {
166  case "sess":
167  return array (
168  "sess_item" => array("ids" => $a_rec["Id"])
169  );
170  }
171 
172  return false;
173  }
174 
175 
182  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
183  {
184  switch ($a_entity)
185  {
186  case "sess":
187  include_once("./Modules/Session/classes/class.ilObjSession.php");
188  include_once("./Modules/Session/classes/class.ilSessionAppointment.php");
189 
190  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
191  {
192  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
193  }
194  else
195  {
196  $newObj = new ilObjSession();
197  $newObj->setType("sess");
198  $newObj->create(true);
199  }
200  $newObj->setTitle($a_rec["Title"]);
201  $newObj->setDescription($a_rec["Description"]);
202  $newObj->setLocation($a_rec["Location"]);
203  $newObj->setName($a_rec["TutorName"]);
204  $newObj->setPhone($a_rec["TutorPhone"]);
205  $newObj->setEmail($a_rec["TutorEmail"]);
206  $newObj->setDetails($a_rec["Details"]);
207  $newObj->enableRegistration($a_rec["Registration"]);
208  $newObj->update();
209 
210  $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
211  $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
212 //echo "<br>".$start->get(IL_CAL_UNIX);
213 //echo "<br>".$start->get(IL_CAL_DATETIME);
214  $app = new ilSessionAppointment();
215  $app->setStart($a_rec["EventStart"]);
216  $app->setEnd($a_rec["EventEnd"]);
217  $app->setStartingTime($start->get(IL_CAL_UNIX));
218  $app->setEndingTime($end->get(IL_CAL_UNIX));
219  $app->toggleFullTime($a_rec["Fulltime"]);
220  $app->setSessionId($newObj->getId());
221  $app->create();
222 
223  //$newObj->setAppointments(array($app));
224  //$newObj->update();
225 
226  $this->current_obj = $newObj;
227  $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId());
228 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
229  break;
230 
231  case "sess_item":
232 
233  if($obj_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['ItemId']))
234  {
235  $ref_id = current(ilObject::_getAllReferences($obj_id));
236  include_once './Modules/Session/classes/class.ilEventItems.php';
237  $evi = new ilEventItems($this->current_obj->getId());
238  $evi->addItem($ref_id);
239  $evi->update();
240  }
241  break;
242  }
243  }
244 }
245 ?>