ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilBlogDataSet.php
Go to the documentation of this file.
1<?php
2
20
29{
30 protected Service $notes;
32 public static array $style_map = array();
33 protected \ILIAS\Style\Content\DomainService $content_style_domain;
34
35 public function __construct()
36 {
37 global $DIC;
39 $this->content_style_domain = $DIC
40 ->contentStyle()
41 ->domain();
42 $this->notes = $DIC->notes();
43 }
44
45 public function getSupportedVersions(): array
46 {
47 return array("4.3.0", "5.0.0", "5.3.0");
48 }
49
50 protected function getXmlNamespace(
51 string $a_entity,
52 string $a_schema_version
53 ): string {
54 return "https://www.ilias.de/xml/Modules/Blog/" . $a_entity;
55 }
56
57 protected function getTypes(
58 string $a_entity,
59 string $a_version
60 ): array {
61 if ($a_entity === "blog") {
62 switch ($a_version) {
63 case "4.3.0":
64 return array(
65 "Id" => "integer",
66 "Title" => "text",
67 "Description" => "text",
68 "Notes" => "integer",
69 "BgColor" => "text",
70 "FontColor" => "text",
71 "Img" => "text",
72 "Ppic" => "integer",
73 "RssActive" => "integer",
74 "Approval" => "integer",
75 "Dir" => "directory"
76 );
77
78 case "5.0.0":
79 return array(
80 "Id" => "integer",
81 "Title" => "text",
82 "Description" => "text",
83 "Notes" => "integer",
84 "BgColor" => "text",
85 "FontColor" => "text",
86 "Img" => "text",
87 "Ppic" => "integer",
88 "RssActive" => "integer",
89 "Approval" => "integer",
90 "Dir" => "directory",
91 "AbsShorten" => "integer",
92 "AbsShortenLen" => "integer",
93 "AbsImage" => "integer",
94 "AbsImgWidth" => "integer",
95 "AbsImgHeight" => "integer",
96 "NavMode" => "integer",
97 "NavListPost" => "integer",
98 "NavListMon" => "integer",
99 "Keywords" => "integer",
100 "Authors" => "integer",
101 "NavOrder" => "text",
102 "OvPost" => "integer",
103 "Style" => "integer"
104 );
105
106 case "5.3.0":
107 return array(
108 "Id" => "integer",
109 "Title" => "text",
110 "Description" => "text",
111 "Notes" => "integer",
112 "BgColor" => "text",
113 "FontColor" => "text",
114 "Img" => "text",
115 "Ppic" => "integer",
116 "RssActive" => "integer",
117 "Approval" => "integer",
118 "Dir" => "directory",
119 "AbsShorten" => "integer",
120 "AbsShortenLen" => "integer",
121 "AbsImage" => "integer",
122 "AbsImgWidth" => "integer",
123 "AbsImgHeight" => "integer",
124 "NavMode" => "integer",
125 "NavListMonWithPost" => "integer",
126 "NavListMon" => "integer",
127 "Keywords" => "integer",
128 "Authors" => "integer",
129 "NavOrder" => "text",
130 "OvPost" => "integer",
131 "Style" => "integer"
132 );
133
134 }
135 }
136
137 if ($a_entity === "blog_posting") {
138 switch ($a_version) {
139 case "4.3.0":
140 case "5.0.0":
141 case "5.3.0":
142 return array(
143 "Id" => "integer",
144 "BlogId" => "integer",
145 "Title" => "integer",
146 "Created" => "text",
147 "Author" => "text",
148 "Approved" => "integer",
149 "LastWithdrawn" => "text"
150 );
151 }
152 }
153 return [];
154 }
155
156 public function readData(
157 string $a_entity,
158 string $a_version,
159 array $a_ids
160 ): void {
161 $ilDB = $this->db;
162
163 if ($a_entity === "blog") {
164 switch ($a_version) {
165 case "4.3.0":
166 $this->getDirectDataFromQuery(
167 "SELECT bl.id,od.title,od.description," .
168 "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval" .
169 " FROM il_blog bl" .
170 " JOIN object_data od ON (od.obj_id = bl.id)" .
171 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
172 " AND od.type = " . $ilDB->quote("blog", "text")
173 );
174 break;
175
176 case "5.0.0":
177 $this->getDirectDataFromQuery(
178 "SELECT bl.id,od.title,od.description," .
179 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
180 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
181 "bl.nav_mode,bl.nav_list_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
182 "bl.ov_post" .
183 " FROM il_blog bl" .
184 " JOIN object_data od ON (od.obj_id = bl.id)" .
185 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
186 " AND od.type = " . $ilDB->quote("blog", "text")
187 );
188 break;
189
190 case "5.3.0":
191 $this->getDirectDataFromQuery(
192 "SELECT bl.id,od.title,od.description," .
193 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
194 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
195 "bl.nav_mode,bl.nav_list_mon_with_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
196 "bl.ov_post" .
197 " FROM il_blog bl" .
198 " JOIN object_data od ON (od.obj_id = bl.id)" .
199 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
200 " AND od.type = " . $ilDB->quote("blog", "text")
201 );
202 break;
203 }
204 }
205
206 if ($a_entity === "blog_posting") {
207 switch ($a_version) {
208 case "4.3.0":
209 case "5.0.0":
210 case "5.3.0":
211 $this->getDirectDataFromQuery(
212 "SELECT id,blog_id,title,created,author,approved,last_withdrawn" .
213 " FROM il_blog_posting WHERE " .
214 $ilDB->in("blog_id", $a_ids, false, "integer")
215 );
216 foreach ($this->data as $idx => $item) {
217 // create full export id
218 $this->data[$idx]["Author"] = $this->createObjectExportId("usr", $item["Author"]);
219 }
220 break;
221 }
222
223 // keywords
224 foreach ($this->data as $idx => $item) {
225 $blog_id = ilBlogPosting::lookupBlogId($item["Id"]);
226 $keywords = ilBlogPosting::getKeywords($blog_id, $item["Id"]);
227 if ($keywords) {
228 foreach ($keywords as $kidx => $keyword) {
229 $this->data[$idx]["Keyword" . $kidx] = $keyword;
230 }
231 }
232 }
233 }
234 }
235
236 protected function getDependencies(
237 string $a_entity,
238 string $a_version,
239 ?array $a_rec = null,
240 ?array $a_ids = null
241 ): array {
242 if ($a_entity === "blog") {
243 return array(
244 "blog_posting" => array("ids" => $a_rec["Id"] ?? null)
245 );
246 }
247 return [];
248 }
249
250 public function getXmlRecord(
251 string $a_entity,
252 string $a_version,
253 array $a_set
254 ): array {
255 if ($a_entity === "blog") {
256 $style = $this->content_style_domain->styleForObjId((int) $a_set["Id"]);
257
258 $dir = ilObjBlog::initStorage($a_set["Id"]);
259 $a_set["Dir"] = $dir;
260
261 $a_set["Style"] = $style->getStyleId();
262
263 // #14734
264 $a_set["Notes"] = $this->notes->domain()->commentsActive((int) $a_set["Id"]);
265 }
266
267 return $a_set;
268 }
269
270 public function importRecord(
271 string $a_entity,
272 array $a_types,
273 array $a_rec,
274 ilImportMapping $a_mapping,
275 string $a_schema_version
276 ): void {
277 $a_rec = $this->stripTags($a_rec);
278 switch ($a_entity) {
279 case "blog":
280
281 // container copy
282 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
283 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
284 } else {
285 $newObj = new ilObjBlog();
286 $newObj->create();
287 }
288
289 $newObj->setTitle($a_rec["Title"] ?? "");
290 $newObj->setDescription($a_rec["Description"] ?? "");
291 $newObj->setNotesStatus((bool) ($a_rec["Notes"] ?? false));
292 $newObj->setBackgroundColor($a_rec["BgColor"] ?? "");
293 $newObj->setFontColor($a_rec["FontColor"] ?? "");
294 $newObj->setProfilePicture((bool) ($a_rec["Ppic"] ?? false));
295 $newObj->setRSS((bool) ($a_rec["RssActive"] ?? false));
296 $newObj->setApproval((bool) ($a_rec["Approval"] ?? false));
297 $newObj->setImage($a_rec["Img"] ?? "");
298
299 $newObj->setAbstractShorten((bool) ($a_rec["AbsShorten"] ?? false));
300 $newObj->setAbstractShortenLength((int) ($a_rec["AbsShortenLen"] ?? 0));
301 $newObj->setAbstractImage((int) ($a_rec["AbsImage"] ?? 0));
302 $newObj->setAbstractImageWidth((int) ($a_rec["AbsImgWidth"] ?? 0));
303 $newObj->setAbstractImageHeight((int) ($a_rec["AbsImgHeight"] ?? 0));
304 $newObj->setNavMode((int) ($a_rec["NavMode"] ?? 0));
305 if (($a_rec["NavListMonWithPost"] ?? 0) == 0) {
306 $newObj->setNavModeListMonthsWithPostings(3);
307 } else {
308 $newObj->setNavModeListMonthsWithPostings((int) $a_rec["NavListMonWithPost"]);
309 }
310 //$newObj->setNavModeListPostings($a_rec["NavListPost"]);
311 if (($nav_list_months = $a_rec["NavListMon"] ?? null) !== null) {
312 $nav_list_months = (int) $nav_list_months;
313 }
314 $newObj->setNavModeListMonths($nav_list_months);
315 $newObj->setKeywords((bool) ($a_rec["Keywords"] ?? false));
316 $newObj->setAuthors((bool) ($a_rec["Authors"] ?? false));
317 $newObj->setOrder(
318 trim($a_rec["NavOrder"])
319 ? explode(";", $a_rec["NavOrder"])
320 : []
321 );
322 if (($ov_post = $a_rec["OvPost"] ?? null) !== null) {
323 $ov_post = (int) $ov_post;
324 }
325 $newObj->setOverviewPostings($ov_post);
326
327 $newObj->update();
328
329 // handle image(s)
330 if ($a_rec["Img"] ?? false) {
331 $dir = str_replace("..", "", $a_rec["Dir"]);
332 if ($dir !== "" && $this->getImportDirectory() !== "") {
333 $source_dir = $this->getImportDirectory() . "/" . $dir;
334 $target_dir = ilObjBlog::initStorage($newObj->getId());
335 ilFileUtils::rCopy($source_dir, $target_dir);
336 }
337 }
338
339 if ($a_rec["Style"] ?? false) {
340 self::$style_map[$a_rec["Style"]][] = $newObj->getId();
341 }
342 $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
343 break;
344
345 case "blog_posting":
346 $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
347 if ($blog_id) {
348 $newObj = new ilBlogPosting();
349 $newObj->setBlogId($blog_id);
350 $newObj->setTitle($a_rec["Title"] ?? "");
351 $newObj->setCreated(new ilDateTime($a_rec["Created"] ?? null, IL_CAL_DATETIME));
352 $newObj->setApproved($a_rec["Approved"] ?? null);
353 $newObj->setWithdrawn(new ilDateTime($a_rec["LastWithdrawn"] ?? null, IL_CAL_DATETIME));
354
355 // parse export id into local id (if possible)
356 $author = $this->parseObjectExportId($a_rec["Author"] ?? "", -1);
357 $newObj->setAuthor((int) $author["id"]);
358
359 $newObj->create(true);
360
361 // keywords
362 $keywords = array();
363 for ($loop = 0; $loop < 1000; $loop++) {
364 $idx = "Keyword" . $loop;
365 if (isset($a_rec[$idx])) {
366 $keyword = trim($a_rec[$idx]);
367 if ($keyword !== '') {
368 $keywords[] = $keyword;
369 }
370 }
371 }
372 if (count($keywords)) {
373 $newObj->updateKeywords($keywords);
374 }
375
376 $a_mapping->addMapping("Services/COPage", "pg", "blp:" . $a_rec["Id"], "blp:" . $newObj->getId());
377 }
378 break;
379 }
380 }
381}
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)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupBlogId(int $a_posting_id)
static getKeywords(int $a_obj_id, int $a_posting_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
static rCopy(string $a_sdir, string $a_tdir, bool $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static initStorage(int $a_id, string $a_subdir=null)
Init file system storage.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc