ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWikiDataSet.php
Go to the documentation of this file.
1 <?php
2 
28 class ilWikiDataSet extends ilDataSet
29 {
30  protected ?ilObjWiki $current_obj = null;
31  protected ilLogger $wiki_log;
32 
33  public function __construct()
34  {
35  global $DIC;
36 
37  $this->db = $DIC->database();
39  $this->wiki_log = ilLoggerFactory::getLogger('wiki');
40  }
41 
42  public function getSupportedVersions(): array
43  {
44  return array("4.1.0", "4.3.0", "4.4.0", "5.1.0", "5.4.0");
45  }
46 
47  protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
48  {
49  return "https://www.ilias.de/xml/Modules/Wiki/" . $a_entity;
50  }
51 
52  protected function getTypes(string $a_entity, string $a_version): array
53  {
54  if ($a_entity === "wiki") {
55  switch ($a_version) {
56  case "4.1.0":
57  return array(
58  "Id" => "integer",
59  "Title" => "text",
60  "Description" => "text",
61  "StartPage" => "text",
62  "Short" => "text",
63  "Introduction" => "text",
64  "Rating" => "integer");
65 
66  case "4.3.0":
67  return array(
68  "Id" => "integer",
69  "Title" => "text",
70  "Description" => "text",
71  "StartPage" => "text",
72  "Short" => "text",
73  "Introduction" => "text",
74  "Rating" => "integer",
75  "PublicNotes" => "integer",
76  // "ImpPages" => "integer",
77  "PageToc" => "integer",
78  "RatingSide" => "integer",
79  "RatingNew" => "integer",
80  "RatingExt" => "integer");
81 
82  case "4.4.0":
83  return array(
84  "Id" => "integer",
85  "Title" => "text",
86  "Description" => "text",
87  "StartPage" => "text",
88  "Short" => "text",
89  "Introduction" => "text",
90  "Rating" => "integer",
91  "PublicNotes" => "integer",
92  // "ImpPages" => "integer",
93  "PageToc" => "integer",
94  "RatingSide" => "integer",
95  "RatingNew" => "integer",
96  "RatingExt" => "integer",
97  "RatingOverall" => "integer");
98 
99  case "5.1.0":
100  return array(
101  "Id" => "integer",
102  "Title" => "text",
103  "Description" => "text",
104  "StartPage" => "text",
105  "Short" => "text",
106  "Introduction" => "text",
107  "Rating" => "integer",
108  "PublicNotes" => "integer",
109  // "ImpPages" => "integer",
110  "PageToc" => "integer",
111  "RatingSide" => "integer",
112  "RatingNew" => "integer",
113  "RatingExt" => "integer",
114  "RatingOverall" => "integer",
115  "LinkMdValues" => "integer"
116  );
117 
118  case "5.4.0":
119  return array(
120  "Id" => "integer",
121  "Title" => "text",
122  "Description" => "text",
123  "StartPage" => "text",
124  "Short" => "text",
125  "Introduction" => "text",
126  "Rating" => "integer",
127  "PublicNotes" => "integer",
128  // "ImpPages" => "integer",
129  "PageToc" => "integer",
130  "RatingSide" => "integer",
131  "RatingNew" => "integer",
132  "RatingExt" => "integer",
133  "RatingOverall" => "integer",
134  "LinkMdValues" => "integer",
135  "EmptyPageTempl" => "integer"
136  );
137  }
138  }
139 
140  if ($a_entity === "wpg") {
141  switch ($a_version) {
142  case "4.1.0":
143  return array(
144  "Id" => "integer",
145  "Title" => "text",
146  "WikiId" => "integer");
147 
148  case "4.3.0":
149  case "4.4.0":
150  case "5.1.0":
151  return array(
152  "Id" => "integer",
153  "Title" => "text",
154  "WikiId" => "integer",
155  "Blocked" => "integer",
156  "Rating" => "integer");
157 
158  case "5.4.0":
159  return array(
160  "Id" => "integer",
161  "Title" => "text",
162  "WikiId" => "integer",
163  "Blocked" => "integer",
164  "Rating" => "integer",
165  "TemplateNewPages" => "integer",
166  "TemplateAddToPage" => "integer"
167  );
168  }
169  }
170 
171  if ($a_entity === "wiki_imp_page") {
172  switch ($a_version) {
173  case "5.1.0":
174  case "5.4.0":
175  return array(
176  "WikiId" => "integer",
177  "PageId" => "integer",
178  "Ord" => "integer",
179  "Indent" => "integer");
180  }
181  }
182  return array();
183  }
184 
185  public function readData(string $a_entity, string $a_version, array $a_ids): void
186  {
187  $ilDB = $this->db;
188 
189  if (!is_array($a_ids)) {
190  $a_ids = array($a_ids);
191  }
192 
193  if ($a_entity === "wiki") {
194  switch ($a_version) {
195  case "4.1.0":
196  $this->getDirectDataFromQuery("SELECT id, title, description," .
197  " startpage start_page, short, rating, introduction" .
198  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
199  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
200  break;
201 
202  case "4.3.0":
203  $this->getDirectDataFromQuery("SELECT id, title, description," .
204  " startpage start_page, short, rating, introduction," . // imp_pages,
205  " public_notes, page_toc, rating_side, rating_new, rating_ext" .
206  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
207  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
208  break;
209 
210  case "4.4.0":
211  $this->getDirectDataFromQuery("SELECT id, title, description," .
212  " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
213  " public_notes, page_toc, rating_side, rating_new, rating_ext" .
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 "5.1.0":
219  $this->getDirectDataFromQuery("SELECT id, title, description," .
220  " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
221  " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values" .
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 "5.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, link_md_values, empty_page_templ" .
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  }
235 
236  if ($a_entity === "wpg") {
237  switch ($a_version) {
238  case "4.1.0":
239  $this->getDirectDataFromQuery("SELECT id, title, wiki_id" .
240  " FROM il_wiki_page" .
241  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
242  break;
243 
244  case "4.3.0":
245  case "4.4.0":
246  case "5.1.0":
247  $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
248  " blocked, rating" .
249  " FROM il_wiki_page" .
250  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
251  break;
252 
253  case "5.4.0":
254  $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
255  " blocked, rating" .
256  " FROM il_wiki_page" .
257  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
258  foreach ($this->data as $k => $v) {
259  $set = $ilDB->queryF(
260  "SELECT * FROM wiki_page_template " .
261  " WHERE wiki_id = %s " .
262  " AND wpage_id = %s ",
263  ["integer", "integer"],
264  [$v["WikiId"], $v["Id"]]
265  );
266  if ($rec = $ilDB->fetchAssoc($set)) {
267  $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
268  $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
269  }
270  }
271  break;
272  }
273  }
274 
275  if ($a_entity === "wiki_imp_page") {
276  switch ($a_version) {
277  case "5.1.0":
278  case "5.4.0":
279  $this->getDirectDataFromQuery("SELECT wiki_id, page_id, ord, indent " .
280  " FROM il_wiki_imp_pages " .
281  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
282  break;
283  }
284  }
285  }
286 
287  protected function getDependencies(
288  string $a_entity,
289  string $a_version,
290  ?array $a_rec = null,
291  ?array $a_ids = null
292  ): array {
293  switch ($a_entity) {
294  case "wiki":
295  return array(
296  "wpg" => array("ids" => $a_rec["Id"] ?? null),
297  "wiki_imp_page" => array("ids" => $a_rec["Id"] ?? null)
298  );
299  }
300 
301  return [];
302  }
303 
304  public function importRecord(
305  string $a_entity,
306  array $a_types,
307  array $a_rec,
308  ilImportMapping $a_mapping,
309  string $a_schema_version
310  ): void {
311  $a_rec = $this->stripTags($a_rec);
312  switch ($a_entity) {
313  case "wiki":
314 
315  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
316  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
317  } else {
318  $newObj = new ilObjWiki();
319  $newObj->setType("wiki");
320  $newObj->create(true);
321  }
322 
323  $newObj->setTitle($a_rec["Title"]);
324  $newObj->setDescription($a_rec["Description"]);
325  $newObj->setShortTitle($a_rec["Short"]);
326  $newObj->setStartPage($a_rec["StartPage"]);
327  $newObj->setRatingOverall($a_rec["RatingOverall"]);
328  $newObj->setRating($a_rec["Rating"]);
329  $newObj->setIntroduction($a_rec["Introduction"]);
330  $newObj->setPublicNotes($a_rec["PublicNotes"]);
331 
332  // >= 4.3
333  if (isset($a_rec["PageToc"])) {
334  $newObj->setPageToc($a_rec["PageToc"]);
335  $newObj->setRatingAsBlock($a_rec["RatingSide"]);
336  $newObj->setRatingForNewPages($a_rec["RatingNew"]);
337  $newObj->setRatingCategories($a_rec["RatingExt"]);
338  }
339  $newObj->setLinkMetadataValues($a_rec["LinkMdValues"]);
340  $newObj->setEmptyPageTemplate((int) $a_rec["EmptyPageTempl"]);
341 
342  $newObj->update(true);
343  $this->current_obj = $newObj;
344  $a_mapping->addMapping("Modules/Wiki", "wiki", $a_rec["Id"], $newObj->getId());
345  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
346  $a_mapping->addMapping("Services/Rating", "rating_category_parent_id", $a_rec["Id"], $newObj->getId());
347  $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
348  break;
349 
350  case "wpg":
351  $wiki_id = $a_mapping->getMapping("Modules/Wiki", "wiki", $a_rec["WikiId"]);
352  $wpage = new ilWikiPage();
353  $wpage->setWikiId($wiki_id);
354  $wpage->setTitle($a_rec["Title"]);
355 
356  // >= 4.3
357  if (isset($a_rec["Blocked"])) {
358  $wpage->setBlocked($a_rec["Blocked"]);
359  $wpage->setRating($a_rec["Rating"]);
360  }
361 
362  $wpage->create(true);
363 
364  if (isset($a_rec["TemplateNewPages"]) || isset($a_rec["TemplateAddToPage"])) {
365  $wtpl = new ilWikiPageTemplate($wiki_id);
366  $wtpl->save($wpage->getId(), (int) $a_rec["TemplateNewPages"], (int) $a_rec["TemplateAddToPage"]);
367  }
368 
369  $a_mapping->addMapping("Modules/Wiki", "wpg", $a_rec["Id"], $wpage->getId());
370  $a_mapping->addMapping("Services/COPage", "pg", "wpg:" . $a_rec["Id"], "wpg:" . $wpage->getId());
371  $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:wpg:" . $a_rec["Id"], $wpage->getId());
372  break;
373 
374  case "wiki_imp_page":
375  $wiki_id = $a_mapping->getMapping("Modules/Wiki", "wiki", $a_rec["WikiId"]);
376  $page_id = $a_mapping->getMapping("Modules/Wiki", "wpg", $a_rec["PageId"]);
377  if ($wiki_id > 0 && $page_id > 0 && is_object($this->current_obj) && $this->current_obj->getId() === (int) $wiki_id) {
378  $this->current_obj->addImportantPage((int) $page_id, (int) $a_rec["Ord"], (int) $a_rec["Indent"]);
379  }
380  break;
381  }
382  }
383 }
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_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)
global $DIC
Definition: feed.php:28
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
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...
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 ...
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
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...
__construct(Container $dic, ilPlugin $plugin)
stripTags(array $rec, array $omit_keys=[])
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...