PHP Class Habari\Vocabulary

Inheritance: extends QueryRecord
Show file Open project: habari/system

Public Properties

Property Type Description
$features of strings $features. An array of the features that limit the behaviour of the vocabulary. Default values can include: hierarchical: The vocabulary's terms exist in a parent child hierarchy required: multiple: More than one term in the vocabulary can be associated with an object free: Terms within the vocabulary can have any value unique: A term may be associated with exactly 0 or 1 object

Public Methods

Method Description
__construct ( array $paramarray = [] ) Vocabulary constructor Creates a Vocabulary instance
__get ( $name ) : mixed function __get Overrides QueryRecord __get to implement custom object properties
add_object_type ( $type ) : none inserts a new object type into the database, if it doesn't exist
add_term ( $term, $target_term = null, $before = false ) : Term Adds a term to the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.
count_total ( ) : integer Returns the number of tags in the database.
create ( array $paramarray ) : Vocabulary Create a vocabulary and save it.
default_fields ( ) : array Return the defined database columns for a Vocabulary.
delete ( ) Delete an existing vocabulary
delete_term ( Term | integer | string $term ) Remove the term from the vocabulary. Convenience method to ->get_term('foo')->delete().
exists ( string $name ) : boolean Determine whether a vocabulary exists
get ( $name ) : Vocabulary Return a Vocabulary by name.
get_all ( ) : array Return all vocabularies as Vocabulary objects
get_all_object_terms ( $object_type, $id ) : array Return the Term objects associated to that type of object with that id in any vocabulary.
get_associations ( $object_id, $object_type = 'post' ) : Terms Get the tags associated with this object
get_by_id ( integer $id ) : Vocabulary Return a Vocabulary by id
get_object_terms ( String $object_type, integer $id ) : Array Gets the Term objects associated to that type of object with that id in this vocabulary For example, return all terms in this vocabulary that are associated with a particular post
get_options ( ) : Array Retrieve the vocabulary as an associative array suitable for FormUI select controls
get_root_terms ( ) : Array Get all root elements in this vocabulary
get_search ( string $search, $orderby = 'mptt_left ASC' ) : Terms Retrieve the terms in the vocabulary that match the specified criteria
get_term ( Term | integer | string | null $term = null, string $term_class = '\Habari\Term' ) : Term Gets the term object by id. No parameter returns the root Term object.
get_tree ( $orderby = 'mptt_left ASC' ) : Terms Retrieve the vocabulary
insert ( ) function insert Saves a new vocabulary to the vocabularies table
is_empty ( ) Check if this vocabulary is empty.
max_count ( ) : integer Returns the number of times the most used tag is used.
merge ( mixed $master, Array $tags, $object_type = 'post' ) Renames terms.
min_count ( ) : integer Returns the number of times the least used tag is used.
move_term ( Term $term, Term | null $target_term = null, boolean $before = false ) : Term Moves a term within the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.
names ( ) : array Return the names of all vocabularies
object_type_id ( $type ) : integer Return the object type id for a named object, such as a post
post_count ( mixed $term, $object_type = 'post' ) : integer Returns the count of times a tag is used.
prep_update ( Terms $terms ) Moves all of the terms into a temporary area so that they can be moved
rename ( $newname ) : boolean Rename a Vocabulary.
search_term ( string $term, string $term_class = '\Habari\Term' ) : Terms Search for matching term objects.
set_object_terms ( String $object_type, integer $id, Array $terms = [] ) : boolean. Sets the Term objects associated to that type of object with that id in this vocabulary
update ( ) function update Updates an existing vocabulary in the vocabularies table

Method Details

__construct() public method

Vocabulary constructor Creates a Vocabulary instance
public __construct ( array $paramarray = [] )
$paramarray array an associative array of initial vocabulary values

__get() public method

function __get Overrides QueryRecord __get to implement custom object properties
public __get ( $name ) : mixed
return mixed The requested field value

add_object_type() public static method

inserts a new object type into the database, if it doesn't exist
public static add_object_type ( $type ) : none
return none

add_term() public method

Adds a term to the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.
public add_term ( $term, $target_term = null, $before = false ) : Term
return Term The Term object added

count_total() public method

Returns the number of tags in the database.
public count_total ( ) : integer
return integer The number of tags in the database.

create() static public method

Create a vocabulary and save it.
static public create ( array $paramarray ) : Vocabulary
$paramarray array An associative array of vocabulary fields
return Vocabulary The new vocabulary object

default_fields() public static method

Return the defined database columns for a Vocabulary.
public static default_fields ( ) : array
return array Array of columns in the Vocabulary table

delete() public method

Delete an existing vocabulary
public delete ( )

delete_term() public method

Remove the term from the vocabulary. Convenience method to ->get_term('foo')->delete().
public delete_term ( Term | integer | string $term )
$term Term | integer | string The term to delete

exists() public static method

Determine whether a vocabulary exists
public static exists ( string $name ) : boolean
$name string a vocabulary name
return boolean whether the vocabulary exists or not

get() public static method

Return a Vocabulary by name.
public static get ( $name ) : Vocabulary
return Vocabulary The requested vocabulary

