ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilExerciseDataSet.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", "4.4.0", "5.0.0", "5.1.0");
24  }
25 
32  function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Modules/Exercise/".$a_entity;
35  }
36 
43  protected function getTypes($a_entity, $a_version)
44  {
45  if ($a_entity == "exc")
46  {
47  switch ($a_version)
48  {
49  case "4.1.0":
50  return array(
51  "Id" => "integer",
52  "Title" => "text",
53  "Description" => "text",
54  "PassMode" => "text",
55  "PassNr" => "integer",
56  "ShowSubmissions" => "integer"
57  );
58 
59  case "4.4.0":
60  case "5.0.0":
61  case "5.1.0":
62  return array(
63  "Id" => "integer",
64  "Title" => "text",
65  "Description" => "text",
66  "PassMode" => "text",
67  "PassNr" => "integer",
68  "ShowSubmissions" => "integer",
69  "ComplBySubmission" => "integer"
70  );
71  }
72  }
73 
74  if ($a_entity == "exc_assignment")
75  {
76  switch ($a_version)
77  {
78  case "4.1.0":
79  return array(
80  "Id" => "integer",
81  "ExerciseId" => "integer",
82  "Deadline" => "text",
83  "Instruction" => "text",
84  "Title" => "text",
85  "Mandatory" => "integer",
86  "OrderNr" => "integer",
87  "Dir" => "directory");
88 
89  case "4.4.0":
90  return array(
91  "Id" => "integer",
92  "ExerciseId" => "integer",
93  "Type" => "integer",
94  "Deadline" => "integer",
95  "Instruction" => "text",
96  "Title" => "text",
97  "Mandatory" => "integer",
98  "OrderNr" => "integer",
99  "Dir" => "directory"
100  // peer
101  ,"Peer" => "integer"
102  ,"PeerMin" => "integer"
103  ,"PeerDeadline" => "integer"
104  // global feedback
105  ,"FeedbackFile" => "integer"
106  ,"FeedbackCron" => "integer"
107  ,"FeedbackDate" => "integer"
108  ,"FeedbackDir" => "directory"
109  );
110 
111  case "5.0.0":
112  return array(
113  "Id" => "integer",
114  "ExerciseId" => "integer",
115  "Type" => "integer",
116  "Deadline" => "integer",
117  "Instruction" => "text",
118  "Title" => "text",
119  "Mandatory" => "integer",
120  "OrderNr" => "integer",
121  "Dir" => "directory"
122  // peer
123  ,"Peer" => "integer"
124  ,"PeerMin" => "integer"
125  ,"PeerDeadline" => "integer"
126  ,"PeerFile" => "integer"
127  ,"PeerPersonal" => "integer"
128  // global feedback
129  ,"FeedbackFile" => "integer"
130  ,"FeedbackCron" => "integer"
131  ,"FeedbackDate" => "integer"
132  ,"FeedbackDir" => "directory"
133  );
134 
135  case "5.1.0":
136  return array(
137  "Id" => "integer",
138  "ExerciseId" => "integer",
139  "Type" => "integer",
140  "Deadline" => "integer",
141  "Deadline2" => "integer",
142  "Instruction" => "text",
143  "Title" => "text",
144  "Mandatory" => "integer",
145  "OrderNr" => "integer",
146  "TeamTutor" => "integer",
147  "MaxFile" => "integer",
148  "Dir" => "directory"
149  // peer
150  ,"Peer" => "integer"
151  ,"PeerMin" => "integer"
152  ,"PeerDeadline" => "integer"
153  ,"PeerFile" => "integer"
154  ,"PeerPersonal" => "integer"
155  ,"PeerChar" => "integer"
156  ,"PeerUnlock" => "integer"
157  ,"PeerValid" => "integer"
158  ,"PeerText" => "integer"
159  ,"PeerRating" => "integer"
160  ,"PeerCritCat" => "integer"
161  // global feedback
162  ,"FeedbackFile" => "integer"
163  ,"FeedbackCron" => "integer"
164  ,"FeedbackDate" => "integer"
165  ,"FeedbackDir" => "directory"
166  );
167  }
168  }
169 
170  if ($a_entity == "exc_cit_cat")
171  {
172  switch ($a_version)
173  {
174  case "5.1.0":
175  return array(
176  "Id" => "integer"
177  ,"Parent" => "integer"
178  ,"Title" => "text"
179  ,"Pos" => "integer"
180  );
181  }
182  }
183 
184  if ($a_entity == "exc_cit")
185  {
186  switch ($a_version)
187  {
188  case "5.1.0":
189  return array(
190  "Id" => "integer"
191  ,"Parent" => "integer"
192  ,"Type" => "text"
193  ,"Title" => "text"
194  ,"Descr" => "text"
195  ,"Pos" => "integer"
196  ,"Required" => "integer"
197  ,"Def" => "text"
198  );
199  }
200  }
201  }
202 
209  function readData($a_entity, $a_version, $a_ids, $a_field = "")
210  {
211  global $ilDB;
212 
213  if (!is_array($a_ids))
214  {
215  $a_ids = array($a_ids);
216  }
217 
218  if ($a_entity == "exc")
219  {
220  switch ($a_version)
221  {
222  case "4.1.0":
223  $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description,".
224  " pass_mode, pass_nr, show_submissions".
225  " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id)".
226  " WHERE ".$ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
227  break;
228 
229  case "4.4.0":
230  case "5.0.0":
231  case "5.1.0":
232  $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description,".
233  " pass_mode, pass_nr, show_submissions, compl_by_submission".
234  " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id)".
235  " WHERE ".$ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
236  break;
237  }
238  }
239 
240  if ($a_entity == "exc_assignment")
241  {
242  switch ($a_version)
243  {
244  case "4.1.0":
245  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline, ".
246  " instruction, title, start_time, mandatory, order_nr".
247  " FROM exc_assignment".
248  " WHERE ".$ilDB->in("exc_id", $a_ids, false, "integer"));
249  break;
250 
251  case "4.4.0":
252  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline,".
253  " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline,".
254  " fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date".
255  " FROM exc_assignment".
256  " WHERE ".$ilDB->in("exc_id", $a_ids, false, "integer"));
257  break;
258 
259  case "5.0.0":
260  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline,".
261  " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline,".
262  " peer_file, peer_prsl peer_personal, fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date".
263  " FROM exc_assignment".
264  " WHERE ".$ilDB->in("exc_id", $a_ids, false, "integer"));
265  break;
266 
267  case "5.1.0":
268  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline, deadline2,".
269  " instruction, title, start_time, mandatory, order_nr, team_tutor, max_file, peer, peer_min,".
270  " peer_dl peer_deadline, peer_file, peer_prsl peer_personal, peer_char, peer_unlock, peer_valid,".
271  " peer_text, peer_rating, peer_crit_cat, fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date".
272  " FROM exc_assignment".
273  " WHERE ".$ilDB->in("exc_id", $a_ids, false, "integer"));
274  break;
275  }
276  }
277 
278  if ($a_entity == "exc_crit_cat")
279  {
280  switch ($a_version)
281  {
282  case "5.1.0":
283  $this->getDirectDataFromQuery("SELECT id, parent, title, pos".
284  " FROM exc_crit_cat".
285  " WHERE ".$ilDB->in("parent", $a_ids, false, "integer"));
286  break;
287  }
288  }
289 
290  if ($a_entity == "exc_crit")
291  {
292  switch ($a_version)
293  {
294  case "5.1.0":
295  $this->getDirectDataFromQuery("SELECT id, parent, type, title".
296  ", descr, pos, required, def".
297  " FROM exc_crit".
298  " WHERE ".$ilDB->in("parent", $a_ids, false, "integer"));
299  break;
300  }
301  }
302  }
303 
310  function getXmlRecord($a_entity, $a_version, $a_set)
311  {
312  if ($a_entity == "exc_assignment")
313  {
314  // convert server dates to utc
315  if($a_set["StartTime"] != "")
316  {
317  $start = new ilDateTime($a_set["StartTime"], IL_CAL_UNIX);
318  $a_set["StartTime"] = $start->get(IL_CAL_DATETIME,'','UTC');
319  }
320  if($a_set["Deadline"] != "")
321  {
322  $deadline = new ilDateTime($a_set["Deadline"], IL_CAL_UNIX);
323  $a_set["Deadline"] = $deadline->get(IL_CAL_DATETIME,'','UTC');
324  }
325  if($a_set["Deadline2"] != "")
326  {
327  $deadline = new ilDateTime($a_set["Deadline2"], IL_CAL_UNIX);
328  $a_set["Deadline2"] = $deadline->get(IL_CAL_DATETIME,'','UTC');
329  }
330 
331  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
332  $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
333  $a_set["Dir"] = $fstorage->getPath();
334 
335  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
336  $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
337  $a_set["FeedbackDir"] = $fstorage->getGlobalFeedbackPath();
338  }
339 
340  return $a_set;
341  }
342 
343 
347  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
348  {
349  switch ($a_entity)
350  {
351  case "exc":
352  return array (
353  "exc_crit_cat" => array("ids" => $a_rec["Id"]),
354  "exc_assignment" => array("ids" => $a_rec["Id"])
355  );
356 
357  case "exc_crit_cat":
358  return array (
359  "exc_crit" => array("ids" => $a_rec["Id"])
360  );
361  }
362 
363  return false;
364  }
365 
366 
373  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
374  {
375 //echo $a_entity;
376 //var_dump($a_rec);
377 
378  switch ($a_entity)
379  {
380  case "exc":
381  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
382 
383  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
384  {
385  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
386  }
387  else
388  {
389  $newObj = new ilObjExercise();
390  $newObj->setType("exc");
391  $newObj->create(true);
392  }
393 
394  $newObj->setTitle($a_rec["Title"]);
395  $newObj->setDescription($a_rec["Description"]);
396  $newObj->setPassMode($a_rec["PassMode"]);
397  $newObj->setPassNr($a_rec["PassNr"]);
398  $newObj->setShowSubmissions($a_rec["ShowSubmissions"]);
399  $newObj->setCompletionBySubmission($a_rec["ComplBySubmission"]);
400  $newObj->update();
401  $newObj->saveData();
402  $this->current_exc = $newObj;
403 
404  $a_mapping->addMapping("Modules/Exercise", "exc", $a_rec["Id"], $newObj->getId());
405  break;
406 
407  case "exc_assignment":
408  $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["ExerciseId"]);
409  if ($exc_id > 0)
410  {
411  if (is_object($this->current_exc) && $this->current_exc->getId() == $exc_id)
412  {
413  $exc = $this->current_exc;
414  }
415  else
416  {
417  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
418  $exc = new ilObjExercise($exc_id, false);
419  }
420 
421  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
422 
423  $ass = new ilExAssignment();
424  $ass->setExerciseId($exc_id);
425 
426  if ($a_rec["StartTime"] != "")
427  {
428  $start = new ilDateTime($a_rec["StartTime"], IL_CAL_DATETIME, "UTC");
429  $ass->setStartTime($start->get(IL_CAL_UNIX));
430  }
431 
432  if ($a_rec["Deadline"] != "")
433  {
434  $deadline = new ilDateTime($a_rec["Deadline"], IL_CAL_DATETIME, "UTC");
435  $ass->setDeadline($deadline->get(IL_CAL_UNIX));
436  }
437 
438  $ass->setInstruction($a_rec["Instruction"]);
439  $ass->setTitle($a_rec["Title"]);
440  $ass->setMandatory($a_rec["Mandatory"]);
441  $ass->setOrderNr($a_rec["OrderNr"]);
442 
443  // 4.2
444  $ass->setType($a_rec["Type"]);
445 
446  // 4.4
447  $ass->setPeerReview($a_rec["Peer"]);
448  $ass->setPeerReviewMin($a_rec["PeerMin"]);
449  $ass->setPeerReviewDeadline($a_rec["PeerDeadline"]);
450  $ass->setFeedbackFile($a_rec["FeedbackFile"]);
451  $ass->setFeedbackCron($a_rec["FeedbackCron"]);
452  $ass->setFeedbackDate($a_rec["FeedbackDate"]);
453 
454  // 5.0
455  $ass->setPeerReviewFileUpload($a_rec["PeerFile"]);
456  $ass->setPeerReviewPersonalized($a_rec["PeerPersonal"]);
457 
458  // 5.1
459  if ($a_rec["Deadline2"] != "")
460  {
461  $deadline = new ilDateTime($a_rec["Deadline2"], IL_CAL_DATETIME, "UTC");
462  $ass->setExtendedDeadline($deadline->get(IL_CAL_UNIX));
463  }
464  $ass->setMaxFile($a_rec["MaxFile"]);
465  $ass->setTeamTutor($a_rec["TeamTutor"]);
466  $ass->setPeerReviewChars($a_rec["PeerChar"]);
467  $ass->setPeerReviewSimpleUnlock($a_rec["PeerUnlock"]);
468  $ass->setPeerReviewValid($a_rec["PeerValid"]);
469  $ass->setPeerReviewText($a_rec["PeerText"]);
470  $ass->setPeerReviewRating($a_rec["PeerRating"]);
471 
472  // criteria catalogue
473  if($a_rec["PeerCritCat"])
474  {
475  $ass->setPeerReviewCriteriaCatalogue($a_mapping->getMapping("Modules/Exercise", "exc_crit_cat", $a_rec["PeerCritCat"]));
476  }
477 
478  $ass->save();
479 
480  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
481  $fstorage = new ilFSStorageExercise($exc_id, $ass->getId());
482  $fstorage->create();
483 
484  // assignment files
485  $dir = str_replace("..", "", $a_rec["Dir"]);
486  if ($dir != "" && $this->getImportDirectory() != "")
487  {
488  $source_dir = $this->getImportDirectory()."/".$dir;
489  $target_dir = $fstorage->getPath();
490  ilUtil::rCopy($source_dir, $target_dir);
491  }
492 
493  // (4.4) global feedback file
494  $dir = str_replace("..", "", $a_rec["FeedbackDir"]);
495  if ($dir != "" && $this->getImportDirectory() != "")
496  {
497  $source_dir = $this->getImportDirectory()."/".$dir;
498  $target_dir = $fstorage->getGlobalFeedbackPath();
499  ilUtil::rCopy($source_dir, $target_dir);
500  }
501 
502  $a_mapping->addMapping("Modules/Exercise", "exc_assignment", $a_rec["Id"], $ass->getId());
503 
504  }
505 
506  break;
507 
508  case "exc_crit_cat":
509  $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["Parent"]);
510  if ($exc_id > 0)
511  {
512  include_once("./Modules/Exercise/classes/class.ilExcCriteriaCatalogue.php");
513  $crit_cat = new ilExcCriteriaCatalogue();
514  $crit_cat->setParent($exc_id);
515  $crit_cat->setTitle($a_rec["Title"]);
516  $crit_cat->setPosition($a_rec["Pos"]);
517  $crit_cat->save();
518 
519  $a_mapping->addMapping("Modules/Exercise", "exc_crit_cat", $a_rec["Id"], $crit_cat->getId());
520  }
521  break;
522 
523  case "exc_crit":
524  $crit_cat_id = $a_mapping->getMapping("Modules/Exercise", "exc_crit_cat", $a_rec["Parent"]);
525  if ($crit_cat_id > 0)
526  {
527  include_once("./Modules/Exercise/classes/class.ilExcCriteria.php");
528  $crit = ilExcCriteria::getInstanceByType($a_rec["Type"]);
529  $crit->setParent($crit_cat_id);
530  $crit->setTitle($a_rec["Title"]);
531  $crit->setDescription($a_rec["Descr"]);
532  $crit->setPosition($a_rec["Pos"]);
533  $crit->setRequired($a_rec["Required"]);
534  $crit->importDefinition($a_rec["Def"]);
535  $crit->save();
536  }
537  break;
538  }
539  }
540 }
541 ?>
static getInstanceByType($a_type)
Class ilExcCriteriaCatalogue.
Exercise assignment.
const IL_CAL_DATETIME
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getTypes($a_entity, $a_version)
Get field types for entity.
getImportDirectory()
Get import directory.
const IL_CAL_UNIX
Class ilObjExercise.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record (export)
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
Exercise data set class.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
Date and time handling
getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
global $ilDB
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getSupportedVersions()
Get supported versions.