Public Member Functions | Static Public Member Functions | Static Public Attributes

Vocabulary Class Reference

Inheritance diagram for Vocabulary:
Collaboration diagram for Vocabulary:

List of all members.

Public Member Functions

 __construct ($paramarray=array())
 __get ($name)
 rename ($newname)
 insert ()
 update ()
 delete ()
 add_term ($term, $target_term=null, $before=false)
 get_term ($term=null, $term_class= '\Habari\Term')
 search_term ($term, $term_class= '\Habari\Term')
 get_object_terms ($object_type, $id)
 set_object_terms ($object_type, $id, $terms=array())
 delete_term ($term)
 is_empty ()
 get_tree ($orderby= 'mptt_left ASC')
 get_search ($search, $orderby= 'mptt_left ASC')
 get_options ()
 get_root_terms ()
 move_term ($term, $target_term=null, $before=false)
 count_total ()
 max_count ()
 merge ($master, $tags, $object_type= 'post')
 get_associations ($object_id, $object_type= 'post')
 post_count ($term, $object_type= 'post')

Static Public Member Functions

static default_fields ()
static create ($paramarray)
static get ($name)
static get_by_id ($id)
static get_all ()
static names ()
static get_all_object_terms ($object_type, $id)
static exists ($name)
static add_object_type ($type)
static object_type_id ($type)
static prep_update ($terms)

Static Public Attributes

static $features = array( 'hierarchical', 'required', 'multiple', 'free', 'unique' )

Detailed Description

Definition at line 17 of file vocabulary.php.


Constructor & Destructor Documentation

Vocabulary::__construct ( paramarray = array()  ) 

Vocabulary constructor Creates a Vocabulary instance

Parameters:
array $paramarray an associative array of initial vocabulary values

Reimplemented from QueryRecord.

Definition at line 51 of file vocabulary.php.


Member Function Documentation

Vocabulary::__get ( name  ) 

function __get Overrides QueryRecord __get to implement custom object properties

Parameters:
string Name of property to return
Returns:
mixed The requested field value

Reimplemented from QueryRecord.

Definition at line 86 of file vocabulary.php.

static Vocabulary::add_object_type ( type  )  [static]

inserts a new object type into the database, if it doesn't exist

Parameters:
string The name of the new post type
bool Whether the new post type is active or not
Returns:
none

Definition at line 631 of file vocabulary.php.

Referenced by Menus::action_plugin_activation().

Vocabulary::add_term ( term,
target_term = null,
before = false 
)

Adds a term to the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.

Returns:
Term The Term object added

Definition at line 313 of file vocabulary.php.

Referenced by merge(), and set_object_terms().

Vocabulary::count_total (  ) 

Returns the number of tags in the database.

Returns:
int The number of tags in the database.

Definition at line 770 of file vocabulary.php.

static Vocabulary::create ( paramarray  )  [static]

Create a vocabulary and save it.

Parameters:
array $paramarray An associative array of vocabulary fields
Returns:
Vocabulary The new vocabulary object

Definition at line 73 of file vocabulary.php.

Referenced by exists(), get(), get_all(), get_all_object_terms(), get_by_id(), get_object_terms(), get_tree(), is_empty(), and names().

static Vocabulary::default_fields (  )  [static]

Return the defined database columns for a Vocabulary.

Returns:
array Array of columns in the Vocabulary table

Definition at line 35 of file vocabulary.php.

Vocabulary::delete (  ) 

Delete an existing vocabulary

Reimplemented from QueryRecord.

Definition at line 278 of file vocabulary.php.

Vocabulary::delete_term ( term  ) 

Remove the term from the vocabulary. Convenience method to ->get_term('foo')->delete().

Parameters:
Term|int|string $term The term to delete

Definition at line 499 of file vocabulary.php.

Referenced by merge().

static Vocabulary::exists ( name  )  [static]

Determine whether a vocabulary exists

Parameters:
string $name a vocabulary name
Returns:
bool whether the vocabulary exists or not

Definition at line 179 of file vocabulary.php.

Referenced by insert(), and update().

static Vocabulary::get ( name  )  [static]

Return a Vocabulary by name.

Returns:
Vocabulary The requested vocabulary

Definition at line 106 of file vocabulary.php.

Referenced by Menus::__get(), and Tags::vocabulary().

static Vocabulary::get_all (  )  [static]

Return all vocabularies as Vocabulary objects

Returns:
array An array of Vocabulary objects

Definition at line 131 of file vocabulary.php.

static Vocabulary::get_all_object_terms ( object_type,
id 
) [static]

Return the Term objects associated to that type of object with that id in any vocabulary. For example, return all terms associated with a particular post, from all vocabularies.

Returns:
array Array of Vocabulary names

Definition at line 165 of file vocabulary.php.

Referenced by Menus::action_form_publish().

Vocabulary::get_associations ( object_id,
object_type = 'post' 
)

Get the tags associated with this object

Parameters:
Integer $object_id. The id of the tagged object
String $object_type. The name of the type of the object being tagged. Defaults to post
Returns:
Terms The terms associated with this object

Definition at line 886 of file vocabulary.php.

static Vocabulary::get_by_id ( id  )  [static]

Return a Vocabulary by id

Parameters:
integer $id The id of the vocabulary
Returns:
Vocabulary The object requested

Reimplemented in Tags.

Definition at line 119 of file vocabulary.php.

Referenced by Term::__get(), Menus::action_admin_theme_get_menus(), and Menus::action_block_content_menu().

Vocabulary::get_object_terms ( object_type,
id 
)

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

Parameters:
String $object_type the name of the object type
integer $id The id of the object for which you want the terms
Returns:
Array The Term objects requested

Definition at line 438 of file vocabulary.php.

Referenced by get_associations(), and set_object_terms().

Vocabulary::get_options (  ) 

Retrieve the vocabulary as an associative array suitable for FormUI select controls

Returns:
Array The Term objects in the vocabulary, in tree order

Definition at line 574 of file vocabulary.php.

Vocabulary::get_root_terms (  ) 

Get all root elements in this vocabulary

Returns:
Array The root Term objects in the vocabulary

If we INNER JOIN the terms table with itself on ALL the descendants, then descendants one level down are listed once, two levels down are listed twice, etc. If we return only those terms which appear once, we get root elements. ORDER BY NULL to avoid the MySQL filesort.

Definition at line 598 of file vocabulary.php.

Vocabulary::get_search ( search,
orderby = 'mptt_left ASC' 
)

Retrieve the terms in the vocabulary that match the specified criteria

Parameters:
string $search The string to search for
Returns:
Terms The Term objects that match the search term

Definition at line 564 of file vocabulary.php.

Vocabulary::get_term ( term = null,
term_class = '\Habari\Term' 
)

Gets the term object by id. No parameter returns the root Term object.

Parameters:
Term|integer|string|null $term 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).
string $term_class The class of the returned term object.
Returns:
Term The Term object requested
Todo:
improve selective fetching by term slug vs term_display

Definition at line 391 of file vocabulary.php.

Referenced by delete_term(), merge(), move_term(), post_count(), and set_object_terms().

Vocabulary::get_tree ( orderby = 'mptt_left ASC'  ) 

Retrieve the vocabulary

Returns:
Terms The Term objects in the vocabulary, in tree order

Definition at line 544 of file vocabulary.php.

Referenced by count_total(), and get_options().

Vocabulary::insert (  ) 

function insert Saves a new vocabulary to the vocabularies table

Reimplemented from QueryRecord.

Definition at line 190 of file vocabulary.php.

Referenced by add_object_type().

Vocabulary::is_empty (  ) 

Check if this vocabulary is empty.

Definition at line 532 of file vocabulary.php.

Referenced by add_term(), and move_term().

Vocabulary::max_count (  ) 

Returns the number of times the most used tag is used.

Returns:
int The number of times the most used tag is used.

Definition at line 780 of file vocabulary.php.

Vocabulary::merge ( master,
tags,
object_type = 'post' 
)

Renames terms. If the master term exists, the terms will be merged with it. If not, it will be created first.

Parameters:
mixed $master The Term to which they should be renamed, or the slug, text or id of it
Array $tags The tag text, slugs or ids to be renamed

Definition at line 793 of file vocabulary.php.

Vocabulary::move_term ( term,
target_term = null,
before = false 
)

Moves a term within the vocabulary. Returns a Term object. null parameters append the term to the end of any hierarchies.

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.

Parameters:
Term $term The term to move.
Term|null $target_term The term to move $term before or after, or null to move it to the very end of the vocabulary.
bool $before True to move $term BEFORE $target_term, false (the default) to move $term AFTER $target_term.
Returns:
Term The Term object moved

Definition at line 670 of file vocabulary.php.

static Vocabulary::names (  )  [static]

Return the names of all vocabularies

Returns:
array Array of Vocabulary names

Definition at line 153 of file vocabulary.php.

static Vocabulary::object_type_id ( type  )  [static]

Return the object type id for a named object, such as a post

Parameters:
string $name The type of object
Returns:
integer The id of the object type

Definition at line 645 of file vocabulary.php.

Referenced by Term::associate(), Term::dissociate(), Posts::get(), merge(), Term::object_count(), Term::objects(), and Charcoal::theme_show_tags().

Vocabulary::post_count ( term,
object_type = 'post' 
)

Returns the count of times a tag is used.

Parameters:
mixed $term The tag to count usage.
Returns:
int The number of times a tag is used.

Definition at line 903 of file vocabulary.php.

static Vocabulary::prep_update ( terms  )  [static]

Moves all of the terms into a temporary area so that they can be moved

Parameters:
Terms $terms An array of Term objects

Definition at line 915 of file vocabulary.php.

Referenced by Terms::field_save().

Vocabulary::rename ( newname  ) 

Rename a Vocabulary.

Returns:
boolean true if the Vocabulary was renamed, false otherwise

Definition at line 141 of file vocabulary.php.

Vocabulary::search_term ( term,
term_class = '\Habari\Term' 
)

Search for matching term objects. Wildcards (eg "%term%") must be passed in; They're not added automatically.

Parameters:
string $term The string to search for as a term slug or text
string $term_class The class of the returned term object.
Returns:
Terms The matching Term objects

Definition at line 422 of file vocabulary.php.

Vocabulary::set_object_terms ( object_type,
id,
terms = array() 
)

Sets the Term objects associated to that type of object with that id in this vocabulary

Parameters:
String $object_type the name of the object type
Integer $id The id of the object for which you want the terms
Array $terms The names of the terms to associate
Returns:
boolean. Whether the associations were successful or not

Definition at line 457 of file vocabulary.php.

Vocabulary::update (  ) 

function update Updates an existing vocabulary in the vocabularies table

Reimplemented from QueryRecord.

Definition at line 239 of file vocabulary.php.

Referenced by rename().


The documentation for this class was generated from the following file: