/** * Retrieve the vocabulary * @return Array The Term objects in the vocabulary, in tree order **/ public function get_tree($orderby = 'mptt_left ASC') { return DB::get_results( "SELECT * FROM {terms} WHERE vocabulary_id=:vid ORDER BY {$orderby}", array('vid' => $this->id), 'Term' ); } /** * Retrieve the vocabulary as an associative array suitable for FormUI select controls * @return Array The Term objects in the vocabulary, in tree order **/ public function get_options() { $tree = $this->get_tree('mptt_left ASC'); $output = array(); $lastright = $lastleft = reset($tree)->mptt_left; $indent = 0; $stack = array(); foreach($tree as $term) { while ( count($stack) > 0 && end($stack)->mptt_right < $term->mptt_left ) { array_pop($stack); } $output[$term->id] = str_repeat('- ', count($stack)) . $term->term_display; $stack[] = $term; } return $output; }