ILIAS  release_8 Revision v8.24
class.ilPollDataSet.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
31{
32 protected \ILIAS\Notes\Service $notes;
33
34 public function __construct()
35 {
36 global $DIC;
37
39 $this->notes = $DIC->notes();
40 }
41
42 public function getSupportedVersions(): array
43 {
44 return array("4.3.0", "5.0.0");
45 }
46
47 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
48 {
49 return "http://www.ilias.de/xml/Modules/Poll/" . $a_entity;
50 }
51
55 protected function getTypes(string $a_entity, string $a_version): array
56 {
57 if ($a_entity === "poll") {
58 switch ($a_version) {
59 case "4.3.0":
60 return array(
61 "Id" => "integer",
62 "Title" => "text",
63 "Description" => "text",
64 "Question" => "text",
65 "Image" => "text",
66 "ViewResults" => "integer",
67 "Dir" => "directory"
68 );
69 break;
70 case "5.0.0":
71 return array(
72 "Id" => "integer",
73 "Title" => "text",
74 "Description" => "text",
75 "Question" => "text",
76 "Image" => "text",
77 "ViewResults" => "integer",
78 "Dir" => "directory",
79 "ShowResultsAs" => "integer",
80 "ShowComments" => "integer",
81 "MaxAnswers" => "integer",
82 "ResultSort" => "integer",
83 "NonAnon" => "integer",
84 "Period" => "integer",
85 "PeriodBegin" => "integer",
86 "PeriodEnd" => "integer"
87
88 );
89 break;
90 }
91 }
92
93 if ($a_entity === "poll_answer") {
94 switch ($a_version) {
95 case "4.3.0":
96 case "5.0.0":
97 return array(
98 "Id" => "integer",
99 "PollId" => "integer",
100 "Answer" => "text",
101 "Pos" => "integer",
102 );
103 break;
104 }
105 }
106
107 return [];
108 }
109
110 public function readData(string $a_entity, string $a_version, array $a_ids): void
111 {
113
114 if ($a_entity === "poll") {
115 switch ($a_version) {
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 switch ($a_version) {
139 case "4.3.0":
140 case "5.0.0":
141 $this->getDirectDataFromQuery("SELECT id,poll_id,answer,pos" .
142 " FROM il_poll_answer WHERE " .
143 $ilDB->in("poll_id", $a_ids, false, "integer"));
144 break;
145 }
146 }
147 }
148
149 protected function getDependencies(
150 string $a_entity,
151 string $a_version,
152 ?array $a_rec = null,
153 ?array $a_ids = null
154 ): array {
155 switch ($a_entity) {
156 case "poll":
157 return array(
158 "poll_answer" => array("ids" => $a_rec["Id"] ?? null)
159 );
160 }
161 return [];
162 }
163
164 public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array
165 {
166 if ($a_entity === "poll") {
167 $dir = ilObjPoll::initStorage((int) $a_set["Id"]);
168 $a_set["Dir"] = $dir;
169
170 $a_set["ShowComments"] = $this->notes->domain()->commentsActive((int) $a_set["Id"]);
171 }
172
173 return $a_set;
174 }
175
176 public function importRecord(
177 string $a_entity,
178 array $a_types,
179 array $a_rec,
180 ilImportMapping $a_mapping,
181 string $a_schema_version
182 ): void {
183 $a_rec = $this->stripTags(
184 $a_rec,
185 [
186 'Id',
187 'MaxAnswers',
188 'ResultSort',
189 'NonAnon',
190 'ShowResultsAs',
191 'ShowComments',
192 'ViewResults',
193 'Period',
194 'PeriodBegin',
195 'PeriodEnd',
196 'PollId',
197 'pos',
198 ]
199 );
200
201 switch ($a_entity) {
202 case "poll":
203 // container copy
204 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", (string) ($a_rec["Id"] ?? "0"))) {
205 $newObj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
206 } else {
207 $newObj = new ilObjPoll();
208 $newObj->create();
209 }
210
212 $newObj->setTitle((string) ($a_rec["Title"] ?? ''));
213 $newObj->setDescription((string) ($a_rec["Description"]));
214 if ((int) $a_rec["MaxAnswers"]) {
215 $newObj->setMaxNumberOfAnswers((int) $a_rec["MaxAnswers"]);
216 }
217 $newObj->setSortResultByVotes((bool) ($a_rec["ResultSort"] ?? false));
218 $newObj->setNonAnonymous((bool) ($a_rec["NonAnon"] ?? false));
219 if ((int) $a_rec["ShowResultsAs"]) {
220 $newObj->setShowResultsAs((int) $a_rec["ShowResultsAs"]);
221 }
222 $newObj->setShowComments((bool) ($a_rec["ShowComments"] ?? false));
223 $newObj->setQuestion((string) ($a_rec["Question"] ?? ''));
224 $newObj->setImage((string) ($a_rec["Image"] ?? ''));
225 $newObj->setViewResults((int) ($a_rec["ViewResults"] ?? ilObjPoll::VIEW_RESULTS_AFTER_VOTE));
226 $newObj->setVotingPeriod((bool) ($a_rec["Period"] ?? 0));
227 $newObj->setVotingPeriodBegin((int) ($a_rec["PeriodBegin"] ?? 0));
228 $newObj->setVotingPeriodEnd((int) ($a_rec["PeriodEnd"] ?? 0));
229 $newObj->update();
230
231 // handle image(s)
232 if ($a_rec["Image"]) {
233 $dir = str_replace("..", "", (string) ($a_rec["Dir"] ?? ''));
234 if ($dir !== "" && $this->getImportDirectory() !== "") {
235 $source_dir = $this->getImportDirectory() . "/" . $dir;
236 $target_dir = ilObjPoll::initStorage($newObj->getId());
237 ilFileUtils::rCopy($source_dir, $target_dir);
238 }
239 }
240
241 $a_mapping->addMapping("Modules/Poll", "poll", (string) ($a_rec["Id"] ?? "0"), (string) $newObj->getId());
242 break;
243
244 case "poll_answer":
245 $poll_id = (int) $a_mapping->getMapping("Modules/Poll", "poll", (string) ($a_rec["PollId"] ?? "0"));
246 if ($poll_id) {
247 $poll = new ilObjPoll($poll_id, false);
248 $poll->saveAnswer((string) ($a_rec["Answer"] ?? ''), (int) ($a_rec["pos"] ?? 10));
249 }
250 break;
251 }
252 }
253}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
ilDBInterface $db
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const VIEW_RESULTS_AFTER_VOTE
static initStorage(int $a_id, ?string $a_subdir=null)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Poll Dataset class.
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.Please note that the abstract fields/types only depen...
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
ILIAS Notes Service $notes
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc