Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class ilInternalLink
00035 {
00042 function _deleteAllLinksOfSource($a_source_type, $a_source_id)
00043 {
00044 global $ilias;
00045
00046 $q = "DELETE FROM int_link WHERE source_type='$a_source_type' AND source_id='$a_source_id'";
00047 $ilias->db->query($q);
00048 }
00049
00059 function _saveLink($a_source_type, $a_source_id, $a_target_type, $a_target_id, $a_target_inst = 0)
00060 {
00061 global $ilias;
00062
00063 $q = "REPLACE INTO int_link (source_type, source_id, target_type, target_id, target_inst) VALUES".
00064 " ('$a_source_type', '$a_source_id', '$a_target_type', '$a_target_id', '$a_target_inst')";
00065 $ilias->db->query($q);
00066 }
00067
00077 function _getSourcesOfTarget($a_target_type, $a_target_id, $a_target_inst)
00078 {
00079 global $ilias;
00080
00081 $q = "SELECT * FROM int_link WHERE ".
00082 "target_type = '$a_target_type' AND ".
00083 "target_id = '$a_target_id' AND ".
00084 "target_inst = '$a_target_inst'";
00085 $source_set = $ilias->db->query($q);
00086 $sources = array();
00087 while ($source_rec = $source_set->fetchRow(DB_FETCHMODE_ASSOC))
00088 {
00089 $sources[$source_rec["source_type"].":".$source_rec["source_id"]] =
00090 array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"]);
00091 }
00092
00093 return $sources;
00094 }
00095
00104 function _getTargetsOfSource($a_source_type, $a_source_id)
00105 {
00106 global $ilDB;
00107
00108 $q = "SELECT * FROM int_link WHERE ".
00109 "source_type = ".$ilDB->quote($a_source_type)." AND ".
00110 "source_id = ".$ilDB->quote($a_source_id);
00111
00112 $target_set = $ilDB->query($q);
00113 $targets = array();
00114 while ($target_rec = $target_set->fetchRow(DB_FETCHMODE_ASSOC))
00115 {
00116 $targets[$target_rec["target_type"].":".$target_rec["target_id"].":".$target_rec["target_inst"]] =
00117 array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
00118 "inst" => $target_rec["target_inst"]);
00119 }
00120
00121 return $targets;
00122 }
00123
00133 function _getIdForImportId($a_type, $a_target)
00134 {
00135 switch($a_type)
00136 {
00137 case "PageObject":
00138 $id = ilLMObject::_getIdForImportId($a_target);
00139 if($id > 0)
00140 {
00141 return "il__pg_".$id;
00142 }
00143 break;
00144
00145 case "StructureObject":
00146 $id = ilLMObject::_getIdForImportId($a_target);
00147 if($id > 0)
00148 {
00149 return "il__st_".$id;
00150 }
00151 break;
00152
00153 case "GlossaryItem":
00154 $id = ilGlossaryTerm::_getIdForImportId($a_target);
00155 if($id > 0)
00156 {
00157 return "il__git_".$id;
00158 }
00159 break;
00160
00161 case "MediaObject":
00162 $id = ilObjMediaObject::_getIdForImportId($a_target);
00163 if($id > 0)
00164 {
00165 return "il__mob_".$id;
00166 }
00167 break;
00168 }
00169 return false;
00170 }
00171
00181 function _exists($a_type, $a_target)
00182 {
00183 global $tree;
00184
00185 switch($a_type)
00186 {
00187 case "PageObject":
00188 case "StructureObject":
00189 return ilLMObject::_exists($a_target);
00190 break;
00191
00192 case "GlossaryItem":
00193 return ilGlossaryTerm::_exists($a_target);
00194 break;
00195
00196 case "MediaObject":
00197 return ilObjMediaObject::_exists($a_target);
00198 break;
00199
00200 case "RepositoryItem":
00201 if (is_int(strpos($a_target, "_")))
00202 {
00203 $ref_id = ilInternalLink::_extractObjIdOfTarget($a_target);
00204 return $tree->isInTree($ref_id);
00205 }
00206 break;
00207 }
00208 return false;
00209 }
00210
00211
00217 function _extractInstOfTarget($a_target)
00218 {
00219 if (!is_int(strpos($a_target, "__")))
00220 {
00221 $target = explode("_", $a_target);
00222 if ($target[1] > 0)
00223 {
00224 return $target[1];
00225 }
00226 }
00227 return false;
00228 }
00229
00235 function _removeInstFromTarget($a_target)
00236 {
00237 if (!is_int(strpos($a_target, "__")))
00238 {
00239 $target = explode("_", $a_target);
00240 if ($target[1] > 0)
00241 {
00242 return "il__".$target[2]."_".$target[3];
00243 }
00244 }
00245 return false;
00246 }
00247
00253 function _extractObjIdOfTarget($a_target)
00254 {
00255 $target = explode("_", $a_target);
00256 return $target[count($target) - 1];
00257 }
00258
00259 }
00260 ?>