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