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