ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
18  private $logger = null;
19 
23  private $target_id = 0;
24 
25  public function __construct()
26  {
27  global $DIC;
28 
29  parent::__construct();
30  $this->logger = $DIC->logger()->sess();
31  }
32 
36  public function setTargetId(int $target_id)
37  {
38  $this->target_id = $target_id;
39  }
40 
47  public function getSupportedVersions()
48  {
49  return array("4.1.0", "5.0.0", "5.1.0", '5.4.0');
50  }
51 
58  public function getXmlNamespace($a_entity, $a_schema_version)
59  {
60  return "http://www.ilias.de/xml/Modules/Session/" . $a_entity;
61  }
62 
69  protected function getTypes($a_entity, $a_version)
70  {
71  if ($a_entity == "sess") {
72  switch ($a_version) {
73  case "4.1.0":
74  return array(
75  "Id" => "integer",
76  "Title" => "text",
77  "Description" => "text",
78  "Location" => "text",
79  "TutorName" => "text",
80  "TutorEmail" => "text",
81  "TutorPhone" => "text",
82  "Details" => "text",
83  "Registration" => "integer",
84  "EventStart" => "text",
85  "EventEnd" => "text",
86  "StartingTime" => "integer",
87  "EndingTime" => "integer",
88  "Fulltime" => "integer"
89  );
90  case "5.0.0":
91  return array(
92  "Id" => "integer",
93  "Title" => "text",
94  "Description" => "text",
95  "Location" => "text",
96  "TutorName" => "text",
97  "TutorEmail" => "text",
98  "TutorPhone" => "text",
99  "Details" => "text",
100  "Registration" => "integer",
101  "EventStart" => "text",
102  "EventEnd" => "text",
103  "StartingTime" => "integer",
104  "EndingTime" => "integer",
105  "Fulltime" => "integer",
106  "LimitedRegistration" => "integer",
107  "WaitingList" => "integer",
108  "LimitUsers" => "integer"
109  );
110  case "5.1.0":
111  return array(
112  "Id" => "integer",
113  "Title" => "text",
114  "Description" => "text",
115  "Location" => "text",
116  "TutorName" => "text",
117  "TutorEmail" => "text",
118  "TutorPhone" => "text",
119  "Details" => "text",
120  "Registration" => "integer",
121  "EventStart" => "text",
122  "EventEnd" => "text",
123  "StartingTime" => "integer",
124  "EndingTime" => "integer",
125  "Fulltime" => "integer",
126  "LimitedRegistration" => "integer",
127  "WaitingList" => "integer",
128  "AutoWait" => "integer",
129  "LimitUsers" => "integer",
130  "MinUsers" => "integer"
131  );
132  case "5.4.0":
133  return array(
134  "Id" => "integer",
135  "Title" => "text",
136  "Description" => "text",
137  "Location" => "text",
138  "TutorName" => "text",
139  "TutorEmail" => "text",
140  "TutorPhone" => "text",
141  "Details" => "text",
142  "Registration" => "integer",
143  "EventStart" => "text",
144  "EventEnd" => "text",
145  "StartingTime" => "integer",
146  "EndingTime" => "integer",
147  "Fulltime" => "integer",
148  "LimitedRegistration" => "integer",
149  "WaitingList" => "integer",
150  "AutoWait" => "integer",
151  "LimitUsers" => "integer",
152  "MinUsers" => "integer",
153  'MailMembers' => 'integer',
154  'ShowMembers' => 'integer',
155  'Type' => 'integer'
156  );
157  }
158  }
159 
160  if ($a_entity == "sess_item") {
161  switch ($a_version) {
162  case "4.1.0":
163  case "5.0.0":
164  case "5.1.0":
165  case "5.4.0":
166  return array(
167  "SessionId" => "integer",
168  "ItemId" => "text",
169  );
170  }
171  }
172  }
173 
180  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
181  {
182  global $DIC;
183 
184  $ilDB = $DIC['ilDB'];
185 
186  if (!is_array($a_ids)) {
187  $a_ids = array($a_ids);
188  }
189 
190  if ($a_entity == "sess") {
191  switch ($a_version) {
192  case "4.1.0":
193  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, od.description description, " .
194  " location, tutor_name, tutor_email, tutor_phone, details, registration, " .
195  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
196  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
197  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
198  "WHERE " .
199  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
200  break;
201  case "5.0.0":
202  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
203  " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
204  " reg_limited limited_registration, reg_waiting_list waiting_list, " .
205  " reg_limit_users limit_users, " .
206  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
207  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
208  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
209  " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
210  "WHERE " .
211  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
212  break;
213  case "5.1.0":
214  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
215  " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
216  " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
217  " reg_limit_users limit_users, reg_min_users min_users, " .
218  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime " .
219  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
220  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
221  " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
222  "WHERE " .
223  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
224  break;
225  case "5.4.0":
226  $this->getDirectDataFromQuery($q = "SELECT ev.obj_id id, od.title title, odes.description description, " .
227  " location, tutor_name, tutor_email, tutor_phone, details, reg_type registration, " .
228  " reg_limited limited_registration, reg_waiting_list waiting_list, reg_auto_wait auto_wait, " .
229  " reg_limit_users limit_users, reg_min_users min_users, " .
230  " e_start event_start, e_end event_end, starting_time, ending_time, fulltime, mail_members, show_members " .
231  " FROM event ev JOIN object_data od ON (ev.obj_id = od.obj_id) " .
232  " JOIN event_appointment ea ON (ev.obj_id = ea.event_id) " .
233  " JOIN object_description odes ON (ev.obj_id = odes.obj_id) " .
234  "WHERE " .
235  $ilDB->in("ev.obj_id", $a_ids, false, "integer"));
236 
237  $this->readDidacticTemplateType($a_ids);
238  break;
239  }
240  }
241 
242  if ($a_entity == "sess_item") {
243  switch ($a_version) {
244  case "4.1.0":
245  case "5.0.0":
246  case "5.1.0":
247  $this->getDirectDataFromQuery($q = "SELECT event_id session_id, item_id " .
248  " FROM event_items " .
249  "WHERE " .
250  $ilDB->in("event_id", $a_ids, false, "integer"));
251  break;
252  }
253  }
254  }
255 
262  public function getXmlRecord($a_entity, $a_version, $a_set)
263  {
264  if ($a_entity == "sess") {
265  // convert server dates to utc
266  if (!$a_set["Fulltime"]) {
267  // nothing has to be done here, since the dates are already stored in UTC
268  #$start = new ilDateTime($a_set["EventStart"], IL_CAL_DATETIME);
269  #$a_set["EventStart"] = $start->get(IL_CAL_DATETIME,'','UTC');
270  #$end = new ilDateTime($a_set["EventEnd"], IL_CAL_DATETIME);
271  #$a_set["EventEnd"] = $end->get(IL_CAL_DATETIME,'','UTC');
272  }
273  }
274  if ($a_entity == "sess_item") {
275  // make ref id an object id
276  $a_set["ItemId"] = ilObject::_lookupObjId($a_set["ItemId"]);
277  }
278  return $a_set;
279  }
280 
281 
282 
286  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
287  {
288  switch ($a_entity) {
289  case "sess":
290  return array(
291  "sess_item" => array("ids" => $a_rec["Id"])
292  );
293  }
294 
295  return false;
296  }
297 
298 
305  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
306  {
307  switch ($a_entity) {
308  case "sess":
309  include_once("./Modules/Session/classes/class.ilObjSession.php");
310  include_once("./Modules/Session/classes/class.ilSessionAppointment.php");
311 
312  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
313  $refs = ilObject::_getAllReferences($new_id);
314  $newObj = ilObjectFactory::getInstanceByRefId(end($refs), false);
315  } else {
316  $this->logger->debug('Session creation without existing instance');
317  $newObj = new ilObjSession();
318  $newObj->setType("sess");
319  $newObj->create(true);
320  $newObj->createReference();
321  $newObj->putInTree($this->target_id);
322  $newObj->setPermissions($this->target_id);
323  }
324  $newObj->setTitle($a_rec["Title"]);
325  $newObj->setDescription($a_rec["Description"]);
326  $newObj->setLocation($a_rec["Location"]);
327  $newObj->setName($a_rec["TutorName"]);
328  $newObj->setPhone($a_rec["TutorPhone"]);
329  $newObj->setEmail($a_rec["TutorEmail"]);
330  $newObj->setDetails($a_rec["Details"]);
331 
332  switch ($a_schema_version) {
333  case "5.0.0":
334  case "5.1.0":
335  $newObj->setRegistrationType($a_rec["Registration"]);
336 
337  $newObj->enableRegistrationUserLimit($a_rec["LimitedRegistration"]);
338  $newObj->setRegistrationMaxUsers($a_rec["LimitUsers"]);
339  $newObj->enableRegistrationWaitingList($a_rec["WaitingList"]);
340 
341  if (isset($a_rec["MinUsers"])) {
342  $newObj->setRegistrationMinUsers($a_rec["MinUsers"]);
343  }
344 
345  if (isset($a_rec["AutoWait"])) {
346  $newObj->setWaitingListAutoFill($a_rec["AutoWait"]);
347  }
348  break;
349  case '5.4.0':
350  if (isset($a_rec['MailMembers'])) {
351  $newObj->setMailToMembersType($a_rec['MailMembers']);
352  }
353  if (isset($a_rec['ShowMembers'])) {
354  $newObj->setShowMembers($a_rec['ShowMembers']);
355  }
356  $this->applyDidacticTemplate($newObj, $a_rec['Type']);
357  break;
358  }
359 
360  $newObj->update(true);
361 
362  $start = new ilDateTime($a_rec["EventStart"], IL_CAL_DATETIME, "UTC");
363  $end = new ilDateTime($a_rec["EventEnd"], IL_CAL_DATETIME, "UTC");
364 //echo "<br>".$start->get(IL_CAL_UNIX);
365 //echo "<br>".$start->get(IL_CAL_DATETIME);
366  $app = new ilSessionAppointment();
367  $app->setStart($a_rec["EventStart"]);
368  $app->setEnd($a_rec["EventEnd"]);
369  $app->setStartingTime($start->get(IL_CAL_UNIX));
370  $app->setEndingTime($end->get(IL_CAL_UNIX));
371  $app->toggleFullTime($a_rec["Fulltime"]);
372  $app->setSessionId($newObj->getId());
373  $app->create();
374 
375  //$newObj->setAppointments(array($app));
376  //$newObj->update();
377 
378  $this->current_obj = $newObj;
379  $a_mapping->addMapping("Modules/Session", "sess", $a_rec["Id"], $newObj->getId());
380  $a_mapping->addMapping('Services/Object', 'objs', $a_rec['Id'], $newObj->getId());
381  $a_mapping->addMapping('Services/AdvancedMetaData', 'parent', $a_rec['Id'], $newObj->getId());
382  $a_mapping->addMapping(
383  "Services/MetaData",
384  "md",
385  $a_rec["Id"] . ":0:sess",
386  $newObj->getId() . ":0:sess"
387  );
388 
389 
390 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
391  break;
392 
393  case "sess_item":
394 
395  if ($obj_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['ItemId'])) {
396  $ref_id = current(ilObject::_getAllReferences($obj_id));
397  include_once './Modules/Session/classes/class.ilEventItems.php';
398  $evi = new ilEventItems($this->current_obj->getId());
399  $evi->addItem($ref_id);
400  $evi->update();
401  }
402  break;
403  }
404  }
405 
409  protected function readDidacticTemplateType($a_obj_ids)
410  {
411  $ref_ids = [];
412  $counter = 0;
413  foreach ($a_obj_ids as $obj_id) {
414  $ref_ids = ilObject::_getAllReferences($obj_id);
415  foreach ($ref_ids as $ref_id) {
417  $this->data[$counter++]['Type'] = (int) $tpl_id;
418  break;
419  }
420  }
421  }
422 
427  protected function applyDidacticTemplate(ilObject $rep_object, $tpl_id)
428  {
429  $this->logger->debug('Apply didactic template');
430 
431  if ((int) $tpl_id == 0) {
432  $this->logger->debug('Default permissions');
433  // Default template
434  return;
435  }
436 
437  $templates = ilDidacticTemplateSettings::getInstanceByObjectType('sess')->getTemplates();
438  foreach ($templates as $template) {
439  if ($template->isAutoGenerated()) {
440  $this->logger->debug('Apply first auto generated');
441  $rep_object->applyDidacticTemplate($template->getId());
442  }
443  }
444  }
445 }
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
getSupportedVersions()
Get supported versions.
applyDidacticTemplate(ilObject $rep_object, $tpl_id)
const IL_CAL_DATETIME
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
setTargetId(int $target_id)
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
$template
global $DIC
Definition: saml.php:7
const IL_CAL_UNIX
static _getAllReferences($a_id)
get all reference ids of object
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
$start
Definition: bench.php:8
getTypes($a_entity, $a_version)
Get field types for entity.
applyDidacticTemplate($a_tpl_id)
Apply template.
Session data set class.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
static _lookupObjId($a_id)
Date and time handling
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
$this data['403_header']
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record (export)
global $ilDB
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
readDidacticTemplateType($a_obj_ids)
addItem($a_item_ref_id)
Add one item.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
class ilEvent
class ilSessionAppointment