Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Public Member Functions | |
__get ($name) | |
Magic getter. More... | |
__isset ($name) | |
Magic isset method. More... | |
add_related_tags ($tagnames) | |
Adds to the list of related tags without removing existing. More... | |
combine_tags ($tags) | |
Combines several other tags into this one. More... | |
count_tagged_items ($component, $itemtype, $subquery='', $params=array()) | |
Count how many items are tagged with a specific tag. More... | |
flag () | |
Flag a tag as inappropriate. | |
get_correlated_tags ($keepduplicates=false) | |
Returns the correlated tags of a tag, retrieved from the tag_correlation table. More... | |
get_display_name ($ashtml=true) | |
Returns tag name ready to be displayed. More... | |
get_formatted_description ($options=array()) | |
Returns formatted description of the tag. More... | |
get_links () | |
Returns the list of tag links available for the current user (edit, flag, etc.) More... | |
get_manual_related_tags () | |
Returns tags that this tag was manually set as related to. More... | |
get_related_tags () | |
Returns tags related to a tag. More... | |
get_tag_index ($tagarea, $exclusivemode, $fromctx, $ctx, $rec, $page=0) | |
Retrieves contents of tag area for the tag/index.php page. More... | |
get_tagged_items ($component, $itemtype, $limitfrom='', $limitnum='', $subquery='', $params=array()) | |
Find all items tagged with a tag of a given type ('post', 'user', etc.) More... | |
get_view_url ($exclusivemode=0, $fromctx=0, $ctx=0, $rec=1) | |
Returns URL to view the tag. More... | |
reset_flag () | |
Remove the inappropriate flag on a tag. | |
set_related_tags ($tagnames) | |
Sets the list of tags related to this one. More... | |
to_object () | |
Converts to object. More... | |
update ($data) | |
Updates the information about the tag. More... | |
Static Public Member Functions | |
static | add_item_tag ($component, $itemtype, $itemid, context $context, $tagname, $tiuserid=0) |
Adds a tag to an item, without overwriting the current tags. More... | |
static | change_instances_context (array $taginstanceids, context $newcontext) |
Moves all of the specified tag instances into a new context. More... | |
static | change_items_context ($component, $itemtype, $itemids, $newcontext) |
Moves all tags of the specified items to the new context. More... | |
static | create_if_missing ($tagcollid, $tags, $isstandard=false) |
Retrieves tags and/or creates them if do not exist yet. More... | |
static | delete_instances ($component, $itemtype=null, $contextid=null) |
Bulk delete all tag instances for a component or tag area. More... | |
static | delete_instances_as_record (array $taginstances) |
Bulk delete all tag instances. More... | |
static | delete_instances_by_id (array $taginstanceids) |
Bulk delete all tag instances by tag id. More... | |
static | delete_tags ($tagids) |
Delete one or more tag, and all their instances if there are any left. More... | |
static | get ($id, $returnfields='id, name, rawname, tagcollid', $strictness=IGNORE_MISSING) |
Simple function to just return a single tag object by its id. More... | |
static | get_bulk ($ids, $returnfields='id, name, rawname, tagcollid') |
Simple function to just return an array of tag objects by their ids. More... | |
static | get_by_name ($tagcollid, $name, $returnfields='id, name, rawname, tagcollid', $strictness=IGNORE_MISSING) |
Simple function to just return a single tag object by tagcollid and name. More... | |
static | get_by_name_bulk ($tagcollid, $tags, $returnfields='id, name, rawname, tagcollid') |
Returns the list of tag objects by tag collection id and the list of tag names. More... | |
static | get_item_tags ($component, $itemtype, $itemid, $standardonly=self::BOTH_STANDARD_AND_NOT, $tiuserid=0) |
Get the array of core_tag_tag objects associated with an item (instances). More... | |
static | get_item_tags_array ($component, $itemtype, $itemid, $standardonly=self::BOTH_STANDARD_AND_NOT, $tiuserid=0, $ashtml=true) |
Returns the list of display names of the tags that are associated with an item. More... | |
static | get_items_tags ($component, $itemtype, $itemids, $standardonly=self::BOTH_STANDARD_AND_NOT, $tiuserid=0) |
Get the array of core_tag_tag objects associated with a list of items. More... | |
static | get_tags_by_area_in_contexts ($component, $itemtype, array $contexts) |
Retrieve a list of tags that have been used to tag the given $component and $itemtype in the provided $contexts. More... | |
static | guess_by_name ($name, $returnfields='id, name, rawname, tagcollid') |
Looking in all tag collections for the tag with the given name. More... | |
static | is_enabled ($component, $itemtype) |
Returns whether the tag area is enabled. More... | |
static | is_item_tagged_with ($component, $itemtype, $itemid, $tagname) |
Determine if an item is tagged with a specific tag. More... | |
static | make_display_name ($tag, $ashtml=true) |
Prepares tag name ready to be displayed. More... | |
static | make_url ($tagcollid, $name, $exclusivemode=0, $fromctx=0, $ctx=0, $rec=1) |
Creates a URL to view a tag. More... | |
static | move_context ($component, $itemtype, $oldcontext, $newcontext) |
Allows to move all tag instances from one context to another. More... | |
static | normalize ($rawtags, $tolowercase=true) |
Function that normalizes a list of tag names. More... | |
static | remove_all_item_tags ($component, $itemtype, $itemid, $tiuserid=0) |
Removes all tags from an item. More... | |
static | remove_item_tag ($component, $itemtype, $itemid, $tagname, $tiuserid=0) |
Removes the tag from an item without changing the other tags. More... | |
static | set_item_tags ($component, $itemtype, $itemid, context $context, $tagnames, $tiuserid=0) |
Sets the list of tag instances for one item (table record). More... | |
Public Attributes | |
int const | BOTH_STANDARD_AND_NOT = 0 |
indicates that both standard and not standard tags can be used (or should be returned) | |
int const | HIDE_STANDARD = 2 |
option to hide standard tags when editing item tags | |
int const | NOT_STANDARD_ONLY = -1 |
indicates that only non-standard tags should be returned - this does not really have use cases, left for BC | |
int const | STANDARD_ONLY = 1 |
indicates that only standard tags can be used (or must be returned) | |
Protected Member Functions | |
__construct ($record) | |
Constructor. More... | |
add_instance ($component, $itemtype, $itemid, context $context, $ordering, $tiuserid=0) | |
Adds a tag instance. More... | |
combine_correlated_tags ($tags) | |
Combine together correlated tags of several tags. More... | |
delete_instance ($component, $itemtype, $itemid, $tiuserid=0) | |
Delete one instance of a tag. More... | |
delete_instance_as_record ($taginstance, $fullobject=false) | |
Deletes the tag instance given the record from tag_instance DB table. More... | |
ensure_fields_exist ($list, $caller) | |
Validates that the required fields were retrieved and retrieves them if missing. More... | |
update_instance_ordering ($instanceid, $ordering) | |
Updates the ordering on tag instance. More... | |
Static Protected Member Functions | |
static | add ($tagcollid, $tags, $isstandard=false) |
Adds one or more tag in the database. More... | |
Protected Attributes | |
stdClass | $record = null |
data about the tag | |
|
protected |
core_tag_tag::__get | ( | $name | ) |
Magic getter.
string | $name |
mixed |
core_tag_tag::__isset | ( | $name | ) |
Magic isset method.
string | $name |
bool |
|
staticprotected |
Adds one or more tag in the database.
This function should not be called directly : you should use tag_set.
int | $tagcollid | |
string | array | $tags | one tag, or an array of tags, to be created |
bool | $isstandard | type of tag to be created. A standard tag is kept even if there are no records tagged with it. |
array | tag objects indexed by their lowercase normalized names. Any boolean false in the array indicates an error while adding the tag. |
|
protected |
Adds a tag instance.
string | $component | |
string | $itemtype | |
string | $itemid | |
context | $context | |
int | $ordering | |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
int | id of tag_instance |
|
static |
Adds a tag to an item, without overwriting the current tags.
If the tag has already been added to the record, no changes are made.
string | $component | the component that was tagged |
string | $itemtype | the type of record to tag ('post' for blogs, 'user' for users, etc.) |
int | $itemid | the id of the record to tag |
context | $context | the context of where this tag was assigned |
string | $tagname | the tag to add |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
int | id of tag_instance that was either created or already existed or null if tagging is not enabled |
core_tag_tag::add_related_tags | ( | $tagnames | ) |
Adds to the list of related tags without removing existing.
Tag relations are recorded by two instances linking two tags to each other. For tag relations ordering is not used and may be random.
array | $tagnames |
|
static |
Moves all of the specified tag instances into a new context.
array | $taginstanceids | The list of tag instance ids that should be moved |
context | $newcontext | The context to move the tag instances into |
|
static |
Moves all tags of the specified items to the new context.
string | $component | the component that was tagged |
string | $itemtype | the type of record to tag ('post' for blogs, 'user' for users, etc.) |
array | $itemids | |
context | int | $newcontext | target context to move tags to |
|
protected |
Combine together correlated tags of several tags.
This is a help method for method combine_tags()
core_tag_tag[] | $tags |
core_tag_tag::combine_tags | ( | $tags | ) |
Combines several other tags into this one.
Combining rules:
core_tag_tag[] | $tags | tags to combine into this one |
core_tag_tag::count_tagged_items | ( | $component, | |
$itemtype, | |||
$subquery = '' , |
|||
$params = array() |
|||
) |
Count how many items are tagged with a specific tag.
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | type to restrict search to |
string | $subquery | additional query to be appended to WHERE clause, refer to the itemtable as 'it' |
array | $params | additional parameters for the DB query |
int | number of mathing tags. |
|
static |
Retrieves tags and/or creates them if do not exist yet.
int | $tagcollid | |
array | $tags | array of raw tag names, do not have to be normalised |
bool | $isstandard | create as standard tag (default false) |
core_tag_tag[] | array of tag objects indexed with lowercase normalised tag name |
|
protected |
Delete one instance of a tag.
If the last instance was deleted, it will also delete the tag, unless it is standard.
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | the type of the record for which to remove the instance |
int | $itemid | the id of the record for which to remove the instance |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
|
protected |
Deletes the tag instance given the record from tag_instance DB table.
stdClass | $taginstance | |
bool | $fullobject | whether $taginstance contains all fields from DB table tag_instance (in this case it is safe to add a record snapshot to the event) |
bool |
|
static |
Bulk delete all tag instances for a component or tag area.
string | $component | |
string | $itemtype | (optional) |
int | $contextid | (optional) |
|
static |
Bulk delete all tag instances.
stdClass[] | $taginstances | A list of tag_instance records to delete. Each record must also contain the name and rawname columns from the related tag record. |
|
static |
Bulk delete all tag instances by tag id.
int[] | $taginstanceids | List of tag instance ids to be deleted. |
|
static |
Delete one or more tag, and all their instances if there are any left.
int | array | $tagids | one tagid (int), or one array of tagids to delete |
bool | true on success, false otherwise |
|
protected |
Validates that the required fields were retrieved and retrieves them if missing.
array | $list | array of the fields that need to be validated |
string | $caller | name of the function that requested it, for the debugging message |
|
static |
Simple function to just return a single tag object by its id.
int | $id | |
string | $returnfields | which fields do we want returned from table {tag}. Default value is 'id,name,rawname,tagcollid', specify '*' to include all fields. |
int | $strictness | IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found |
core_tag_tag|false | tag object |
|
static |
Simple function to just return an array of tag objects by their ids.
int[] | $ids | |
string | $returnfields | which fields do we want returned from table {tag}. Default value is 'id,name,rawname,tagcollid', specify '*' to include all fields. |
core_tag_tag[] | array of retrieved tags |
|
static |
Simple function to just return a single tag object by tagcollid and name.
int | $tagcollid | tag collection to use, if 0 is given we will try to guess the tag collection and return the first match |
string | $name | tag name |
string | $returnfields | which fields do we want returned. This is a comma separated string containing any combination of 'id', 'name', 'rawname', 'tagcollid' or '*' to include all fields. |
int | $strictness | IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found |
core_tag_tag|false | tag object |
|
static |
Returns the list of tag objects by tag collection id and the list of tag names.
int | $tagcollid | |
array | $tags | array of tags to look for |
string | $returnfields | list of DB fields to return, must contain 'id', 'name' and 'rawname' |
array | tag-indexed array of objects. No value for a key means the tag wasn't found. |
core_tag_tag::get_correlated_tags | ( | $keepduplicates = false | ) |
Returns the correlated tags of a tag, retrieved from the tag_correlation table.
Correlated tags are calculated in cron based on existing tag instances.
bool | $keepduplicates | if true, will return one record for each existing tag instance which may result in duplicates of the actual tags |
core_tag_tag[] | an array of tag objects |
core_tag_tag::get_display_name | ( | $ashtml = true | ) |
Returns tag name ready to be displayed.
bool | $ashtml | (default true) if true will return htmlspecialchars encoded string |
string |
core_tag_tag::get_formatted_description | ( | $options = array() | ) |
Returns formatted description of the tag.
array | $options |
string |
|
static |
Get the array of core_tag_tag objects associated with an item (instances).
Use core_tag_tag::get_item_tags_array() if you wish to get the same data as simple array.
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | type of the tagged item |
int | $itemid | |
int | $standardonly | wether to return only standard tags or any |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging |
core_tag_tag[] | each object contains additional fields taginstanceid, taginstancecontextid and ordering |
|
static |
Returns the list of display names of the tags that are associated with an item.
This method is usually used to prefill the form data for the 'tags' form element
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | type of the tagged item |
int | $itemid | |
int | $standardonly | wether to return only standard tags or any |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging |
bool | $ashtml | (default true) if true will return htmlspecialchars encoded tag names |
string[] | array of tags display names |
|
static |
Get the array of core_tag_tag objects associated with a list of items.
Use core_tag_tag::get_item_tags_array() if you wish to get the same data as simple array.
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | type of the tagged item |
int[] | $itemids | |
int | $standardonly | wether to return only standard tags or any |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging |
core_tag_tag[][] | first array key is itemid. For each itemid, an array tagid => tag object with additional fields taginstanceid, taginstancecontextid and ordering |
core_tag_tag::get_links | ( | ) |
Returns the list of tag links available for the current user (edit, flag, etc.)
array |
core_tag_tag::get_manual_related_tags | ( | ) |
Returns tags that this tag was manually set as related to.
core_tag_tag[] |
core_tag_tag::get_related_tags | ( | ) |
Returns tags related to a tag.
Related tags of a tag come from two sources:
core_tag_tag[] | an array of tag objects |
core_tag_tag::get_tag_index | ( | $tagarea, | |
$exclusivemode, | |||
$fromctx, | |||
$ctx, | |||
$rec, | |||
$page = 0 |
|||
) |
Retrieves contents of tag area for the tag/index.php page.
stdClass | $tagarea | |
bool | $exclusivemode | if set to true it means that no other entities tagged with this tag are displayed on the page and the per-page limit may be bigger |
int | $fromctx | context id where the link was displayed, may be used by callbacks to display items in the same context first |
int | $ctx | context id where to search for records |
bool | $rec | search in subcontexts as well |
int | $page | 0-based number of page being displayed |
core_tag |
core_tag_tag::get_tagged_items | ( | $component, | |
$itemtype, | |||
$limitfrom = '' , |
|||
$limitnum = '' , |
|||
$subquery = '' , |
|||
$params = array() |
|||
) |
Find all items tagged with a tag of a given type ('post', 'user', etc.)
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | type to restrict search to |
int | $limitfrom | (optional, required if $limitnum is set) return a subset of records, starting at this point. |
int | $limitnum | (optional, required if $limitfrom is set) return a subset comprising this many records. |
string | $subquery | additional query to be appended to WHERE clause, refer to the itemtable as 'it' |
array | $params | additional parameters for the DB query |
array | of matching objects, indexed by record id, from the table containing the type requested |
|
static |
Retrieve a list of tags that have been used to tag the given $component and $itemtype in the provided $contexts.
string | $component | The tag instance component |
string | $itemtype | The tag instance item type |
context[] | $contexts | The list of contexts to look for tag instances in |
core_tag_tag[] |
core_tag_tag::get_view_url | ( | $exclusivemode = 0 , |
|
$fromctx = 0 , |
|||
$ctx = 0 , |
|||
$rec = 1 |
|||
) |
Returns URL to view the tag.
int | $exclusivemode | |
int | $fromctx | context id where this tag cloud is displayed |
int | $ctx | context id for tag view link |
int | $rec | recursive argument for tag view link |
moodle_url |
|
static |
Looking in all tag collections for the tag with the given name.
string | $name | tag name |
string | $returnfields |
array | array of core_tag_tag instances |
|
static |
Returns whether the tag area is enabled.
string | $component | component responsible for tagging |
string | $itemtype | what is being tagged, for example, 'post', 'course', 'user', etc. |
bool|null |
|
static |
Determine if an item is tagged with a specific tag.
Note that this is a static method and not a method of core_tag object because the tag might not exist yet, for example user searches for "php" and we offer him to add "php" to his interests.
string | $component | component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. |
string | $itemtype | the record type to look for |
int | $itemid | the record id to look for |
string | $tagname | a tag name |
int | 1 if it is tagged, 0 otherwise |
|
static |
Prepares tag name ready to be displayed.
stdClass | core_tag_tag | $tag | record from db table tag, must contain properties name and rawname |
bool | $ashtml | (default true) if true will return htmlspecialchars encoded string |
string |
|
static |
Creates a URL to view a tag.
int | $tagcollid | |
string | $name | |
int | $exclusivemode | |
int | $fromctx | context id where this tag cloud is displayed |
int | $ctx | context id for tag view link |
int | $rec | recursive argument for tag view link |
moodle_url |
|
static |
Allows to move all tag instances from one context to another.
string | $component | the component that was tagged |
string | $itemtype | the type of record to tag ('post' for blogs, 'user' for users, etc.) |
context | $oldcontext | |
context | $newcontext |
|
static |
Function that normalizes a list of tag names.
array | $rawtags | array of tags |
bool | $tolowercase | convert to lower case? |
array | lowercased normalized tags, indexed by the normalized tag, in the same order as the original array. (Eg: 'Banana' => 'banana'). |
|
static |
Removes all tags from an item.
All tags will be removed even if tagging is disabled in this area. This is usually called when the item itself has been deleted.
string | $component | component responsible for tagging |
string | $itemtype | type of the tagged item |
int | $itemid | |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
|
static |
Removes the tag from an item without changing the other tags.
string | $component | the component that was tagged |
string | $itemtype | the type of record to tag ('post' for blogs, 'user' for users, etc.) |
int | $itemid | the id of the record to tag |
string | $tagname | the tag to remove |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
|
static |
Sets the list of tag instances for one item (table record).
Extra exsisting instances are removed, new ones are added. New tags are created if needed.
This method can not be used for setting tags relations, please use set_related_tags()
string | $component | component responsible for tagging |
string | $itemtype | type of the tagged item |
int | $itemid | |
context | $context | |
array | $tagnames | |
int | $tiuserid | tag instance user id, only needed for tag areas with user tagging (such as core/course) |
core_tag_tag::set_related_tags | ( | $tagnames | ) |
Sets the list of tags related to this one.
Tag relations are recorded by two instances linking two tags to each other. For tag relations ordering is not used and may be random.
array | $tagnames |
core_tag_tag::to_object | ( | ) |
Converts to object.
stdClass |
core_tag_tag::update | ( | $data | ) |
Updates the information about the tag.
array | stdClass | $data | data to update, may contain: isstandard, description, descriptionformat, rawname |
bool | whether the tag was updated. False may be returned if: all new values match the existing, or it was attempted to rename the tag to the name that is already used. |
|
protected |
Updates the ordering on tag instance.
int | $instanceid | |
int | $ordering |