ILIAS  release_8 Revision v8.24
ilTagging Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilTagging:

Public Member Functions

 __construct ()
 Constructor. More...
 

Static Public Member Functions

static writeTagsForUserAndObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id, array $a_tags)
 
static getTagsForUserAndObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, int $a_user_id)
 
static getTagsForObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, bool $a_only_online=true)
 
static getTagsForUser (int $a_user_id, int $a_max=0, bool $a_only_online=true)
 
static getObjectsForTagAndUser (int $a_user_id, string $a_tag)
 
static getRelevanceClass (int $cnt, int $max)
 
static setTagsOfObjectOffline (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, bool $a_offline=true)
 
static deleteTagsOfObject (int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type)
 
static deleteTagOfObjectForUser (int $a_user_id, int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type, string $a_tag)
 
static getUsersForTag (string $a_tag)
 
static _countTags (array $a_obj_ids, bool $a_all_users=false)
 Count all tags for repository objects. More...
 
static _getTagCloudForObjects (array $a_obj_ids, ?int $a_user_id=null, int $a_divide=0)
 Count tags for given object ids. More...
 
static _findObjectsByTag (string $a_tag, int $a_user_id=null, bool $a_invert=false)
 Find all objects with given tag. More...
 
static _getListTagsForObjects (array $a_obj_ids, int $a_user_id=null)
 Get tags for given object ids. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class ilTagging

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ilTagging.php.

Constructor & Destructor Documentation

◆ __construct()

ilTagging::__construct ( )

Constructor.

Definition at line 31 of file class.ilTagging.php.

32 {
33 }

Member Function Documentation

◆ _countTags()

static ilTagging::_countTags ( array  $a_obj_ids,
bool  $a_all_users = false 
)
static

Count all tags for repository objects.

Parameters
int[]$a_obj_ids
bool$a_all_users
Returns
int[] key is object id

Definition at line 342 of file class.ilTagging.php.

345 : array {
346 global $DIC;
347
348 $ilDB = $DIC->database();
349 $ilUser = $DIC->user();
350
351 $q = "SELECT count(*) c, obj_id FROM il_tag WHERE " .
352 $ilDB->in("obj_id", $a_obj_ids, false, "integer");
353 // PHP8 Review: Type cast is unnecessary
354 if (!(bool) $a_all_users) {
355 $q .= " AND user_id = " . $ilDB->quote($ilUser->getId(), "integer");
356 }
357 $q .= " GROUP BY obj_id";
358
359 $cnt = array();
360 $set = $ilDB->query($q);
361 while ($rec = $ilDB->fetchAssoc($set)) {
362 $cnt[$rec["obj_id"]] = $rec["c"];
363 }
364
365 return $cnt;
366 }
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34

References $ilDB, and $ilUser.

Referenced by ilObjectListGUI\preloadCommonProperties().

+ Here is the caller graph for this function:

◆ _findObjectsByTag()

static ilTagging::_findObjectsByTag ( string  $a_tag,
int  $a_user_id = null,
bool  $a_invert = false 
)
static

Find all objects with given tag.

Parameters
?int$a_user_id
Returns
int[]

Definition at line 422 of file class.ilTagging.php.

426 : array {
427 global $DIC;
428
429 $ilDB = $DIC->database();
430
431 $res = array();
432
433 $sql = "SELECT obj_id, obj_type" .
434 " FROM il_tag" .
435 " WHERE tag = " . $ilDB->quote($a_tag, "text") .
436 " AND is_offline = " . $ilDB->quote(0, "integer");
437 if ($a_user_id) {
438 if (!$a_invert) {
439 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
440 } else {
441 $sql .= " AND user_id <> " . $ilDB->quote($a_user_id, "integer");
442 }
443 }
444 $set = $ilDB->query($sql);
445 while ($row = $ilDB->fetchAssoc($set)) {
446 $res[$row["obj_id"]] = $row["obj_type"];
447 }
448
449 return $res;
450 }
$res
Definition: ltiservices.php:69

Referenced by ilTaggingClassificationProvider\getFilteredObjects().

+ Here is the caller graph for this function:

◆ _getListTagsForObjects()

static ilTagging::_getListTagsForObjects ( array  $a_obj_ids,
int  $a_user_id = null 
)
static

Get tags for given object ids.

Parameters
array$a_obj_ids
?int$a_user_id
Returns
array

Definition at line 458 of file class.ilTagging.php.

