ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
23  static function _deleteAllLinksOfSource($a_source_type, $a_source_id, $a_lang = "-")
24  {
25  global $ilias, $ilDB;
26 
27  $lang_where = "";
28  if ($a_lang != "")
29  {
30  $lang_where = " AND source_lang = ".$ilDB->quote($a_lang, "text");
31  }
32 
33  $q = "DELETE FROM int_link WHERE source_type = ".
34  $ilDB->quote($a_source_type, "text")." AND source_id=".
35  $ilDB->quote((int) $a_source_id, "integer").
36  $lang_where;
37  $ilDB->manipulate($q);
38  }
39 
47  static function _deleteAllLinksToTarget($a_target_type, $a_target_id, $a_target_inst = 0)
48  {
49  global $ilias, $ilDB;
50 
51  $ilDB->manipulateF("DELETE FROM int_link WHERE target_type = %s ".
52  " AND target_id = %s AND target_inst = %s ",
53  array("text", "integer", "integer"),
54  array($a_target_type, (int) $a_target_id, (int) $a_target_inst));
55  }
56 
66  static function _saveLink($a_source_type, $a_source_id, $a_target_type, $a_target_id, $a_target_inst = 0,
67  $a_source_lang = "-")
68  {
69  global $ilDB;
70 
71  $ilDB->replace("int_link",
72  array(
73  "source_type" => array("text", $a_source_type),
74  "source_id" => array("integer", (int) $a_source_id),
75  "source_lang" => array("text", $a_source_lang),
76  "target_type" => array("text", $a_target_type),
77  "target_id" => array("integer", (int) $a_target_id),
78  "target_inst" => array("integer", (int) $a_target_inst)
79  ),
80  array()
81  );
82  }
83 
93  static function _getSourcesOfTarget($a_target_type, $a_target_id, $a_target_inst)
94  {
95  global $ilias, $ilDB;
96 
97  $q = "SELECT * FROM int_link WHERE ".
98  "target_type = ".$ilDB->quote($a_target_type, "text")." AND ".
99  "target_id = ".$ilDB->quote((int) $a_target_id, "integer")." AND ".
100  "target_inst = ".$ilDB->quote((int) $a_target_inst, "integer");
101  $source_set = $ilDB->query($q);
102  $sources = array();
103  while ($source_rec = $ilDB->fetchAssoc($source_set))
104  {
105  $sources[$source_rec["source_type"].":".$source_rec["source_id"].":".$source_rec["source_lang"]] =
106  array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"],
107  "lang" => $source_rec["source_lang"]);
108  }
109 
110  return $sources;
111  }
112 
121  static function _getTargetsOfSource($a_source_type, $a_source_id, $a_source_lang = "-")
122  {
123  global $ilDB;
124 
125  $lang_where = "";
126  if ($a_source_lang != "")
127  {
128  $lang_where = " AND source_lang = ".$ilDB->quote($a_source_lang, "text");
129  }
130 
131  $q = "SELECT * FROM int_link WHERE ".
132  "source_type = ".$ilDB->quote($a_source_type, "text")." AND ".
133  "source_id = ".$ilDB->quote((int) $a_source_id, "integer").
134  $lang_where;
135 
136  $target_set = $ilDB->query($q);
137  $targets = array();
138  while ($target_rec = $ilDB->fetchAssoc($target_set))
139  {
140  $targets[$target_rec["target_type"].":".$target_rec["target_id"].":".$target_rec["target_inst"]] =
141  array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
142  "inst" => $target_rec["target_inst"]);
143  }
144 
145  return $targets;
146  }
147 
157  static function _getIdForImportId($a_type, $a_target)
158  {
159  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
160  switch($a_type)
161  {
162  case "PageObject":
163  $id = ilLMObject::_getIdForImportId($a_target);
164  if($id > 0)
165  {
166  return "il__pg_".$id;
167  }
168  break;
169 
170  case "StructureObject":
171  $id = ilLMObject::_getIdForImportId($a_target);
172  if($id > 0)
173  {
174  return "il__st_".$id;
175  }
176  break;
177 
178  case "GlossaryItem":
179  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
180  $id = ilGlossaryTerm::_getIdForImportId($a_target);
181  //echo "+".$id."+".$a_target."+";
182  if($id > 0)
183  {
184  return "il__git_".$id;
185  }
186  break;
187 
188  case "WikiPage":
189  // no import IDs for wiki pages (yet)
190  //$id = ilGlossaryTerm::_getIdForImportId($a_target);
191  $id = 0;
192  if($id > 0)
193  {
194  return "il__wpage_".$id;
195  }
196  break;
197 
198  case "MediaObject":
199  $id = ilObjMediaObject::_getIdForImportId($a_target);
200  if($id > 0)
201  {
202  return "il__mob_".$id;
203  }
204  break;
205 
206  case "RepositoryItem":
207 
208  $tarr = explode("_", $a_target);
209  $import_id = $a_target;
210 
211  // if a ref id part is given, strip this
212  // since this will not be part of an import id
213  // see also bug #6685
214  if ($tarr[4] != "")
215  {
216  $import_id = $tarr[0]."_".$tarr[1]."_".$tarr[2]."_".$tarr[3];
217  }
218 
219  $id = ilObject::_getIdForImportId($import_id);
220 
221  // get ref id for object id
222  // (see ilPageObject::insertInstIntoIDs for the export procedure)
223  if($id > 0)
224  {
225  $refs = ilObject::_getAllReferences($id);
226  foreach ($refs as $ref)
227  {
228  return "il__obj_".$ref;
229  }
230  }
231 
232  // 26 Sep 2018: moved this under the import id handling above
233  // If an imported object is found, this is always preferred.
234  // see also bug #23324
235  if (ilInternalLink::_extractInstOfTarget($a_target) == IL_INST_ID
236  && IL_INST_ID > 0)
237  {
238  // does it have a ref id part?
239  if ($tarr[4] != "")
240  {
241  return "il__obj_".$tarr[4];
242  }
243  }
244 
245  break;
246 
247  }
248  return false;
249  }
250 
260  static function _exists($a_type, $a_target)
261  {
262  global $tree;
263 
264  switch($a_type)
265  {
266  case "PageObject":
267  case "StructureObject":
268  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
269  return ilLMObject::_exists($a_target);
270  break;
271 
272  case "GlossaryItem":
273  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
274  return ilGlossaryTerm::_exists($a_target);
275  break;
276 
277  case "MediaObject":
278  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
279  return ilObjMediaObject::_exists($a_target);
280  break;
281 
282  case "WikiPage":
283  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
284  return ilWikiPage::_exists("wiki", (int)$a_target);
285  break;
286 
287  case "RepositoryItem":
288  if (is_int(strpos($a_target, "_")))
289  {
291  return $tree->isInTree($ref_id);
292  }
293  break;
294  }
295  return false;
296  }
297 
298 
304  static function _extractInstOfTarget($a_target)
305  {
306  if (!is_int(strpos($a_target, "__")))
307  {
308  $target = explode("_", $a_target);
309  if ($target[1] > 0)
310  {
311  return $target[1];
312  }
313  }
314  return false;
315  }
316 
322  static function _removeInstFromTarget($a_target)
323  {
324  if (!is_int(strpos($a_target, "__")))
325  {
326  $target = explode("_", $a_target);
327  if ($target[1] > 0)
328  {
329  return "il__".$target[2]."_".$target[3];
330  }
331  }
332  return false;
333  }
334 
340  static function _extractObjIdOfTarget($a_target)
341  {
342  $target = explode("_", $a_target);
343  return $target[count($target) - 1];
344  }
345 
351  static function _extractTypeOfTarget($a_target)
352  {
353  $target = explode("_", $a_target);
354  return $target[count($target) - 2];
355  }
356 }
357 ?>
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static _exists($a_id, $a_reference=false, $a_type=NULL)
checks wether a lm content object with specified id exists or not
static _exists($a_id)
checks wether a lm content object with specified id exists or not
static _getIdForImportId($a_import_id)
get current object id for import id (static)
static _getIdForImportId($a_import_id)
get current term id for import id (static)
static _getAllReferences($a_id)
get all reference ids of object
static _exists($a_id)
checks wether a glossary term with specified id exists or not
$a_type
Definition: workflow.php:93
Create styles array
The data for the language used.
$ref_id
Definition: sahs_server.php:39
global $ilDB
static _getIdForImportId($a_import_id)
get current object id for import id (static)