ILIAS  release_7 Revision v7.30-3-g800a261c036
ilTagging Class Reference

Class ilTagging. More...

+ Collaboration diagram for ilTagging:

Public Member Functions

 __construct ()
 Constructor. More...
 

Static Public Member Functions

static writeTagsForUserAndObject ( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id, $a_tags)
 Write tags for a user and an object. More...
 
static getTagsForUserAndObject ( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_user_id)
 Get tags for a user and an object. More...
 
static getTagsForObject ( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_only_online=true)
 Get tags for an object. More...
 
static getTagsForUser ($a_user_id, $a_max=0, $a_only_online=true)
 Get tags for a user. More...
 
static getObjectsForTagAndUser ($a_user_id, $a_tag)
 Get objects for tag and user. More...
 
static calculateFontSize ($cnt, $max)
 Returns 100(%) for 1 and 150(%) for $max y = a + mx 100 = a + m (1) 150 = a + m * max (2) (1): a = 100 - m (3) (2): a = 150 - max*m (4) (3)&(4): m - 100 = max*m - 150 (5) (5) 50 = (max-1)*m => m = 50/(max -1) => a = 100 - 50/(max -1) More...
 
static getRelevanceClass ($cnt, $max)
 Get style class for tag relevance. More...
 
static setTagsOfObjectOffline ( $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_offline=true)
 Set offline. More...
 
static deleteTagsOfObject ($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type)
 Deletes tags of an object. More...
 
static deleteTagOfObjectForUser ($a_user_id, $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type, $a_tag)
 Deletes tag of an object. More...
 
static getUsersForTag ($a_tag)
 Get users for tag. More...
 
static _countTags ($a_obj_ids, $a_all_users=false)
 Count all tags for repository objects. More...
 
static _getTagCloudForObjects (array $a_obj_ids, $a_user_id=null, $a_divide=false)
 Count tags for given object ids. More...
 
static _findObjectsByTag ($a_tag, $a_user_id=null, $a_invert=false)
 Find all objects with given tag. More...
 
static _getListTagsForObjects (array $a_obj_ids, $a_user_id=null)
 Get tags for given object ids. More...
 

Protected Attributes

 $db
 

Detailed Description

Class ilTagging.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilTagging::__construct ( )

Constructor.

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

27 {
28 global $DIC;
29
30 $this->db = $DIC->database();
31 }
global $DIC
Definition: goto.php:24

References $DIC.

Member Function Documentation

◆ _countTags()

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

Count all tags for repository objects.

Parameters
array$a_obj_idsrepository object IDs array
bool$a_all_users

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

405 {
406 global $DIC;
407
408 $ilDB = $DIC->database();
409 $ilUser = $DIC->user();
410
411 $q = "SELECT count(*) c, obj_id FROM il_tag WHERE " .
412 $ilDB->in("obj_id", $a_obj_ids, false, "integer");
413 if (!(bool) $a_all_users) {
414 $q .= " AND user_id = " . $ilDB->quote($ilUser->getId(), "integer");
415 }
416 $q .= " GROUP BY obj_id";
417
418 $cnt = array();
419 $set = $ilDB->query($q);
420 while ($rec = $ilDB->fetchAssoc($set)) {
421 $cnt[$rec["obj_id"]] = $rec["c"];
422 }
423
424 return $cnt;
425 }
$ilUser
Definition: imgupload.php:18
global $ilDB

References $DIC, $ilDB, and $ilUser.

Referenced by ilObjectListGUI\preloadCommonProperties().

+ Here is the caller graph for this function:

◆ _findObjectsByTag()

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

Find all objects with given tag.

Parameters
string$a_tag
int$a_user_id
Returns
array

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

485 {
486 global $DIC;
487
488 $ilDB = $DIC->database();
489
490 $res = array();
491
492 $sql = "SELECT obj_id, obj_type" .
493 " FROM il_tag" .
494 " WHERE tag = " . $ilDB->quote($a_tag, "text") .
495 " AND is_offline = " . $ilDB->quote(0, "integer");
496 if ($a_user_id) {
497 if (!$a_invert) {
498 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
499 } else {
500 $sql .= " AND user_id <> " . $ilDB->quote($a_user_id, "integer");
501 }
502 }
503 $set = $ilDB->query($sql);
504 while ($row = $ilDB->fetchAssoc($set)) {
505 $res[$row["obj_id"]] = $row["obj_type"];
506 }
507
508 return $res;
509 }
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, and $res.

Referenced by ilTaggingClassificationProvider\getFilteredObjects().

+ Here is the caller graph for this function:

◆ _getListTagsForObjects()

static ilTagging::_getListTagsForObjects ( array  $a_obj_ids,
  $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 518 of file class.ilTagging.php.

519 {
520 global $DIC;
521
522 $ilDB = $DIC->database();
523 $ilUser = $DIC->user();
524
525 $res = array();
526
527 $sql = "SELECT obj_id, tag, user_id" .
528 " FROM il_tag" .
529 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, false, "integer") .
530 " AND is_offline = " . $ilDB->quote(0, "integer");
531 if ($a_user_id) {
532 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
533 }
534 $sql .= " ORDER BY tag";
535 $set = $ilDB->query($sql);
536 while ($row = $ilDB->fetchAssoc($set)) {
537 $tag = $row["tag"];
538 $res[$row["obj_id"]][$tag] = false;
539 if ($row["user_id"] == $ilUser->getId()) {
540 $res[$row["obj_id"]][$tag] = true;
541 }
542 }
543
544 return $res;
545 }

References $DIC, $ilDB, $ilUser, and $res.

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

+ Here is the caller graph for this function:

◆ _getTagCloudForObjects()

static ilTagging::_getTagCloudForObjects ( array  $a_obj_ids,
  $a_user_id = null,
  $a_divide = false 
)
static

Count tags for given object ids.

Parameters
array$a_obj_idsobj_id => type
int$a_user_id
int$a_divide
Returns
array obj_id => counter

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

436 {
437 global $DIC;
438
439 $ilDB = $DIC->database();
440
441 $res = array();
442
443 $sql = "SELECT obj_id, obj_type, tag, user_id" .
444 " FROM il_tag" .
445 " WHERE " . $ilDB->in("obj_id", array_keys($a_obj_ids), false, "integer") .
446 " AND is_offline = " . $ilDB->quote(0, "integer");
447 if ($a_user_id) {
448 $sql .= " AND user_id = " . $ilDB->quote($a_user_id, "integer");
449 }
450 $sql .= " ORDER BY tag";
451 $set = $ilDB->query($sql);
452 while ($row = $ilDB->fetchAssoc($set)) {
453 if ($a_obj_ids[$row["obj_id"]] == $row["obj_type"]) {
454 $tag = $row["tag"];
455
456 if ($a_divide) {
457 if ($row["user_id"] == $a_divide) {
458 $res["personal"][$tag] = isset($res["personal"][$tag])
459 ? $res["personal"][$tag]++
460 : 1;
461 } else {
462 $res["other"][$tag] = isset($res["other"][$tag])
463 ? $res["other"][$tag]++
464 : 1;
465 }
466 } else {
467 $res[$tag] = isset($res[$tag])
468 ? $res[$tag]++
469 : 1;
470 }
471 }
472 }
473
474 return $res;
475 }

References $DIC, $ilDB, and $res.

Referenced by ilTaggingClassificationProvider\getSubTreeTags().

+ Here is the caller graph for this function:

◆ calculateFontSize()

static ilTagging::calculateFontSize (   $cnt,
  $max 
)
static

Returns 100(%) for 1 and 150(%) for $max y = a + mx 100 = a + m (1) 150 = a + m * max (2) (1): a = 100 - m (3) (2): a = 150 - max*m (4) (3)&(4): m - 100 = max*m - 150 (5) (5) 50 = (max-1)*m => m = 50/(max -1) => a = 100 - 50/(max -1)

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

250 {
251 $m = ($max == 1)
252 ? 0
253 : 50 / ($max - 1);
254 $a = 100 - $m;
255 $font_size = round($a + ($m * $cnt));
256 return (int) $font_size;
257 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a.

◆ deleteTagOfObjectForUser()

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

Deletes tag of an object.

Parameters
int$a_user_idUser Id
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
string$a_tagTag

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

355 {
356 global $DIC;
357
358 $ilDB = $DIC->database();
359
360 if ($a_sub_obj_type == "") {
361 $a_sub_obj_type = "-";
362 }
363
364 $ilDB->manipulateF(
365 "DELETE FROM il_tag " .
366 "WHERE " .
367 "user_id = %s AND " .
368 "obj_id = %s AND " .
369 "obj_type = %s AND " .
370 "sub_obj_id = %s AND " .
371 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) . " AND " .
372 "tag = %s",
373 array("integer", "integer", "text", "integer", "text"),
374 array($a_user_id, $a_obj_id, $a_obj_type, $a_sub_obj_id, $a_tag)
375 );
376 }

References $DIC, and $ilDB.

Referenced by ilTaggingSlateContentGUI\removeTagsWithoutAccess().

+ Here is the caller graph for this function:

◆ deleteTagsOfObject()

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

Deletes tags of an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type

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

323 {
324 global $DIC;
325
326 $ilDB = $DIC->database();
327
328 if ($a_sub_obj_type == "") {
329 $a_sub_obj_type = "-";
330 }
331
332 $ilDB->manipulateF(
333 "DELETE FROM il_tag " .
334 "WHERE " .
335 "obj_id = %s AND " .
336 "obj_type = %s AND " .
337 "sub_obj_id = %s AND " .
338 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true),
339 array("integer", "text", "integer"),
340 array($a_obj_id, $a_obj_type, $a_sub_obj_id)
341 );
342 }

References $DIC, and $ilDB.

Referenced by getObjectsForTagAndUser(), and ilTaggingAppEventListener\handleEvent().

+ Here is the caller graph for this function:

◆ getObjectsForTagAndUser()

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

Get objects for tag and user.

Parameters
int$a_user_idUser ID

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

207 {
208 global $DIC;
209
210 $ilDB = $DIC->database();
211
212 $q = "SELECT * FROM il_tag WHERE " .
213 "user_id = " . $ilDB->quote($a_user_id, "integer") .
214 " AND tag = " . $ilDB->quote($a_tag, "text");
215
216 $set = $ilDB->query($q);
217 $objects = array();
218 while ($rec = $ilDB->fetchAssoc($set)) {
219 if (ilObject::_exists($rec["obj_id"])) {
220 if ($rec["sub_obj_type"] == "-") {
221 $rec["sub_obj_type"] = "";
222 }
223 $objects[] = $rec;
224 } else {
226 $rec["obj_id"],
227 $rec["obj_type"],
228 $rec["sub_obj_id"],
229 $rec["sub_obj_type"]
230 );
231 }
232 }
233
234 return $objects;
235 }
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static deleteTagsOfObject($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type)
Deletes tags of an object.

References $DIC, $ilDB, ilObject\_exists(), and deleteTagsOfObject().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRelevanceClass()

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

Get style class for tag relevance.

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

263 {
264 $m = $cnt / $max;
265 if ($m >= 0.8) {
266 return "ilTagRelVeryHigh";
267 } elseif ($m >= 0.6) {
268 return "ilTagRelHigh";
269 } elseif ($m >= 0.4) {
270 return "ilTagRelMiddle";
271 } elseif ($m >= 0.2) {
272 return "ilTagRelLow";
273 }
274
275 return "ilTagRelVeryLow";
276 }

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML(), ilTaggingClassificationProvider\render(), ilObjBlogGUI\renderNavigationByKeywords(), and ilTaggingSlateContentGUI\renderTagCloud().

+ Here is the caller graph for this function:

◆ getTagsForObject()

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

Get tags for an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type

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

141 {
142 global $DIC;
143
144 $ilDB = $DIC->database();
145
146 $online_str = ($a_only_online)
147 ? $online_str = " AND is_offline = " . $ilDB->quote(0, "integer") . " "
148 : "";
149
150 if ($a_sub_obj_type == "") {
151 $a_sub_obj_type = "-";
152 }
153
154 $q = "SELECT count(user_id) as cnt, tag FROM il_tag WHERE " .
155 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
156 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
157 "sub_obj_id = " . $ilDB->quote($a_sub_obj_id, "integer") . " AND " .
158 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) .
159 $online_str .
160 "GROUP BY tag ORDER BY tag ASC";
161 $set = $ilDB->query($q);
162 $tags = array();
163 while ($rec = $ilDB->fetchAssoc($set)) {
164 $tags[] = $rec;
165 }
166
167 return $tags;
168 }

References $DIC, and $ilDB.

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML().

+ Here is the caller graph for this function:

◆ getTagsForUser()

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

Get tags for a user.

Parameters
int$a_user_idUser ID

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

176 {
177 global $DIC;
178
179 $ilDB = $DIC->database();
180
181 $online_str = ($a_only_online)
182 ? $online_str = " AND is_offline = " . $ilDB->quote(0, "integer") . " "
183 : "";
184
185 $set = $ilDB->query("SELECT count(*) as cnt, tag FROM il_tag WHERE " .
186 "user_id = " . $ilDB->quote($a_user_id, "integer") . " " .
187 $online_str .
188 " GROUP BY tag ORDER BY cnt DESC");
189 $tags = array();
190 $cnt = 1;
191 while (($rec = $ilDB->fetchAssoc($set)) &&
192 ($a_max == 0 || $cnt <= $a_max)) {
193 $tags[] = $rec;
194 $cnt++;
195 }
196 $tags = ilUtil::sortArray($tags, "tag", "asc");
197
198 return $tags;
199 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray

References $DIC, $ilDB, and ilUtil\sortArray().

Referenced by ilTaggingSlateContentGUI\__construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTagsForUserAndObject()

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

Get tags for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID

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

102 {
103 global $DIC;
104
105 $ilDB = $DIC->database();
106
107 if ($a_sub_obj_type == "") {
108 $a_sub_obj_type = "-";
109 }
110
111 $q = "SELECT * FROM il_tag WHERE " .
112 "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
113 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
114 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
115 "sub_obj_id = " . $ilDB->quote((int) $a_sub_obj_id, "integer") . " AND " .
116 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true) .
117 " ORDER BY tag ASC";
118 $set = $ilDB->query($q);
119 $tags = array();
120 while ($rec = $ilDB->fetchAssoc($set)) {
121 $tags[] = $rec["tag"];
122 }
123
124 return $tags;
125 }

References $DIC, and $ilDB.

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

+ Here is the caller graph for this function:

◆ getUsersForTag()

static ilTagging::getUsersForTag (   $a_tag)
static

Get users for tag.

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

382 {
383 global $DIC;
384 $ilDB = $DIC->database();
385
386 $set = $ilDB->query(
387 "SELECT DISTINCT user_id, firstname, lastname FROM il_tag JOIN usr_data ON (user_id = usr_id) " .
388 " WHERE LOWER(tag) = LOWER(" . $ilDB->quote($a_tag, "text") . ")" .
389 " ORDER BY lastname, firstname"
390 );
391 $users = array();
392 while ($rec = $ilDB->fetchAssoc($set)) {
393 $users[] = array("id" => $rec["user_id"]);
394 }
395 return $users;
396 }

References $DIC, and $ilDB.

Referenced by ilUserForTagTableGUI\__construct().

+ Here is the caller graph for this function:

◆ setTagsOfObjectOffline()

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

Set offline.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
boolean$a_offlineOffline (true/false, true means offline!)

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

293 {
294 global $DIC;
295
296 $ilDB = $DIC->database();
297
298 if ($a_sub_obj_type == "") {
299 $a_sub_obj_type = "-";
300 }
301
302 $ilDB->manipulateF(
303 "UPDATE il_tag SET is_offline = %s " .
304 "WHERE " .
305 "obj_id = %s AND " .
306 "obj_type = %s AND " .
307 "sub_obj_id = %s AND " .
308 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true),
309 array("boolean", "integer", "text", "integer"),
310 array($a_offline, $a_obj_id, $a_obj_type, $a_sub_obj_id)
311 );
312 }

References $DIC, and $ilDB.

Referenced by ilTaggingAppEventListener\handleEvent().

+ Here is the caller graph for this function:

◆ writeTagsForUserAndObject()

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

Write tags for a user and an object.

Parameters
int$a_obj_idObject ID
string$a_obj_typeObject Type
int$a_sub_obj_idSubobject ID
string$a_sub_obj_typeSubobject Type
int$a_user_idUser ID
array$a_tagsTags

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

50 {
51 global $DIC;
52
53 $ilDB = $DIC->database();
54
55 if ($a_sub_obj_type == "") {
56 $a_sub_obj_type = "-";
57 }
58
59 $ilDB->manipulate("DELETE FROM il_tag WHERE " .
60 "user_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
61 "obj_id = " . $ilDB->quote($a_obj_id, "integer") . " AND " .
62 "obj_type = " . $ilDB->quote($a_obj_type, "text") . " AND " .
63 "sub_obj_id = " . $ilDB->quote((int) $a_sub_obj_id, "integer") . " AND " .
64 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true));
65 //"sub_obj_type = ".$ilDB->quote($a_sub_obj_type, "text"));
66
67 if (is_array($a_tags)) {
68 $inserted = array();
69 foreach ($a_tags as $tag) {
70 if (!in_array(strtolower($tag), $inserted)) {
71 //$tag = str_replace(" ", "_", trim($tag));
72 $ilDB->manipulate("INSERT INTO il_tag (user_id, obj_id, obj_type," .
73 "sub_obj_id, sub_obj_type, tag) VALUES (" .
74 $ilDB->quote($a_user_id, "integer") . "," .
75 $ilDB->quote($a_obj_id, "integer") . "," .
76 $ilDB->quote($a_obj_type, "text") . "," .
77 $ilDB->quote((int) $a_sub_obj_id, "integer") . "," .
78 $ilDB->quote($a_sub_obj_type, "text") . "," .
79 $ilDB->quote($tag, "text") . ")");
80
81 $inserted[] = strtolower($tag);
82 }
83 }
84 }
85 }

References $DIC, and $ilDB.

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

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilTagging::$db
protected

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


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