ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilBlogDataSet.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
31 class ilBlogDataSet extends ilDataSet
32 {
34  protected Service $notes;
36  public static array $style_map = array();
37  protected \ILIAS\Style\Content\DomainService $content_style_domain;
38 
39  public function __construct()
40  {
41  global $DIC;
43  $this->content_style_domain = $DIC
44  ->contentStyle()
45  ->domain();
46  $this->notes = $DIC->notes();
47  $this->reading_time = $DIC->blog()->internal()->domain()->readingTime();
48  }
49 
50  public function getSupportedVersions(): array
51  {
52  return array("4.3.0", "5.0.0", "5.3.0", "8.0");
53  }
54 
55  protected function getXmlNamespace(
56  string $a_entity,
57  string $a_schema_version
58  ): string {
59 
60  if ($a_entity === 'blog' || $a_entity == 'blog_posting') {
61  // they share the same xsd, therfore the same namespace
62  return "http://www.ilias.de/xml/Modules/Blog/blog";
63  }
64  return "http://www.ilias.de/xml/Modules/Blog/" . $a_entity;
65  }
66 
67  protected function getTypes(
68  string $a_entity,
69  string $a_version
70  ): array {
71  if ($a_entity === "blog") {
72  switch ($a_version) {
73  case "4.3.0":
74  return array(
75  "Id" => "integer",
76  "Title" => "text",
77  "Description" => "text",
78  "Notes" => "integer",
79  "BgColor" => "text",
80  "FontColor" => "text",
81  "Img" => "text",
82  "Ppic" => "integer",
83  "RssActive" => "integer",
84  "Approval" => "integer",
85  "Dir" => "directory"
86  );
87 
88  case "5.0.0":
89  return array(
90  "Id" => "integer",
91  "Title" => "text",
92  "Description" => "text",
93  "Notes" => "integer",
94  "BgColor" => "text",
95  "FontColor" => "text",
96  "Img" => "text",
97  "Ppic" => "integer",
98  "RssActive" => "integer",
99  "Approval" => "integer",
100  "Dir" => "directory",
101  "AbsShorten" => "integer",
102  "AbsShortenLen" => "integer",
103  "AbsImage" => "integer",
104  "AbsImgWidth" => "integer",
105  "AbsImgHeight" => "integer",
106  "NavMode" => "integer",
107  "NavListPost" => "integer",
108  "NavListMon" => "integer",
109  "Keywords" => "integer",
110  "Authors" => "integer",
111  "NavOrder" => "text",
112  "OvPost" => "integer",
113  "Style" => "integer"
114  );
115 
116  case "5.3.0":
117  return array(
118  "Id" => "integer",
119  "Title" => "text",
120  "Description" => "text",
121  "Notes" => "integer",
122  "BgColor" => "text",
123  "FontColor" => "text",
124  "Img" => "text",
125  "Ppic" => "integer",
126  "RssActive" => "integer",
127  "Approval" => "integer",
128  "Dir" => "directory",
129  "AbsShorten" => "integer",
130  "AbsShortenLen" => "integer",
131  "AbsImage" => "integer",
132  "AbsImgWidth" => "integer",
133  "AbsImgHeight" => "integer",
134  "NavMode" => "integer",
135  "NavListMonWithPost" => "integer",
136  "NavListMon" => "integer",
137  "Keywords" => "integer",
138  "Authors" => "integer",
139  "NavOrder" => "text",
140  "OvPost" => "integer",
141  "Style" => "integer"
142  );
143 
144  case "8.0":
145  return array(
146  "Id" => "integer",
147  "Title" => "text",
148  "Description" => "text",
149  "Notes" => "integer",
150  "BgColor" => "text",
151  "FontColor" => "text",
152  "Img" => "text",
153  "Ppic" => "integer",
154  "RssActive" => "integer",
155  "Approval" => "integer",
156  "Dir" => "directory",
157  "AbsShorten" => "integer",
158  "AbsShortenLen" => "integer",
159  "AbsImage" => "integer",
160  "AbsImgWidth" => "integer",
161  "AbsImgHeight" => "integer",
162  "NavMode" => "integer",
163  "NavListMonWithPost" => "integer",
164  "NavListMon" => "integer",
165  "Keywords" => "integer",
166  "Authors" => "integer",
167  "NavOrder" => "text",
168  "OvPost" => "integer",
169  "Style" => "integer",
170  "ReadingTime" => "integer"
171  );
172  }
173  }
174 
175  if ($a_entity === "blog_posting") {
176  switch ($a_version) {
177  case "4.3.0":
178  case "5.0.0":
179  case "5.3.0":
180  case "8.0":
181  return array(
182  "Id" => "integer",
183  "BlogId" => "integer",
184  "Title" => "integer",
185  "Created" => "text",
186  "Author" => "text",
187  "Approved" => "integer",
188  "LastWithdrawn" => "text"
189  );
190  }
191  }
192  return [];
193  }
194 
195  public function readData(
196  string $a_entity,
197  string $a_version,
198  array $a_ids
199  ): void {
200  $ilDB = $this->db;
201 
202  if ($a_entity === "blog") {
203  switch ($a_version) {
204  case "4.3.0":
205  $this->getDirectDataFromQuery(
206  "SELECT bl.id,od.title,od.description," .
207  "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval" .
208  " FROM il_blog bl" .
209  " JOIN object_data od ON (od.obj_id = bl.id)" .
210  " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
211  " AND od.type = " . $ilDB->quote("blog", "text")
212  );
213  break;
214 
215  case "5.0.0":
216  $this->getDirectDataFromQuery(
217  "SELECT bl.id,od.title,od.description," .
218  "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
219  "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
220  "bl.nav_mode,bl.nav_list_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
221  "bl.ov_post" .
222  " FROM il_blog bl" .
223  " JOIN object_data od ON (od.obj_id = bl.id)" .
224  " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
225  " AND od.type = " . $ilDB->quote("blog", "text")
226  );
227  break;
228 
229  case "5.3.0":
230  $this->getDirectDataFromQuery(
231  "SELECT bl.id,od.title,od.description," .
232  "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
233  "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
234  "bl.nav_mode,bl.nav_list_mon_with_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
235  "bl.ov_post" .
236  " FROM il_blog bl" .
237  " JOIN object_data od ON (od.obj_id = bl.id)" .
238  " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
239  " AND od.type = " . $ilDB->quote("blog", "text")
240  );
241  break;
242 
243  case "8.0":
244  $this->getDirectDataFromQuery(
245  "SELECT bl.id,od.title,od.description," .
246  "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
247  "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
248  "bl.nav_mode,bl.nav_list_mon_with_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
249  "bl.ov_post" .
250  " FROM il_blog bl" .
251  " JOIN object_data od ON (od.obj_id = bl.id)" .
252  " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
253  " AND od.type = " . $ilDB->quote("blog", "text")
254  );
255  foreach ($this->data as $idx => $item) {
256  $this->data[$idx]["ReadingTime"] = (int) $this->reading_time->isActivated((int) $item["Id"]);
257  }
258  break;
259  }
260  }
261 
262  if ($a_entity === "blog_posting") {
263  switch ($a_version) {
264  case "4.3.0":
265  case "5.0.0":
266  case "5.3.0":
267  case "8.0":
268  $this->getDirectDataFromQuery(
269  "SELECT id,blog_id,title,created,author,approved,last_withdrawn" .
270  " FROM il_blog_posting WHERE " .
271  $ilDB->in("blog_id", $a_ids, false, "integer")
272  );
273  foreach ($this->data as $idx => $item) {
274  // create full export id
275  $this->data[$idx]["Author"] = $this->createObjectExportId("usr", (string) $item["Author"]);
276  }
277  break;
278  }
279 
280  // keywords
281  foreach ($this->data as $idx => $item) {
282  $blog_id = ilBlogPosting::lookupBlogId($item["Id"]);
283  $keywords = ilBlogPosting::getKeywords($blog_id, $item["Id"]);
284  if ($keywords) {
285  foreach ($keywords as $kidx => $keyword) {
286  $this->data[$idx]["Keyword" . $kidx] = $keyword;
287  }
288  }
289  }
290  }
291  }
292 
293  protected function getDependencies(
294  string $a_entity,
295  string $a_version,
296  ?array $a_rec = null,
297  ?array $a_ids = null
298  ): array {
299  if ($a_entity === "blog") {
300  return array(
301  "blog_posting" => array("ids" => $a_rec["Id"] ?? null)
302  );
303  }
304  return [];
305  }
306 
307  public function getXmlRecord(
308  string $a_entity,
309  string $a_version,
310  array $a_set
311  ): array {
312  if ($a_entity === "blog") {
313  $style = $this->content_style_domain->styleForObjId((int) $a_set["Id"]);
314 
315  $dir = ilObjBlog::initStorage($a_set["Id"]);
316  $a_set["Dir"] = $dir;
317 
318  $a_set["Style"] = $style->getStyleId();
319 
320  // #14734
321  $a_set["Notes"] = $this->notes->domain()->commentsActive((int) $a_set["Id"]);
322  }
323 
324  return $a_set;
325  }
326 
327  public function importRecord(
328  string $a_entity,
329  array $a_types,
330  array $a_rec,
331  ilImportMapping $a_mapping,
332  string $a_schema_version
333  ): void {
334  $a_rec = $this->stripTags($a_rec);
335  switch ($a_entity) {
336  case "blog":
337 
338  // container copy
339  if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
340  $newObj = ilObjectFactory::getInstanceByObjId((int) $new_id, false);
341  } else {
342  $newObj = new ilObjBlog();
343  $newObj->create();
344  }
345 
346  $newObj->setTitle($a_rec["Title"] ?? "");
347  $newObj->setDescription($a_rec["Description"] ?? "");
348  $newObj->setNotesStatus((bool) ($a_rec["Notes"] ?? false));
349  $newObj->setBackgroundColor($a_rec["BgColor"] ?? "");
350  $newObj->setFontColor($a_rec["FontColor"] ?? "");
351  $newObj->setProfilePicture((bool) ($a_rec["Ppic"] ?? false));
352  $newObj->setRSS((bool) ($a_rec["RssActive"] ?? false));
353  $newObj->setApproval((bool) ($a_rec["Approval"] ?? false));
354  $newObj->setImage($a_rec["Img"] ?? "");
355 
356  $newObj->setAbstractShorten((bool) ($a_rec["AbsShorten"] ?? false));
357  $newObj->setAbstractShortenLength((int) ($a_rec["AbsShortenLen"] ?? 0));
358  $newObj->setAbstractImage((bool) ($a_rec["AbsImage"] ?? 0));
359  $newObj->setAbstractImageWidth((int) ($a_rec["AbsImgWidth"] ?? 0));
360  $newObj->setAbstractImageHeight((int) ($a_rec["AbsImgHeight"] ?? 0));
361  $newObj->setNavMode((int) ($a_rec["NavMode"] ?? 0));
362  if (($a_rec["NavListMonWithPost"] ?? 0) == 0) {
363  $newObj->setNavModeListMonthsWithPostings(3);
364  } else {
365  $newObj->setNavModeListMonthsWithPostings((int) $a_rec["NavListMonWithPost"]);
366  }
367  //$newObj->setNavModeListPostings($a_rec["NavListPost"]);
368  if (($nav_list_months = $a_rec["NavListMon"] ?? null) !== null) {
369  $nav_list_months = (int) $nav_list_months;
370  }
371  $newObj->setNavModeListMonths($nav_list_months);
372  $newObj->setKeywords((bool) ($a_rec["Keywords"] ?? false));
373  $newObj->setAuthors((bool) ($a_rec["Authors"] ?? false));
374  $newObj->setOrder(
375  trim($a_rec["NavOrder"])
376  ? explode(";", $a_rec["NavOrder"])
377  : []
378  );
379  if (($ov_post = $a_rec["OvPost"] ?? null) !== null) {
380  $ov_post = (int) $ov_post;
381  }
382  $newObj->setOverviewPostings($ov_post);
383 
384  $newObj->update();
385 
386  // handle image(s)
387  if ($a_rec["Img"] ?? false) {
388  $dir = str_replace("..", "", $a_rec["Dir"]);
389  if ($dir !== "" && $this->getImportDirectory() !== "") {
390  $source_dir = $this->getImportDirectory() . "/" . $dir;
391  $target_dir = ilObjBlog::initStorage($newObj->getId());
392  ilFileUtils::rCopy($source_dir, $target_dir);
393  }
394  }
395 
396  if ($a_rec["Style"] ?? false) {
397  self::$style_map[$a_rec["Style"]][] = $newObj->getId();
398  }
399 
400  // reading time
401  $this->reading_time->activate($newObj->getId(), (bool) ($a_rec["ReadingTime"] ?? false));
402 
403  $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], (string) $newObj->getId());
404  break;
405 
406  case "blog_posting":
407  $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
408  if ($blog_id) {
409  $newObj = new ilBlogPosting();
410  $newObj->setBlogId($blog_id);
411  $newObj->setTitle($a_rec["Title"] ?? "");
412  $newObj->setCreated(new ilDateTime($a_rec["Created"] ?? null, IL_CAL_DATETIME));
413  $newObj->setApproved((bool) ($a_rec["Approved"] ?? null));
414  $newObj->setWithdrawn(new ilDateTime($a_rec["LastWithdrawn"] ?? null, IL_CAL_DATETIME));
415 
416  // parse export id into local id (if possible)
417  $author = $this->parseObjectExportId($a_rec["Author"] ?? "", "-1");
418  $newObj->setAuthor((int) $author["id"]);
419 
420  $newObj->create(true);
421 
422  // keywords
423  $keywords = array();
424  for ($loop = 0; $loop < 1000; $loop++) {
425  $idx = "Keyword" . $loop;
426  if (isset($a_rec[$idx])) {
427  $keyword = trim($a_rec[$idx]);
428  if ($keyword !== '') {
429  $keywords[] = $keyword;
430  }
431  }
432  }
433  if (count($keywords)) {
434  $newObj->updateKeywords($keywords);
435  }
436 
437  $a_mapping->addMapping("Services/COPage", "pg", "blp:" . $a_rec["Id"], "blp:" . $newObj->getId());
438  }
439  break;
440  }
441  }
442 }
getXmlNamespace(string $a_entity, string $a_schema_version)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_DATETIME
static array $style_map
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ReadingTimeManager $reading_time
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
parseObjectExportId(string $a_id, ?string $a_fallback_id=null)
Parse export id.
ILIAS Style Content DomainService $content_style_domain
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
Blog Data set class This class implements the following entities:
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
global $DIC
Definition: feed.php:28
createObjectExportId(string $a_type, string $a_id)
Build ilias export id.
__construct(VocabulariesInterface $vocabularies)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
ilDBInterface $db
static initStorage(int $a_id, string $a_subdir=null)
Init file system storage.
Class ilObjBlog.
readData(string $a_entity, string $a_version, array $a_ids)
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 ...
static lookupBlogId(int $a_posting_id)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
getXmlRecord(string $a_entity, string $a_version, array $a_set)
static getKeywords(int $a_obj_id, int $a_posting_id)
getTypes(string $a_entity, string $a_version)
stripTags(array $rec, array $omit_keys=[])
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)