ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public static function _deleteAllLinksOfSource($a_source_type, $a_source_id, $a_lang = "-")
24 {
25 global $DIC;
26
27 $ilDB = $DIC->database();
28
29 $lang_where = "";
30 if ($a_lang != "") {
31 $lang_where = " AND source_lang = " . $ilDB->quote($a_lang, "text");
32 }
33
34 $q = "DELETE FROM int_link WHERE source_type = " .
35 $ilDB->quote($a_source_type, "text") . " AND source_id=" .
36 $ilDB->quote((int) $a_source_id, "integer") .
37 $lang_where;
38 $ilDB->manipulate($q);
39 }
40
48 public static function _deleteAllLinksToTarget($a_target_type, $a_target_id, $a_target_inst = 0)
49 {
50 global $DIC;
51
52 $ilDB = $DIC->database();
53
54 $ilDB->manipulateF(
55 "DELETE FROM int_link WHERE target_type = %s " .
56 " AND target_id = %s AND target_inst = %s ",
57 array("text", "integer", "integer"),
58 array($a_target_type, (int) $a_target_id, (int) $a_target_inst)
59 );
60 }
61
71 public static function _saveLink(
72 $a_source_type,
73 $a_source_id,
74 $a_target_type,
75 $a_target_id,
76 $a_target_inst = 0,
77 $a_source_lang = "-"
78 ) {
79 global $DIC;
80
81 $ilDB = $DIC->database();
82
83 $ilDB->replace(
84 "int_link",
85 array(
86 "source_type" => array("text", $a_source_type),
87 "source_id" => array("integer", (int) $a_source_id),
88 "source_lang" => array("text", $a_source_lang),
89 "target_type" => array("text", $a_target_type),
90 "target_id" => array("integer", (int) $a_target_id),
91 "target_inst" => array("integer", (int) $a_target_inst)
92 ),
93 array()
94 );
95 }
96
106 public static function _getSourcesOfTarget($a_target_type, $a_target_id, $a_target_inst)
107 {
108 global $DIC;
109
110 $ilDB = $DIC->database();
111
112 $q = "SELECT * FROM int_link WHERE " .
113 "target_type = " . $ilDB->quote($a_target_type, "text") . " AND " .
114 "target_id = " . $ilDB->quote((int) $a_target_id, "integer") . " AND " .
115 "target_inst = " . $ilDB->quote((int) $a_target_inst, "integer");
116 $source_set = $ilDB->query($q);
117 $sources = array();
118 while ($source_rec = $ilDB->fetchAssoc($source_set)) {
119 $sources[$source_rec["source_type"] . ":" . $source_rec["source_id"] . ":" . $source_rec["source_lang"]] =
120 array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"],
121 "lang" => $source_rec["source_lang"]);
122 }
123
124 return $sources;
125 }
126
135 public static function _getTargetsOfSource($a_source_type, $a_source_id, $a_source_lang = "-")
136 {
137 global $DIC;
138
139 $ilDB = $DIC->database();
140
141 $lang_where = "";
142 if ($a_source_lang != "") {
143 $lang_where = " AND source_lang = " . $ilDB->quote($a_source_lang, "text");
144 }
145
146 $q = "SELECT * FROM int_link WHERE " .
147 "source_type = " . $ilDB->quote($a_source_type, "text") . " AND " .
148 "source_id = " . $ilDB->quote((int) $a_source_id, "integer") .
149 $lang_where;
150
151 $target_set = $ilDB->query($q);
152 $targets = array();
153 while ($target_rec = $ilDB->fetchAssoc($target_set)) {
154 $targets[$target_rec["target_type"] . ":" . $target_rec["target_id"] . ":" . $target_rec["target_inst"]] =
155 array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
156 "inst" => $target_rec["target_inst"]);
157 }
158
159 return $targets;
160 }
161
171 public static function _getIdForImportId($a_type, $a_target)
172 {
173 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
174 switch ($a_type) {
175 case "PageObject":
176 $id = ilLMObject::_getIdForImportId($a_target);
177 if ($id > 0) {
178 return "il__pg_" . $id;
179 }
180 break;
181
182 case "StructureObject":
183 $id = ilLMObject::_getIdForImportId($a_target);
184 if ($id > 0) {
185 return "il__st_" . $id;
186 }
187 break;
188
189 case "GlossaryItem":
190 $id = ilGlossaryTerm::_getIdForImportId($a_target);
191 //echo "+".$id."+".$a_target."+";
192 if ($id > 0) {
193 return "il__git_" . $id;
194 }
195 break;
196
197 case "WikiPage":
198 // no import IDs for wiki pages (yet)
199 //$id = ilGlossaryTerm::_getIdForImportId($a_target);
200 $id = 0;
201 if ($id > 0) {
202 return "il__wpage_" . $id;
203 }
204 break;
205
206 case "MediaObject":
208 if ($id > 0) {
209 return "il__mob_" . $id;
210 }
211 break;
212
213 case "RepositoryItem":
214
215 $tarr = explode("_", $a_target);
216 $import_id = $a_target;
217
218 // if a ref id part is given, strip this
219 // since this will not be part of an import id
220 // see also bug #6685
221 if ($tarr[4] != "") {
222 $import_id = $tarr[0] . "_" . $tarr[1] . "_" . $tarr[2] . "_" . $tarr[3];
223 }
224
225 $id = ilObject::_getIdForImportId($import_id);
226
227 // get ref id for object id
228 // (see ilPageObject::insertInstIntoIDs for the export procedure)
229 if ($id > 0) {
230 $refs = ilObject::_getAllReferences($id);
231 foreach ($refs as $ref) {
232 return "il__obj_" . $ref;
233 }
234 }
235
236 // 26 Sep 2018: moved this under the import id handling above
237 // If an imported object is found, this is always preferred.
238 // see also bug #23324
239 if (ilInternalLink::_extractInstOfTarget($a_target) == IL_INST_ID
240 && IL_INST_ID > 0) {
241 // does it have a ref id part?
242 if ($tarr[4] != "") {
243 return "il__obj_" . $tarr[4];
244 }
245 }
246
247 break;
248
249 }
250 return false;
251 }
252
262 public static function _exists($a_type, $a_target)
263 {
264 global $DIC;
265
266 $tree = $DIC->repositoryTree();
267
268 switch ($a_type) {
269 case "PageObject":
270 case "StructureObject":
271 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
272 return ilLMObject::_exists($a_target);
273 break;
274
275 case "GlossaryItem":
276 return ilGlossaryTerm::_exists($a_target);
277 break;
278
279 case "MediaObject":
280 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
281 return ilObjMediaObject::_exists($a_target);
282 break;
283
284 case "WikiPage":
285 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
286 return ilWikiPage::_exists("wiki", (int) $a_target);
287 break;
288
289 case "RepositoryItem":
290 if (is_int(strpos($a_target, "_"))) {
291 $ref_id = ilInternalLink::_extractObjIdOfTarget($a_target);
292 return $tree->isInTree($ref_id);
293 }
294 break;
295 }
296 return false;
297 }
298
299
305 public static function _extractInstOfTarget($a_target)
306 {
307 if (!is_int(strpos($a_target, "__"))) {
308 $target = explode("_", $a_target);
309 if ($target[1] > 0) {
310 return $target[1];
311 }
312 }
313 return false;
314 }
315
321 public static function _removeInstFromTarget($a_target)
322 {
323 if (!is_int(strpos($a_target, "__"))) {
324 $target = explode("_", $a_target);
325 if ($target[1] > 0) {
326 return "il__" . $target[2] . "_" . $target[3];
327 }
328 }
329 return false;
330 }
331
337 public static function _extractObjIdOfTarget($a_target)
338 {
339 $target = explode("_", $a_target);
340 return $target[count($target) - 1];
341 }
342
348 public static function _extractTypeOfTarget($a_target)
349 {
350 $target = explode("_", $a_target);
351 return $target[count($target) - 2];
352 }
353
360 public static function searchUsers($a_search_str)
361 {
362 $result = new ilSearchResult();
363
364 $query_parser = new ilQueryParser($a_search_str, '%_');
365 $query_parser->setCombination(QP_COMBINATION_AND);
366 $query_parser->setMinWordLength(3);
367 $query_parser->parse();
368
369 $user_search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
370 $user_search->enableActiveCheck(true);
371 $user_search->setFields(array('login'));
372 $result_obj = $user_search->performSearch();
373 $result->mergeEntries($result_obj);
374
375 $user_search->setFields(array('firstname'));
376 $result_obj = $user_search->performSearch();
377 $result->mergeEntries($result_obj);
378
379 $user_search->setFields(array('lastname'));
380 $result_obj = $user_search->performSearch();
381 $result->mergeEntries($result_obj);
382
383 $result->setMaxHits(100000);
384 $result->preventOverwritingMaxhits(true);
385 $result->filter(ROOT_FOLDER_ID, true);
386
387 // Filter users (depends on setting in user accounts)
388 include_once 'Services/User/classes/class.ilUserFilter.php';
389 $users = ilUserFilter::getInstance()->filter($result->getResultIds());
390
391 include_once("./Services/User/classes/class.ilObjUser.php");
393
394 $users = array_intersect($users, $p["public"]);
395
396 return $users;
397 }
398}
$result
An exception for terminatinating execution or to throw for unit testing.
const QP_COMBINATION_AND
static _exists($a_id)
checks wether a glossary term with specified id exists or not
static _getIdForImportId($a_import_id)
get current term id for import id (static)
static _getIdForImportId($a_import_id)
get current object id for import id (static)
static _exists($a_id)
checks wether a lm content object with specified id exists or not
static _exists($a_id, $a_reference=false, $a_type=null)
checks wether a lm content object with specified id exists or not
static getProfileStatusOfUsers($a_user_ids)
Get profile status.
static _getUserSearchInstance($query_parser)
get reference of ilLikeUserSearch
static _getAllReferences($a_id)
get all reference ids of object
static _getIdForImportId($a_import_id)
get current object id for import id (static)
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static getInstance()
Singelton get instance.
global $ilDB
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46