get_all() public static method

Return all vocabularies as Vocabulary objects
public static get_all ( ) : array
return array An array of Vocabulary objects

get_all_object_terms() public static method

For example, return all terms associated with a particular post, from all vocabularies.
public static get_all_object_terms ( $object_type, $id ) : array
return array Array of Vocabulary names

get_associations() public method

Get the tags associated with this object
public get_associations ( $object_id, $object_type = 'post' ) : Terms
return Terms The terms associated with this object

get_by_id() public static method

Return a Vocabulary by id
public static get_by_id ( integer $id ) : Vocabulary
$id integer The id of the vocabulary
return Vocabulary The object requested

get_object_terms() public method

Gets the Term objects associated to that type of object with that id in this vocabulary For example, return all terms in this vocabulary that are associated with a particular post
public get_object_terms ( String $object_type, integer $id ) : Array
$object_type String the name of the object type
$id integer The id of the object for which you want the terms
return Array The Term objects requested

get_options() public method

Retrieve the vocabulary as an associative array suitable for FormUI select controls
public get_options ( ) : Array
return Array The Term objects in the vocabulary, in tree order

get_root_terms() public method

Get all root elements in this vocabulary
public get_root_terms ( ) : Array
return Array The root Term objects in the vocabulary

get_term() public method

Gets the term object by id. No parameter returns the root Term object.
public get_term ( Term | integer | string | null $term = null, string $term_class = '\Habari\Term' ) : Term
$term Term | integer | string | null A Term object, null (for the first node in the tree), a string (for a term slug or display), or an integer (for a Term ID).
$term_class string The class of the returned term object.
return Term The Term object requested

get_tree() public method

Retrieve the vocabulary
public get_tree ( $orderby = 'mptt_left ASC' ) : Terms
return Terms The Term objects in the vocabulary, in tree order

insert() public method

function insert Saves a new vocabulary to the vocabularies table
public insert ( )

is_empty() public method

Check if this vocabulary is empty.
public is_empty ( )

max_count() public method

Returns the number of times the most used tag is used.
public max_count ( ) : integer
return integer The number of times the most used tag is used.

merge() public method

If the master term exists, the terms will be merged with it. If not, it will be created first.
public merge ( mixed $master, Array $tags, $object_type = 'post' )
$master mixed The Term to which they should be renamed, or the slug, text or id of it
$tags Array The tag text, slugs or ids to be renamed

min_count() public method

Returns the number of times the least used tag is used.
public min_count ( ) : integer
return integer The number of times the least used tag is used.

move_term() public method

The MPTT operations can seem complex, but they're actually pretty simple: 1: Find our insertion point: Either at the very end of the vocabulary, or before / after the given term 2: Create a gap at that point: We'll bump everything at that point or after up enough to fit in the term we're moving 3: Move the term: We know the offset between the old point and the new point, so move the range up that number of spaces. 4: Close the original gap: Now we've got all our terms moved, but we need to bump everything back down to close the gap it left, similar to #2.
public move_term ( Term $term, Term | null $target_term = null, boolean $before = false ) : Term
$term Term The term to move.
$target_term Term | null The term to move $term before or after, or null to move it to the very end of the vocabulary.
$before boolean True to move $term BEFORE $target_term, false (the default) to move $term AFTER $target_term.
return Term The Term object moved

names() public static method

Return the names of all vocabularies
public static names ( ) : array
return array Array of Vocabulary names

object_type_id() public static method

Return the object type id for a named object, such as a post
public static object_type_id ( $type ) : integer
return integer The id of the object type

post_count() public method

Returns the count of times a tag is used.
public post_count ( mixed $term, $object_type = 'post' ) : integer
$term mixed The tag to count usage.
return integer The number of times a tag is used.

prep_update() public static method

Moves all of the terms into a temporary area so that they can be moved
public static prep_update ( Terms $terms )
$terms Terms An array of Term objects

rename() public method

Rename a Vocabulary.
public rename ( $newname ) : boolean
return boolean true if the Vocabulary was renamed, false otherwise

search_term() public method

Wildcards (eg "%term%") must be passed in; They're not added automatically.
public search_term ( string $term, string $term_class = '\Habari\Term' ) : Terms
$term string The string to search for as a term slug or text
$term_class string The class of the returned term object.
return Terms The matching Term objects

set_object_terms() public method

Sets the Term objects associated to that type of object with that id in this vocabulary
public set_object_terms ( String $object_type, integer $id, Array $terms = [] ) : boolean.
$object_type String the name of the object type
$id integer The id of the object for which you want the terms
$terms Array The names of the terms to associate
return boolean.

update() public method

function update Updates an existing vocabulary in the vocabularies table
public update ( )

Property Details

$features public static property

of strings $features. An array of the features that limit the behaviour of the vocabulary. Default values can include: hierarchical: The vocabulary's terms exist in a parent child hierarchy required: multiple: More than one term in the vocabulary can be associated with an object free: Terms within the vocabulary can have any value unique: A term may be associated with exactly 0 or 1 object
public static $features