/** * function __get * Overrides QueryRecord __get to implement custom object properties * @param string Name of property to return * @return mixed The requested field value **/ public function __get($name) { $term = Term::get(Tags::vocabulary()->id, $this->id); switch ($name) { case 'tag': case 'tag_text': $out = $term->term_display; break; case 'tag_text_searchable': // if it's got spaces, then quote it. if (strpos($term->term_display, ' ') !== FALSE) { $out = '\'' . str_replace("'", "\\'", $term->term_display) . '\''; } else { $out = $term->term_display; } break; case 'slug': case 'tag_slug': $out = $term->term; break; case 'count': $out = $this->get_count(); break; default: break; } return $out; }
public function term_form_save($form) { $menu_vocab = intval($form->menu->value); $menu = Vocabulary::get_by_id($menu_vocab); $menu_type_data = $this->get_menu_type_data(); if (isset($form->term)) { $term = Term::get(intval((string) $form->term->value)); // maybe we should check if term exists? Or put that in the conditional above? $object_types = $term->object_types(); $type = $object_types[0]->type; // that's twice we've grabbed the $term->object_types()[0]. Maybe this is a job for a function? if (isset($menu_type_data[$type]['save'])) { $menu_type_data[$type]['save']($menu, $form); } } else { // if no term is set, create a new item. // create a term for the link, store the URL $type = $form->menu_type->value; if (isset($menu_type_data[$type]['save'])) { $menu_type_data[$type]['save']($menu, $form); } // if not for this redirect, this whole if/else could be simplified considerably. Utils::redirect(URL::get('admin', array('page' => 'menu_iframe', 'action' => $type, 'menu' => $menu_vocab, 'result' => 'added'))); } }
public function term_form_save($form) { $menu_vocab = intval($form->menu->value); $menu = Vocabulary::get_by_id($menu_vocab); $menu_type_data = $this->get_menu_type_data(); if (isset($form->term)) { $term = Term::get(intval((string) $form->term->value)); // maybe we should check if term exists? Or put that in the conditional above? $object_types = $term->object_types(); $type = $object_types[0]->type; // that's twice we've grabbed the $term->object_types()[0]. Maybe this is a job for a function? if (isset($menu_type_data[$type]['save'])) { $menu_type_data[$type]['save']($menu, $form); } $form->has_result = 'updated'; } else { // if no term is set, create a new item. // create a term for the link, store the URL $type = $form->menu_type->value; if (isset($menu_type_data[$type]['save'])) { $menu_type_data[$type]['save']($menu, $form); } $form->has_result = 'added'; } }
/** * Gets the term object by id. No parameter returns the root Term object. * @param integer $term_id The id of the term to fetch, or null for the root node * @return Term The Term object requested **/ public function get_term($term_id = null) { return Term::get($this->id, $term_id); }
public function test_not_descendants() { $v = Vocabulary::create(array('name' => 'animals', 'description' => 'Types of animals.', 'features' => array('hierarchical'))); $root = $v->add_term('Animal Kingdom'); $backbone = $v->add_term('Backbone', $root); $mammal = $v->add_term('Mammal', $backbone); $lungs = $v->add_term('Lungs', $backbone); $reptile = $v->add_term('Reptile', $backbone); $bird = $v->add_term('Bird', $backbone); $gills = $v->add_term('Gills', $backbone); $fish = $v->add_term('Fish', $gills); $amphibian = $v->add_term('Amphibian', $gills); $no_backbone = $v->add_term('No Backbone', $root); $starfish = $v->add_term('Starfish', $no_backbone); $mollusk = $v->add_term('Mollusk', $no_backbone); $legs = $v->add_term('Jointed Legs', $no_backbone); $snail = $v->add_term('Snail', $v->get_term($mollusk->id)); $clam = $v->add_term('Clam', $v->get_term($mollusk->id)); $insect = $v->add_term('Insect', $v->get_term($legs->id)); $spider = $v->add_term('Spider', $v->get_term($legs->id)); $crustacean = $v->add_term('Crustacean', $v->get_term($legs->id)); $not_descendants = Term::get($v, $backbone->id)->not_descendants(); $s = array(); foreach ($not_descendants as $el) { $s[] = (string) $el; } $expected = array($root, $no_backbone, $starfish, $mollusk, $legs, $snail, $clam, $insect, $spider, $crustacean); $this->assertTrue(10 == count($not_descendants), sprintf('Found: %s', implode(', ', $s))); $e = array(); foreach ($expected as $el) { $e[] = (string) $el; } $this->assertTrue(0 == count(array_diff($s, $e))); // clean up $v->delete(); }