ILIAS  Release_4_1_x_branch Revision 61804
 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($a_entity)
22  {
23  switch ($a_entity)
24  {
25  case "exc":
26  return array("4.1.0");
27  }
28  }
29 
36  function getXmlNamespace($a_entity, $a_target_release)
37  {
38  return "http://www.ilias.de/xml/Modules/Exercise/".$a_entity;
39  }
40 
47  protected function getTypes($a_entity, $a_version)
48  {
49  if ($a_entity == "exc")
50  {
51  switch ($a_version)
52  {
53  case "4.1.0":
54  return array(
55  "Id" => "integer",
56  "Title" => "text",
57  "Description" => "text",
58  "PassMode" => "text",
59  "PassNr" => "integer",
60  "ShowSubmissions" => "integer");
61  }
62  }
63 
64  if ($a_entity == "exc_assignment")
65  {
66  switch ($a_version)
67  {
68  case "4.1.0":
69  return array(
70  "Id" => "integer",
71  "ExerciseId" => "integer",
72  "Deadline" => "text",
73  "Instruction" => "text",
74  "Title" => "text",
75  "Mandatory" => "integer",
76  "OrderNr" => "integer",
77  "Dir" => "directory");
78  }
79  }
80 
81  }
82 
89  function readData($a_entity, $a_version, $a_ids, $a_field = "")
90  {
91  global $ilDB;
92 
93  if (!is_array($a_ids))
94  {
95  $a_ids = array($a_ids);
96  }
97 
98  if ($a_entity == "exc")
99  {
100  switch ($a_version)
101  {
102  case "4.1.0":
103  $this->getDirectDataFromQuery("SELECT exc_data.obj_id id, title, description, ".
104  " pass_mode, pass_nr, show_submissions".
105  " FROM exc_data JOIN object_data ON (exc_data.obj_id = object_data.obj_id) ".
106  "WHERE ".
107  $ilDB->in("exc_data.obj_id", $a_ids, false, "integer"));
108  break;
109  }
110  }
111 
112  if ($a_entity == "exc_assignment")
113  {
114  switch ($a_version)
115  {
116  case "4.1.0":
117  $this->getDirectDataFromQuery("SELECT id, exc_id exercise_id, time_stamp deadline, ".
118  " instruction, title, start_time, mandatory, order_nr".
119  " FROM exc_assignment ".
120  "WHERE ".
121  $ilDB->in("exc_id", $a_ids, false, "integer"));
122  break;
123  }
124  }
125 
126  }
127 
134  function getXmlRecord($a_entity, $a_version, $a_set)
135  {
136  if ($a_entity == "exc_assignment")
137  {
138  // convert server dates to utc
139  if($a_set["StartTime"] != "")
140  {
141  $start = new ilDateTime($a_set["StartTime"], IL_CAL_UNIX);
142  $a_set["StartTime"] = $start->get(IL_CAL_DATETIME,'','UTC');
143  }
144  if($a_set["Deadline"] != "")
145  {
146  $deadline = new ilDateTime($a_set["Deadline"], IL_CAL_UNIX);
147  $a_set["Deadline"] = $deadline->get(IL_CAL_DATETIME,'','UTC');
148  }
149 
150  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
151  $fstorage = new ilFSStorageExercise($a_set["ExerciseId"], $a_set["Id"]);
152  $a_set["Dir"] = $fstorage->getPath();
153 
154  }
155 
156  return $a_set;
157  }
158 
159 
163  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
164  {
165  switch ($a_entity)
166  {
167  case "exc":
168  return array (
169  "exc_assignment" => array("ids" => $a_rec["Id"])
170  );
171  }
172 
173  return false;
174  }
175 
176 
183  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
184  {
185 //echo $a_entity;
186 //var_dump($a_rec);
187 
188  switch ($a_entity)
189  {
190  case "exc":
191  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
192 
193  if($new_id = $a_mapping->getMapping('Services/Container','objs',$a_rec['Id']))
194  {
195  $newObj = ilObjectFactory::getInstanceByObjId($new_id,false);
196  }
197  else
198  {
199  $newObj = new ilObjExercise();
200  $newObj->setType("exc");
201  $newObj->create(true);
202  }
203 
204  $newObj->setTitle($a_rec["Title"]);
205  $newObj->setDescription($a_rec["Description"]);
206  $newObj->setPassMode($a_rec["PassMode"]);
207  $newObj->setPassNr($a_rec["PassNr"]);
208  $newObj->setShowSubmissions($a_rec["ShowSubmissions"]);
209  $newObj->update();
210  $newObj->saveData();
211 //var_dump($a_rec);
212  $this->current_exc = $newObj;
213 
214  $a_mapping->addMapping("Modules/Exercise", "exc", $a_rec["Id"], $newObj->getId());
215 //var_dump($a_mapping->mappings["Services/News"]["news_context"]);
216  break;
217 
218  case "exc_assignment":
219  $exc_id = $a_mapping->getMapping("Modules/Exercise", "exc", $a_rec["ExerciseId"]);
220  if ($exc_id > 0)
221  {
222  if (is_object($this->current_exc) && $this->current_exc->getId() == $exc_id)
223  {
224  $exc = $this->current_exc;
225  }
226  else
227  {
228  include_once("./Modules/Exercise/classes/class.ilObjExercise.php");
229  $exc = new ilObjExercise($exc_id, false);
230  }
231 
232  include_once("./Modules/Exercise/classes/class.ilExAssignment.php");
233 
234  $ass = new ilExAssignment();
235  $ass->setExerciseId($exc_id);
236 
237  if ($a_rec["StartTime"] != "")
238  {
239  $start = new ilDateTime($a_rec["StartTime"], IL_CAL_DATETIME, "UTC");
240  $ass->setStartTime($start->get(IL_CAL_UNIX));
241  }
242 
243  if ($a_rec["Deadline"] != "")
244  {
245  $deadline = new ilDateTime($a_rec["Deadline"], IL_CAL_DATETIME, "UTC");
246  $ass->setDeadline($deadline->get(IL_CAL_UNIX));
247  }
248 //var_dump($a_rec);
249  $ass->setInstruction($a_rec["Instruction"]);
250  $ass->setTitle($a_rec["Title"]);
251  $ass->setMandatory($a_rec["Mandatory"]);
252  $ass->setOrderNr($a_rec["OrderNr"]);
253  $ass->save();
254 
255  include_once("./Modules/Exercise/classes/class.ilFSStorageExercise.php");
256  $fstorage = new ilFSStorageExercise($exc_id, $ass->getId());
257  $fstorage->create();
258  $dir = str_replace("..", "", $a_rec["Dir"]);
259  if ($dir != "" && $this->getImportDirectory() != "")
260  {
261  $source_dir = $this->getImportDirectory()."/".$dir;
262  $target_dir = $fstorage->getPath();
263  ilUtil::rCopy($source_dir, $target_dir);
264  }
265 
266  $a_mapping->addMapping("Modules/Exercise", "exc_assignment", $a_rec["Id"], $ass->getId());
267 
268  }
269 
270  break;
271  }
272  }
273 }
274 ?>