ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public 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  switch ($a_version) {
44  case "4.3.0":
45  return array(
46  "Id" => "integer",
47  "Title" => "text",
48  "Description" => "text",
49  "Question" => "text",
50  "Image" => "text",
51  "ViewResults" => "integer",
52  "Dir" => "directory"
53  );
54  break;
55  case "5.0.0":
56  return array(
57  "Id" => "integer",
58  "Title" => "text",
59  "Description" => "text",
60  "Question" => "text",
61  "Image" => "text",
62  "ViewResults" => "integer",
63  "Dir" => "directory",
64  "ShowResultsAs" => "integer",
65  "ShowComments" => "integer",
66  "MaxAnswers" => "integer",
67  "ResultSort" => "integer",
68  "NonAnon" => "integer",
69  "Period" => "integer",
70  "PeriodBegin" => "integer",
71  "PeriodEnd" => "integer"
72 
73  );
74  break;
75  }
76  }
77 
78  if ($a_entity == "poll_answer") {
79  switch ($a_version) {
80  case "4.3.0":
81  case "5.0.0":
82  return array(
83  "Id" => "integer",
84  "PollId" => "integer",
85  "Answer" => "text",
86  "Pos" => "integer",
87  );
88  break;
89  }
90  }
91  }
92 
99  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
100  {
101  $ilDB = $this->db;
102 
103  if (!is_array($a_ids)) {
104  $a_ids = array($a_ids);
105  }
106 
107  if ($a_entity == "poll") {
108  switch ($a_version) {
109  case "4.3.0":
110  $this->getDirectDataFromQuery("SELECT pl.id,od.title,od.description," .
111  "pl.question,pl.image,pl.view_results" .
112  " FROM il_poll pl" .
113  " JOIN object_data od ON (od.obj_id = pl.id)" .
114  " WHERE " . $ilDB->in("pl.id", $a_ids, false, "integer") .
115  " AND od.type = " . $ilDB->quote("poll", "text"));
116  break;
117  case "5.0.0":
118  $this->getDirectDataFromQuery("SELECT pl.id,od.title,od.description" .
119  ",pl.question,pl.image,pl.view_results,pl.show_results_as" .
120  ",pl.max_answers,pl.result_sort,pl.non_anon,pl.period,pl.period_begin,pl.period_end" .
121  " FROM il_poll pl" .
122  " JOIN object_data od ON (od.obj_id = pl.id)" .
123  " WHERE " . $ilDB->in("pl.id", $a_ids, false, "integer") .
124  " AND od.type = " . $ilDB->quote("poll", "text"));
125  break;
126 
127  }
128  }
129 
130  if ($a_entity == "poll_answer") {
131  switch ($a_version) {
132  case "4.3.0":
133  case "5.0.0":
134  $this->getDirectDataFromQuery("SELECT id,poll_id,answer,pos" .
135  " FROM il_poll_answer WHERE " .
136  $ilDB->in("poll_id", $a_ids, false, "integer"));
137  break;
138  }
139  }
140  }
141 
145  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
146  {
147  switch ($a_entity) {
148  case "poll":
149  return array(
150  "poll_answer" => array("ids" => $a_rec["Id"])
151  );
152  }
153  return false;
154  }
155 
162  public function getXmlRecord($a_entity, $a_version, $a_set)
163  {
164  if ($a_entity == "poll") {
165  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
166  $dir = ilObjPoll::initStorage($a_set["Id"]);
167  $a_set["Dir"] = $dir;
168 
169  include_once("./Services/Notes/classes/class.ilNote.php");
170  $a_set["ShowComments"] = ilNote::commentsActivated($a_set["Id"], 0, "poll");
171  }
172 
173  return $a_set;
174  }
175 
182  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
183  {
184  switch ($a_entity) {
185  case "poll":
186  include_once("./Modules/Poll/classes/class.ilObjPoll.php");
187 
188  // container copy
189  if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
190  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
191  } else {
192  $newObj = new ilObjPoll();
193  $newObj->create();
194  }
195 
196  $newObj->setTitle($a_rec["Title"]);
197  $newObj->setDescription($a_rec["Description"]);
198  if ((int) $a_rec["MaxAnswers"]) {
199  $newObj->setMaxNumberOfAnswers($a_rec["MaxAnswers"]);
200  }
201  $newObj->setSortResultByVotes((bool) $a_rec["ResultSort"]);
202  $newObj->setNonAnonymous((bool) $a_rec["NonAnon"]);
203  if ((int) $a_rec["ShowResultsAs"]) {
204  $newObj->setShowResultsAs($a_rec["ShowResultsAs"]);
205  }
206  $newObj->setShowComments($a_rec["ShowComments"]);
207  $newObj->setQuestion($a_rec["Question"]);
208  $newObj->setImage($a_rec["Image"]);
209  $newObj->setViewResults($a_rec["ViewResults"]);
210  $newObj->setVotingPeriod($a_rec["Period"]);
211  $newObj->setVotingPeriodBegin($a_rec["PeriodBegin"]);
212  $newObj->setVotingPeriodEnd($a_rec["PeriodEnd"]);
213  $newObj->update();
214 
215  // handle image(s)
216  if ($a_rec["Image"]) {
217  $dir = str_replace("..", "", $a_rec["Dir"]);
218  if ($dir != "" && $this->getImportDirectory() != "") {
219  $source_dir = $this->getImportDirectory() . "/" . $dir;
220  $target_dir = ilObjPoll::initStorage($newObj->getId());
221  ilUtil::rCopy($source_dir, $target_dir);
222  }
223  }
224 
225  $a_mapping->addMapping("Modules/Poll", "poll", $a_rec["Id"], $newObj->getId());
226  break;
227 
228  case "poll_answer":
229  $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", $a_rec["PollId"]);
230  if ($poll_id) {
231  $poll = new ilObjPoll($poll_id, false);
232  $poll->saveAnswer($a_rec["Answer"], $a_rec["pos"]);
233  }
234  break;
235  }
236  }
237 }
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getSupportedVersions()
Get supported versions.
getImportDirectory()
Get import directory.
getTypes($a_entity, $a_version)
Get field types for entity.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
Class ilObjPoll.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type)
Are comments activated for object?
global $ilDB
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
Poll Dataset class.