ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilBlogDataSet.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
15{
16 protected $current_blog;
17
18 public static $style_map = array();
19
23 public function getSupportedVersions()
24 {
25 return array("4.3.0", "5.0.0", "5.3.0");
26 }
27
31 public function getXmlNamespace($a_entity, $a_schema_version)
32 {
33 return "http://www.ilias.de/xml/Modules/Blog/" . $a_entity;
34 }
35
39 protected function getTypes($a_entity, $a_version)
40 {
41 if ($a_entity == "blog") {
42 switch ($a_version) {
43 case "4.3.0":
44 return array(
45 "Id" => "integer",
46 "Title" => "text",
47 "Description" => "text",
48 "Notes" => "integer",
49 "BgColor" => "text",
50 "FontColor" => "text",
51 "Img" => "text",
52 "Ppic" => "integer",
53 "RssActive" => "integer",
54 "Approval" => "integer",
55 "Dir" => "directory"
56 );
57
58 case "5.0.0":
59 return array(
60 "Id" => "integer",
61 "Title" => "text",
62 "Description" => "text",
63 "Notes" => "integer",
64 "BgColor" => "text",
65 "FontColor" => "text",
66 "Img" => "text",
67 "Ppic" => "integer",
68 "RssActive" => "integer",
69 "Approval" => "integer",
70 "Dir" => "directory",
71 "AbsShorten" => "integer",
72 "AbsShortenLen" => "integer",
73 "AbsImage" => "integer",
74 "AbsImgWidth" => "integer",
75 "AbsImgHeight" => "integer",
76 "NavMode" => "integer",
77 "NavListPost" => "integer",
78 "NavListMon" => "integer",
79 "Keywords" => "integer",
80 "Authors" => "integer",
81 "NavOrder" => "text",
82 "OvPost" => "integer",
83 "Style" => "integer"
84 );
85
86 case "5.3.0":
87 return array(
88 "Id" => "integer",
89 "Title" => "text",
90 "Description" => "text",
91 "Notes" => "integer",
92 "BgColor" => "text",
93 "FontColor" => "text",
94 "Img" => "text",
95 "Ppic" => "integer",
96 "RssActive" => "integer",
97 "Approval" => "integer",
98 "Dir" => "directory",
99 "AbsShorten" => "integer",
100 "AbsShortenLen" => "integer",
101 "AbsImage" => "integer",
102 "AbsImgWidth" => "integer",
103 "AbsImgHeight" => "integer",
104 "NavMode" => "integer",
105 "NavListMonWithPost" => "integer",
106 "NavListMon" => "integer",
107 "Keywords" => "integer",
108 "Authors" => "integer",
109 "NavOrder" => "text",
110 "OvPost" => "integer",
111 "Style" => "integer"
112 );
113
114 }
115 }
116
117 if ($a_entity == "blog_posting") {
118 switch ($a_version) {
119 case "4.3.0":
120 case "5.0.0":
121 case "5.3.0":
122 return array(
123 "Id" => "integer",
124 "BlogId" => "integer",
125 "Title" => "integer",
126 "Created" => "text",
127 "Author" => "text",
128 "Approved" => "integer",
129 "LastWithdrawn" => "text"
130 );
131 }
132 }
133 }
134
141 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
142 {
144
145 if (!is_array($a_ids)) {
146 $a_ids = array($a_ids);
147 }
148
149 if ($a_entity == "blog") {
150 switch ($a_version) {
151 case "4.3.0":
152 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
153 "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval" .
154 " FROM il_blog bl" .
155 " JOIN object_data od ON (od.obj_id = bl.id)" .
156 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
157 " AND od.type = " . $ilDB->quote("blog", "text"));
158 break;
159
160 case "5.0.0":
161 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
162 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
163 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
164 "bl.nav_mode,bl.nav_list_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
165 "bl.ov_post" .
166 " FROM il_blog bl" .
167 " JOIN object_data od ON (od.obj_id = bl.id)" .
168 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
169 " AND od.type = " . $ilDB->quote("blog", "text"));
170 break;
171
172 case "5.3.0":
173 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
174 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
175 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
176 "bl.nav_mode,bl.nav_list_mon_with_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
177 "bl.ov_post" .
178 " FROM il_blog bl" .
179 " JOIN object_data od ON (od.obj_id = bl.id)" .
180 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
181 " AND od.type = " . $ilDB->quote("blog", "text"));
182 break;
183 }
184 }
185
186 if ($a_entity == "blog_posting") {
187 switch ($a_version) {
188 case "4.3.0":
189 case "5.0.0":
190 case "5.3.0":
191 $this->getDirectDataFromQuery("SELECT id,blog_id,title,created,author,approved,last_withdrawn" .
192 " FROM il_blog_posting WHERE " .
193 $ilDB->in("blog_id", $a_ids, false, "integer"));
194 foreach ($this->data as $idx => $item) {
195 // create full export id
196 $this->data[$idx]["Author"] = $this->createObjectExportId("usr", $item["Author"]);
197 }
198 break;
199 }
200
201 // keywords
202 foreach ($this->data as $idx => $item) {
203 $blog_id = ilBlogPosting::lookupBlogId($item["Id"]);
204 $keywords = ilBlogPosting::getKeywords($blog_id, $item["Id"]);
205 if ($keywords) {
206 foreach ($keywords as $kidx => $keyword) {
207 $this->data[$idx]["Keyword" . $kidx] = $keyword;
208 }
209 }
210 }
211 }
212 }
213
217 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
218 {
219 switch ($a_entity) {
220 case "blog":
221 return array(
222 "blog_posting" => array("ids" => $a_rec["Id"])
223 );
224 }
225 return false;
226 }
227
234 public function getXmlRecord($a_entity, $a_version, $a_set)
235 {
236 if ($a_entity == "blog") {
237 $dir = ilObjBlog::initStorage($a_set["Id"]);
238 $a_set["Dir"] = $dir;
239
240 $a_set["Style"] = ilObjStyleSheet::lookupObjectStyle($a_set["Id"]);
241
242 // #14734
243 $a_set["Notes"] = ilNote::commentsActivated($a_set["Id"], 0, "blog");
244 }
245
246 return $a_set;
247 }
248
255 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
256 {
257 $a_rec = $this->stripTags($a_rec);
258 switch ($a_entity) {
259 case "blog":
260
261 // container copy
262 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
263 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
264 } else {
265 $newObj = new ilObjBlog();
266 $newObj->create();
267 }
268
269 $newObj->setTitle($a_rec["Title"]);
270 $newObj->setDescription($a_rec["Description"]);
271 $newObj->setNotesStatus($a_rec["Notes"]);
272 $newObj->setBackgroundColor($a_rec["BgColor"]);
273 $newObj->setFontColor($a_rec["FontColor"]);
274 $newObj->setProfilePicture($a_rec["Ppic"]);
275 $newObj->setRSS($a_rec["RssActive"]);
276 $newObj->setApproval($a_rec["Approval"]);
277 $newObj->setImage($a_rec["Img"]);
278
279 $newObj->setAbstractShorten($a_rec["AbsShorten"]);
280 $newObj->setAbstractShortenLength($a_rec["AbsShortenLen"]);
281 $newObj->setAbstractImage($a_rec["AbsImage"]);
282 $newObj->setAbstractImageWidth($a_rec["AbsImgWidth"]);
283 $newObj->setAbstractImageHeight($a_rec["AbsImgHeight"]);
284 $newObj->setNavMode($a_rec["NavMode"]);
285 if ($a_rec["NavListMonWithPost"] == 0) {
286 $newObj->setNavModeListMonthsWithPostings(3);
287 } else {
288 $newObj->setNavModeListMonthsWithPostings($a_rec["NavListMonWithPost"]);
289 }
290 //$newObj->setNavModeListPostings($a_rec["NavListPost"]);
291 $newObj->setNavModeListMonths($a_rec["NavListMon"]);
292 $newObj->setKeywords($a_rec["Keywords"]);
293 $newObj->setAuthors($a_rec["Authors"]);
294 $newObj->setOrder(trim($a_rec["NavOrder"])
295 ? explode(";", $a_rec["NavOrder"])
296 : null);
297 $newObj->setOverviewPostings($a_rec["OvPost"]);
298
299 $newObj->update();
300
301 // handle image(s)
302 if ($a_rec["Img"]) {
303 $dir = str_replace("..", "", $a_rec["Dir"]);
304 if ($dir != "" && $this->getImportDirectory() != "") {
305 $source_dir = $this->getImportDirectory() . "/" . $dir;
306 $target_dir = ilObjBlog::initStorage($newObj->getId());
307 ilUtil::rCopy($source_dir, $target_dir);
308 }
309 }
310
311 if ($a_rec["Style"]) {
312 self::$style_map[$a_rec["Style"]][] = $newObj->getId();
313 }
314 $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
315 break;
316
317 case "blog_posting":
318 $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
319 if ($blog_id) {
320 $newObj = new ilBlogPosting();
321 $newObj->setBlogId($blog_id);
322 $newObj->setTitle($a_rec["Title"]);
323 $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
324 $newObj->setApproved($a_rec["Approved"]);
325 $newObj->setWithdrawn(new ilDateTime($a_rec["LastWithdrawn"], IL_CAL_DATETIME));
326
327 // parse export id into local id (if possible)
328 $author = $this->parseObjectExportId($a_rec["Author"], -1);
329 $newObj->setAuthor($author["id"]);
330
331 $newObj->create(true);
332
333 // keywords
334 $keywords = array();
335 for ($loop = 0; $loop < 1000; $loop++) {
336 if (isset($a_rec["Keyword" . $loop])) {
337 $keyword = trim($a_rec["Keyword" . $loop]);
338 if (strlen($keyword)) {
339 $keywords[] = $keyword;
340 }
341 }
342 }
343 if (sizeof($keywords)) {
344 $newObj->updateKeywords($keywords);
345 }
346
347 $a_mapping->addMapping("Services/COPage", "pg", "blp:" . $a_rec["Id"], "blp:" . $newObj->getId());
348 }
349 break;
350 }
351 }
352}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
Blog Data set class.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
getSupportedVersions()
Get supported versions.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
Class ilBlogPosting.
static lookupBlogId($a_posting_id)
Lookup blog id.
static getKeywords($a_obj_id, $a_posting_id)
A dataset contains in data in a common structure that can be shared and transformed for different pur...
stripTags(array $rec, array $omit_keys=[])
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 ...
getImportDirectory()
Get import directory.
parseObjectExportId($a_id, $a_fallback_id=null)
Parse export id.
createObjectExportId($a_type, $a_id)
Build ilias export id.
@classDescription Date and time handling
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id=0)
Are comments activated for object?
Class ilObjBlog.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
static lookupObjectStyle($a_obj_id)
Lookup object style.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
global $ilDB