ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilBlogDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
18{
19 protected $current_blog;
20
21 public static $style_map = array();
22
26 public function getSupportedVersions()
27 {
28 return array("4.3.0", "5.0.0", "5.3.0");
29 }
30
34 public function getXmlNamespace($a_entity, $a_schema_version)
35 {
36 return "http://www.ilias.de/xml/Modules/Blog/" . $a_entity;
37 }
38
42 protected function getTypes($a_entity, $a_version)
43 {
44 if ($a_entity == "blog") {
45 switch ($a_version) {
46 case "4.3.0":
47 return array(
48 "Id" => "integer",
49 "Title" => "text",
50 "Description" => "text",
51 "Notes" => "integer",
52 "BgColor" => "text",
53 "FontColor" => "text",
54 "Img" => "text",
55 "Ppic" => "integer",
56 "RssActive" => "integer",
57 "Approval" => "integer",
58 "Dir" => "directory"
59 );
60
61 case "5.0.0":
62 return array(
63 "Id" => "integer",
64 "Title" => "text",
65 "Description" => "text",
66 "Notes" => "integer",
67 "BgColor" => "text",
68 "FontColor" => "text",
69 "Img" => "text",
70 "Ppic" => "integer",
71 "RssActive" => "integer",
72 "Approval" => "integer",
73 "Dir" => "directory",
74 "AbsShorten" => "integer",
75 "AbsShortenLen" => "integer",
76 "AbsImage" => "integer",
77 "AbsImgWidth" => "integer",
78 "AbsImgHeight" => "integer",
79 "NavMode" => "integer",
80 "NavListPost" => "integer",
81 "NavListMon" => "integer",
82 "Keywords" => "integer",
83 "Authors" => "integer",
84 "NavOrder" => "text",
85 "OvPost" => "integer",
86 "Style" => "integer"
87 );
88
89 case "5.3.0":
90 return array(
91 "Id" => "integer",
92 "Title" => "text",
93 "Description" => "text",
94 "Notes" => "integer",
95 "BgColor" => "text",
96 "FontColor" => "text",
97 "Img" => "text",
98 "Ppic" => "integer",
99 "RssActive" => "integer",
100 "Approval" => "integer",
101 "Dir" => "directory",
102 "AbsShorten" => "integer",
103 "AbsShortenLen" => "integer",
104 "AbsImage" => "integer",
105 "AbsImgWidth" => "integer",
106 "AbsImgHeight" => "integer",
107 "NavMode" => "integer",
108 "NavListMonWithPost" => "integer",
109 "NavListMon" => "integer",
110 "Keywords" => "integer",
111 "Authors" => "integer",
112 "NavOrder" => "text",
113 "OvPost" => "integer",
114 "Style" => "integer"
115 );
116
117 }
118 }
119
120 if ($a_entity == "blog_posting") {
121 switch ($a_version) {
122 case "4.3.0":
123 case "5.0.0":
124 case "5.3.0":
125 return array(
126 "Id" => "integer",
127 "BlogId" => "integer",
128 "Title" => "integer",
129 "Created" => "text",
130 "Author" => "text",
131 "Approved" => "integer"
132 );
133 }
134 }
135 }
136
143 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
144 {
146
147 if (!is_array($a_ids)) {
148 $a_ids = array($a_ids);
149 }
150
151 if ($a_entity == "blog") {
152 switch ($a_version) {
153 case "4.3.0":
154 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
155 "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval" .
156 " FROM il_blog bl" .
157 " JOIN object_data od ON (od.obj_id = bl.id)" .
158 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
159 " AND od.type = " . $ilDB->quote("blog", "text"));
160 break;
161
162 case "5.0.0":
163 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
164 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
165 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
166 "bl.nav_mode,bl.nav_list_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
167 "bl.ov_post" .
168 " FROM il_blog bl" .
169 " JOIN object_data od ON (od.obj_id = bl.id)" .
170 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
171 " AND od.type = " . $ilDB->quote("blog", "text"));
172 break;
173
174 case "5.3.0":
175 $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description," .
176 "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval," .
177 "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height," .
178 "bl.nav_mode,bl.nav_list_mon_with_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order," .
179 "bl.ov_post" .
180 " FROM il_blog bl" .
181 " JOIN object_data od ON (od.obj_id = bl.id)" .
182 " WHERE " . $ilDB->in("bl.id", $a_ids, false, "integer") .
183 " AND od.type = " . $ilDB->quote("blog", "text"));
184 break;
185 }
186 }
187
188 if ($a_entity == "blog_posting") {
189 switch ($a_version) {
190 case "4.3.0":
191 case "5.0.0":
192 case "5.3.0":
193 $this->getDirectDataFromQuery("SELECT id,blog_id,title,created,author,approved" .
194 " FROM il_blog_posting WHERE " .
195 $ilDB->in("blog_id", $a_ids, false, "integer"));
196 foreach ($this->data as $idx => $item) {
197 // create full export id
198 $this->data[$idx]["Author"] = $this->createObjectExportId("usr", $item["Author"]);
199 }
200 break;
201 }
202
203 // keywords
204 include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
205 include_once("./Services/MetaData/classes/class.ilMDKeyword.php");
206 foreach ($this->data as $idx => $item) {
207 $blog_id = ilBlogPosting::lookupBlogId($item["Id"]);
208 $keywords = ilBlogPosting::getKeywords($blog_id, $item["Id"]);
209 if ($keywords) {
210 foreach ($keywords as $kidx => $keyword) {
211 $this->data[$idx]["Keyword" . $kidx] = $keyword;
212 }
213 }
214 }
215 }
216 }
217
221 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
222 {
223 switch ($a_entity) {
224 case "blog":
225 return array(
226 "blog_posting" => array("ids" => $a_rec["Id"])
227 );
228 }
229 return false;
230 }
231
238 public function getXmlRecord($a_entity, $a_version, $a_set)
239 {
240 if ($a_entity == "blog") {
241 include_once("./Modules/Blog/classes/class.ilObjBlog.php");
242 $dir = ilObjBlog::initStorage($a_set["Id"]);
243 $a_set["Dir"] = $dir;
244
245 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
246 $a_set["Style"] = ilObjStyleSheet::lookupObjectStyle($a_set["Id"]);
247
248 // #14734
249 include_once("./Services/Notes/classes/class.ilNote.php");
250 $a_set["Notes"] = ilNote::commentsActivated($a_set["Id"], 0, "blog");
251 }
252
253 return $a_set;
254 }
255
262 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
263 {
264 switch ($a_entity) {
265 case "blog":
266 include_once("./Modules/Blog/classes/class.ilObjBlog.php");
267
268 // container copy
269 if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
270 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
271 } else {
272 $newObj = new ilObjBlog();
273 $newObj->create();
274 }
275
276 $newObj->setTitle($a_rec["Title"]);
277 $newObj->setDescription($a_rec["Description"]);
278 $newObj->setNotesStatus($a_rec["Notes"]);
279 $newObj->setBackgroundColor($a_rec["BgColor"]);
280 $newObj->setFontColor($a_rec["FontColor"]);
281 $newObj->setProfilePicture($a_rec["Ppic"]);
282 $newObj->setRSS($a_rec["RssActive"]);
283 $newObj->setApproval($a_rec["Approval"]);
284 $newObj->setImage($a_rec["Img"]);
285
286 $newObj->setAbstractShorten($a_rec["AbsShorten"]);
287 $newObj->setAbstractShortenLength($a_rec["AbsShortenLen"]);
288 $newObj->setAbstractImage($a_rec["AbsImage"]);
289 $newObj->setAbstractImageWidth($a_rec["AbsImgWidth"]);
290 $newObj->setAbstractImageHeight($a_rec["AbsImgHeight"]);
291 $newObj->setNavMode($a_rec["NavMode"]);
292 if ($a_rec["NavListMonWithPost"] == 0) {
293 $newObj->setNavModeListMonthsWithPostings(3);
294 } else {
295 $newObj->setNavModeListMonthsWithPostings($a_rec["NavListMonWithPost"]);
296 }
297 //$newObj->setNavModeListPostings($a_rec["NavListPost"]);
298 $newObj->setNavModeListMonths($a_rec["NavListMon"]);
299 $newObj->setKeywords($a_rec["Keywords"]);
300 $newObj->setAuthors($a_rec["Authors"]);
301 $newObj->setOrder(trim($a_rec["NavOrder"])
302 ? explode(";", $a_rec["NavOrder"])
303 : null);
304 $newObj->setOverviewPostings($a_rec["OvPost"]);
305
306 $newObj->update();
307
308 // handle image(s)
309 if ($a_rec["Img"]) {
310 $dir = str_replace("..", "", $a_rec["Dir"]);
311 if ($dir != "" && $this->getImportDirectory() != "") {
312 $source_dir = $this->getImportDirectory() . "/" . $dir;
313 $target_dir = ilObjBlog::initStorage($newObj->getId());
314 ilUtil::rCopy($source_dir, $target_dir);
315 }
316 }
317
318 if ($a_rec["Style"]) {
319 self::$style_map[$a_rec["Style"]][] = $newObj->getId();
320 }
321 $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
322 break;
323
324 case "blog_posting":
325 $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
326 if ($blog_id) {
327 include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
328 $newObj = new ilBlogPosting();
329 $newObj->setBlogId($blog_id);
330 $newObj->setTitle($a_rec["Title"]);
331 $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
332 $newObj->setApproved($a_rec["Approved"]);
333
334 // parse export id into local id (if possible)
335 $author = $this->parseObjectExportId($a_rec["Author"], -1);
336 $newObj->setAuthor($author["id"]);
337
338 $newObj->create(true);
339
340 // keywords
341 $keywords = array();
342 for ($loop = 0; $loop < 1000; $loop++) {
343 if (isset($a_rec["Keyword" . $loop])) {
344 $keyword = trim($a_rec["Keyword" . $loop]);
345 if (strlen($keyword)) {
346 $keywords[] = $keyword;
347 }
348 }
349 }
350 if (sizeof($keywords)) {
351 $newObj->updateKeywords($keywords);
352 }
353
354 $a_mapping->addMapping("Services/COPage", "pg", "blp:" . $a_rec["Id"], "blp:" . $newObj->getId());
355 }
356 break;
357 }
358 }
359}
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...
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)
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
$this data['403_header']