本文整理汇总了PHP中Term::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Term::get方法的具体用法?PHP Term::get怎么用?PHP Term::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Term
的用法示例。
在下文中一共展示了Term::get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __get
/**
* 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;
}
示例2: term_form_save
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')));
}
}
示例3: term_form_save
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';
}
}
示例4: get_term
/**
* 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);
}
示例5: test_not_descendants
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();
}