ILIAS  release_4-3 Revision
 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  $start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
143  $a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
144  $end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
145  $a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
146  }
147  }
148  if ($a_entity == "sess_item")
149  {
150  // make ref id an object id
151  $a_set["ItemId"] = ilObject::_lookupObjId($a_set["ItemId"]);
152  }
153  return $a_set;
154  }
155 
156 
157 
161  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
162  {
163  switch ($a_entity)
164  {
165  case "sess":
166  return array (
167  "sess_item" => array("ids" => $a_rec["Id"])
168  );
169  }
170 
171  return false;
172  }
173 
174 
181  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
182  {
183  switch ($a_entity)
184  {
185  case "sess":
186  include_once("./Modules/Session/classes/class.ilObjSession.php");
187  include_once("./Modules/Session/classes/class.ilSessionAppointment.php");
188 
189  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
190  {
191  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
192  }
193  else
194  {
195  $newObj = new ilObjSession();
196  $newObj->setType("sess");
197  $newObj->create(true);
198  }
199  $newObj->setTitle($a_rec["Title"]);
200  $newObj->setDescription($a_rec["Description"]);
201  $newObj->setLocation($a_rec["Location"]);
202  $newObj->setName($a_rec["TutorName"]);
203  $newObj->setPhone($a_rec["TutorPhone"]);
204  $newObj->setEmail($a_rec["TutorEmail"]);
205  $newObj->setDetails($a_rec["Details"]);
206  $newObj->enableRegistration($a_rec["Registration"]);
207  $newObj->update();
208 
209  $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
210  $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
211 //echo "<br>".$start->get(IL_CAL_UNIX);
212 //echo "<br>".$start->get(IL_CAL_DATETIME);
213  $app = new ilSessionAppointment();
214  $app->setStart($a_rec["EventStart"]);
215  $app->setEnd($a_rec["EventEnd"]);
216  $app->setStartingTime($start->get(IL_CAL_UNIX));
217  $app->setEndingTime($end->get(IL_CAL_UNIX));
218  $app->toggleFullTime($a_rec["Fulltime"]);
219  $app->setSessionId($newObj->getId());
220  $app->create();
221 
222  //$newObj->setAppointments(array($app));
223  //$newObj->update();
224 
225  $this->current_obj = $newObj;
226  $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId());
227 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
228  break;
229 
230  case "sess_item":
231 
232  if($obj_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['ItemId']))
233  {
234  $ref_id = current(ilObject::_getAllReferences($obj_id));
235  include_once './Modules/Session/classes/class.ilEventItems.php';
236  $evi = new ilEventItems($this->current_obj->getId());
237  $evi->addItem($ref_id);
238  $evi->update();
239  }
240  break;
241  }
242  }
243 }
244 ?>