ILIAS  release_8 Revision v8.24
class.ilInternalLink.php
Go to the documentation of this file.
1<?php
2
25{
29 public static function _deleteAllLinksOfSource(
30 string $a_source_type,
31 int $a_source_id,
32 string $a_lang = "-"
33 ): void {
34 global $DIC;
35
36 $ilDB = $DIC->database();
37
38 $lang_where = "";
39 if ($a_lang !== "") {
40 $lang_where = " AND source_lang = " . $ilDB->quote($a_lang, "text");
41 }
42
43 $q = "DELETE FROM int_link WHERE source_type = " .
44 $ilDB->quote($a_source_type, "text") . " AND source_id=" .
45 $ilDB->quote($a_source_id, "integer") .
46 $lang_where;
47 $ilDB->manipulate($q);
48 }
49
53 public static function _deleteAllLinksToTarget(
54 string $a_target_type,
55 int $a_target_id,
56 int $a_target_inst = 0
57 ): void {
58 global $DIC;
59
60 $ilDB = $DIC->database();
61
62 $ilDB->manipulateF(
63 "DELETE FROM int_link WHERE target_type = %s " .
64 " AND target_id = %s AND target_inst = %s ",
65 array("text", "integer", "integer"),
66 array($a_target_type, $a_target_id, $a_target_inst)
67 );
68 }
69
73 public static function _saveLink(
74 string $a_source_type,
75 int $a_source_id,
76 string $a_target_type,
77 int $a_target_id,
78 int $a_target_inst = 0,
79 string $a_source_lang = "-"
80 ): void {
81 global $DIC;
82
83 $ilDB = $DIC->database();
84
85 $ilDB->replace(
86 "int_link",
87 array(
88 "source_type" => array("text", $a_source_type),
89 "source_id" => array("integer", $a_source_id),
90 "source_lang" => array("text", $a_source_lang),
91 "target_type" => array("text", $a_target_type),
92 "target_id" => array("integer", $a_target_id),
93 "target_inst" => array("integer", $a_target_inst)
94 ),
95 array()
96 );
97 }
98
106 public static function _getSourcesOfTarget(
107 string $a_target_type,
108 int $a_target_id,
109 int $a_target_inst
110 ): array {
111 global $DIC;
112
113 $ilDB = $DIC->database();
114
115 $q = "SELECT * FROM int_link WHERE " .
116 "target_type = " . $ilDB->quote($a_target_type, "text") . " AND " .
117 "target_id = " . $ilDB->quote($a_target_id, "integer") . " AND " .
118 "target_inst = " . $ilDB->quote($a_target_inst, "integer");
119 $source_set = $ilDB->query($q);
120 $sources = array();
121 while ($source_rec = $ilDB->fetchAssoc($source_set)) {
122 $sources[$source_rec["source_type"] . ":" . $source_rec["source_id"] . ":" . $source_rec["source_lang"]] =
123 array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"],
124 "lang" => $source_rec["source_lang"]);
125 }
126
127 return $sources;
128 }
129
137 public static function _getTargetsOfSource(
138 string $a_source_type,
139 int $a_source_id,
140 string $a_source_lang = "-"
141 ): array {
142 global $DIC;
143
144 $ilDB = $DIC->database();
145
146 $lang_where = "";
147 if ($a_source_lang !== "") {
148 $lang_where = " AND source_lang = " . $ilDB->quote($a_source_lang, "text");
149 }
150
151 $q = "SELECT * FROM int_link WHERE " .
152 "source_type = " . $ilDB->quote($a_source_type, "text") . " AND " .
153 "source_id = " . $ilDB->quote($a_source_id, "integer") .
154 $lang_where;
155
156 $target_set = $ilDB->query($q);
157 $targets = array();
158 while ($target_rec = $ilDB->fetchAssoc($target_set)) {
159 $targets[$target_rec["target_type"] . ":" . $target_rec["target_id"] . ":" . $target_rec["target_inst"]] =
160 array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
161 "inst" => $target_rec["target_inst"]);
162 }
163
164 return $targets;
165 }
166
174 public static function _getIdForImportId(
175 string $a_type,
176 string $a_target
177 ): ?string {
178 switch ($a_type) {
179 case "PageObject":
181 if ($id > 0) {
182 return "il__pg_" . $id;
183 }
184 break;
185
186 case "StructureObject":
188 if ($id > 0) {
189 return "il__st_" . $id;
190 }
191 break;
192
193 case "GlossaryItem":
195 //echo "+".$id."+".$a_target."+";
196 if ($id > 0) {
197 return "il__git_" . $id;
198 }
199 break;
200
201 case "WikiPage":
202 // no import IDs for wiki pages (yet)
203 //$id = ilGlossaryTerm::_getIdForImportId($a_target);
204 $id = 0;
205 /*
206 if ($id > 0) {
207 return "il__wpage_" . $id;
208 }*/
209 break;
210
211 case "MediaObject":
213 if ($id > 0) {
214 return "il__mob_" . $id;
215 }
216 break;
217
218 case "RepositoryItem":
219
220 $tarr = explode("_", $a_target);
221 $import_id = $a_target;
222
223 // if a ref id part is given, strip this
224 // since this will not be part of an import id
225 // see also bug #6685
226 if (($tarr[4] ?? "") != "") {
227 $import_id = $tarr[0] . "_" . $tarr[1] . "_" . $tarr[2] . "_" . $tarr[3];
228 }
229
230 $id = ilObject::_getIdForImportId($import_id);
231
232 // get ref id for object id
233 // (see ilPageObject::insertInstIntoIDs for the export procedure)
234 if ($id > 0) {
236 foreach ($refs as $ref) {
237 return "il__obj_" . $ref;
238 }
239 }
240
241 // 26 Sep 2018: moved this under the import id handling above
242 // If an imported object is found, this is always preferred.
243 // see also bug #23324
244 if (self::_extractInstOfTarget($a_target) == IL_INST_ID
245 && IL_INST_ID > 0) {
246 // does it have a ref id part?
247 if (($tarr[4] ?? "") != "") {
248 return "il__obj_" . $tarr[4];
249 }
250 }
251
252 break;
253
254 }
255 return null;
256 }
257
265 public static function _exists(
266 string $a_type,
267 string $a_target
268 ): bool {
269 global $DIC;
270
271 $tree = $DIC->repositoryTree();
272
273 switch ($a_type) {
274 case "PageObject":
275 case "StructureObject":
276 return ilLMObject::_exists((int) $a_target);
277
278 case "GlossaryItem":
279 return ilGlossaryTerm::_exists((int) $a_target);
280
281 case "MediaObject":
282 return ilObjMediaObject::_exists((int) $a_target);
283
284 case "WikiPage":
285 return ilWikiPage::_exists("wiki", (int) $a_target);
286
287 case "RepositoryItem":
288 if (is_int(strpos($a_target, "_"))) {
289 $ref_id = self::_extractObjIdOfTarget($a_target);
290 return $tree->isInTree($ref_id);
291 }
292 break;
293 }
294 return false;
295 }
296
297
302 public static function _extractInstOfTarget(string $a_target): ?int
303 {
304 if (!is_int(strpos($a_target, "__"))) {
305 $target = explode("_", $a_target);
306 if (isset($target[1]) && $target[1] > 0) {
307 return (int) $target[1];
308 }
309 }
310 return null;
311 }
312
317 public static function _removeInstFromTarget(string $a_target): ?string
318 {
319 if (!is_int(strpos($a_target, "__"))) {
320 $target = explode("_", $a_target);
321 if ($target[1] > 0) {
322 return "il__" . $target[2] . "_" . $target[3];
323 }
324 }
325 return null;
326 }
327
332 public static function _extractObjIdOfTarget(string $a_target): int
333 {
334 $target = explode("_", $a_target);
335 return (int) $target[count($target) - 1];
336 }
337
342 public static function _extractTypeOfTarget(string $a_target): string
343 {
344 $target = explode("_", $a_target);
345 return (string) ($target[count($target) - 2] ?? "");
346 }
347
351 public static function searchUsers(string $a_search_str): array
352 {
353 $result = new ilSearchResult();
354
355 $query_parser = new ilQueryParser($a_search_str);
356 $query_parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
357 $query_parser->setMinWordLength(3);
358 $query_parser->parse();
359
360 $user_search = ilObjectSearchFactory::_getUserSearchInstance($query_parser);
361 $user_search->enableActiveCheck(true);
362 $user_search->setFields(array('login'));
363 $result_obj = $user_search->performSearch();
364 $result->mergeEntries($result_obj);
365
366 $user_search->setFields(array('firstname'));
367 $result_obj = $user_search->performSearch();
368 $result->mergeEntries($result_obj);
369
370 $user_search->setFields(array('lastname'));
371 $result_obj = $user_search->performSearch();
372 $result->mergeEntries($result_obj);
373
374 $result->setMaxHits(100000);
375 $result->preventOverwritingMaxhits(true);
376 $result->filter(ROOT_FOLDER_ID, true);
377
378 // Filter users (depends on setting in user accounts)
379 $users = ilUserFilter::getInstance()->filter($result->getResultIds());
380
382
383 $users = array_intersect($users, $p["public"]);
384
385 return $users;
386 }
387}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _exists(int $a_id)
checks whether a glossary term with specified id exists or not
static _getIdForImportId(string $a_import_id)
static _exists(int $a_id)
checks wether a lm content object with specified id exists or not
static _getIdForImportId(string $a_import_id)
get current object id for import id (static)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static getProfileStatusOfUsers(array $a_user_ids)
Get profile status.
static _getUserSearchInstance(ilQueryParser $query_parser)
static _getAllReferences(int $id)
get all reference ids for object ID
static _getIdForImportId(string $import_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
const IL_INST_ID
Definition: constants.php:40
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67