ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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":
177 if ($id > 0) {
178 return "il__pg_" . $id;
179 }
180 break;
181
182 case "StructureObject":
184 if ($id > 0) {
185 return "il__st_" . $id;
186 }
187 break;
188
189 case "GlossaryItem":
190 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
192 //echo "+".$id."+".$a_target."+";
193 if ($id > 0) {
194 return "il__git_" . $id;
195 }
196 break;
197
198 case "WikiPage":
199 // no import IDs for wiki pages (yet)
200 //$id = ilGlossaryTerm::_getIdForImportId($a_target);
201 $id = 0;
202 if ($id > 0) {
203 return "il__wpage_" . $id;
204 }
205 break;
206
207 case "MediaObject":
209 if ($id > 0) {
210 return "il__mob_" . $id;
211 }
212 break;
213
214 case "RepositoryItem":
215
216 $tarr = explode("_", $a_target);
217 $import_id = $a_target;
218
219 // if a ref id part is given, strip this
220 // since this will not be part of an import id
221 // see also bug #6685
222 if ($tarr[4] != "") {
223 $import_id = $tarr[0] . "_" . $tarr[1] . "_" . $tarr[2] . "_" . $tarr[3];
224 }
225
226 $id = ilObject::_getIdForImportId($import_id);
227
228 // get ref id for object id
229 // (see ilPageObject::insertInstIntoIDs for the export procedure)
230 if ($id > 0) {
232 foreach ($refs as $ref) {
233 return "il__obj_" . $ref;
234 }
235 }
236
237 // 26 Sep 2018: moved this under the import id handling above
238 // If an imported object is found, this is always preferred.
239 // see also bug #23324
240 if (ilInternalLink::_extractInstOfTarget($a_target) == IL_INST_ID
241 && IL_INST_ID > 0) {
242 // does it have a ref id part?
243 if ($tarr[4] != "") {
244 return "il__obj_" . $tarr[4];
245 }
246 }
247
248 break;
249
250 }
251 return false;
252 }
253
263 public static function _exists($a_type, $a_target)
264 {
265 global $DIC;
266
267 $tree = $DIC->repositoryTree();
268
269 switch ($a_type) {
270 case "PageObject":
271 case "StructureObject":
272 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
273 return ilLMObject::_exists($a_target);
274 break;
275
276 case "GlossaryItem":
277 include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
278 return ilGlossaryTerm::_exists($a_target);
279 break;
280
281 case "MediaObject":
282 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
283 return ilObjMediaObject::_exists($a_target);
284 break;
285
286 case "WikiPage":
287 include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
288 return ilWikiPage::_exists("wiki", (int) $a_target);
289 break;
290
291 case "RepositoryItem":
292 if (is_int(strpos($a_target, "_"))) {
293 $ref_id = ilInternalLink::_extractObjIdOfTarget($a_target);
294 return $tree->isInTree($ref_id);
295 }
296 break;
297 }
298 return false;
299 }
300
301
307 public static function _extractInstOfTarget($a_target)
308 {
309 if (!is_int(strpos($a_target, "__"))) {
310 $target = explode("_", $a_target);
311 if ($target[1] > 0) {
312 return $target[1];
313 }
314 }
315 return false;
316 }
317
323 public static function _removeInstFromTarget($a_target)
324 {
325 if (!is_int(strpos($a_target, "__"))) {
326 $target = explode("_", $a_target);
327 if ($target[1] > 0) {
328 return "il__" . $target[2] . "_" . $target[3];
329 }
330 }
331 return false;
332 }
333
339 public static function _extractObjIdOfTarget($a_target)
340 {
341 $target = explode("_", $a_target);
342 return $target[count($target) - 1];
343 }
344
350 public static function _extractTypeOfTarget($a_target)
351 {
352 $target = explode("_", $a_target);
353 return $target[count($target) - 2];
354 }
355
362 public static function searchUsers($a_search_str)
363 {
364 $result = new ilSearchResult();
365
366 $query_parser = new ilQueryParser($a_search_str, '%_');
367 $query_parser->setCombination(QP_COMBINATION_AND);
368 $query_parser->setMinWordLength(3);
369 $query_parser->parse();
370
371 $user_search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
372 $user_search->enableActiveCheck(true);
373 $user_search->setFields(array('login'));
374 $result_obj = $user_search->performSearch();
375 $result->mergeEntries($result_obj);
376
377 $user_search->setFields(array('firstname'));
378 $result_obj = $user_search->performSearch();
379 $result->mergeEntries($result_obj);
380
381 $user_search->setFields(array('lastname'));
382 $result_obj = $user_search->performSearch();
383 $result->mergeEntries($result_obj);
384
385 $result->setMaxHits(100000);
386 $result->preventOverwritingMaxhits(true);
387 $result->filter(ROOT_FOLDER_ID, true);
388
389 // Filter users (depends on setting in user accounts)
390 include_once 'Services/User/classes/class.ilUserFilter.php';
391 $users = ilUserFilter::getInstance()->filter($result->getResultIds());
392
393 include_once("./Services/User/classes/class.ilObjUser.php");
395
396 $users = array_intersect($users, $p["public"]);
397
398 return $users;
399 }
400}
$result
$users
Definition: authpage.php:44
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
global $DIC
Definition: saml.php:7
global $ilDB
$a_type
Definition: workflow.php:92