ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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");
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  case "4.4.0":
51  case "5.0.0":
52  return array(
53  "Id" => "integer",
54  "Title" => "text",
55  "Description" => "text",
56  "PassMode" => "text",
57  "PassNr" => "integer",
58  "ShowSubmissions" => "integer");
59  }
60  }
61 
62  if ($a_entity == "exc_assignment")
63  {
64  switch ($a_version)
65  {
66  case "4.1.0":
67  return array(
68  "Id" => "integer",
69  "ExerciseId" => "integer",
70  "Deadline" => "text",
71  "Instruction" => "text",
72  "Title" => "text",
73  "Mandatory" => "integer",
74  "OrderNr" => "integer",
75  "Dir" => "directory");
76 
77  case "4.4.0":
78  return array(
79  "Id" => "integer",
80  "ExerciseId" => "integer",
81  "Type" => "integer",
82  "Deadline" => "integer",
83  "Instruction" => "text",
84  "Title" => "text",
85  "Mandatory" => "integer",
86  "OrderNr" => "integer",
87  "Dir" => "directory"
88  // peer
89  ,"Peer" => "integer"
90  ,"PeerMin" => "integer"
91  ,"PeerDeadline" => "integer"
92  // global feedback
93  ,"FeedbackFile" => "integer"
94  ,"FeedbackCron" => "integer"
95  ,"FeedbackDate" => "integer"
96  ,"FeedbackDir" => "directory"
97  );
98 
99  case "5.0.0":
100  return array(
101  "Id" => "integer",
102  "ExerciseId" => "integer",
103  "Type" => "integer",
104  "Deadline" => "integer",
105  "Instruction" => "text",
106  "Title" => "text",
107  "Mandatory" => "integer",
108  "OrderNr" => "integer",
109  "Dir" => "directory"
110  // peer
111  ,"Peer" => "integer"
112  ,"PeerMin" => "integer"
113  ,"PeerDeadline" => "integer"
114  ,"PeerFile" => "integer"
115  ,"PeerPersonal" => "integer"
116  // global feedback
117  ,"FeedbackFile" => "integer"
118  ,"FeedbackCron" => "integer"
119  ,"FeedbackDate" => "integer"
120  ,"FeedbackDir" => "directory"
121  );
122  }
123  }
124 
125  }
126 
133  function readData($a_entity, $a_version, $a_ids, $a_field = "")
134  {
135  global $ilDB;
136 
137  if (!is_array($a_ids))
138  {
139  $a_ids = array($a_ids);
140  }
141 
142  if ($a_entity == "exc")
143  {
144  switch ($a_version)
145  {
146  case "4.1.0":
147  case "4.4.0":
148  case "5.0.0":
149  $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description, ".
150  " pass_mode, pass_nr, show_submissions".
151  " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id) ".
152  "WHERE ".
153  $ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
154  break;
155  }
156  }
157 
158  if ($a_entity == "exc_assignment")
159  {
160  switch ($a_version)
161  {
162  case "4.1.0":
163  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline, ".
164  " instruction, title, start_time, mandatory, order_nr".
165  " FROM exc_assignment ".
166  "WHERE ".
167  $ilDB->in("exc_id", $a_ids, false, "integer"));
168  break;
169 
170  case "4.4.0":
171  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline,".
172  " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline,".
173  " fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date".
174  " FROM exc_assignment".
175  " WHERE ".
176  $ilDB->in("exc_id", $a_ids, false, "integer"));
177  break;
178 
179  case "5.0.0":
180  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline,".
181  " instruction, title, start_time, mandatory, order_nr, peer, peer_min, peer_dl peer_deadline,".
182  " peer_file, peer_prsl peer_personal, fb_file feedback_file, fb_cron feedback_cron, fb_date feedback_date".
183  " FROM exc_assignment".
184  " WHERE ".
185  $ilDB->in("exc_id", $a_ids, false, "integer"));
186  break;
187  }
188  }
189 
190  }
191 
198  function getXmlRecord($a_entity, $a_version, $a_set)
199  {
200  if ($a_entity == "exc_assignment")
201  {
202  // convert server dates to utc
203  if($a_set["StartTime"] != "")
204  {
205  $start = new ilDateTime($a_set["StartTime"], IL_CAL_UNIX);
206  $a_set["StartTime"] = $start->get(IL_CAL_DATETIME,'','UTC');
207  }
208  if($a_set["Deadline"] != "")
209  {
210  $deadline = new ilDateTime($a_set["Deadline"], IL_CAL_UNIX);
211  $a_set["Deadline"] = $deadline->get(IL_CAL_DATETIME,'','UTC');
212  }
213 
214  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
215  $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
216  $a_set["Dir"] = $fstorage->getPath();
217 
218  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
219  $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
220  $a_set["FeedbackDir"] = $fstorage->getGlobalFeedbackPath();
221  }
222 
223  return $a_set;
224  }
225 
226 
230  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
231  {
232  switch ($a_entity)
233  {
234  case "exc":
235  return array (
236  "exc_assignment" => array("ids" => $a_rec["Id"])
237  );
238  }
239 
240  return false;
241  }
242 
243 
250  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
251  {
252 //echo $a_entity;
253 //var_dump($a_rec);
254 
255  switch ($a_entity)
256  {
257  case "exc":
258  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
259 
260  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
261  {
262  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
263  }
264  else
265  {
266  $newObj = new ilObjExercise();
267  $newObj->setType("exc");
268  $newObj->create(true);
269  }
270 
271  $newObj->setTitle($a_rec["Title"]);
272  $newObj->setDescription($a_rec["Description"]);
273  $newObj->setPassMode($a_rec["PassMode"]);
274  $newObj->setPassNr($a_rec["PassNr"]);
275  $newObj->setShowSubmissions($a_rec["ShowSubmissions"]);
276  $newObj->update();
277  $newObj->saveData();
278 //var_dump($a_rec);
279  $this->current_exc = $newObj;
280 
281  $a_mapping->addMapping("Modules/Exercise", "exc", $a_rec["Id"], $newObj->getId());
282 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
283  break;
284 
285  case "exc_assignment":
286  $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["ExerciseId"]);
287  if ($exc_id > 0)
288  {
289  if (is_object($this->current_exc) && $this->current_exc->getId() == $exc_id)
290  {
291  $exc = $this->current_exc;
292  }
293  else
294  {
295  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
296  $exc = new ilObjExercise($exc_id, false);
297  }
298 
299  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
300 
301  $ass = new ilExAssignment();
302  $ass->setExerciseId($exc_id);
303 
304  if ($a_rec["StartTime"] != "")
305  {
306  $start = new ilDateTime($a_rec["StartTime"], IL_CAL_DATETIME, "UTC");
307  $ass->setStartTime($start->get(IL_CAL_UNIX));
308  }
309 
310  if ($a_rec["Deadline"] != "")
311  {
312  $deadline = new ilDateTime($a_rec["Deadline"], IL_CAL_DATETIME, "UTC");
313  $ass->setDeadline($deadline->get(IL_CAL_UNIX));
314  }
315 //var_dump($a_rec);
316  $ass->setInstruction($a_rec["Instruction"]);
317  $ass->setTitle($a_rec["Title"]);
318  $ass->setMandatory($a_rec["Mandatory"]);
319  $ass->setOrderNr($a_rec["OrderNr"]);
320 
321  // 4.2
322  $ass->setType($a_rec["Type"]);
323 
324  // 4.4
325  $ass->setPeerReview($a_rec["Peer"]);
326  $ass->setPeerReviewMin($a_rec["PeerMin"]);
327  $ass->setPeerReviewDeadline($a_rec["PeerDeadline"]);
328  $ass->setFeedbackFile($a_rec["FeedbackFile"]);
329  $ass->setFeedbackCron($a_rec["FeedbackCron"]);
330  $ass->setFeedbackDate($a_rec["FeedbackDate"]);
331 
332  // 5.0
333  $ass->setPeerReviewFileUpload($a_rec["PeerFile"]);
334  $ass->setPeerReviewPersonalized($a_rec["PeerPersonal"]);
335 
336  $ass->save();
337 
338  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
339  $fstorage = new ilFSStorageExercise($exc_id, $ass->getId());
340  $fstorage->create();
341 
342  // assignment files
343  $dir = str_replace("..", "", $a_rec["Dir"]);
344  if ($dir != "" && $this->getImportDirectory() != "")
345  {
346  $source_dir = $this->getImportDirectory()."/".$dir;
347  $target_dir = $fstorage->getPath();
348  ilUtil::rCopy($source_dir, $target_dir);
349  }
350 
351  // (4.4) global feedback file
352  $dir = str_replace("..", "", $a_rec["FeedbackDir"]);
353  if ($dir != "" && $this->getImportDirectory() != "")
354  {
355  $source_dir = $this->getImportDirectory()."/".$dir;
356  $target_dir = $fstorage->getGlobalFeedbackPath();
357  ilUtil::rCopy($source_dir, $target_dir);
358  }
359 
360  $a_mapping->addMapping("Modules/Exercise", "exc_assignment", $a_rec["Id"], $ass->getId());
361 
362  }
363 
364  break;
365  }
366  }
367 }
368 ?>
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.