461 : array {
462 global $DIC;
463
464 $ilDB = $DIC->database();
465 $ilUser = $DIC->user();
466
467 $res = array();
468
469 $sql = "SELECT obj_id, tag, user_id" .
470 " FROM il_tag" .
471 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, false, "integer") .
472 " AND is_offline = " . $ilDB->quote(0, "integer");
473 if ($a_user_id) {
474 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
475 }
476 $sql .= " ORDER BY tag";
477 $set = $ilDB->query($sql);
478 while ($row = $ilDB->fetchAssoc($set)) {
479 $tag = $row["tag"];
480 $res[$row["obj_id"]][$tag] = false;
481 if ($row["user_id"] == $ilUser->getId()) {
482 $res[$row["obj_id"]][$tag] = true;
483 }
484 }
485
486 return $res;
487 }

Referenced by ilTaggingGUI\getHTML(), and ilObjectListGUI\preloadCommonProperties().

+ Here is the caller graph for this function:

◆ _getTagCloudForObjects()

static ilTagging::_getTagCloudForObjects ( array  $a_obj_ids,
?int  $a_user_id = null,
int  $a_divide = 0 
)
static

Count tags for given object ids.

Parameters
int[]$a_obj_ids

Definition at line 372 of file class.ilTagging.php.

376 : array {
377 global $DIC;
378
379 $ilDB = $DIC->database();
380
381 $res = array();
382
383 $sql = "SELECT obj_id, obj_type, tag, user_id" .
384 " FROM il_tag" .
385 " WHERE " . $ilDB->in("obj_id", array_keys($a_obj_ids), false, "integer") .
386 " AND is_offline = " . $ilDB->quote(0, "integer");
387 if ($a_user_id) {
388 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
389 }
390 $sql .= " ORDER BY tag";
391 $set = $ilDB->query($sql);
392 while ($row = $ilDB->fetchAssoc($set)) {
393 if ($a_obj_ids[$row["obj_id"]] == $row["obj_type"]) {
394 $tag = $row["tag"];
395
396 if ($a_divide > 0) {
397 if ($row["user_id"] == $a_divide) {
398 $res["personal"][$tag] = isset($res["personal"][$tag])
399 ? $res["personal"][$tag]++
400 : 1;
401 } else {
402 $res["other"][$tag] = isset($res["other"][$tag])
403 ? $res["other"][$tag]++
404 : 1;
405 }
406 } else {
407 $res[$tag] = isset($res[$tag])
408 ? $res[$tag]++
409 : 1;
410 }
411 }
412 }
413
414 return $res;
415 }

Referenced by ilTaggingClassificationProvider\getSubTreeTags().

+ Here is the caller graph for this function:

◆ deleteTagOfObjectForUser()

static ilTagging::deleteTagOfObjectForUser ( int  $a_user_id,
int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type,
string  $a_tag 
)
static

Definition at line 287 of file class.ilTagging.php.

294 : void {
295 global $DIC;
296
297 $ilDB = $DIC->database();
298
299 if ($a_sub_obj_type == "") {
300 $a_sub_obj_type = "-";
301 }
302
303 $ilDB->manipulateF(
304 "DELETE FROM il_tag " .
305 "WHERE " .
306 "user_id = %s AND " .
307 "obj_id = %s AND " .
308 "obj_type = %s AND " .
309 "sub_obj_id = %s AND " .
310 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) . " AND " .
311 "tag = %s",
312 array("integer", "integer", "text", "integer", "text"),
313 array($a_user_id, $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_tag)
314 );
315 }

Referenced by ilTaggingSlateContentGUI\removeTagsWithoutAccess().

+ Here is the caller graph for this function:

◆ deleteTagsOfObject()

static ilTagging::deleteTagsOfObject ( int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type 
)
static

Definition at line 260 of file class.ilTagging.php.

265 : void {
266 global $DIC;
267
268 $ilDB = $DIC->database();
269
270 if ($a_sub_obj_type == "") {
271 $a_sub_obj_type = "-";
272 }
273
274 $ilDB->manipulateF(
275 "DELETE FROM il_tag " .
276 "WHERE " .
277 "obj_id = %s AND " .
278 "obj_type = %s AND " .
279 "sub_obj_id = %s AND " .
280 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true),
281 array("integer", "text", "integer"),
282 array($a_obj_id, $a_obj_type, $a_sub_obj_id)
283 );
284 }

Referenced by ilTaggingAppEventListener\handleEvent().

+ Here is the caller graph for this function:

◆ getObjectsForTagAndUser()

static ilTagging::getObjectsForTagAndUser ( int  $a_user_id,
string  $a_tag 
)
static

Definition at line 179 of file class.ilTagging.php.

182 : array {
183 global $DIC;
184
185 $ilDB = $DIC->database();
186
187 $q = "SELECT * FROM il_tag WHERE " .
188 "user_id = " . $ilDB->quote($a_user_id, "integer") .
189 " AND tag = " . $ilDB->quote($a_tag, "text");
190
191 $set = $ilDB->query($q);
192 $objects = array();
193 while ($rec = $ilDB->fetchAssoc($set)) {
194 if (ilObject::_exists((int) $rec["obj_id"])) {
195 if ($rec["sub_obj_type"] == "-") {
196 $rec["sub_obj_type"] = "";
197 }
198 $objects[] = $rec;
199 } else {
201 (int) $rec["obj_id"],
202 $rec["obj_type"],
203 (int) $rec["sub_obj_id"],
204 $rec["sub_obj_type"]
205 );
206 }
207 }
208
209 return $objects;
210 }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static deleteTagsOfObject(int $a_obj_id, string $a_obj_type, int $a_sub_obj_id, string $a_sub_obj_type)

Referenced by ilTaggingSlateContentGUI\removeTagsWithoutAccess(), and ilTaggingSlateContentGUI\renderResourcesForTag().

+ Here is the caller graph for this function:

◆ getRelevanceClass()

static ilTagging::getRelevanceClass ( int  $cnt,
int  $max 
)
static

Definition at line 213 of file class.ilTagging.php.

216 : string {
217 $m = $cnt / $max;
218 if ($m >= 0.8) {
219 return "ilTagRelVeryHigh";
220 } elseif ($m >= 0.6) {
221 return "ilTagRelHigh";
222 } elseif ($m >= 0.4) {
223 return "ilTagRelMiddle";
224 } elseif ($m >= 0.2) {
225 return "ilTagRelLow";
226 }
227
228 return "ilTagRelVeryLow";
229 }

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML(), ilTaggingSlateContentGUI\renderTagCloud(), and TagRelevanceTest\testTagRelevance().

+ Here is the caller graph for this function:

◆ getTagsForObject()

static ilTagging::getTagsForObject ( int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type,
bool  $a_only_online = true 
)
static

Definition at line 113 of file class.ilTagging.php.

119 : array {
120 global $DIC;
121
122 $ilDB = $DIC->database();
123
124 $online_str = ($a_only_online)
125 ? $online_str = " AND is_offline = " . $ilDB->quote(0, "integer") . " "
126 : "";
127
128 if ($a_sub_obj_type == "") {
129 $a_sub_obj_type = "-";
130 }
131
132 $q = "SELECT count(user_id) as cnt, tag FROM il_tag WHERE " .
133 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
134 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
135 "sub_obj_id = " . $ilDB->quote($a_sub_obj_id, "integer") . " AND " .
136 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) .
137 $online_str .
138 "GROUP BY tag ORDER BY tag ASC";
139 $set = $ilDB->query($q);
140 $tags = array();
141 while ($rec = $ilDB->fetchAssoc($set)) {
142 $tags[] = $rec;
143 }
144
145 return $tags;
146 }

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML().

+ Here is the caller graph for this function:

◆ getTagsForUser()

static ilTagging::getTagsForUser ( int  $a_user_id,
int  $a_max = 0,
bool  $a_only_online = true 
)
static

Definition at line 149 of file class.ilTagging.php.

153 : array {
154 global $DIC;
155
156 $ilDB = $DIC->database();
157
158 $online_str = ($a_only_online)
159 ? $online_str = " AND is_offline = " . $ilDB->quote(0, "integer") . " "
160 : "";
161
162 $set = $ilDB->query("SELECT count(*) as cnt, tag FROM il_tag WHERE " .
163 "user_id = " . $ilDB->quote($a_user_id, "integer") . " " .
164 $online_str .
165 " GROUP BY tag ORDER BY cnt DESC");
166 $tags = array();
167 $cnt = 1;
168 while (($rec = $ilDB->fetchAssoc($set)) &&
169 ($a_max == 0 || $cnt <= $a_max)) {
170 $tags[] = $rec;
171 $cnt++;
172 }
173 $tags = ilArrayUtil::sortArray($tags, "tag", "asc");
174
175 return $tags;
176 }
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)

Referenced by ilTaggingSlateContentGUI\__construct().

+ Here is the caller graph for this function:

◆ getTagsForUserAndObject()

static ilTagging::getTagsForUserAndObject ( int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type,
int  $a_user_id 
)
static

Definition at line 80 of file class.ilTagging.php.

