ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 
14 class ilBlogDataSet extends ilDataSet
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  {
143  $ilDB = $this->db;
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  switch ($a_entity) {
258  case "blog":
259 
260  // container copy
261  if ($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"])) {
262  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
263  } else {
264  $newObj = new ilObjBlog();
265  $newObj->create();
266  }
267 
268  $newObj->setTitle($a_rec["Title"]);
269  $newObj->setDescription($a_rec["Description"]);
270  $newObj->setNotesStatus($a_rec["Notes"]);
271  $newObj->setBackgroundColor($a_rec["BgColor"]);
272  $newObj->setFontColor($a_rec["FontColor"]);
273  $newObj->setProfilePicture($a_rec["Ppic"]);
274  $newObj->setRSS($a_rec["RssActive"]);
275  $newObj->setApproval($a_rec["Approval"]);
276  $newObj->setImage($a_rec["Img"]);
277 
278  $newObj->setAbstractShorten($a_rec["AbsShorten"]);
279  $newObj->setAbstractShortenLength($a_rec["AbsShortenLen"]);
280  $newObj->setAbstractImage($a_rec["AbsImage"]);
281  $newObj->setAbstractImageWidth($a_rec["AbsImgWidth"]);
282  $newObj->setAbstractImageHeight($a_rec["AbsImgHeight"]);
283  $newObj->setNavMode($a_rec["NavMode"]);
284  if ($a_rec["NavListMonWithPost"] == 0) {
285  $newObj->setNavModeListMonthsWithPostings(3);
286  } else {
287  $newObj->setNavModeListMonthsWithPostings($a_rec["NavListMonWithPost"]);
288  }
289  //$newObj->setNavModeListPostings($a_rec["NavListPost"]);
290  $newObj->setNavModeListMonths($a_rec["NavListMon"]);
291  $newObj->setKeywords($a_rec["Keywords"]);
292  $newObj->setAuthors($a_rec["Authors"]);
293  $newObj->setOrder(trim($a_rec["NavOrder"])
294  ? explode(";", $a_rec["NavOrder"])
295  : null);
296  $newObj->setOverviewPostings($a_rec["OvPost"]);
297 
298  $newObj->update();
299 
300  // handle image(s)
301  if ($a_rec["Img"]) {
302  $dir = str_replace("..", "", $a_rec["Dir"]);
303  if ($dir != "" && $this->getImportDirectory() != "") {
304  $source_dir = $this->getImportDirectory() . "/" . $dir;
305  $target_dir = ilObjBlog::initStorage($newObj->getId());
306  ilUtil::rCopy($source_dir, $target_dir);
307  }
308  }
309 
310  if ($a_rec["Style"]) {
311  self::$style_map[$a_rec["Style"]][] = $newObj->getId();
312  }
313  $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
314  break;
315 
316  case "blog_posting":
317  $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
318  if ($blog_id) {
319  $newObj = new ilBlogPosting();
320  $newObj->setBlogId($blog_id);
321  $newObj->setTitle($a_rec["Title"]);
322  $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
323  $newObj->setApproved($a_rec["Approved"]);
324  $newObj->setWithdrawn(new ilDateTime($a_rec["LastWithdrawn"], IL_CAL_DATETIME));
325 
326  // parse export id into local id (if possible)
327  $author = $this->parseObjectExportId($a_rec["Author"], -1);
328  $newObj->setAuthor($author["id"]);
329 
330  $newObj->create(true);
331 
332  // keywords
333  $keywords = array();
334  for ($loop = 0; $loop < 1000; $loop++) {
335  if (isset($a_rec["Keyword" . $loop])) {
336  $keyword = trim($a_rec["Keyword" . $loop]);
337  if (strlen($keyword)) {
338  $keywords[] = $keyword;
339  }
340  }
341  }
342  if (sizeof($keywords)) {
343  $newObj->updateKeywords($keywords);
344  }
345 
346  $a_mapping->addMapping("Services/COPage", "pg", "blp:" . $a_rec["Id"], "blp:" . $newObj->getId());
347  }
348  break;
349  }
350  }
351 }
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id=0)
Are comments activated for object?
getSupportedVersions()
Get supported versions.
static lookupBlogId($a_posting_id)
Lookup blog id.
Class ilBlogPosting.
const IL_CAL_DATETIME
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 ...
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
createObjectExportId($a_type, $a_id)
Build ilias export id.
Blog Data set class.
static getKeywords($a_obj_id, $a_posting_id)
getImportDirectory()
Get import directory.
static lookupObjectStyle($a_obj_id)
Lookup object style.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
static initStorage($a_id, $a_subdir=null)
Init file system storage.
Class ilObjBlog.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
getTypes($a_entity, $a_version)
Get field types for entity.
global $ilDB
parseObjectExportId($a_id, $a_fallback_id=null)
Parse export id.
A dataset contains in data in a common structure that can be shared and transformed for different pur...