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