From Habari Project

Jump to: navigation, search


Vocabulary Model

Represents a vocabulary of terms. Extends QueryRecord.

Vocabulary Static Methods

Vocabulary::__construct($name, $description, BitMask $properties)

Add a new vocabulary with the specified features.


Retrieves an instance of a Vocabulary object for manipulating a specific Vocabulary.

Vocabulary::rename($name, $newname)

Rename the vocabulary.

Vocabulary::feature_mask($hierarchical, $required, $multiple, $free)

Produce a BitMask for a feature mask. Convenience method for use when creating a Vocabulary.


List active vocabularies.

Vocabulary::get_all_object_terms($object_type, $id)

Gets the Term objects associated to that type of object with that id in any vocabulary.

Vocabulary Dynamic Methods


From QueryRecord.


From QueryRecord.


From QueryRecord.

->add_term($term, $parent_term = null, $before_term = null)

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


Gets the term object for that string.  No parameter returns the root Term object.

->get_object_terms($object_type, $id)

Gets the Term objects associated to that type of object with that id.


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

Term Model

Represents a single term in a specific vocabulary. Extends QueryRecord.

Term Static Methods

Term Dynamic Methods


From QueryRecord.


From QueryRecord.


From QueryRecord.


Array of direct ancestors from the root to this Term in descendant order.


Array of all descendants in MPTT left-to-right order.


The Term that is this Term's parent in hierarchy.


Array of all siblings including self in MPTT left-to-right order.


Array of all direct children (compare to descendants()) in MPTT left-to-right order.


The term text.  Gets converted to slug.


The term text, unconverted.


Array of object ids that are associated with this term for the given type.

->associate($type, $id)

Associate this term to an object of a certain type via its id.


The Vocabulary object in which this Term is assigned.

Example Code

// Should create:
|_ Green Tomatoes
|_ Red Apples
$v = new Vocabulary(array(
  'name' => 'foods',
  'description' => 'Types of foods you might eat.',
  'feature_mask' => Vocabulary::feature_mask(true, false, false, false)
$fruit = $v->add_term('Fruit')->term_display = 'Fruit';
$red_apples = $v->add_term(new Term('red_apples', 'Red Apples'), $fruit);
$v->add_term('green_tomatos', $fruit, $red_apples)->term_display = 'Green Tomatoes';
// Both of the following code chunks should output this:
<ul><li>Fruit<ul><li>Green Tomatoes</li><li>Red Apples</li></ul></li></ul>
//***  There's probably a better way to do this with MPTT:
function list_terms($term = null) {
  $term = is_null($term) 
    ? $v->get_term() // Get root term
    : $term->first_child;
  echo '<ul>';
  while($term) {
    echo '<li>'.$term->term_display;
    if($term->has_children) {
    echo '</li>';
  echo '</ul>';
//***  With theming instead
function theme_list_terms($theme, $term = null) {
  $term = is_null($term) 
    ? $v->get_term() // Get root term
    : $term->first_child;
  $terms_out = '';
  while($term) {
    $theme->term = $term;
    $terms_out .= $theme->fetch('term', true);
  $theme->terms = $terms_out;
  $out = $theme->fetch('termlist', true);
  return $out;
Personal tools
This is a cached copy of the requested page, and may not be up to date.

Sorry! This site is experiencing technical difficulties.
Try waiting a few minutes and reloading.

(Cannot contact the database server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) (localhost))

You can try searching via Google in the meantime.
Note that their indexes of our content may be out of date.