ILIAS  Release_4_4_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 
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  if($new_id = $a_mapping->getMapping("Services/Container", "objs", $a_rec["Id"]))
175  {
176  $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
177  }
178  else
179  {
180  $newObj = new ilObjBlog();
181  $newObj->create();
182  }
183 
184  $newObj->setTitle($a_rec["Title"]);
185  $newObj->setDescription($a_rec["Description"]);
186  $newObj->setNotesStatus($a_rec["Notes"]);
187  $newObj->setBackgroundColor($a_rec["BgColor"]);
188  $newObj->setFontColor($a_rec["FontColor"]);
189  $newObj->setProfilePicture($a_rec["Ppic"]);
190  $newObj->setRSS($a_rec["RssActive"]);
191  $newObj->setApproval($a_rec["Approval"]);
192  $newObj->setImage($a_rec["Img"]);
193  $newObj->update();
194 
195  // handle image(s)
196  if($a_rec["Img"])
197  {
198  $dir = str_replace("..", "", $a_rec["Dir"]);
199  if ($dir != "" && $this->getImportDirectory() != "")
200  {
201  $source_dir = $this->getImportDirectory()."/".$dir;
202  $target_dir = ilObjBlog::initStorage($newObj->getId());
203  ilUtil::rCopy($source_dir, $target_dir);
204  }
205  }
206 
207  $a_mapping->addMapping("Modules/Blog", "blog", $a_rec["Id"], $newObj->getId());
208  break;
209 
210  case "blog_posting":
211  $blog_id = (int) $a_mapping->getMapping("Modules/Blog", "blog", $a_rec["BlogId"]);
212  if($blog_id)
213  {
214  include_once("./Modules/Blog/classes/class.ilBlogPosting.php");
215  $newObj = new ilBlogPosting();
216  $newObj->setBlogId($blog_id);
217  $newObj->setTitle($a_rec["Title"]);
218  $newObj->setCreated(new ilDateTime($a_rec["Created"], IL_CAL_DATETIME));
219  $newObj->setApproved($a_rec["Approved"]);
220 
221  // parse export id into local id (if possible)
222  $author = $this->parseObjectExportId($a_rec["Author"], -1);
223  $newObj->setAuthor($author["id"]);
224 
225  $newObj->create(true);
226 
227  $a_mapping->addMapping("Services/COPage", "pg", "blp:".$a_rec["Id"], "blp:".$newObj->getId());
228  }
229  break;
230  }
231  }
232 }
233 
234 ?>