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