ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWikiDataSet.php
Go to the documentation of this file.
1<?php
2
29{
30 protected \ILIAS\Wiki\Navigation\ImportantPageDBRepository $imp_page_repo;
31 protected ?ilObjWiki $current_obj = null;
33
34 public function __construct()
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
40 $this->wiki_log = ilLoggerFactory::getLogger('wiki');
41 $this->imp_page_repo = $DIC->wiki()->internal()->repo()->importantPage();
42 }
43
44 public function getSupportedVersions(): array
45 {
46 return array("4.1.0", "4.3.0", "4.4.0", "5.1.0", "5.4.0", "8.0");
47 }
48
49 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
50 {
51 return "https://www.ilias.de/xml/Modules/Wiki/" . $a_entity;
52 }
53
54 protected function getTypes(string $a_entity, string $a_version): array
55 {
56 if ($a_entity === "wiki") {
57 switch ($a_version) {
58 case "4.1.0":
59 return array(
60 "Id" => "integer",
61 "Title" => "text",
62 "Description" => "text",
63 "StartPage" => "text",
64 "Short" => "text",
65 "Introduction" => "text",
66 "Rating" => "integer");
67
68 case "4.3.0":
69 return array(
70 "Id" => "integer",
71 "Title" => "text",
72 "Description" => "text",
73 "StartPage" => "text",
74 "Short" => "text",
75 "Introduction" => "text",
76 "Rating" => "integer",
77 "PublicNotes" => "integer",
78 // "ImpPages" => "integer",
79 "PageToc" => "integer",
80 "RatingSide" => "integer",
81 "RatingNew" => "integer",
82 "RatingExt" => "integer");
83
84 case "4.4.0":
85 return array(
86 "Id" => "integer",
87 "Title" => "text",
88 "Description" => "text",
89 "StartPage" => "text",
90 "Short" => "text",
91 "Introduction" => "text",
92 "Rating" => "integer",
93 "PublicNotes" => "integer",
94 // "ImpPages" => "integer",
95 "PageToc" => "integer",
96 "RatingSide" => "integer",
97 "RatingNew" => "integer",
98 "RatingExt" => "integer",
99 "RatingOverall" => "integer");
100
101 case "5.1.0":
102 return array(
103 "Id" => "integer",
104 "Title" => "text",
105 "Description" => "text",
106 "StartPage" => "text",
107 "Short" => "text",
108 "Introduction" => "text",
109 "Rating" => "integer",
110 "PublicNotes" => "integer",
111 // "ImpPages" => "integer",
112 "PageToc" => "integer",
113 "RatingSide" => "integer",
114 "RatingNew" => "integer",
115 "RatingExt" => "integer",
116 "RatingOverall" => "integer",
117 "LinkMdValues" => "integer"
118 );
119
120 case "5.4.0":
121 case "8.0":
122 return array(
123 "Id" => "integer",
124 "Title" => "text",
125 "Description" => "text",
126 "StartPage" => "text",
127 "Short" => "text",
128 "Introduction" => "text",
129 "Rating" => "integer",
130 "PublicNotes" => "integer",
131 // "ImpPages" => "integer",
132 "PageToc" => "integer",
133 "RatingSide" => "integer",
134 "RatingNew" => "integer",
135 "RatingExt" => "integer",
136 "RatingOverall" => "integer",
137 "LinkMdValues" => "integer",
138 "EmptyPageTempl" => "integer"
139 );
140 }
141 }
142
143 if ($a_entity === "wpg") {
144 switch ($a_version) {
145 case "4.1.0":
146 return array(
147 "Id" => "integer",
148 "Title" => "text",
149 "WikiId" => "integer");
150
151 case "4.3.0":
152 case "4.4.0":
153 case "5.1.0":
154 return array(
155 "Id" => "integer",
156 "Title" => "text",
157 "WikiId" => "integer",
158 "Blocked" => "integer",
159 "Rating" => "integer");
160
161 case "5.4.0":
162 return array(
163 "Id" => "integer",
164 "Title" => "text",
165 "WikiId" => "integer",
166 "Blocked" => "integer",
167 "Rating" => "integer",
168 "TemplateNewPages" => "integer",
169 "TemplateAddToPage" => "integer"
170 );
171
172 case "8.0":
173 return array(
174 "Id" => "integer",
175 "Title" => "text",
176 "WikiId" => "integer",
177 "Blocked" => "integer",
178 "Rating" => "integer",
179 "TemplateNewPages" => "integer",
180 "TemplateAddToPage" => "integer",
181 "Lang" => "text"
182 );
183 }
184 }
185
186 if ($a_entity === "wiki_imp_page") {
187 switch ($a_version) {
188 case "5.1.0":
189 case "5.4.0":
190 case "8.0":
191 return array(
192 "WikiId" => "integer",
193 "PageId" => "integer",
194 "Ord" => "integer",
195 "Indent" => "integer");
196 }
197 }
198 return array();
199 }
200
201 public function readData(string $a_entity, string $a_version, array $a_ids): void
202 {
204
205 if (!is_array($a_ids)) {
206 $a_ids = array($a_ids);
207 }
208
209 if ($a_entity === "wiki") {
210 switch ($a_version) {
211 case "4.1.0":
212 $this->getDirectDataFromQuery("SELECT id, title, description," .
213 " startpage start_page, short, rating, introduction" .
214 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
215 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
216 break;
217
218 case "4.3.0":
219 $this->getDirectDataFromQuery("SELECT id, title, description," .
220 " startpage start_page, short, rating, introduction," . // imp_pages,
221 " public_notes, page_toc, rating_side, rating_new, rating_ext" .
222 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
223 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
224 break;
225
226 case "4.4.0":
227 $this->getDirectDataFromQuery("SELECT id, title, description," .
228 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
229 " public_notes, page_toc, rating_side, rating_new, rating_ext" .
230 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
231 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
232 break;
233
234 case "5.1.0":
235 $this->getDirectDataFromQuery("SELECT id, title, description," .
236 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
237 " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values" .
238 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
239 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
240 break;
241
242 case "5.4.0":
243 case "8.0":
244 $this->getDirectDataFromQuery("SELECT id, title, description," .
245 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
246 " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values, empty_page_templ" .
247 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
248 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
249 break;
250 }
251 }
252
253 if ($a_entity === "wpg") {
254 switch ($a_version) {
255 case "4.1.0":
256 $this->getDirectDataFromQuery("SELECT id, title, wiki_id" .
257 " FROM il_wiki_page" .
258 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
259 break;
260
261 case "4.3.0":
262 case "4.4.0":
263 case "5.1.0":
264 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
265 " blocked, rating" .
266 " FROM il_wiki_page" .
267 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
268 break;
269
270 case "5.4.0":
271 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
272 " blocked, rating" .
273 " FROM il_wiki_page" .
274 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
275 foreach ($this->data as $k => $v) {
276 $set = $ilDB->queryF(
277 "SELECT * FROM wiki_page_template " .
278 " WHERE wiki_id = %s " .
279 " AND wpage_id = %s ",
280 ["integer", "integer"],
281 [$v["WikiId"], $v["Id"]]
282 );
283 if ($rec = $ilDB->fetchAssoc($set)) {
284 $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
285 $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
286 }
287 }
288 break;
289
290 case "8.0":
291 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
292 " blocked, rating, lang" .
293 " FROM il_wiki_page" .
294 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
295 foreach ($this->data as $k => $v) {
296 $set = $ilDB->queryF(
297 "SELECT * FROM wiki_page_template " .
298 " WHERE wiki_id = %s " .
299 " AND wpage_id = %s ",
300 ["integer", "integer"],
301 [$v["WikiId"], $v["Id"]]
302 );
303 if ($rec = $ilDB->fetchAssoc($set)) {
304 $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
305 $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
306 }
307 }
308 break;
309 }
310 }
311
312 if ($a_entity === "wiki_imp_page") {
313 switch ($a_version) {
314 case "5.1.0":
315 case "5.4.0":
316 case "8.0":
317 $this->getDirectDataFromQuery("SELECT wiki_id, page_id, ord, indent " .
318 " FROM il_wiki_imp_pages " .
319 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
320 break;
321 }
322 }
323 }
324
325 protected function getDependencies(
326 string $a_entity,
327 string $a_version,
328 ?array $a_rec = null,
329 ?array $a_ids = null
330 ): array {
331 switch ($a_entity) {
332 case "wiki":
333 return array(
334 "wpg" => array("ids" => $a_rec["Id"] ?? null),
335 "wiki_imp_page" => array("ids" => $a_rec["Id"] ?? null)
336 );
337 }
338
339 return [];
340 }
341
342 public function importRecord(
343 string $a_entity,
344 array $a_types,
345 array $a_rec,
346 ilImportMapping $a_mapping,
347 string $a_schema_version
348 ): void {
349 $a_rec = $this->stripTags($a_rec);
350 switch ($a_entity) {
351 case "wiki":
352
353 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['Id'])) {
354 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
355 } else {
356 $newObj = new ilObjWiki();
357 $newObj->setType("wiki");
358 $newObj->create(true);
359 }
360
361 $newObj->setTitle($a_rec["Title"]);
362 $newObj->setDescription($a_rec["Description"]);
363 $newObj->setShortTitle($a_rec["Short"]);
364 $newObj->setStartPage($a_rec["StartPage"]);
365 $newObj->setRatingOverall($a_rec["RatingOverall"]);
366 $newObj->setRatingPages($a_rec["Rating"]);
367 $newObj->setIntroduction($a_rec["Introduction"]);
368 $newObj->setPublicNotes($a_rec["PublicNotes"]);
369
370 // >= 4.3
371 if (isset($a_rec["PageToc"])) {
372 $newObj->setPageToc($a_rec["PageToc"]);
373 $newObj->setRatingAsBlock($a_rec["RatingSide"]);
374 $newObj->setRatingForNewPages($a_rec["RatingNew"]);
375 $newObj->setRatingCategories($a_rec["RatingExt"]);
376 }
377 $newObj->setLinkMetadataValues($a_rec["LinkMdValues"]);
378 $newObj->setEmptyPageTemplate((int) $a_rec["EmptyPageTempl"]);
379
380 $newObj->update(true);
381 $this->current_obj = $newObj;
382 $a_mapping->addMapping("components/ILIAS/Wiki", "wiki", $a_rec["Id"], $newObj->getId());
383 $a_mapping->addMapping("components/ILIAS/ILIASObject", "obj", $a_rec["Id"], $newObj->getId());
384 $a_mapping->addMapping("components/ILIAS/Rating", "rating_category_parent_id", $a_rec["Id"], $newObj->getId());
385 $a_mapping->addMapping("components/ILIAS/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
386 $a_mapping->addMapping(
387 "components/ILIAS/MetaData",
388 "md",
389 $a_rec["Id"] . ":0:wiki",
390 $newObj->getId() . ":0:wiki"
391 );
392 break;
393
394 case "wpg":
395 $wiki_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wiki", $a_rec["WikiId"]);
396 $lang = ($a_rec["Lang"] ?? "");
397 $wpage = new ilWikiPage();
398 if (!in_array($lang, ["", "-"])) {
399 $wpage->setLanguage($lang);
400 }
401 $wpage->setWikiId($wiki_id);
402 $wpage->setTitle($a_rec["Title"]);
403
404 // >= 4.3
405 if (isset($a_rec["Blocked"])) {
406 $wpage->setBlocked($a_rec["Blocked"]);
407 $wpage->setRating($a_rec["Rating"]);
408 }
409
410 $wpage->create(true);
411
412 if (isset($a_rec["TemplateNewPages"]) || isset($a_rec["TemplateAddToPage"])) {
413 $wtpl = new ilWikiPageTemplate($wiki_id);
414 $wtpl->save($wpage->getId(), (int) $a_rec["TemplateNewPages"], (int) $a_rec["TemplateAddToPage"]);
415 }
416
417 $a_mapping->addMapping("components/ILIAS/Wiki", "wpg", $a_rec["Id"], $wpage->getId());
418 $a_mapping->addMapping("components/ILIAS/COPage", "pg", "wpg:" . $a_rec["Id"], "wpg:" . $wpage->getId());
419 $a_mapping->addMapping("components/ILIAS/AdvancedMetaData", "advmd_sub_item", "advmd:wpg:" . $a_rec["Id"], $wpage->getId());
420 break;
421
422 case "wiki_imp_page":
423 $wiki_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wiki", $a_rec["WikiId"]);
424 $page_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wpg", $a_rec["PageId"]);
425 if ($wiki_id > 0 && $page_id > 0 && is_object($this->current_obj) && $this->current_obj->getId() === (int) $wiki_id) {
426 $this->imp_page_repo->add($this->current_obj->getId(), (int) $page_id, (int) $a_rec["Ord"], (int) $a_rec["Indent"]);
427 }
428 break;
429 }
430 }
431}
A dataset contains in data in a common structure that can be shared and transformed for different pur...
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
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)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
ILIAS Wiki Navigation ImportantPageDBRepository $imp_page_repo
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$lang
Definition: xapiexit.php:25