Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

Class to manage tag collections

Copyright: 2015 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 418 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

core_tag_collection:: (14 methods):
  get_collections()
  get_by_id()
  get_collections_menu()
  get_default()
  display_name()
  get_areas()
  get_areas_names()
  create()
  update()
  delete()
  change_sortorder()
  cleanup_unused_tags()
  get_tag_cloud()
  cloud_sort()


Class: core_tag_collection  - X-Ref

Class to manage tag collections

get_collections($onlysearchable = false)   X-Ref
Returns the list of tag collections defined in the system.

param: bool $onlysearchable only return collections that can be searched.
return: array array of objects where each object has properties: id, name, isdefault, itemtypes, sortorder

get_by_id($tagcollid)   X-Ref
Returns the tag collection object

param: int $tagcollid
return: stdClass

get_collections_menu($unlockedonly = false, $onlysearchable = false,$selectalllabel = null)   X-Ref
Returns the list of existing tag collections as id=>name

param: bool $unlockedonly
param: bool $onlysearchable
param: string $selectalllabel
return: array

get_default()   X-Ref
Returns id of the default tag collection

return: int

display_name($record)   X-Ref
Returns formatted name of the tag collection

param: stdClass $record record from DB table tag_coll
return: string

get_areas($tagcollid)   X-Ref
Returns all tag areas in the given tag collection

param: int $tagcollid
return: array

get_areas_names($tagcollid, $enabledonly = true)   X-Ref
Returns the list of names of areas (enabled only) that are in this collection.

param: int $tagcollid
return: array

create($data)   X-Ref
Creates a new tag collection

param: stdClass $data data from form core_tag_collection_form
return: int|false id of created tag collection or false if failed

update($tagcoll, $data)   X-Ref
Updates the tag collection information

param: stdClass $tagcoll existing record in DB table tag_coll
param: stdClass $data data to update
return: bool wether the record was updated

delete($tagcoll)   X-Ref
Deletes a custom tag collection

param: stdClass $tagcoll existing record in DB table tag_coll
return: bool wether the tag collection was deleted

change_sortorder($tagcoll, $direction)   X-Ref
Moves the tag collection in the list one position up or down

param: stdClass $tagcoll existing record in DB table tag_coll
param: int $direction move direction: +1 or -1
return: bool

cleanup_unused_tags($collections = null)   X-Ref
Permanently deletes all non-standard tags that no longer have any instances pointing to them

param: array $collections optional list of tag collections ids to cleanup

get_tag_cloud($tagcollid, $isstandard = false, $limit = 150, $sort = 'name',$search = '', $fromctx = 0, $ctx = 0, $rec = 1)   X-Ref
Returns the list of tags with number of items tagged

param: int $tagcollid
param: null|bool $isstandard return only standard tags
param: int $limit maximum number of tags to retrieve, tags are sorted by the instance count
param: string $sort sort order for display, default 'name' - tags will be sorted after they are retrieved
param: string $search search string
param: int $fromctx context id where this tag cloud is displayed
param: int $ctx only retrieve tag instances in this context
param: int $rec retrieve tag instances in the $ctx context and it's children (default 1)
return: \core_tag\output\tagcloud

cloud_sort($a, $b)   X-Ref
This function is used to sort the tags in the cloud.

param: string $a Tag name to compare against $b
param: string $b Tag name to compare against $a
return: int    The result of the comparison/validation 1, 0 or -1