ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
17 class ilBlogDataSet extends ilDataSet
18 {
19  protected $current_blog;
20 
21  static public $style_map = array();
22 
26  public function getSupportedVersions()
27  {
28  return array("4.3.0", "5.0.0");
29  }
30 
34  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  {
46  switch ($a_version)
47  {
48  case "4.3.0":
49  return array(
50  "Id" => "integer",
51  "Title" => "text",
52  "Description" => "text",
53  "Notes" => "integer",
54  "BgColor" => "text",
55  "FontColor" => "text",
56  "Img" => "text",
57  "Ppic" => "integer",
58  "RssActive" => "integer",
59  "Approval" => "integer",
60  "Dir" => "directory"
61  );
62 
63  case "5.0.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  "AbsShorten" => "integer",
77  "AbsShortenLen" => "integer",
78  "AbsImage" => "integer",
79  "AbsImgWidth" => "integer",
80  "AbsImgHeight" => "integer",
81  "NavMode" => "integer",
82  "NavListPost" => "integer",
83  "NavListMon" => "integer",
84  "Keywords" => "integer",
85  "Authors" => "integer",
86  "NavOrder" => "text",
87  "OvPost" => "integer",
88  "Style" => "integer"
89  );
90  }
91  }
92 
93  if ($a_entity == "blog_posting")
94  {
95  switch ($a_version)
96  {
97  case "4.3.0":
98  case "5.0.0":
99  return array(
100  "Id" => "integer",
101  "BlogId" => "integer",
102  "Title" => "integer",
103  "Created" => "text",
104  "Author" => "text",
105  "Approved" => "integer"
106  );
107  }
108  }
109  }
110 
117  function readData($a_entity, $a_version, $a_ids, $a_field = "")
118  {
119  global $ilDB;
120 
121  if (!is_array($a_ids))
122  {
123  $a_ids = array($a_ids);
124  }
125 
126  if ($a_entity == "blog")
127  {
128  switch ($a_version)
129  {
130  case "4.3.0":
131  $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description,".
132  "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval".
133  " FROM il_blog bl".
134  " JOIN object_data od ON (od.obj_id = bl.id)".
135  " WHERE ".$ilDB->in("bl.id", $a_ids, false, "integer").
136  " AND od.type = ".$ilDB->quote("blog", "text"));
137  break;
138 
139  case "5.0.0":
140  $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description,".
141  "bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval,".
142  "bl.abs_shorten,bl.abs_shorten_len,bl.abs_image,bl.abs_img_width,bl.abs_img_height,".
143  "bl.nav_mode,bl.nav_list_post,bl.nav_list_mon,bl.keywords,bl.authors,bl.nav_order,".
144  "bl.ov_post".
145  " FROM il_blog bl".
146  " JOIN object_data od ON (od.obj_id = bl.id)".
147  " WHERE ".$ilDB->in("bl.id", $a_ids, false, "integer").
148  " AND od.type = ".$ilDB->quote("blog", "text"));
149  break;
150  }
151  }
152 
153  if ($a_entity == "blog_posting")
154  {
155  switch ($a_version)
156  {
157  case "4.3.0":
158  case "5.0.0":
159  $this->getDirectDataFromQuery("SELECT id,blog_id,title,created,author,approved".
160  " FROM il_blog_posting WHERE ".
161  $ilDB->in("blog_id", $a_ids, false, "integer"));
162  foreach($this->data as $idx => $item)
163  {
164  // create full export id
165  $this->data[$idx]["Author"] = $this->createObjectExportId("usr", $item["Author"]);
166  }
167  break;
168  }
169 
170  // keywords
171  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
172  include_once("./Services/MetaData/classes/class.ilMDKeyword.php");
173  foreach($this->data as $idx => $item)
174  {
175  $blog_id = ilBlogPosting::lookupBlogId($item["Id"]);
176  $keywords = ilBlogPosting::getKeywords($blog_id, $item["Id"]);
177  if($keywords)
178  {
179  foreach($keywords as $kidx => $keyword)
180  {
181  $this->data[$idx]["Keyword".$kidx] = $keyword;
182  }
183  }
184  }
185  }
186  }
187 
191  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
192  {
193  switch ($a_entity)
194  {
195  case "blog":
196  return array (
197  "blog_posting" => array("ids" => $a_rec["Id"])
198  );
199  }
200  return false;
201  }
202 
209  function getXmlRecord($a_entity, $a_version, $a_set)
210  {
211  if ($a_entity == "blog")
212  {
213  include_once("./Modules/Blog/classes/class.ilObjBlog.php");
214  $dir = ilObjBlog::initStorage($a_set["Id"]);
215  $a_set["Dir"] = $dir;
216 
217  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
218  $a_set["Style"] = ilObjStyleSheet::lookupObjectStyle($a_set["Id"]);
219 
220  // #14734
221  include_once("./Services/Notes/classes/class.ilNote.php");
222  $a_set["Notes"] = ilNote::commentsActivated($a_set["Id"], 0, "blog");
223  }
224 
225  return $a_set;
226  }
227 
234  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
235  {
236  switch ($a_entity)
237  {
238  case "blog":
239  include_once("./Modules/Blog/classes/class.ilObjBlog.php");
240 
241  // container copy
242  if($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"]))
243  {
244  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
245  }
246  else
247  {
248  $newObj = new ilObjBlog();
249  $newObj->create();
250  }
251 
252  $newObj->setTitle($a_rec["Title"]);
253  $newObj->setDescription($a_rec["Description"]);
254  $newObj->setNotesStatus($a_rec["Notes"]);
255  $newObj->setBackgroundColor($a_rec["BgColor"]);
256  $newObj->setFontColor($a_rec["FontColor"]);
257  $newObj->setProfilePicture($a_rec["Ppic"]);
258  $newObj->setRSS($a_rec["RssActive"]);
259  $newObj->setApproval($a_rec["Approval"]);
260  $newObj->setImage($a_rec["Img"]);
261 
262  $newObj->setAbstractShorten($a_rec["AbsShorten"]);
263  $newObj->setAbstractShortenLength($a_rec["AbsShortenLen"]);
264  $newObj->setAbstractImage($a_rec["AbsImage"]);
265  $newObj->setAbstractImageWidth($a_rec["AbsImgWidth"]);
266  $newObj->setAbstractImageHeight($a_rec["AbsImgHeight"]);
267  $newObj->setNavMode($a_rec["NavMode"]);
268  $newObj->setNavModeListPostings($a_rec["NavListPost"]);
269  $newObj->setNavModeListMonths($a_rec["NavListMon"]);
270  $newObj->setKeywords($a_rec["Keywords"]);
271  $newObj->setAuthors($a_rec["Authors"]);
272  $newObj->setOrder(trim($a_rec["NavOrder"])
273  ? explode(";", $a_rec["NavOrder"])
274  : null);
275  $newObj->setOverviewPostings($a_rec["OvPost"]);
276 
277  $newObj->update();
278 
279  // handle image(s)
280  if($a_rec["Img"])
281  {
282  $dir = str_replace("..", "", $a_rec["Dir"]);
283  if ($dir != "" && $this->getImportDirectory() != "")
284  {
285  $source_dir = $this->getImportDirectory()."/".$dir;
286  $target_dir = ilObjBlog::initStorage($newObj->getId());
287  ilUtil::rCopy($source_dir, $target_dir);
288  }
289  }
290 
291  if($a_rec["Style"])
292  {
293  self::$style_map[$a_rec["Style"]][] = $newObj->getId();
294  }
295  $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
296  break;
297 
298  case "blog_posting":
299  $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
300  if($blog_id)
301  {
302  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
303  $newObj = new ilBlogPosting();
304  $newObj->setBlogId($blog_id);
305  $newObj->setTitle($a_rec["Title"]);
306  $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
307  $newObj->setApproved($a_rec["Approved"]);
308 
309  // parse export id into local id (if possible)
310  $author = $this->parseObjectExportId($a_rec["Author"], -1);
311  $newObj->setAuthor($author["id"]);
312 
313  $newObj->create(true);
314 
315  // keywords
316  $keywords = array();
317  for($loop = 0; $loop < 1000; $loop++)
318  {
319  if(isset($a_rec["Keyword".$loop]))
320  {
321  $keyword = trim($a_rec["Keyword".$loop]);
322  if(strlen($keyword))
323  {
324  $keywords[] = $keyword;
325  }
326  }
327  }
328  if(sizeof($keywords))
329  {
330  $newObj->updateKeywords($keywords);
331  }
332 
333  $a_mapping->addMapping("Services/COPage", "pg", "blp:".$a_rec["Id"], "blp:".$newObj->getId());
334  }
335  break;
336  }
337  }
338 }
339 
340 ?>