ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilInternalLink.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
35 {
42  function _deleteAllLinksOfSource($a_source_type, $a_source_id)
43  {
44  global $ilias, $ilDB;
45 
46  $q = "DELETE FROM int_link WHERE source_type=".$ilDB->quote($a_source_type).
47  " AND source_id=".$ilDB->quote($a_source_id);
48  $ilias->db->query($q);
49  }
50 
58  function _deleteAllLinksToTarget($a_target_type, $a_target_id, $a_target_inst = 0)
59  {
60  global $ilias, $ilDB;
61 
62  $st = $ilDB->prepareManip("DELETE FROM int_link WHERE target_type = ? ".
63  " AND target_id = ? AND target_inst = ? ",
64  array("text", "integer", "integer"));
65  $ilDB->execute($st, array($a_target_type, $a_target_id, $a_target_inst));
66  }
67 
77  function _saveLink($a_source_type, $a_source_id, $a_target_type, $a_target_id, $a_target_inst = 0)
78  {
79  global $ilias, $ilDB;
80 
81  $q = "REPLACE INTO int_link (source_type, source_id, target_type, target_id, target_inst) VALUES".
82  " (".$ilDB->quote($a_source_type).
83  ",".$ilDB->quote($a_source_id).
84  ",".$ilDB->quote($a_target_type).
85  ",".$ilDB->quote($a_target_id).
86  ",".$ilDB->quote($a_target_inst).")";
87  $ilias->db->query($q);
88  }
89 
99  function _getSourcesOfTarget($a_target_type, $a_target_id, $a_target_inst)
100  {
101  global $ilias, $ilDB;
102 
103  $q = "SELECT * FROM int_link WHERE ".
104  "target_type = ".$ilDB->quote($a_target_type)." AND ".
105  "target_id = ".$ilDB->quote($a_target_id)." AND ".
106  "target_inst = ".$ilDB->quote($a_target_inst);
107  $source_set = $ilias->db->query($q);
108  $sources = array();
109  while ($source_rec = $source_set->fetchRow(DB_FETCHMODE_ASSOC))
110  {
111  $sources[$source_rec["source_type"].":".$source_rec["source_id"]] =
112  array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"]);
113  }
114 
115  return $sources;
116  }
117 
126  function _getTargetsOfSource($a_source_type, $a_source_id)
127  {
128  global $ilDB;
129 
130  $q = "SELECT * FROM int_link WHERE ".
131  "source_type = ".$ilDB->quote($a_source_type)." AND ".
132  "source_id = ".$ilDB->quote($a_source_id);
133 
134  $target_set = $ilDB->query($q);
135  $targets = array();
136  while ($target_rec = $target_set->fetchRow(DB_FETCHMODE_ASSOC))
137  {
138  $targets[$target_rec["target_type"].":".$target_rec["target_id"].":".$target_rec["target_inst"]] =
139  array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
140  "inst" => $target_rec["target_inst"]);
141  }
142 
143  return $targets;
144  }
145 
155  function _getIdForImportId($a_type, $a_target)
156  {
157  switch($a_type)
158  {
159  case "PageObject":
160  $id = ilLMObject::_getIdForImportId($a_target);
161  if($id > 0)
162  {
163  return "il__pg_".$id;
164  }
165  break;
166 
167  case "StructureObject":
168  $id = ilLMObject::_getIdForImportId($a_target);
169  if($id > 0)
170  {
171  return "il__st_".$id;
172  }
173  break;
174 
175  case "GlossaryItem":
176  $id = ilGlossaryTerm::_getIdForImportId($a_target);
177  if($id > 0)
178  {
179  return "il__git_".$id;
180  }
181  break;
182 
183  case "MediaObject":
184  $id = ilObjMediaObject::_getIdForImportId($a_target);
185  if($id > 0)
186  {
187  return "il__mob_".$id;
188  }
189  break;
190 
191  case "RepositoryItem":
192  $id = ilObject::_getIdForImportId($a_target);
193 //echo "-$a_target-$id-";
194  // get ref id for object id
195  // (see ilPageObject::insertInstIntoIDs for the export procedure)
196  if($id > 0)
197  {
198  $refs = ilObject::_getAllReferences($id);
199 //var_dump($refs);
200  foreach ($refs as $ref)
201  {
202  return "il__obj_".$ref;
203  }
204  }
205  break;
206 
207  }
208  return false;
209  }
210 
220  function _exists($a_type, $a_target)
221  {
222  global $tree;
223 
224  switch($a_type)
225  {
226  case "PageObject":
227  case "StructureObject":
228  return ilLMObject::_exists($a_target);
229  break;
230 
231  case "GlossaryItem":
232  return ilGlossaryTerm::_exists($a_target);
233  break;
234 
235  case "MediaObject":
236  return ilObjMediaObject::_exists($a_target);
237  break;
238 
239  case "RepositoryItem":
240  if (is_int(strpos($a_target, "_")))
241  {
243  return $tree->isInTree($ref_id);
244  }
245  break;
246  }
247  return false;
248  }
249 
250 
256  function _extractInstOfTarget($a_target)
257  {
258  if (!is_int(strpos($a_target, "__")))
259  {
260  $target = explode("_", $a_target);
261  if ($target[1] > 0)
262  {
263  return $target[1];
264  }
265  }
266  return false;
267  }
268 
274  function _removeInstFromTarget($a_target)
275  {
276  if (!is_int(strpos($a_target, "__")))
277  {
278  $target = explode("_", $a_target);
279  if ($target[1] > 0)
280  {
281  return "il__".$target[2]."_".$target[3];
282  }
283  }
284  return false;
285  }
286 
292  function _extractObjIdOfTarget($a_target)
293  {
294  $target = explode("_", $a_target);
295  return $target[count($target) - 1];
296  }
297 
303  function _extractTypeOfTarget($a_target)
304  {
305  $target = explode("_", $a_target);
306  return $target[count($target) - 2];
307  }
308 }
309 ?>