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