ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilInternalLink.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
22  function _deleteAllLinksOfSource($a_source_type, $a_source_id)
23  {
24  global $ilias, $ilDB;
25 
26  $q = "DELETE FROM int_link WHERE source_type = ".
27  $ilDB->quote($a_source_type, "text")." AND source_id=".
28  $ilDB->quote((int) $a_source_id, "integer");
29  $ilDB->manipulate($q);
30  }
31 
39  function _deleteAllLinksToTarget($a_target_type, $a_target_id, $a_target_inst = 0)
40  {
41  global $ilias, $ilDB;
42 
43  $ilDB->manipulateF("DELETE FROM int_link WHERE target_type = %s ".
44  " AND target_id = %s AND target_inst = %s ",
45  array("text", "integer", "integer"),
46  array($a_target_type, (int) $a_target_id, (int) $a_target_inst));
47  }
48 
58  function _saveLink($a_source_type, $a_source_id, $a_target_type, $a_target_id, $a_target_inst = 0)
59  {
60  global $ilias, $ilDB;
61 
62  $ilDB->manipulate("DELETE FROM int_link WHERE ".
63  "source_type = ".$ilDB->quote($a_source_type, "text")." AND ".
64  "source_id = ".$ilDB->quote((int) $a_source_id, "integer")." AND ".
65  "target_type = ".$ilDB->quote($a_target_type, "text")." AND ".
66  "target_id = ".$ilDB->quote((int) $a_target_id, "integer")." AND ".
67  "target_inst = ".$ilDB->quote((int) $a_target_inst, "integer"));
68  $ilDB->manipulate("INSERT INTO int_link ".
69  "(source_type, source_id, target_type, target_id, target_inst) VALUES (".
70  $ilDB->quote($a_source_type, "text").",".
71  $ilDB->quote((int) $a_source_id, "integer").",".
72  $ilDB->quote($a_target_type, "text").",".
73  $ilDB->quote((int) $a_target_id, "integer").",".
74  $ilDB->quote((int) $a_target_inst, "integer").")");
75  }
76 
86  function _getSourcesOfTarget($a_target_type, $a_target_id, $a_target_inst)
87  {
88  global $ilias, $ilDB;
89 
90  $q = "SELECT * FROM int_link WHERE ".
91  "target_type = ".$ilDB->quote($a_target_type, "text")." AND ".
92  "target_id = ".$ilDB->quote((int) $a_target_id, "integer")." AND ".
93  "target_inst = ".$ilDB->quote((int) $a_target_inst, "integer");
94  $source_set = $ilDB->query($q);
95  $sources = array();
96  while ($source_rec = $ilDB->fetchAssoc($source_set))
97  {
98  $sources[$source_rec["source_type"].":".$source_rec["source_id"]] =
99  array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"]);
100  }
101 
102  return $sources;
103  }
104 
113  function _getTargetsOfSource($a_source_type, $a_source_id)
114  {
115  global $ilDB;
116 
117  $q = "SELECT * FROM int_link WHERE ".
118  "source_type = ".$ilDB->quote($a_source_type, "text")." AND ".
119  "source_id = ".$ilDB->quote((int) $a_source_id, "integer");
120 
121  $target_set = $ilDB->query($q);
122  $targets = array();
123  while ($target_rec = $ilDB->fetchAssoc($target_set))
124  {
125  $targets[$target_rec["target_type"].":".$target_rec["target_id"].":".$target_rec["target_inst"]] =
126  array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
127  "inst" => $target_rec["target_inst"]);
128  }
129 
130  return $targets;
131  }
132 
142  function _getIdForImportId($a_type, $a_target)
143  {
144  switch($a_type)
145  {
146  case "PageObject":
147  $id = ilLMObject::_getIdForImportId($a_target);
148  if($id > 0)
149  {
150  return "il__pg_".$id;
151  }
152  break;
153 
154  case "StructureObject":
155  $id = ilLMObject::_getIdForImportId($a_target);
156  if($id > 0)
157  {
158  return "il__st_".$id;
159  }
160  break;
161 
162  case "GlossaryItem":
163  $id = ilGlossaryTerm::_getIdForImportId($a_target);
164  if($id > 0)
165  {
166  return "il__git_".$id;
167  }
168  break;
169 
170  case "MediaObject":
171  $id = ilObjMediaObject::_getIdForImportId($a_target);
172  if($id > 0)
173  {
174  return "il__mob_".$id;
175  }
176  break;
177 
178  case "RepositoryItem":
179  $id = ilObject::_getIdForImportId($a_target);
180 //echo "-$a_target-$id-";
181  // get ref id for object id
182  // (see ilPageObject::insertInstIntoIDs for the export procedure)
183  if($id > 0)
184  {
185  $refs = ilObject::_getAllReferences($id);
186 //var_dump($refs);
187  foreach ($refs as $ref)
188  {
189  return "il__obj_".$ref;
190  }
191  }
192  break;
193 
194  }
195  return false;
196  }
197 
207  function _exists($a_type, $a_target)
208  {
209  global $tree;
210 
211  switch($a_type)
212  {
213  case "PageObject":
214  case "StructureObject":
215  return ilLMObject::_exists($a_target);
216  break;
217 
218  case "GlossaryItem":
219  return ilGlossaryTerm::_exists($a_target);
220  break;
221 
222  case "MediaObject":
223  return ilObjMediaObject::_exists($a_target);
224  break;
225 
226  case "RepositoryItem":
227  if (is_int(strpos($a_target, "_")))
228  {
230  return $tree->isInTree($ref_id);
231  }
232  break;
233  }
234  return false;
235  }
236 
237 
243  function _extractInstOfTarget($a_target)
244  {
245  if (!is_int(strpos($a_target, "__")))
246  {
247  $target = explode("_", $a_target);
248  if ($target[1] > 0)
249  {
250  return $target[1];
251  }
252  }
253  return false;
254  }
255 
261  function _removeInstFromTarget($a_target)
262  {
263  if (!is_int(strpos($a_target, "__")))
264  {
265  $target = explode("_", $a_target);
266  if ($target[1] > 0)
267  {
268  return "il__".$target[2]."_".$target[3];
269  }
270  }
271  return false;
272  }
273 
279  function _extractObjIdOfTarget($a_target)
280  {
281  $target = explode("_", $a_target);
282  return $target[count($target) - 1];
283  }
284 
290  function _extractTypeOfTarget($a_target)
291  {
292  $target = explode("_", $a_target);
293  return $target[count($target) - 2];
294  }
295 }
296 ?>