ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilInternalLink.php
Go to the documentation of this file.
1<?php
2
26{
30 public static function _deleteAllLinksOfSource(
31 string $a_source_type,
32 int $a_source_id,
33 string $a_lang = "-"
34 ): void {
35 global $DIC;
36
37 $ilDB = $DIC->database();
38
39 $lang_where = "";
40 if ($a_lang !== "") {
41 $lang_where = " AND source_lang = " . $ilDB->quote($a_lang, "text");
42 }
43
44 $q = "DELETE FROM int_link WHERE source_type = " .
45 $ilDB->quote($a_source_type, "text") . " AND source_id=" .
46 $ilDB->quote($a_source_id, "integer") .
47 $lang_where;
48 $ilDB->manipulate($q);
49 }
50
54 public static function _deleteAllLinksToTarget(
55 string $a_target_type,
56 int $a_target_id,
57 int $a_target_inst = 0
58 ): void {
59 global $DIC;
60
61 $ilDB = $DIC->database();
62
63 $ilDB->manipulateF(
64 "DELETE FROM int_link WHERE target_type = %s " .
65 " AND target_id = %s AND target_inst = %s ",
66 array("text", "integer", "integer"),
67 array($a_target_type, $a_target_id, $a_target_inst)
68 );
69 }
70
74 public static function _saveLink(
75 string $a_source_type,
76 int $a_source_id,
77 string $a_target_type,
78 int $a_target_id,
79 int $a_target_inst = 0,
80 string $a_source_lang = "-"
81 ): void {
82 global $DIC;
83
84 $ilDB = $DIC->database();
85
86 $ilDB->replace(
87 "int_link",
88 array(
89 "source_type" => array("text", $a_source_type),
90 "source_id" => array("integer", $a_source_id),
91 "source_lang" => array("text", $a_source_lang),
92 "target_type" => array("text", $a_target_type),
93 "target_id" => array("integer", $a_target_id),
94 "target_inst" => array("integer", $a_target_inst)
95 ),
96 array()
97 );
98 }
99
107 public static function _getSourcesOfTarget(
108 string $a_target_type,
109 int $a_target_id,
110 int $a_target_inst
111 ): array {
112 global $DIC;
113
114 $ilDB = $DIC->database();
115
116 $q = "SELECT * FROM int_link WHERE " .
117 "target_type = " . $ilDB->quote($a_target_type, "text") . " AND " .
118 "target_id = " . $ilDB->quote($a_target_id, "integer") . " AND " .
119 "target_inst = " . $ilDB->quote($a_target_inst, "integer");
120 $source_set = $ilDB->query($q);
121 $sources = array();
122 while ($source_rec = $ilDB->fetchAssoc($source_set)) {
123 $sources[$source_rec["source_type"] . ":" . $source_rec["source_id"] . ":" . $source_rec["source_lang"]] =
124 array("type" => $source_rec["source_type"], "id" => $source_rec["source_id"],
125 "lang" => $source_rec["source_lang"]);
126 }
127
128 return $sources;
129 }
130
138 public static function _getTargetsOfSource(
139 string $a_source_type,
140 int $a_source_id,
141 string $a_source_lang = "-"
142 ): array {
143 global $DIC;
144
145 $ilDB = $DIC->database();
146
147 $lang_where = "";
148 if ($a_source_lang !== "") {
149 $lang_where = " AND source_lang = " . $ilDB->quote($a_source_lang, "text");
150 }
151
152 $q = "SELECT * FROM int_link WHERE " .
153 "source_type = " . $ilDB->quote($a_source_type, "text") . " AND " .
154 "source_id = " . $ilDB->quote($a_source_id, "integer") .
155 $lang_where;
156
157 $target_set = $ilDB->query($q);
158 $targets = array();
159 while ($target_rec = $ilDB->fetchAssoc($target_set)) {
160 $targets[$target_rec["target_type"] . ":" . $target_rec["target_id"] . ":" . $target_rec["target_inst"]] =
161 array("type" => $target_rec["target_type"], "id" => $target_rec["target_id"],
162 "inst" => $target_rec["target_inst"]);
163 }
164
165 return $targets;
166 }
167
175 public static function _getIdForImportId(
176 string $a_type,
177 string $a_target
178 ): ?string {
179 switch ($a_type) {
180 case "PageObject":
182 if ($id > 0) {
183 return "il__pg_" . $id;
184 }
185 break;
186
187 case "StructureObject":
189 if ($id > 0) {
190 return "il__st_" . $id;
191 }
192 break;
193
194 case "GlossaryItem":
196 //echo "+".$id."+".$a_target."+";
197 if ($id > 0) {
198 return "il__git_" . $id;
199 }
200 break;
201
202 case "WikiPage":
203 // no import IDs for wiki pages (yet)
204 //$id = ilGlossaryTerm::_getIdForImportId($a_target);
205 $id = 0;
206 /*
207 if ($id > 0) {
208 return "il__wpage_" . $id;
209 }*/
210 break;
211
212 case "MediaObject":
214 if ($id > 0) {
215 return "il__mob_" . $id;
216 }
217 break;
218
219 case "RepositoryItem":
220
221 $tarr = explode("_", $a_target);
222 $import_id = $a_target;
223
224 // if a ref id part is given, strip this
225 // since this will not be part of an import id
226 // see also bug #6685
227 if (($tarr[4] ?? "") != "") {
228 $import_id = $tarr[0] . "_" . $tarr[1] . "_" . $tarr[2] . "_" . $tarr[3];
229 }
230
231 $id = ilObject::_getIdForImportId($import_id);
232
233 // get ref id for object id
234 // (see ilPageObject::insertInstIntoIDs for the export procedure)
235 if ($id > 0) {
237 foreach ($refs as $ref) {
238 return "il__obj_" . $ref;
239 }
240 }
241
242 // 26 Sep 2018: moved this under the import id handling above
243 // If an imported object is found, this is always preferred.
244 // see also bug #23324
245 if (self::_extractInstOfTarget($a_target) == IL_INST_ID
246 && IL_INST_ID > 0) {
247 // does it have a ref id part?
248 if (($tarr[4] ?? "") != "") {
249 return "il__obj_" . $tarr[4];
250 }
251 }
252
253 break;
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($a_target);
277
278 case "GlossaryItem":
279 return ilGlossaryTerm::_exists($a_target);
280
281 case "MediaObject":
282 return ilObjMediaObject::_exists($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)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
const ROOT_FOLDER_ID
Definition: constants.php:32
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23