PHP Class Habari\Vocabulary

Inheritance: extends QueryRecord
Afficher le fichier Open project: habari/system

Méthodes publiques

Свойство 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

Méthodes publiques

Méthode 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 méthode

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

__get() public méthode

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

add_object_type() public static méthode

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

add_term() public méthode

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
Résultat Term The Term object added

count_total() public méthode

Returns the number of tags in the database.
public count_total ( ) : integer
Résultat integer The number of tags in the database.

create() static public méthode

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

default_fields() public static méthode

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

delete() public méthode

Delete an existing vocabulary
public delete ( )

delete_term() public méthode

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 méthode

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

get() public static méthode

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

get_all() public static méthode

Return all vocabularies as Vocabulary objects
public static get_all ( ) : array
Résultat array An array of Vocabulary objects

get_all_object_terms() public static méthode

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

get_associations() public méthode

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

get_by_id() public static méthode

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

get_object_terms() public méthode

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
Résultat Array The Term objects requested

get_options() public méthode

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

get_root_terms() public méthode

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

get_term() public méthode

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.
Résultat Term The Term object requested

get_tree() public méthode

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

insert() public méthode

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

is_empty() public méthode

Check if this vocabulary is empty.
public is_empty ( )

max_count() public méthode

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

merge() public méthode

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 méthode

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

move_term() public méthode

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.
Résultat Term The Term object moved

names() public static méthode

Return the names of all vocabularies
public static names ( ) : array
Résultat array Array of Vocabulary names

object_type_id() public static méthode

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

post_count() public méthode

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.
Résultat integer The number of times a tag is used.

prep_update() public static méthode

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 méthode

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

search_term() public méthode

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.
Résultat Terms The matching Term objects

set_object_terms() public méthode

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
Résultat boolean.

update() public méthode

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

Property Details

$features public_oe static_oe 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