ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilTagging Class Reference

Class ilTagging. More...

+ Collaboration diagram for ilTagging:

Public Member Functions

 getUsersForTag ($a_tag)
 Get users for tag. 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 _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 368 of file class.ilTagging.php.

References $ilDB, and $ilUser.

Referenced by ilObjectListGUI\preloadCommonProperties().

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

References $ilDB, $res, and $row.

Referenced by ilTaggingClassificationProvider\getFilteredObjects().

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

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

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

492  {
493  global $ilDB, $ilUser;
494 
495  $res = array();
496 
497  $sql = "SELECT obj_id, tag, user_id".
498  " FROM il_tag".
499  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, false, "integer").
500  " AND is_offline = ".$ilDB->quote(0, "integer");
501  if($a_user_id)
502  {
503  $sql .= " AND user_id = ".$ilDB->quote($a_user_id, "integer");
504  }
505  $sql .= " ORDER BY tag";
506  $set = $ilDB->query($sql);
507  while($row = $ilDB->fetchAssoc($set))
508  {
509  $tag = $row["tag"];
510  $res[$row["obj_id"]][$tag] = false;
511  if($row["user_id"] == $ilUser->getId())
512  {
513  $res[$row["obj_id"]][$tag] = true;
514  }
515  }
516 
517  return $res;
518  }
global $ilUser
Definition: imgupload.php:15
global $ilDB
+ 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 398 of file class.ilTagging.php.

References $ilDB, $res, and $row.

Referenced by ilTaggingClassificationProvider\getSubTreeTags().

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

References $ilDB.

Referenced by ilPDTaggingBlockGUI\removeTagsWithoutAccess().

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  }
global $ilDB
+ 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.

References $ilDB.

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

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  }
global $ilDB
+ 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.

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

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

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
static deleteTagsOfObject($a_obj_id, $a_obj_type, $a_sub_obj_id, $a_sub_obj_type)
Deletes tags of an object.
global $ilDB
+ 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.

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

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

References $ilDB.

Referenced by ilTaggingGUI\getAllUserTagsForObjectHTML().

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  }
global $ilDB
+ 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.

References $ilDB, and ilUtil\sortArray().

Referenced by ilPDTaggingBlockGUI\fillDataSection().

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
global $ilDB
+ 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.

References $ilDB.

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

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  }
global $ilDB
+ Here is the caller graph for this function:

◆ getUsersForTag()

ilTagging::getUsersForTag (   $a_tag)

Get users for tag.

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

References $ilDB.

Referenced by ilUserForTagTableGUI\__construct().

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

References $ilDB.

Referenced by ilTaggingAppEventListener\handleEvent().

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  }
global $ilDB
+ 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.

References $ilDB.

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

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  }
global $ilDB
+ Here is the caller graph for this function:

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