ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPollDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
17 class ilPollDataSet extends ilDataSet
18 {
19  protected $current_blog;
20 
24  public function getSupportedVersions()
25  {
26  return array("4.3.0");
27  }
28 
32  function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Modules/Poll/".$a_entity;
35  }
36 
40  protected function getTypes($a_entity, $a_version)
41  {
42  if ($a_entity == "poll")
43  {
44  switch ($a_version)
45  {
46  case "4.3.0":
47  return array(
48  "Id" => "integer",
49  "Title" => "text",
50  "Description" => "text",
51  "Question" => "text",
52  "Image" => "text",
53  "ViewResults" => "integer",
54  "Dir" => "directory"
55  );
56  }
57  }
58 
59  if ($a_entity == "poll_answer")
60  {
61  switch ($a_version)
62  {
63  case "4.3.0":
64  return array(
65  "Id" => "integer",
66  "PollId" => "integer",
67  "Answer" => "text",
68  "Pos" => "integer",
69  );
70  }
71  }
72  }
73 
80  function readData($a_entity, $a_version, $a_ids, $a_field = "")
81  {
82  global $ilDB;
83 
84  if (!is_array($a_ids))
85  {
86  $a_ids = array($a_ids);
87  }
88 
89  if ($a_entity == "poll")
90  {
91  switch ($a_version)
92  {
93  case "4.3.0":
94  $this->getDirectDataFromQuery("SELECT pl.id,od.title,od.description,".
95  "pl.question,pl.image,pl.view_results".
96  " FROM il_poll pl".
97  " JOIN object_data od ON (od.obj_id = pl.id)".
98  " WHERE ".$ilDB->in("pl.id", $a_ids, false, "integer").
99  " AND od.type = ".$ilDB->quote("poll", "text"));
100  break;
101  }
102  }
103 
104  if ($a_entity == "poll_answer")
105  {
106  switch ($a_version)
107  {
108  case "4.3.0":
109  $this->getDirectDataFromQuery("SELECT id,poll_id,answer,pos".
110  " FROM il_poll_answer WHERE ".
111  $ilDB->in("poll_id", $a_ids, false, "integer"));
112  break;
113  }
114  }
115  }
116 
120  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
121  {
122  switch ($a_entity)
123  {
124  case "poll":
125  return array (
126  "poll_answer" => array("ids" => $a_rec["Id"])
127  );
128  }
129  return false;
130  }
131 
138  function getXmlRecord($a_entity, $a_version, $a_set)
139  {
140  if ($a_entity == "poll")
141  {
142  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
143  $dir = ilObjPoll::initStorage($a_set["Id"]);
144  $a_set["Dir"] = $dir;
145  }
146 
147  return $a_set;
148  }
149 
156  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
157  {
158  switch ($a_entity)
159  {
160  case "poll":
161  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
162 
163  // #13605
164  if($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"]))
165  {
166  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
167  }
168  else
169  {
170  $newObj = new ilObjPoll();
171  $newObj->create();
172  }
173 
174  $newObj->setTitle($a_rec["Title"]);
175  $newObj->setDescription($a_rec["Description"]);
176  $newObj->setQuestion($a_rec["Question"]);
177  $newObj->setImage($a_rec["Image"]);
178  $newObj->setViewResults($a_rec["ViewResults"]);
179  $newObj->update();
180 
181  // handle image(s)
182  if($a_rec["Image"])
183  {
184  $dir = str_replace("..", "", $a_rec["Dir"]);
185  if ($dir != "" && $this->getImportDirectory() != "")
186  {
187  $source_dir = $this->getImportDirectory()."/".$dir;
188  $target_dir = ilObjPoll::initStorage($newObj->getId());
189  ilUtil::rCopy($source_dir, $target_dir);
190  }
191  }
192 
193  $a_mapping->addMapping("Modules/Poll", "poll", $a_rec["Id"], $newObj->getId());
194  break;
195 
196  case "poll_answer":
197  $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", $a_rec["PollId"]);
198  if($poll_id)
199  {
200  $poll = new ilObjPoll($poll_id, false);
201  $poll->saveAnswer($a_rec["Answer"], $a_rec["pos"]);
202  }
203  break;
204  }
205  }
206 }
207 
208 ?>