ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWikiDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
17 class ilWikiDataSet extends ilDataSet
18 {
22  protected $wiki_log;
23 
30  public function __construct()
31  {
32  global $DIC;
33 
34  $this->db = $DIC->database();
35  parent::__construct();
36  $this->wiki_log = ilLoggerFactory::getLogger('wiki');
37  }
38 
39 
46  public function getSupportedVersions()
47  {
48  return array("4.1.0", "4.3.0", "4.4.0", "5.1.0", "5.4.0");
49  }
50 
57  public function getXmlNamespace($a_entity, $a_schema_version)
58  {
59  return "http://www.ilias.de/xml/Modules/Wiki/" . $a_entity;
60  }
61 
68  protected function getTypes($a_entity, $a_version)
69  {
70  if ($a_entity == "wiki") {
71  switch ($a_version) {
72  case "4.1.0":
73  return array(
74  "Id" => "integer",
75  "Title" => "text",
76  "Description" => "text",
77  "StartPage" => "text",
78  "Short" => "text",
79  "Introduction" => "text",
80  "Rating" => "integer");
81 
82  case "4.3.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 
98  case "4.4.0":
99  return array(
100  "Id" => "integer",
101  "Title" => "text",
102  "Description" => "text",
103  "StartPage" => "text",
104  "Short" => "text",
105  "Introduction" => "text",
106  "Rating" => "integer",
107  "PublicNotes" => "integer",
108  // "ImpPages" => "integer",
109  "PageToc" => "integer",
110  "RatingSide" => "integer",
111  "RatingNew" => "integer",
112  "RatingExt" => "integer",
113  "RatingOverall" => "integer");
114 
115  case "5.1.0":
116  return array(
117  "Id" => "integer",
118  "Title" => "text",
119  "Description" => "text",
120  "StartPage" => "text",
121  "Short" => "text",
122  "Introduction" => "text",
123  "Rating" => "integer",
124  "PublicNotes" => "integer",
125  // "ImpPages" => "integer",
126  "PageToc" => "integer",
127  "RatingSide" => "integer",
128  "RatingNew" => "integer",
129  "RatingExt" => "integer",
130  "RatingOverall" => "integer",
131  "LinkMdValues" => "integer"
132  );
133 
134  case "5.4.0":
135  return array(
136  "Id" => "integer",
137  "Title" => "text",
138  "Description" => "text",
139  "StartPage" => "text",
140  "Short" => "text",
141  "Introduction" => "text",
142  "Rating" => "integer",
143  "PublicNotes" => "integer",
144  // "ImpPages" => "integer",
145  "PageToc" => "integer",
146  "RatingSide" => "integer",
147  "RatingNew" => "integer",
148  "RatingExt" => "integer",
149  "RatingOverall" => "integer",
150  "LinkMdValues" => "integer",
151  "EmptyPageTempl" => "integer"
152  );
153  }
154  }
155 
156  if ($a_entity == "wpg") {
157  switch ($a_version) {
158  case "4.1.0":
159  return array(
160  "Id" => "integer",
161  "Title" => "text",
162  "WikiId" => "integer");
163 
164  case "4.3.0":
165  case "4.4.0":
166  case "5.1.0":
167  return array(
168  "Id" => "integer",
169  "Title" => "text",
170  "WikiId" => "integer",
171  "Blocked" => "integer",
172  "Rating" => "integer");
173 
174  case "5.4.0":
175  return array(
176  "Id" => "integer",
177  "Title" => "text",
178  "WikiId" => "integer",
179  "Blocked" => "integer",
180  "Rating" => "integer",
181  "TemplateNewPages" => "integer",
182  "TemplateAddToPage" => "integer"
183  );
184  }
185  }
186 
187  if ($a_entity == "wiki_imp_page") {
188  switch ($a_version) {
189  case "5.1.0":
190  case "5.4.0":
191  return array(
192  "WikiId" => "integer",
193  "PageId" => "integer",
194  "Ord" => "integer",
195  "Indent" => "integer");
196  }
197  }
198  return array();
199  }
200 
207  public function readData($a_entity, $a_version, $a_ids, $a_field = "")
208  {
209  $ilDB = $this->db;
210 
211  if (!is_array($a_ids)) {
212  $a_ids = array($a_ids);
213  }
214 
215  if ($a_entity == "wiki") {
216  switch ($a_version) {
217  case "4.1.0":
218  $this->getDirectDataFromQuery("SELECT id, title, description," .
219  " startpage start_page, short, rating, introduction" .
220  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
221  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
222  break;
223 
224  case "4.3.0":
225  $this->getDirectDataFromQuery("SELECT id, title, description," .
226  " startpage start_page, short, rating, introduction," . // imp_pages,
227  " public_notes, page_toc, rating_side, rating_new, rating_ext" .
228  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
229  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
230  break;
231 
232  case "4.4.0":
233  $this->getDirectDataFromQuery("SELECT id, title, description," .
234  " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
235  " public_notes, page_toc, rating_side, rating_new, rating_ext" .
236  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
237  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
238  break;
239 
240  case "5.1.0":
241  $this->getDirectDataFromQuery("SELECT id, title, description," .
242  " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
243  " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values" .
244  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
245  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
246  break;
247 
248  case "5.4.0":
249  $this->getDirectDataFromQuery("SELECT id, title, description," .
250  " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
251  " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values, empty_page_templ" .
252  " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
253  " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
254  break;
255  }
256  }
257 
258  if ($a_entity == "wpg") {
259  switch ($a_version) {
260  case "4.1.0":
261  $this->getDirectDataFromQuery("SELECT id, title, wiki_id" .
262  " FROM il_wiki_page" .
263  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
264  break;
265 
266  case "4.3.0":
267  case "4.4.0":
268  case "5.1.0":
269  $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
270  " blocked, rating" .
271  " FROM il_wiki_page" .
272  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
273  break;
274 
275  case "5.4.0":
276  $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
277  " blocked, rating" .
278  " FROM il_wiki_page" .
279  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
280  foreach ($this->data as $k => $v) {
281  $set = $ilDB->queryF(
282  "SELECT * FROM wiki_page_template " .
283  " WHERE wiki_id = %s " .
284  " AND wpage_id = %s ",
285  ["integer", "integer"],
286  [$v["WikiId"], $v["Id"]]
287  );
288  if ($rec = $ilDB->fetchAssoc($set)) {
289  $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
290  $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
291  }
292  }
293  break;
294  }
295  }
296 
297  if ($a_entity == "wiki_imp_page") {
298  switch ($a_version) {
299  case "5.1.0":
300  case "5.4.0":
301  $this->getDirectDataFromQuery("SELECT wiki_id, page_id, ord, indent " .
302  " FROM il_wiki_imp_pages " .
303  " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
304  break;
305  }
306  }
307  }
308 
312  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
313  {
314  switch ($a_entity) {
315  case "wiki":
316  return array(
317  "wpg" => array("ids" => $a_rec["Id"]),
318  "wiki_imp_page" => array("ids" => $a_rec["Id"])
319  );
320  }
321 
322  return false;
323  }
324 
325 
332  public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
333  {
334  //echo $a_entity;
335  //var_dump($a_rec);
336 
337  switch ($a_entity) {
338  case "wiki":
339 
340  include_once("./Modules/Wiki/classes/class.ilObjWiki.php");
341  if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) {
342  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
343  } else {
344  $newObj = new ilObjWiki();
345  $newObj->setType("wiki");
346  $newObj->create(true);
347  }
348 
349  $newObj->setTitle($a_rec["Title"]);
350  $newObj->setDescription($a_rec["Description"]);
351  $newObj->setShortTitle($a_rec["Short"]);
352  $newObj->setStartPage($a_rec["StartPage"]);
353  $newObj->setRatingOverall($a_rec["RatingOverall"]);
354  $newObj->setRating($a_rec["Rating"]);
355  $newObj->setIntroduction($a_rec["Introduction"]);
356  $newObj->setPublicNotes($a_rec["PublicNotes"]);
357 
358  // >= 4.3
359  if (isset($a_rec["PageToc"])) {
360  // $newObj->setImportantPages($a_rec["ImpPages"]);
361  $newObj->setPageToc($a_rec["PageToc"]);
362  $newObj->setRatingAsBlock($a_rec["RatingSide"]);
363  $newObj->setRatingForNewPages($a_rec["RatingNew"]);
364  $newObj->setRatingCategories($a_rec["RatingExt"]);
365  }
366  $newObj->setLinkMetadataValues($a_rec["LinkMdValues"]);
367  $newObj->setEmptyPageTemplate((int) $a_rec["EmptyPageTempl"]);
368 
369  $newObj->update(true);
370  $this->current_obj = $newObj;
371  $a_mapping->addMapping("Modules/Wiki", "wiki", $a_rec["Id"], $newObj->getId());
372  $a_mapping->addMapping("Services/Object", "obj", $a_rec["Id"], $newObj->getId());
373  $a_mapping->addMapping("Services/Rating", "rating_category_parent_id", $a_rec["Id"], $newObj->getId());
374  $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
375  break;
376 
377  case "wpg":
378  $wiki_id = $a_mapping->getMapping("Modules/Wiki", "wiki", $a_rec["WikiId"]);
379  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
380  $wpage = new ilWikiPage();
381  $wpage->setWikiId($wiki_id);
382  $wpage->setTitle($a_rec["Title"]);
383 
384  // >= 4.3
385  if (isset($a_rec["Blocked"])) {
386  $wpage->setBlocked($a_rec["Blocked"]);
387  $wpage->setRating($a_rec["Rating"]);
388  }
389 
390  $wpage->create(true);
391 
392  if (isset($a_rec["TemplateNewPages"]) || isset($a_rec["TemplateAddToPage"])) {
393  $wtpl = new ilWikiPageTemplate($wiki_id);
394  $wtpl->save($wpage->getId(), (int) $a_rec["TemplateNewPages"], (int) $a_rec["TemplateAddToPage"]);
395  }
396 
397  $a_mapping->addMapping("Modules/Wiki", "wpg", $a_rec["Id"], $wpage->getId());
398  $a_mapping->addMapping("Services/COPage", "pg", "wpg:" . $a_rec["Id"], "wpg:" . $wpage->getId());
399  $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:wpg:" . $a_rec["Id"], $wpage->getId());
400  break;
401 
402  case "wiki_imp_page":
403  $wiki_id = $a_mapping->getMapping("Modules/Wiki", "wiki", $a_rec["WikiId"]);
404  $page_id = $a_mapping->getMapping("Modules/Wiki", "wpg", $a_rec["PageId"]);
405  if ($wiki_id > 0 && $page_id > 0 && is_object($this->current_obj) && $this->current_obj->getId() == $wiki_id) {
406  $this->current_obj->addImportantPage($page_id, $a_rec["Ord"], $a_rec["Indent"]);
407  }
408  break;
409  }
410  }
411 }
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 ...
global $DIC
Definition: saml.php:7
getSupportedVersions()
Get supported versions.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getTypes($a_entity, $a_version)
Get field types for entity.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
__construct()
construct
Class ilObjWiki.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
Class ilWikiPage.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Wiki Data set class.
$this data['403_header']
global $ilDB
static getLogger($a_component_id)
Get component logger.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.