ILIAS  release_4-3 Revision
 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 
24  public function getSupportedVersions()
25  {
26  return array("4.3.0");
27  }
28 
32  function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Modules/Blog/".$a_entity;
35  }
36 
40  protected function getTypes($a_entity, $a_version)
41  {
42  if ($a_entity == "blog")
43  {
44  switch ($a_version)
45  {
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  }
62 
63  if ($a_entity == "blog_posting")
64  {
65  switch ($a_version)
66  {
67  case "4.3.0":
68  return array(
69  "Id" => "integer",
70  "BlogId" => "integer",
71  "Title" => "integer",
72  "Created" => "text",
73  "Author" => "text",
74  "Approved" => "integer"
75  );
76  }
77  }
78  }
79 
86  function readData($a_entity, $a_version, $a_ids, $a_field = "")
87  {
88  global $ilDB;
89 
90  if (!is_array($a_ids))
91  {
92  $a_ids = array($a_ids);
93  }
94 
95  if ($a_entity == "blog")
96  {
97  switch ($a_version)
98  {
99  case "4.3.0":
100  $this->getDirectDataFromQuery("SELECT bl.id,od.title,od.description,".
101  "bl.notes,bl.bg_color,bl.font_color,bl.img,bl.ppic,bl.rss_active,bl.approval".
102  " FROM il_blog bl".
103  " JOIN object_data od ON (od.obj_id = bl.id)".
104  " WHERE ".$ilDB->in("bl.id", $a_ids, false, "integer").
105  " AND od.type = ".$ilDB->quote("blog", "text"));
106  break;
107  }
108  }
109 
110  if ($a_entity == "blog_posting")
111  {
112  switch ($a_version)
113  {
114  case "4.3.0":
115  $this->getDirectDataFromQuery("SELECT id,blog_id,title,created,author,approved".
116  " FROM il_blog_posting WHERE ".
117  $ilDB->in("blog_id", $a_ids, false, "integer"));
118  foreach($this->data as $idx => $item)
119  {
120  // create full export id
121  $this->data[$idx]["Author"] = $this->createObjectExportId("usr", $item["Author"]);
122  }
123  break;
124  }
125  }
126  }
127 
131  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
132  {
133  switch ($a_entity)
134  {
135  case "blog":
136  return array (
137  "blog_posting" => array("ids" => $a_rec["Id"])
138  );
139  }
140  return false;
141  }
142 
149  function getXmlRecord($a_entity, $a_version, $a_set)
150  {
151  if ($a_entity == "blog")
152  {
153  include_once("./Modules/Blog/classes/class.ilObjBlog.php");
154  $dir = ilObjBlog::initStorage($a_set["Id"]);
155  $a_set["Dir"] = $dir;
156  }
157 
158  return $a_set;
159  }
160 
167  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
168  {
169  switch ($a_entity)
170  {
171  case "blog":
172  include_once("./Modules/Blog/classes/class.ilObjBlog.php");
173 
174  // container copy
175  if($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"]))
176  {
177  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
178  }
179  else
180  {
181  $newObj = new ilObjBlog();
182  $newObj->create();
183  }
184 
185  $newObj->setTitle($a_rec["Title"]);
186  $newObj->setDescription($a_rec["Description"]);
187  $newObj->setNotesStatus($a_rec["Notes"]);
188  $newObj->setBackgroundColor($a_rec["BgColor"]);
189  $newObj->setFontColor($a_rec["FontColor"]);
190  $newObj->setProfilePicture($a_rec["Ppic"]);
191  $newObj->setRSS($a_rec["RssActive"]);
192  $newObj->setApproval($a_rec["Approval"]);
193  $newObj->setImage($a_rec["Img"]);
194  $newObj->update();
195 
196  // handle image(s)
197  if($a_rec["Img"])
198  {
199  $dir = str_replace("..", "", $a_rec["Dir"]);
200  if ($dir != "" && $this->getImportDirectory() != "")
201  {
202  $source_dir = $this->getImportDirectory()."/".$dir;
203  $target_dir = ilObjBlog::initStorage($newObj->getId());
204  ilUtil::rCopy($source_dir, $target_dir);
205  }
206  }
207 
208  $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
209  break;
210 
211  case "blog_posting":
212  $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
213  if($blog_id)
214  {
215  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
216  $newObj = new ilBlogPosting();
217  $newObj->setBlogId($blog_id);
218  $newObj->setTitle($a_rec["Title"]);
219  $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
220  $newObj->setApproved($a_rec["Approved"]);
221 
222  // parse export id into local id (if possible)
223  $author = $this->parseObjectExportId($a_rec["Author"], -1);
224  $newObj->setAuthor($author["id"]);
225 
226  $newObj->create(true);
227 
228  $a_mapping->addMapping("Services/COPage", "pg", "blp:".$a_rec["Id"], "blp:".$newObj->getId());
229  }
230  break;
231  }
232  }
233 }
234 
235 ?>