ILIAS  Release_5_0_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", "5.0.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  break;
57  case "5.0.0":
58  return array(
59  "Id" => "integer",
60  "Title" => "text",
61  "Description" => "text",
62  "Question" => "text",
63  "Image" => "text",
64  "ViewResults" => "integer",
65  "Dir" => "directory",
66  "ShowResultsAs" => "integer",
67  "ShowComments" => "integer",
68  "MaxAnswers" => "integer",
69  "ResultSort" => "integer",
70  "NonAnon" => "integer",
71  "Period" => "integer",
72  "PeriodBegin" => "integer",
73  "PeriodEnd" => "integer"
74 
75  );
76  break;
77  }
78  }
79 
80  if ($a_entity == "poll_answer")
81  {
82  switch ($a_version)
83  {
84  case "4.3.0":
85  case "5.0.0":
86  return array(
87  "Id" => "integer",
88  "PollId" => "integer",
89  "Answer" => "text",
90  "Pos" => "integer",
91  );
92  break;
93  }
94  }
95  }
96 
103  function readData($a_entity, $a_version, $a_ids, $a_field = "")
104  {
105  global $ilDB;
106 
107  if (!is_array($a_ids))
108  {
109  $a_ids = array($a_ids);
110  }
111 
112  if ($a_entity == "poll")
113  {
114  switch ($a_version)
115  {
116  case "4.3.0":
117  $this->getDirectDataFromQuery("SELECT pl.id,od.title,od.description,".
118  "pl.question,pl.image,pl.view_results".
119  " FROM il_poll pl".
120  " JOIN object_data od ON (od.obj_id = pl.id)".
121  " WHERE ".$ilDB->in("pl.id", $a_ids, false, "integer").
122  " AND od.type = ".$ilDB->quote("poll", "text"));
123  break;
124  case "5.0.0":
125  $this->getDirectDataFromQuery("SELECT pl.id,od.title,od.description".
126  ",pl.question,pl.image,pl.view_results,pl.show_results_as".
127  ",pl.max_answers,pl.result_sort,pl.non_anon,pl.period,pl.period_begin,pl.period_end".
128  " FROM il_poll pl".
129  " JOIN object_data od ON (od.obj_id = pl.id)".
130  " WHERE " . $ilDB->in("pl.id", $a_ids, false, "integer").
131  " AND od.type = " . $ilDB->quote("poll", "text"));
132  break;
133 
134  }
135  }
136 
137  if ($a_entity == "poll_answer")
138  {
139  switch ($a_version)
140  {
141  case "4.3.0":
142  case "5.0.0":
143  $this->getDirectDataFromQuery("SELECT id,poll_id,answer,pos".
144  " FROM il_poll_answer WHERE ".
145  $ilDB->in("poll_id", $a_ids, false, "integer"));
146  break;
147  }
148  }
149  }
150 
154  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
155  {
156  switch ($a_entity)
157  {
158  case "poll":
159  return array (
160  "poll_answer" => array("ids" => $a_rec["Id"])
161  );
162  }
163  return false;
164  }
165 
172  function getXmlRecord($a_entity, $a_version, $a_set)
173  {
174  if ($a_entity == "poll")
175  {
176  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
177  $dir = ilObjPoll::initStorage($a_set["Id"]);
178  $a_set["Dir"] = $dir;
179 
180  include_once("./Services/Notes/classes/class.ilNote.php");
181  $a_set["ShowComments"] = ilNote::commentsActivated($a_set["Id"], 0, "poll");
182  }
183 
184  return $a_set;
185  }
186 
193  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
194  {
195  switch ($a_entity)
196  {
197  case "poll":
198  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
199 
200  // container copy
201  if($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"]))
202  {
203  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
204  }
205  else
206  {
207  $newObj = new ilObjPoll();
208  $newObj->create();
209  }
210 
211  $newObj->setTitle($a_rec["Title"]);
212  $newObj->setDescription($a_rec["Description"]);
213  if((int)$a_rec["MaxAnswers"])
214  {
215  $newObj->setMaxNumberOfAnswers($a_rec["MaxAnswers"]);
216  }
217  $newObj->setSortResultByVotes((bool)$a_rec["ResultSort"]);
218  $newObj->setNonAnonymous((bool)$a_rec["NonAnon"]);
219  if((int)$a_rec["ShowResultsAs"])
220  {
221  $newObj->setShowResultsAs($a_rec["ShowResultsAs"]);
222  }
223  $newObj->setShowComments($a_rec["ShowComments"]);
224  $newObj->setQuestion($a_rec["Question"]);
225  $newObj->setImage($a_rec["Image"]);
226  $newObj->setViewResults($a_rec["ViewResults"]);
227  $newObj->setVotingPeriod($a_rec["Period"]);
228  $newObj->setVotingPeriodBegin($a_rec["PeriodBegin"]);
229  $newObj->setVotingPeriodEnd($a_rec["PeriodEnd"]);
230  $newObj->update();
231 
232  // handle image(s)
233  if($a_rec["Image"])
234  {
235  $dir = str_replace("..", "", $a_rec["Dir"]);
236  if ($dir != "" && $this->getImportDirectory() != "")
237  {
238  $source_dir = $this->getImportDirectory()."/".$dir;
239  $target_dir = ilObjPoll::initStorage($newObj->getId());
240  ilUtil::rCopy($source_dir, $target_dir);
241  }
242  }
243 
244  $a_mapping->addMapping("Modules/Poll", "poll", $a_rec["Id"], $newObj->getId());
245  break;
246 
247  case "poll_answer":
248  $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", $a_rec["PollId"]);
249  if($poll_id)
250  {
251  $poll = new ilObjPoll($poll_id, false);
252  $poll->saveAnswer($a_rec["Answer"], $a_rec["pos"]);
253  }
254  break;
255  }
256  }
257 }
258 
259 ?>