| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: term_parent.inc,v 1.2.2.2 2010/01/29 20:18:26 merlinofchaos Exp $ 3 4 /** 5 * @file relationships/term_parent.inc 6 * Plugin to provide an relationship handler for term parent. 7 */ 8 9 /** 10 * Plugins are described by creating a $plugin array which will be used 11 * by the system that includes this file. 12 */ 13 $plugin = array( 14 'title' => t('Term parent'), 15 'keyword' => 'parent_term', 16 'description' => t('Adds a taxonomy term parent from a term context.'), 17 'required context' => new ctools_context_required(t('Term'), 'term'), 18 'context' => 'ctools_term_parent_context', 19 'settings form' => 'ctools_term_parent_settings_form', 20 'settings form validate' => 'ctools_term_parent_settings_form_validate', 21 ); 22 23 /** 24 * Return a new context based on an existing context. 25 */ 26 function ctools_term_parent_context($context, $conf) { 27 // If unset it wants a generic, unfilled context, which is just NULL. 28 if (empty($context->data)) { 29 return ctools_context_create_empty('term'); 30 } 31 32 if (isset($context->data)) { 33 $result = db_fetch_array(db_query("SELECT t1.* FROM {term_hierarchy} t1 INNER JOIN {term_hierarchy} t2 ON t1.tid = t2.parent WHERE t2.tid = %d", $context->data->tid)); 34 35 // If top level term, keep looking up until we see a top level. 36 if ($conf['type'] == 'top') { 37 // If looking for top level, and there are no parents at all, make sure 38 // the current term is the 'top level'. 39 if (empty($result)) { 40 $result['tid'] = $context->data->tid; 41 } 42 while (!empty($result['parent'])) { 43 $result = db_fetch_array(db_query("SELECT * FROM {term_hierarchy} WHERE tid = %d", $result['parent'])); 44 } 45 } 46 47 // Load the term. 48 if ($result) { 49 $term = taxonomy_get_term($result['tid']); 50 return ctools_context_create('term', $term); 51 } 52 } 53 } 54 55 /** 56 * Settings form for the relationship. 57 */ 58 function ctools_term_parent_settings_form($conf) { 59 $form['type'] = array( 60 '#type' => 'select', 61 '#title' => t('Relationship type'), 62 '#options' => array('parent' => t('Immediate parent'), 'top' => t('Top level term')), 63 '#default_value' => $conf['type'], 64 ); 65 66 return $form; 67 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |