ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilTagging Class Reference
+ Collaboration diagram for ilTagging:

Public Member Functions

 __construct ()
 

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

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

Constructor & Destructor Documentation

◆ __construct()

ilTagging::__construct ( )

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

24 {
25 }

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 339 of file class.ilTagging.php.

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

References $ilDB, and $q.

◆ _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 419 of file class.ilTagging.php.

423 : array {
424 global $DIC;
425
426 $ilDB = $DIC->database();
427
428 $res = array();
429
430 $sql = "SELECT obj_id, obj_type" .
431 " FROM il_tag" .
432 " WHERE tag = " . $ilDB->quote($a_tag, "text") .
433 " AND is_offline = " . $ilDB->quote(0, "integer");
434 if ($a_user_id) {
435 if (!$a_invert) {
436 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
437 } else {
438 $sql .= " AND user_id <> " . $ilDB->quote($a_user_id, "integer");
439 }
440 }
441 $set = $ilDB->query($sql);
442 while ($row = $ilDB->fetchAssoc($set)) {
443 $res[$row["obj_id"]] = $row["obj_type"];
444 }
445
446 return $res;
447 }
$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 455 of file class.ilTagging.php.

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

Referenced by ilTaggingGUI\getHTML().

+ 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 369 of file class.ilTagging.php.

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

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 284 of file class.ilTagging.php.

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

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 257 of file class.ilTagging.php.

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

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 176 of file class.ilTagging.php.

179 : array {
180 global $DIC;
181
182 $ilDB = $DIC->database();
183
184 $q = "SELECT * FROM il_tag WHERE " .
185 "user_id = " . $ilDB->quote($a_user_id, "integer") .
186 " AND tag = " . $ilDB->quote($a_tag, "text");
187
188 $set = $ilDB->query($q);
189 $objects = array();
190 while ($rec = $ilDB->fetchAssoc($set)) {
191 if (ilObject::_exists((int) $rec["obj_id"])) {
192 if ($rec["sub_obj_type"] == "-") {
193 $rec["sub_obj_type"] = "";
194 }
195 $objects[] = $rec;
196 } else {
198 (int) $rec["obj_id"],
199 $rec["obj_type"],
200 (int) $rec["sub_obj_id"],
201 $rec["sub_obj_type"]
202 );
203 }
204 }
205
206 return $objects;
207 }
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 210 of file class.ilTagging.php.

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

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 110 of file class.ilTagging.php.

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

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 146 of file class.ilTagging.php.

150 : array {
151 global $DIC;
152
153 $ilDB = $DIC->database();
154
155 $online_str = ($a_only_online)
156 ? $online_str = " AND is_offline = " . $ilDB->quote(0, "integer") . " "
157 : "";
158
159 $set = $ilDB->query("SELECT count(*) as cnt, tag FROM il_tag WHERE " .
160 "user_id = " . $ilDB->quote($a_user_id, "integer") . " " .
161 $online_str .
162 " GROUP BY tag ORDER BY cnt DESC");
163 $tags = array();
164 $cnt = 1;
165 while (($rec = $ilDB->fetchAssoc($set)) &&
166 ($a_max == 0 || $cnt <= $a_max)) {
167 $tags[] = $rec;
168 $cnt++;
169 }
170 $tags = ilArrayUtil::sortArray($tags, "tag", "asc");
171
172 return $tags;
173 }
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 77 of file class.ilTagging.php.

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

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 315 of file class.ilTagging.php.

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

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 229 of file class.ilTagging.php.

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

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 28 of file class.ilTagging.php.

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

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: