ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilTagging Class Reference

Class ilTagging. More...

+ Collaboration diagram for ilTagging:

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...
 

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.

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

370 {
371 global $ilDB, $ilUser;
372
373 $q = "SELECT count(*) c, obj_id FROM il_tag WHERE ".
374 $ilDB->in("obj_id", $a_obj_ids, false, "integer");
375 if(!(bool)$a_all_users)
376 {
377 $q .= " AND user_id = ".$ilDB->quote($ilUser->getId(), "integer");
378 }
379 $q .= " GROUP BY obj_id";
380
381 $cnt = array();
382 $set = $ilDB->query($q);
383 while ($rec = $ilDB->fetchAssoc($set))
384 {
385 $cnt[$rec["obj_id"]] = $rec["c"];
386 }
387
388 return $cnt;
389 }
global $ilDB
$ilUser
Definition: imgupload.php:18

References $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 455 of file class.ilTagging.php.

456 {
457 global $ilDB;
458
459 $res = array();
460
461 $sql = "SELECT obj_id, obj_type".
462 " FROM il_tag".
463 " WHERE tag = ".$ilDB->quote($a_tag, "text").
464 " AND is_offline = ".$ilDB->quote(0, "integer");
465 if($a_user_id)
466 {
467 if(!$a_invert)
468 {
469 $sql .= " AND user_id = ".$ilDB->quote($a_user_id, "integer");
470 }
471 else
472 {
473 $sql .= " AND user_id <> ".$ilDB->quote($a_user_id, "integer");
474 }
475 }
476 $set = $ilDB->query($sql);
477 while($row = $ilDB->fetchAssoc($set))
478 {
479 $res[$row["obj_id"]] = $row["obj_type"];
480 }
481
482 return $res;
483 }

References $ilDB, $res, and $row.

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

493 {
494 global $ilDB, $ilUser;
495
496 $res = array();
497
498 $sql = "SELECT obj_id, tag, user_id".
499 " FROM il_tag".
500 " WHERE ".$ilDB->in("obj_id", $a_obj_ids, false, "integer").
501 " AND is_offline = ".$ilDB->quote(0, "integer");
502 if($a_user_id)
503 {
504 $sql .= " AND user_id = ".$ilDB->quote($a_user_id, "integer");
505 }
506 $sql .= " ORDER BY tag";
507 $set = $ilDB->query($sql);
508 while($row = $ilDB->fetchAssoc($set))
509 {
510 $tag = $row["tag"];
511 $res[$row["obj_id"]][$tag] = false;
512 if($row["user_id"] == $ilUser->getId())
513 {
514 $res[$row["obj_id"]][$tag] = true;
515 }
516 }
517
518 return $res;
519 }

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

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

400 {
401 global $ilDB;
402
403 $res = array();
404
405 $sql = "SELECT obj_id, obj_type, tag, user_id".
406 " FROM il_tag".
407 " WHERE ".$ilDB->in("obj_id", array_keys($a_obj_ids), false, "integer").
408 " AND is_offline = ".$ilDB->quote(0, "integer");
409 if($a_user_id)
410 {
411 $sql .= " AND user_id = ".$ilDB->quote($a_user_id, "integer");
412 }
413 $sql .= " ORDER BY tag";
414 $set = $ilDB->query($sql);
415 while($row = $ilDB->fetchAssoc($set))
416 {
417 if($a_obj_ids[$row["obj_id"]] == $row["obj_type"])
418 {
419 $tag = $row["tag"];
420
421 if($a_divide)
422 {
423 if($row["user_id"] == $a_divide)
424 {
425 $res["personal"][$tag] = isset($res["personal"][$tag])
426 ? $res["personal"][$tag]++
427 : 1;
428 }
429 else
430 {
431 $res["other"][$tag] = isset($res["other"][$tag])
432 ? $res["other"][$tag]++
433 : 1;
434 }
435 }
436 else
437 {
438 $res[$tag] = isset($res[$tag])
439 ? $res[$tag]++
440 : 1;
441 }
442 }
443 }
444
445 return $res;
446 }

References $ilDB, $res, and $row.

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

221 {
222 $m = ($max == 1)
223 ? 0
224 : 50 / ($max - 1);
225 $a = 100 - $m;
226 $font_size = round($a + ($m * $cnt));
227 return (int) $font_size;
228 }

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

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

References $ilDB.

Referenced by ilPDTaggingBlockGUI\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 293 of file class.ilTagging.php.

294 {
295 global $ilDB;
296
297 if ($a_sub_obj_type == "")
298 {
299 $a_sub_obj_type = "-";
300 }
301
302 $ilDB->manipulateF("DELETE FROM il_tag ".
303 "WHERE ".
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),
308 array("integer", "text", "integer"),
309 array($a_obj_id, $a_obj_type, $a_sub_obj_id));
310 }

References $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 178 of file class.ilTagging.php.

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

Referenced by ilPDTaggingBlockGUI\removeTagsWithoutAccess(), and ilPDTaggingBlockGUI\showResourcesForTag().

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

234 {
235 $m = $cnt / $max;
236 if ($m >= 0.8)
237 {
238 return "ilTagRelVeryHigh";
239 }
240 else if ($m >= 0.6)
241 {
242 return "ilTagRelHigh";
243 }
244 else if ($m >= 0.4)
245 {
246 return "ilTagRelMiddle";
247 }
248 else if ($m >= 0.2)
249 {
250 return "ilTagRelLow";
251 }
252
253 return "ilTagRelVeryLow";
254 }

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML(), ilPDTaggingBlockGUI\getTagCloud(), ilTaggingClassificationProvider\render(), and ilObjBlogGUI\renderNavigationByKeywords().

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

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

References $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 148 of file class.ilTagging.php.

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

References $ilDB, and ilUtil\sortArray().

Referenced by ilPDTaggingBlockGUI\fillDataSection().

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

79 {
80 global $ilDB;
81
82 if ($a_sub_obj_type == "")
83 {
84 $a_sub_obj_type = "-";
85 }
86
87 $q = "SELECT * FROM il_tag WHERE ".
88 "user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
89 "obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
90 "obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
91 "sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
92 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true).
93 " ORDER BY tag ASC";
94 $set = $ilDB->query($q);
95 $tags = array();
96 while($rec = $ilDB->fetchAssoc($set))
97 {
98 $tags[] = $rec["tag"];
99 }
100
101 return $tags;
102 }

References $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 346 of file class.ilTagging.php.

347 {
348 global $DIC;
349 $ilDB = $DIC->database();
350
351 $set = $ilDB->query("SELECT DISTINCT user_id, firstname, lastname FROM il_tag JOIN usr_data ON (user_id = usr_id) ".
352 " WHERE LOWER(tag) = LOWER(".$ilDB->quote($a_tag, "text").")".
353 " ORDER BY lastname, firstname"
354 );
355 $users = array();
356 while ($rec = $ilDB->fetchAssoc($set))
357 {
358 $users[] = array("id" => $rec["user_id"]);
359 }
360 return $users;
361 }
global $DIC

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

267 {
268 global $ilDB;
269
270 if ($a_sub_obj_type == "")
271 {
272 $a_sub_obj_type = "-";
273 }
274
275 $ilDB->manipulateF("UPDATE il_tag SET is_offline = %s ".
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("boolean", "integer", "text", "integer"),
282 array($a_offline, $a_obj_id, $a_obj_type, $a_sub_obj_id));
283 }

References $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 27 of file class.ilTagging.php.

29 {
30 global $ilDB;
31
32 if ($a_sub_obj_type == "")
33 {
34 $a_sub_obj_type = "-";
35 }
36
37 $ilDB->manipulate("DELETE FROM il_tag WHERE ".
38 "user_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
39 "obj_id = ".$ilDB->quote($a_obj_id, "integer")." AND ".
40 "obj_type = ".$ilDB->quote($a_obj_type, "text")." AND ".
41 "sub_obj_id = ".$ilDB->quote((int) $a_sub_obj_id, "integer")." AND ".
42 $ilDB->equals("sub_obj_type", $a_sub_obj_type, "text", true));
43 //"sub_obj_type = ".$ilDB->quote($a_sub_obj_type, "text"));
44
45 if (is_array($a_tags))
46 {
47 $inserted = array();
48 foreach($a_tags as $tag)
49 {
50 if (!in_array(strtolower($tag), $inserted))
51 {
52 //$tag = str_replace(" ", "_", trim($tag));
53 $ilDB->manipulate("INSERT INTO il_tag (user_id, obj_id, obj_type,".
54 "sub_obj_id, sub_obj_type, tag) VALUES (".
55 $ilDB->quote($a_user_id, "integer").",".
56 $ilDB->quote($a_obj_id, "integer").",".
57 $ilDB->quote($a_obj_type, "text").",".
58 $ilDB->quote((int) $a_sub_obj_id, "integer").",".
59 $ilDB->quote($a_sub_obj_type, "text").",".
60 $ilDB->quote($tag, "text").")");
61
62 $inserted[] = strtolower($tag);
63 }
64 }
65 }
66 }

References $ilDB.

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: