[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/tag/ -> lib.php (summary)

Moodle tag library Tag strings : you can use any character in tags, except the comma (which is the separator) and the '\' (backslash).  Note that many spaces (or other blank characters) will get "compressed" into one. A tag string is always a rawurlencode'd string. This is the same behavior as http://del.icio.us.

Version: : $Id: lib.php,v 1.43.2.41 2008/09/19 10:02:30 scyrma Exp $
File Size: 1004 lines (36 kb)
Included or required: 7 times
Referenced: 11 times
Includes or requires: 0 files

Defines 32 functions

  tag_set()
  tag_set_add()
  tag_set_delete()
  tag_type_set()
  tag_description_set()
  tag_get()
  tag_get_tags()
  tag_get_tags_array()
  tag_get_tags_csv()
  tag_get_tags_ids()
  tag_get_id()
  tag_get_related_tags()
  tag_get_related_tags_csv()
  tag_rename()
  tag_delete()
  tag_delete_instance()
  tag_display_name()
  tag_find_records()
  tag_add()
  tag_assign()
  tag_autocomplete()
  tag_cleanup()
  tag_compute_correlations()
  tag_cron()
  tag_find_tags()
  tag_get_name()
  tag_get_correlated()
  tag_normalize()
  tag_record_count()
  tag_record_tagged_with()
  tag_set_flag()
  tag_unset_flag()

Functions
Functions that are not part of a class:

tag_set($record_type, $record_id, $tags)   X-Ref
Set the tags assigned to a record.  This overwrites the current tags.

This function is meant to be fed the string coming up from the user
interface, which contains all tags assigned to a record.

param: string $record_type the type of record to tag ('post' for blogs,
param: int $record_id the id of the record to tag
param: array $tags the array of tags to set on the record. If
return: void

tag_set_add($record_type, $record_id, $tag)   X-Ref
Adds a tag to a record, without overwriting the current tags.

param: string $record_type the type of record to tag ('post' for blogs,
param: int $record_id the id of the record to tag
param: string $tag the tag to add
return: void

tag_set_delete($record_type, $record_id, $tag)   X-Ref
Removes a tag from a record, without overwriting other current tags.

param: string $record_type the type of record to tag ('post' for blogs,
param: int $record_id the id of the record to tag
param: string $tag the tag to delete
return: void

tag_type_set($tagid, $type)   X-Ref
Set the type of a tag.  At this time (version 1.9) the possible values
are 'default' or 'official'.  Official tags will be displayed separately "at
tagging time" (while selecting the tags to apply to a record).

param: string $tagid tagid to modify
param: string $type either 'default' or 'official'
return: true on success, false otherwise

tag_description_set($tagid, $description, $descriptionformat)   X-Ref
Set the description of a tag

param: int $tagid the id of the tag
param: string $description the description
param: int $descriptionformat the moodle text format of the description
return: true on success, false otherwise

tag_get($field, $value, $returnfields='id, name, rawname')   X-Ref
Simple function to just return a single tag object when you know the name or something

param: string $field which field do we use to identify the tag: id, name or rawname
param: string $value the required value of the aforementioned field
param: string $returnfields which fields do we want returned?
return: tag object

tag_get_tags($record_type, $record_id, $type=null)   X-Ref
Get the array of db record of tags associated to a record (instances).  Use
tag_get_tags_csv to get the same information in a comma-separated string.

param: string $record_type the record type for which we want to get the tags
param: int $record_id the record id for which we want to get the tags
param: string $type the tag type (either 'default' or 'official'). By default,
return: array the array of tags

tag_get_tags_array($record_type, $record_id, $type=null)   X-Ref
Get the array of tags display names, indexed by id.

param: string $record_type the record type for which we want to get the tags
param: int $record_id the record id for which we want to get the tags
param: string $type the tag type (either 'default' or 'official'). By default,
return: array the array of tags (with the value returned by tag_display_name), indexed by id

tag_get_tags_csv($record_type, $record_id, $html=TAG_RETURN_HTML, $type=null)   X-Ref
Get a comma-separated string of tags associated to a record.  Use tag_get_tags
to get the same information in an array.

param: string $record_type the record type for which we want to get the tags
param: int $record_id the record id for which we want to get the tags
param: int $html either TAG_RETURN_HTML or TAG_RETURN_TEXT, depending
param: string $type either 'official' or 'default', if null, all tags are
return: string the comma-separated list of tags.

tag_get_tags_ids($record_type, $record_id)   X-Ref
Get an array of tag ids associated to a record.

param: string $record_type the record type for which we want to get the tags
param: int $record_id the record id for which we want to get the tags
return: array of tag ids, indexed and sorted by 'ordering'

tag_get_id($tags, $return_value=null)   X-Ref
Returns the database ID of a set of tags.

param: mixed $tags one tag, or array of tags, to look for.
param: bool $return_value specify the type of the returned value. Either
return: mixed tag-indexed array of ids (or objects, if second parameter is

tag_get_related_tags($tagid, $type=TAG_RELATED_ALL, $limitnum=10)   X-Ref
Returns tags related to a tag

Related tags of a tag come from two sources:
- manually added related tags, which are tag_instance entries for that tag
- correlated tags, which are a calculated

param: string $tag_name_or_id is a single **normalized** tag name or the id
param: int $type the function will return either manually
param: int $limitnum return a subset comprising this many records (optional,
return: array an array of tag objects

tag_get_related_tags_csv($related_tags, $html=TAG_RETURN_HTML)   X-Ref
Get a comma-separated list of tags related to another tag.

param: array $related_tags the array returned by tag_get_related_tags
param: int $html either TAG_RETURN_HTML (default) or TAG_RETURN_TEXT : return html links, or just text.
return: string comma-separated list

tag_rename($tagid, $newrawname)   X-Ref
Change the "value" of a tag, and update the associated 'name'.

param: int $tagid the id of the tag to modify
param: string $newtag the new rawname
return: bool true on success, false otherwise

tag_delete($tagids)   X-Ref
Delete one or more tag, and all their instances if there are any left.

param: mixed $tagids one tagid (int), or one array of tagids to delete
return: bool true on success, false otherwise

tag_delete_instance($record_type, $record_id, $tagid)   X-Ref
Delete one instance of a tag.  If the last instance was deleted, it will
also delete the tag, unless its type is 'official'.

param: string $record_type the type of the record for which to remove the instance
param: int $record_id the id of the record for which to remove the instance
param: int $tagid the tagid that needs to be removed
return: bool true on success, false otherwise

tag_display_name($tagobject, $html=TAG_RETURN_HTML)   X-Ref
Function that returns the name that should be displayed for a specific tag

param: object $tag_object a line out of tag table, as returned by the adobd functions
param: int $html TAG_RETURN_HTML (default) will return htmlspecialchars encoded string, TAG_RETURN_TEXT will not encode.
return: string

tag_find_records($tag, $type, $limitfrom='', $limitnum='')   X-Ref
Find all records tagged with a tag of a given type ('post', 'user', etc.)

param: string $tag tag to look for
param: string $type type to restrict search to.  If null, every matching
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: array of matching objects, indexed by record id, from the table containing the type requested

tag_add($tags, $type="default")   X-Ref
Adds one or more tag in the database.  This function should not be called
directly : you should use tag_set.

param: mixed $tags one tag, or an array of tags, to be created
param: string $type type of tag to be created ("default" is the default
return: an array of tags ids, indexed by their lowercase normalized names.

tag_assign($record_type, $record_id, $tagid, $ordering)   X-Ref
Assigns a tag to a record: if the record already exists, the time and
ordering will be updated.

param: string $record_type the type of the record that will be tagged
param: int $record_id the id of the record that will be tagged
param: string $tagid the tag id to set on the record.
param: int $ordering the order of the instance for this record
return: bool true on success, false otherwise

tag_autocomplete($text)   X-Ref
Function that returns tags that start with some text, for use by the autocomplete feature

param: string $text string that the tag names will be matched against
return: mixed an array of objects, or false if no records were found or an error occured.

tag_cleanup()   X-Ref
Clean up the tag tables, making sure all tagged object still exists.

This should normally not be necessary, but in case related tags are not deleted
when the tagged record is removed, this should be done once in a while, perhaps on
an occasional cron run.  On a site with lots of tags, this could become an expensive
function to call: don't run at peak time.

tag_compute_correlations($min_correlation=2)   X-Ref
Calculates and stores the correlated tags of all tags.
The correlations are stored in the 'tag_correlation' table.

Two tags are correlated if they appear together a lot.
Ex.: Users tagged with "computers" will probably also be tagged with "algorithms".

The rationale for the 'tag_correlation' table is performance.
It works as a cache for a potentially heavy load query done at the 'tag_instance' table.
So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table.

param: number $min_correlation cutoff percentage (optional, default is 2)

tag_cron()   X-Ref
Tasks that should be performed at cron time


tag_find_tags($text, $ordered=true, $limitfrom='', $limitnum='')   X-Ref
Search for tags with names that match some text

param: string $text escaped string that the tag names will be matched against
param: boolean $ordered If true, tags are ordered by their popularity. If false, no ordering.
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: mixed an array of objects, or false if no records were found or an error occured.

tag_get_name($tagids)   X-Ref
Get the name of a tag

param: mixed $tagids the id of the tag, or an array of ids
return: mixed string name of one tag, or id-indexed array of strings

tag_get_correlated($tag_id, $limitnum=null)   X-Ref
Returns the correlated tags of a tag, retrieved from the tag_correlation
table.  Make sure cron runs, otherwise the table will be empty and this
function won't return anything.

param: int $tag_id is a single tag id
return: array an array of tag objects, empty if no correlated tags are found

tag_normalize($rawtags, $case = TAG_CASE_LOWER)   X-Ref
Function that normalizes a list of tag names.

param: mixed $tags array of tags, or a single tag.
param: int $case case to use for returned value (default: lower case).
return: array of lowercased normalized tags, indexed by the normalized tag,

tag_record_count($record_type, $tagid)   X-Ref
Count how many records are tagged with a specific tag,

param: string $record record to look for ('post', 'user', etc.)
param: int $tag is a single tag id
return: int number of mathing tags.

tag_record_tagged_with($record_type, $record_id, $tag)   X-Ref
Determine if a record is tagged with a specific tag

param: string $record_type the record type to look for
param: int $record_id the record id to look for
param: string $tag a tag name
return: bool true if it is tagged, false otherwise

tag_set_flag($tagids)   X-Ref
Flag a tag as inapropriate

param: mixed $tagids one (int) tagid, or an array of tagids
return: void

tag_unset_flag($tagids)   X-Ref
Remove the inapropriate flag on a tag

param: mixed $tagids one (int) tagid, or an array of tagids
return: bool true if function succeeds, false otherwise



Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7