ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
22{
29 public function getSupportedVersions()
30 {
31 return array("4.1.0", "4.4.0", "5.0.0", "5.1.0", "5.2.0", "5.3.0");
32 }
33
40 public function getXmlNamespace($a_entity, $a_schema_version)
41 {
42 return "http://www.ilias.de/xml/Modules/Exercise/" . $a_entity;
43 }
44
51 protected function getTypes($a_entity, $a_version)
52 {
53 if ($a_entity == "exc") {
54 switch ($a_version) {
55 case "4.1.0":
56 return array(
57 "Id" => "integer",
58 "Title" => "text",
59 "Description" => "text",
60 "PassMode" => "text",
61 "PassNr" => "integer",
62 "ShowSubmissions" => "integer"
63 );
64
65 case "4.4.0":
66 case "5.0.0":
67 case "5.1.0":
68 return array(
69 "Id" => "integer",
70 "Title" => "text",
71 "Description" => "text",
72 "PassMode" => "text",
73 "PassNr" => "integer",
74 "ShowSubmissions" => "integer",
75 "ComplBySubmission" => "integer"
76 );
77
78 case "5.2.0":
79 case "5.3.0":
80 return array(
81 "Id" => "integer",
82 "Title" => "text",
83 "Description" => "text",
84 "PassMode" => "text",
85 "PassNr" => "integer",
86 "ShowSubmissions" => "integer",
87 "ComplBySubmission" => "integer",
88 "Tfeedback" => "integer"
89 );
90 }
91 }
92
93 if ($a_entity == "exc_assignment") {
94 switch ($a_version) {
95 case "4.1.0":
96 return array(
97 "Id" => "integer",
98 "ExerciseId" => "integer",
99 "Deadline" => "text",
100 "Instruction" => "text",
101 "Title" => "text",
102 "Mandatory" => "integer",
103 "OrderNr" => "integer",
104 "Dir" => "directory");
105
106 case "4.4.0":
107 return array(
108 "Id" => "integer",
109 "ExerciseId" => "integer",
110 "Type" => "integer",
111 "Deadline" => "integer",
112 "Instruction" => "text",
113 "Title" => "text",
114 "Mandatory" => "integer",
115 "OrderNr" => "integer",
116 "Dir" => "directory"
117 // peer
118 ,"Peer" => "integer"
119 ,"PeerMin" => "integer"
120 ,"PeerDeadline" => "integer"
121 // global feedback
122 ,"FeedbackFile" => "integer"
123 ,"FeedbackCron" => "integer"
124 ,"FeedbackDate" => "integer"
125 ,"FeedbackDir" => "directory"
126 );
127
128 case "5.0.0":
129 return array(
130 "Id" => "integer",
131 "ExerciseId" => "integer",
132 "Type" => "integer",
133 "Deadline" => "integer",
134 "Instruction" => "text",
135 "Title" => "text",
136 "Mandatory" => "integer",
137 "OrderNr" => "integer",
138 "Dir" => "directory"
139 // peer
140 ,"Peer" => "integer"
141 ,"PeerMin" => "integer"
142 ,"PeerDeadline" => "integer"
143 ,"PeerFile" => "integer"
144 ,"PeerPersonal" => "integer"
145 // global feedback
146 ,"FeedbackFile" => "integer"
147 ,"FeedbackCron" => "integer"
148 ,"FeedbackDate" => "integer"
149 ,"FeedbackDir" => "directory"
150 );
151
152 case "5.1.0":
153 case "5.2.0":
154 return array(
155 "Id" => "integer",
156 "ExerciseId" => "integer",
157 "Type" => "integer",
158 "Deadline" => "integer",
159 "Deadline2" => "integer",
160 "Instruction" => "text",
161 "Title" => "text",
162 "Mandatory" => "integer",
163 "OrderNr" => "integer",
164 "TeamTutor" => "integer",
165 "MaxFile" => "integer",
166 "Dir" => "directory"
167 // peer
168 ,"Peer" => "integer"
169 ,"PeerMin" => "integer"
170 ,"PeerDeadline" => "integer"
171 ,"PeerFile" => "integer"
172 ,"PeerPersonal" => "integer"
173 ,"PeerChar" => "integer"
174 ,"PeerUnlock" => "integer"
175 ,"PeerValid" => "integer"
176 ,"PeerText" => "integer"
177 ,"PeerRating" => "integer"
178 ,"PeerCritCat" => "integer"
179 // global feedback
180 ,"FeedbackFile" => "integer"
181 ,"FeedbackCron" => "integer"
182 ,"FeedbackDate" => "integer"
183 ,"FeedbackDir" => "directory"
184 );
185 case "5.3.0":
186 return array(
187 "Id" => "integer",
188 "ExerciseId" => "integer",
189 "Type" => "integer",
190 "Deadline" => "integer",
191 "Deadline2" => "integer",
192 "Instruction" => "text",
193 "Title" => "text",
194 "Mandatory" => "integer",
195 "OrderNr" => "integer",
196 "TeamTutor" => "integer",
197 "MaxFile" => "integer",
198 "Dir" => "directory",
199 //web data directory
200 "WebDataDir" => "directory"
201 // peer
202 ,"Peer" => "integer"
203 ,"PeerMin" => "integer"
204 ,"PeerDeadline" => "integer"
205 ,"PeerFile" => "integer"
206 ,"PeerPersonal" => "integer"
207 ,"PeerChar" => "integer"
208 ,"PeerUnlock" => "integer"
209 ,"PeerValid" => "integer"
210 ,"PeerText" => "integer"
211 ,"PeerRating" => "integer"
212 ,"PeerCritCat" => "integer"
213 // global feedback
214 ,"FeedbackFile" => "integer"
215 ,"FeedbackCron" => "integer"
216 ,"FeedbackDate" => "integer"
217 ,"FeedbackDir" => "directory"
218 );
219 }
220 }
221
222 if ($a_entity == "exc_cit_cat") {
223 switch ($a_version) {
224 case "5.1.0":
225 case "5.2.0":
226 case "5.3.0":
227 return array(
228 "Id" => "integer"
229 ,"Parent" => "integer"
230 ,"Title" => "text"
231 ,"Pos" => "integer"
232 );
233 }
234 }
235
236 if ($a_entity == "exc_cit") {
237 switch ($a_version) {
238 case "5.1.0":
239 case "5.2.0":
240 case "5.3.0":
241 return array(
242 "Id" => "integer"
243 ,"Parent" => "integer"
244 ,"Type" => "text"
245 ,"Title" => "text"
246 ,"Descr" => "text"
247 ,"Pos" => "integer"
248 ,"Required" => "integer"
249 ,"Def" => "text"
250 ,"DefJson" => "text"
251 );
252 }
253 }
254
255 if ($a_entity == "exc_ass_file_order") {
256 switch ($a_version) {
257 case "5.3.0":
258 return array(
259 "Id" => "integer"
260 , "AssignmentId" => "integer"
261 , "Filename" => "text"
262 , "OrderNr" => "integer"
263 );
264 }
265 }
266 return false;
267 }
268
275 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
276 {
278
279 if (!is_array($a_ids)) {
280 $a_ids = array($a_ids);
281 }
282
283 if ($a_entity == "exc") {
284 switch ($a_version) {
285 case "4.1.0":
286 $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description," .
287 " pass_mode, pass_nr, show_submissions" .
288 " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id)" .
289 " WHERE " . $ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
290 break;
291
292 case "4.4.0":
293 case "5.0.0":
294 case "5.1.0":
295 $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description," .
296 " pass_mode, pass_nr, show_submissions, compl_by_submission" .
297 " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id)" .
298 " WHERE " . $ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
299 break;
300
301 case "5.2.0":
302 case "5.3.0":
303 $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description," .
304 " pass_mode, pass_nr, show_submissions, compl_by_submission, tfeedback" .
305 " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id)" .
306 " WHERE " . $ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
307 break;
308 }
309 }
310
311 if ($a_entity == "exc_assignment") {
312 switch ($a_version) {
313 case "4.1.0":
314 $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline, " .
315 " instruction, title, start_time, mandatory, order_nr" .
316 " FROM exc_assignment" .
317 " WHERE " . $ilDB->in("exc_id", $a_ids, false, "integer"));
318 break;
319
320 case "4.4.0":
321 $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline," .
322 " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline," .
323 " fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date" .
324 " FROM exc_assignment" .
325 " WHERE " . $ilDB->in("exc_id", $a_ids, false, "integer"));
326 break;
327
328 case "5.0.0":
329 $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline," .
330 " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline," .
331 " peer_file, peer_prsl peer_personal, fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date" .
332 " FROM exc_assignment" .
333 " WHERE " . $ilDB->in("exc_id", $a_ids, false, "integer"));
334 break;
335
336 case "5.1.0":
337 case "5.2.0":
338 case "5.3.0":
339 $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, type, time_stamp deadline, deadline2," .
340 " instruction, title, start_time, mandatory, order_nr, team_tutor, max_file, peer, peer_min," .
341 " peer_dl peer_deadline, peer_file, peer_prsl peer_personal, peer_char, peer_unlock, peer_valid," .
342 " peer_text, peer_rating, peer_crit_cat, fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date" .
343 " FROM exc_assignment" .
344 " WHERE " . $ilDB->in("exc_id", $a_ids, false, "integer"));
345 break;
346 }
347 }
348
349 if ($a_entity == "exc_crit_cat") {
350 switch ($a_version) {
351 case "5.1.0":
352 case "5.2.0":
353 case "5.3.0":
354 $this->getDirectDataFromQuery("SELECT id, parent, title, pos" .
355 " FROM exc_crit_cat" .
356 " WHERE " . $ilDB->in("parent", $a_ids, false, "integer"));
357 break;
358 }
359 }
360
361 if ($a_entity == "exc_crit") {
362 switch ($a_version) {
363 case "5.1.0":
364 case "5.2.0":
365 case "5.3.0":
366 $this->getDirectDataFromQuery("SELECT id, parent, type, title" .
367 ", descr, pos, required, def" .
368 " FROM exc_crit" .
369 " WHERE " . $ilDB->in("parent", $a_ids, false, "integer"));
370 foreach ($this->data as $k => $v) {
371 $this->data[$k]["DefJson"] = "";
372 if ($v["Def"] != "") {
373 $this->data[$k]["DefJson"] = json_encode(unserialize($v["Def"]));
374 }
375 }
376 break;
377 }
378 }
379
380 if ($a_entity == "exc_ass_file_order") {
381 switch ($a_version) {
382 case "5.3.0":
383 $this->getDirectDataFromQuery("SELECT id, assignment_id, filename, order_nr" .
384 " FROM exc_ass_file_order" .
385 " WHERE " . $ilDB->in("assignment_id", $a_ids, false, "integer"));
386 break;
387 }
388 }
389 }
390
397 public function getXmlRecord($a_entity, $a_version, $a_set)
398 {
399 if ($a_entity == "exc_assignment") {
400 // convert server dates to utc
401 if ($a_set["StartTime"] != "") {
402 $start = new ilDateTime($a_set["StartTime"], IL_CAL_UNIX);
403 $a_set["StartTime"] = $start->get(IL_CAL_DATETIME, '', 'UTC');
404 }
405 if ($a_set["Deadline"] != "") {
406 $deadline = new ilDateTime($a_set["Deadline"], IL_CAL_UNIX);
407 $a_set["Deadline"] = $deadline->get(IL_CAL_DATETIME, '', 'UTC');
408 }
409 if ($a_set["Deadline2"] != "") {
410 $deadline = new ilDateTime($a_set["Deadline2"], IL_CAL_UNIX);
411 $a_set["Deadline2"] = $deadline->get(IL_CAL_DATETIME, '', 'UTC');
412 }
413
414 include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
415 $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
416 $a_set["Dir"] = $fstorage->getPath();
417
418 include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
419 $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
420 $a_set["FeedbackDir"] = $fstorage->getGlobalFeedbackPath();
421
422 //now the instruction files inside the root directory
423 include_once("./Modules/Exercise/classes/class.ilFSWebStorageExercise.php");
424 $fswebstorage = new ilFSWebStorageExercise($a_set['ExerciseId'], $a_set['Id']);
425 $a_set['WebDataDir'] = $fswebstorage->getPath();
426 }
427
428 return $a_set;
429 }
430
431
435 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
436 {
437 switch ($a_entity) {
438 case "exc":
439 switch ($a_version) {
440 case "4.1.0":
441 case "4.4.0":
442 case "5.0.0":
443 return array(
444 "exc_assignment" => array("ids" => $a_rec["Id"])
445 );
446
447 case "5.1.0":
448 case "5.2.0":
449 case "5.3.0":
450 return array(
451 "exc_crit_cat" => array("ids" => $a_rec["Id"]),
452 "exc_assignment" => array("ids" => $a_rec["Id"])
453 );
454 }
455 break;
456
457 case "exc_crit_cat":
458 return array(
459 "exc_crit" => array("ids" => $a_rec["Id"])
460 );
461
462 case "exc_assignment":
463 switch ($a_version) {
464 case "5.3.0":
465 return array(
466 "exc_ass_file_order" => array("ids" => $a_rec["Id"])
467 );
468
469 }
470 break;
471 }
472 return false;
473 }
474
475
482 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
483 {
484 //echo $a_entity;
485 //var_dump($a_rec);
486
487 switch ($a_entity) {
488 case "exc":
489 include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
490
491 if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
492 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
493 } else {
494 $newObj = new ilObjExercise();
495 $newObj->setType("exc");
496 $newObj->create(true);
497 }
498
499 $newObj->setTitle($a_rec["Title"]);
500 $newObj->setDescription($a_rec["Description"]);
501 $newObj->setPassMode($a_rec["PassMode"]);
502 $newObj->setPassNr($a_rec["PassNr"]);
503 $newObj->setShowSubmissions($a_rec["ShowSubmissions"]);
504 $newObj->setCompletionBySubmission($a_rec["ComplBySubmission"]);
505 $newObj->setTutorFeedback($a_rec["Tfeedback"]);
506 $newObj->update();
507 $newObj->saveData();
508 $this->current_exc = $newObj;
509
510 $a_mapping->addMapping("Modules/Exercise", "exc", $a_rec["Id"], $newObj->getId());
511 break;
512
513 case "exc_assignment":
514 $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["ExerciseId"]);
515 if ($exc_id > 0) {
516 if (is_object($this->current_exc) && $this->current_exc->getId() == $exc_id) {
517 $exc = $this->current_exc;
518 } else {
519 include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
520 $exc = new ilObjExercise($exc_id, false);
521 }
522
523 include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
524
525 $ass = new ilExAssignment();
526 $ass->setExerciseId($exc_id);
527
528 if ($a_rec["StartTime"] != "") {
529 $start = new ilDateTime($a_rec["StartTime"], IL_CAL_DATETIME, "UTC");
530 $ass->setStartTime($start->get(IL_CAL_UNIX));
531 }
532
533 if ($a_rec["Deadline"] != "") {
534 $deadline = new ilDateTime($a_rec["Deadline"], IL_CAL_DATETIME, "UTC");
535 $ass->setDeadline($deadline->get(IL_CAL_UNIX));
536 }
537
538 $ass->setInstruction($a_rec["Instruction"]);
539 $ass->setTitle($a_rec["Title"]);
540 $ass->setMandatory($a_rec["Mandatory"]);
541 $ass->setOrderNr($a_rec["OrderNr"]);
542
543 // 4.2
544 $ass->setType($a_rec["Type"]);
545
546 // 4.4
547 $ass->setPeerReview($a_rec["Peer"]);
548 $ass->setPeerReviewMin($a_rec["PeerMin"]);
549 $ass->setPeerReviewDeadline($a_rec["PeerDeadline"]);
550 $ass->setFeedbackFile($a_rec["FeedbackFile"]);
551 $ass->setFeedbackCron($a_rec["FeedbackCron"]);
552 $ass->setFeedbackDate($a_rec["FeedbackDate"]);
553
554 // 5.0
555 $ass->setPeerReviewFileUpload($a_rec["PeerFile"]);
556 $ass->setPeerReviewPersonalized($a_rec["PeerPersonal"]);
557
558 // 5.1
559 if ($a_rec["Deadline2"] != "") {
560 $deadline = new ilDateTime($a_rec["Deadline2"], IL_CAL_DATETIME, "UTC");
561 $ass->setExtendedDeadline($deadline->get(IL_CAL_UNIX));
562 }
563 $ass->setMaxFile($a_rec["MaxFile"]);
564 $ass->setTeamTutor($a_rec["TeamTutor"]);
565 $ass->setPeerReviewChars($a_rec["PeerChar"]);
566 $ass->setPeerReviewSimpleUnlock($a_rec["PeerUnlock"]);
567 $ass->setPeerReviewValid($a_rec["PeerValid"]);
568 $ass->setPeerReviewText($a_rec["PeerText"]);
569 $ass->setPeerReviewRating($a_rec["PeerRating"]);
570
571 // criteria catalogue
572 if ($a_rec["PeerCritCat"]) {
573 $ass->setPeerReviewCriteriaCatalogue($a_mapping->getMapping("Modules/Exercise", "exc_crit_cat", $a_rec["PeerCritCat"]));
574 }
575
576 $ass->save();
577
578 include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
579 $fstorage = new ilFSStorageExercise($exc_id, $ass->getId());
580 $fstorage->create();
581
582 // assignment files
583 $dir = str_replace("..", "", $a_rec["Dir"]);
584 if ($dir != "" && $this->getImportDirectory() != "") {
585 $source_dir = $this->getImportDirectory() . "/" . $dir;
586 $target_dir = $fstorage->getPath();
587 ilUtil::rCopy($source_dir, $target_dir);
588 }
589
590 // (4.4) global feedback file
591 $dir = str_replace("..", "", $a_rec["FeedbackDir"]);
592 if ($dir != "" && $this->getImportDirectory() != "") {
593 $source_dir = $this->getImportDirectory() . "/" . $dir;
594 $target_dir = $fstorage->getGlobalFeedbackPath();
595 ilUtil::rCopy($source_dir, $target_dir);
596 }
597
598 // (5.3) assignment files inside ILIAS
599 include_once("./Modules/Exercise/classes/class.ilFSWebStorageExercise.php");
600 $fwebstorage = new ilFSWebStorageExercise($exc_id, $ass->getId());
601 $fwebstorage->create();
602 $dir = str_replace("..", "", $a_rec["WebDataDir"]);
603 if ($dir != "" && $this->getImportDirectory() != "") {
604 $source_dir = $this->getImportDirectory() . "/" . $dir;
605 $target_dir = $fwebstorage->getPath();
606 ilUtil::rCopy($source_dir, $target_dir);
607 }
608
609 $a_mapping->addMapping("Modules/Exercise", "exc_assignment", $a_rec["Id"], $ass->getId());
610 }
611
612 break;
613
614 case "exc_crit_cat":
615 $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["Parent"]);
616 if ($exc_id > 0) {
617 include_once("./Modules/Exercise/classes/class.ilExcCriteriaCatalogue.php");
618 $crit_cat = new ilExcCriteriaCatalogue();
619 $crit_cat->setParent($exc_id);
620 $crit_cat->setTitle($a_rec["Title"]);
621 $crit_cat->setPosition($a_rec["Pos"]);
622 $crit_cat->save();
623
624 $a_mapping->addMapping("Modules/Exercise", "exc_crit_cat", $a_rec["Id"], $crit_cat->getId());
625 }
626 break;
627
628 case "exc_crit":
629 $crit_cat_id = $a_mapping->getMapping("Modules/Exercise", "exc_crit_cat", $a_rec["Parent"]);
630 if ($crit_cat_id > 0) {
631 include_once("./Modules/Exercise/classes/class.ilExcCriteria.php");
632 $crit = ilExcCriteria::getInstanceByType($a_rec["Type"]);
633 $crit->setParent($crit_cat_id);
634 $crit->setTitle($a_rec["Title"]);
635 $crit->setDescription($a_rec["Descr"]);
636 $crit->setPosition($a_rec["Pos"]);
637 $crit->setRequired($a_rec["Required"]);
638 $crit->importDefinition($a_rec["Def"], $a_rec["DefJson"]);
639 $crit->save();
640 }
641 break;
642
643 case "exc_ass_file_order":
644
645 $ass_id = $a_mapping->getMapping("Modules/Exercise", "exc_assignment", $a_rec["AssignmentId"]);
646 if ($ass_id > 0) {
647 ilExAssignment::instructionFileInsertOrder($a_rec["Filename"], $ass_id, $a_rec["OrderNr"]);
648 }
649 break;
650 }
651 }
652}
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.
static instructionFileInsertOrder($a_filename, $a_ass_id, $a_order_nr=0)
Store the file order in the database.
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
$this data['403_header']