86 : array {
87 global $DIC;
88
89 $ilDB = $DIC->database();
90
91 if ($a_sub_obj_type == "") {
92 $a_sub_obj_type = "-";
93 }
94
95 $q = "SELECT * FROM il_tag WHERE " .
96 "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
97 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
98 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
99 // PHP8 Review: Type cast is unnecessary
100 "sub_obj_id = " . $ilDB->quote((int) $a_sub_obj_id, "integer") . " AND " .
101 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) .
102 " ORDER BY tag";
103 $set = $ilDB->query($q);
104 $tags = array();
105 while ($rec = $ilDB->fetchAssoc($set)) {
106 $tags[] = $rec["tag"];
107 }
108
109 return $tags;
110 }

Referenced by ilObjectListGUI\getHeaderAction(), ilTaggingGUI\getHTML(), and ilTaggingGUI\getTaggingInputHTML().

+ Here is the caller graph for this function:

◆ getUsersForTag()

static ilTagging::getUsersForTag ( string  $a_tag)
static

Definition at line 318 of file class.ilTagging.php.

320 : array {
321 global $DIC;
322 $ilDB = $DIC->database();
323
324 $set = $ilDB->query(
325 "SELECT DISTINCT user_id, firstname, lastname FROM il_tag JOIN usr_data ON (user_id = usr_id) " .
326 " WHERE LOWER(tag) = LOWER(" . $ilDB->quote($a_tag, "text") . ")" .
327 " ORDER BY lastname, firstname"
328 );
329 $users = array();
330 while ($rec = $ilDB->fetchAssoc($set)) {
331 $users[] = array("id" => $rec["user_id"]);
332 }
333 return $users;
334 }

Referenced by ilUserForTagTableGUI\__construct().

+ Here is the caller graph for this function:

◆ setTagsOfObjectOffline()

static ilTagging::setTagsOfObjectOffline ( int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type,
bool  $a_offline = true 
)
static

Definition at line 232 of file class.ilTagging.php.

238 : void {
239 global $DIC;
240
241 $ilDB = $DIC->database();
242
243 if ($a_sub_obj_type == "") {
244 $a_sub_obj_type = "-";
245 }
246
247 $ilDB->manipulateF(
248 "UPDATE il_tag SET is_offline = %s " .
249 "WHERE " .
250 "obj_id = %s AND " .
251 "obj_type = %s AND " .
252 "sub_obj_id = %s AND " .
253 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true),
254 array("boolean", "integer", "text", "integer"),
255 array($a_offline, $a_obj_id, $a_obj_type, $a_sub_obj_id)
256 );
257 }

Referenced by ilTaggingAppEventListener\handleEvent().

+ Here is the caller graph for this function:

◆ writeTagsForUserAndObject()

static ilTagging::writeTagsForUserAndObject ( int  $a_obj_id,
string  $a_obj_type,
int  $a_sub_obj_id,
string  $a_sub_obj_type,
int  $a_user_id,
array  $a_tags 
)
static

Definition at line 36 of file class.ilTagging.php.

43 : void {
44 global $DIC;
45
46 $ilDB = $DIC->database();
47
48 if ($a_sub_obj_type == "") {
49 $a_sub_obj_type = "-";
50 }
51
52 $ilDB->manipulate("DELETE FROM il_tag WHERE " .
53 "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
54 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
55 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
56 // PHP8 Review: Type cast is unnecessary
57 "sub_obj_id = " . $ilDB->quote((int) $a_sub_obj_id, "integer") . " AND " .
58 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true));
59
60 if (is_array($a_tags)) {
61 $inserted = array();
62 foreach ($a_tags as $tag) {
63 if (!in_array(strtolower($tag), $inserted)) {
64 $ilDB->manipulate("INSERT INTO il_tag (user_id, obj_id, obj_type," .
65 "sub_obj_id, sub_obj_type, tag) VALUES (" .
66 $ilDB->quote($a_user_id, "integer") . "," .
67 $ilDB->quote($a_obj_id, "integer") . "," .
68 $ilDB->quote($a_obj_type, "text") . "," .
69 // PHP8 Review: Type cast is unnecessary
70 $ilDB->quote((int) $a_sub_obj_id, "integer") . "," .
71 $ilDB->quote($a_sub_obj_type, "text") . "," .
72 $ilDB->quote($tag, "text") . ")");
73 $inserted[] = strtolower($tag);
74 }
75 }
76 }
77 }

Referenced by ilTaggingGUI\saveInput(), and ilTaggingGUI\saveJS().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: