ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBookmarkDataSet.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
14 {
21  public function getSupportedVersions()
22  {
23  return array("4.3.0");
24  }
25 
32  function getXmlNamespace($a_entity, $a_schema_version)
33  {
34  return "http://www.ilias.de/xml/Services/Bookmarks/".$a_entity;
35  }
36 
43  protected function getTypes($a_entity, $a_version)
44  {
45  // bookmarks
46  if ($a_entity == "bookmarks")
47  {
48  switch ($a_version)
49  {
50  case "4.3.0":
51  return array(
52  "UserId" => "integer"
53  );
54  }
55  }
56 
57  // bookmark_tree
58  if ($a_entity == "bookmark_tree")
59  {
60  switch ($a_version)
61  {
62  case "4.3.0":
63  return array(
64  "UserId" => "integer",
65  "Child" => "integer",
66  "Parent" => "integer",
67  "Depth" => "integer",
68  "Type" => "text",
69  "Title" => "text",
70  "Description" => "text",
71  "Target" => "text"
72  );
73  }
74  }
75  }
76 
83  function readData($a_entity, $a_version, $a_ids, $a_field = "")
84  {
85  global $ilDB;
86 
87  if (!is_array($a_ids))
88  {
89  $a_ids = array($a_ids);
90  }
91 
92  // bookmarks
93  if ($a_entity == "bookmarks")
94  {
95  switch ($a_version)
96  {
97  case "4.3.0":
98  $this->data = array();
99  foreach ($a_ids as $id)
100  {
101  $this->data[] = array("UserId" => $id);
102  }
103  break;
104  }
105  }
106 
107  // bookmark_tree
108  if ($a_entity == "bookmark_tree")
109  {
110  switch ($a_version)
111  {
112  case "4.3.0":
113  $this->getDirectDataFromQuery("SELECT tree user_id, child ".
114  " ,parent,depth,type,title,description,target ".
115  " FROM bookmark_tree JOIN bookmark_data ON (child = obj_id) ".
116  " WHERE ".
117  $ilDB->in("tree", $a_ids, false, "integer").
118  " ORDER BY tree, depth");
119  break;
120  }
121  }
122  }
123 
127  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
128  {
129  switch ($a_entity)
130  {
131  case "bookmarks":
132  return array (
133  "bookmark_tree" => array("ids" => $a_rec["UserId"])
134  );
135  }
136  return false;
137  }
138 
142 
143 
150  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
151  {
152  switch ($a_entity)
153  {
154  case "bookmarks":
155  break;
156 
157  case "bookmark_tree":
158  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
159  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
160  {
161 //echo "<br><br>";
162 //var_dump($a_rec);
163  switch ($a_rec["Type"])
164  {
165  case "bmf":
166  if ($a_rec["Parent"] > 0)
167  {
168  $parent = (int) $a_mapping->getMapping("Services/Bookmarks", "bookmark_tree", $a_rec["Parent"]);
169  include_once("./Services/Bookmarks/classes/class.ilBookmarkFolder.php");
170  $bmf = new ilBookmarkFolder(0, $usr_id);
171  $bmf->setTitle($a_rec["Title"]);
172  $bmf->setParent($parent);
173  $bmf->create();
174  $fold_id = $bmf->getId();
175  }
176  else
177  {
178  $tree = new ilTree($usr_id);
179  $tree->setTableNames('bookmark_tree','bookmark_data');
180  $fold_id = $tree->readRootId();
181  }
182  $a_mapping->addMapping("Services/Bookmarks", "bookmark_tree", $a_rec["Child"],
183  $fold_id);
184  break;
185 
186  case "bm":
187  $parent = 0;
188  if (((int) $a_rec["Parent"]) > 0)
189  {
190  $parent = (int) $a_mapping->getMapping("Services/Bookmarks", "bookmark_tree", $a_rec["Parent"]);
191  }
192  else
193  {
194  return;
195  }
196 
197  if ($parent == 0)
198  {
199  $tree = new ilTree($usr_id);
200  $tree->setTableNames('bookmark_tree','bookmark_data');
201  $parent = $tree->readRootId();
202  }
203 //echo "-$parent-";
204  include_once("./Services/Bookmarks/classes/class.ilBookmark.php");
205  $bm = new ilBookmark(0, $usr_id);
206  $bm->setTitle($a_rec["Title"]);
207  $bm->setDescription($a_rec["Description"]);
208  $bm->setTarget($a_rec["Target"]);
209  $bm->setParent($parent);
210  $bm->create();
211  break;
212 
213  }
214  }
215  break;
216  }
217  }
218 }
219 ?>