Core:Taxonomy

From Habari Project

Jump to: navigation, search

Contents

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.

Vocabulary::get($name)

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.

Vocabulary::names()

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

->insert()

From QueryRecord.

->delete()

From QueryRecord.

->update()

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.

->get_term($term)

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.

->delete_term($term)

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

->insert()

From QueryRecord.

->delete()

From QueryRecord.

->update()

From QueryRecord.

->ancestors()

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

->descendants()

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

->parent()

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

->siblings()

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

->children()

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

->term

The term text.  Gets converted to slug.

->term_display

The term text, unconverted.

->objects($type)

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.

->vocabulary

The Vocabulary object in which this Term is assigned.


Example Code

/**
// Should create:
 
Fruit
|_ 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) {
      list_terms($term);
    }
    echo '</li>';
    $term->next_sibling;
  }
  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->start_buffer();
    $theme->term = $term;
    $terms_out .= $theme->fetch('term', true);
    $term->next_sibling;
  }
  $theme->start_buffer();
  $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: Access denied for user 'habari'@'localhost' to database 'habari_wiki' (localhost))


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