Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Tag API before 3.1: Difference between revisions

From MoodleDocs
(Adding tag example)
(Removing the Tag_Correlation table as I don't yet have a clear understanding of what it is used for as it isn't currently being populated in my tests.)
Line 208: Line 208:
| 0
| 0
|
|
|}
===Tag_Correlation===
This table only exists for performance reasons
{| class="nicetable"
|-
! Field
! Type
! Default
! Info
|-
| id
| int(10)
| auto-incrementing
| The unique ID for this tag correlation.
|-
| tagid
| int(10)
|
| The the id of the tag
|-
| correlatedtags
| text
|
|
|}
|}


==See also==
==See also==

Revision as of 16:32, 23 January 2012

Moodle 2.0


WORK IN PROGRESS: I've currently just created a template, so please ignore this page until this wip notices has been removed. However, you are free to help in the construction of this page by improving it. Please review the edit history if you would like to contact the user who put up this notice. If this article has not been edited by that user in a while, please remove this template.


Tag API overview

The Tag API has been implemented in lib/moodlelib.php.

examplefunction()

Example function description.

Tag API Usage

Example

$id = mt_rand(1000000000, 9999999999); // Generating a key that is unlikely to be taken

tag_set('foo_user', $id, array()); // Delete all foo_user->$id tags by passing an empty array tag_get_tags('foo_user', $id); // returns an empty array()

tag_set_add('foo_user', $id, 'chess'); // Add chess to the list of tags for foo_user->$id tag_get_tags('foo_user', $id); /* returns: Array (

   [14] => stdClass Object
       (
           [id] => 14
           [tagtype] => default
           [name] => chess
           [rawname] => chess
           [flag] => 0
           [ordering] => 0
       )

)

  • /

tag_set_delete('foo_user', $id, 'chess'); //Delete the chess tag for foo_user->$id tag_get_tags('foo_user', $id); // returns an empty array()


br(""); tag_set('foo_user', $id, array('table tennis', 'foosball', 'programming')); //Add some more tags for foo_user->$id $tags = tag_get_tags('foo_user', $id); /* $tags = Array (

   [15] => stdClass Object
       (
           [id] => 15
           [tagtype] => official
           [name] => table tennis
           [rawname] => table tennis
           [flag] => 0
           [ordering] => 0
       )
   [16] => stdClass Object
       (
           [id] => 16
           [tagtype] => default
           [name] => foosball
           [rawname] => foosball
           [flag] => 0
           [ordering] => 1
       )
   [17] => stdClass Object
       (
           [id] => 17
           [tagtype] => default
           [name] => programming
           [rawname] => programming
           [flag] => 0
           [ordering] => 2
       )

)

  • /

$firstTagKey = key($tags); // Grab the first key (which happens to be the key for table tennis). tag_type_set($firstTagKey, 'official'); // Make table tennis an official tag // output only official foo_user->$id tags tag_get_tags('foo_user', $id, 'official'); /* Returns: Array (

   [15] => stdClass Object
       (
           [id] => 15
           [tagtype] => official
           [name] => table tennis
           [rawname] => table tennis
           [flag] => 0
           [ordering] => 0
       )

)

  • /

// Set a description for the table tennis tag.

tag_description_set($firstTagKey, '

Another name for wiff-waff"

', FORMAT_HTML);

// Output a tag cloud for all tags in the system. tag_print_cloud();

Tag API database tables

Tag

This table holds all of the tags which are currently available in the system.

Field Type Default Info
id int(10) auto-incrementing The unique ID for this Tag.
userid int(10) The user that the Tag belongs to
name varchar(255) null
rawname varchar(255)
tagtype varchar(255) NULL null
description text NULL
descriptionformat tinyint(2) unsigned 0
flag smallint(4) 0
timemodified bigint(10)

Tag_Instance

This table is use to record the instances of each tag's use. It has a many to one relationship with the tag table shown above.

Field Type Default Info
id int(10) auto-incrementing The unique ID for this Tag.
tagid int(10) The user that the Tag belongs to
itemtype varchar(255) null
itemid int(10)
tiuserid int(10) 0 ???The userid of the user which owns the tag instance???
ordering int(10)
timemodified int(10) 0

See also