term_parent.inc
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 function panels_term_parent_panels_relationships() {
00012 $args['term_parent'] = array(
00013 'title' => t("Term parent"),
00014 'keyword' => 'parent_term',
00015 'description' => t('Adds a taxonomy term parent from a term context.'),
00016 'required context' => new panels_required_context(t('Term'), 'term'),
00017 'context' => 'panels_term_parent_context',
00018 'settings form' => 'panels_term_parent_settings_form',
00019 'settings form validate' => 'panels_term_parent_settings_form_validate',
00020 );
00021 return $args;
00022 }
00023
00024
00025
00026
00027 function panels_term_parent_context($context = NULL, $conf) {
00028
00029 if (empty($context->data)) {
00030 return panels_context_create_empty('term');
00031 }
00032
00033 if (isset($context->data)) {
00034 $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));
00035
00036
00037 if ($conf['type'] == 'top') {
00038
00039
00040 if (empty($result)) {
00041 $result['tid'] = $context->data->tid;
00042 }
00043 while (!empty($result['parent'])) {
00044 $result = db_fetch_array(db_query("SELECT * FROM {term_hierarchy} WHERE tid = %d", $result['parent']));
00045 }
00046 }
00047
00048
00049 if ($result) {
00050 $term = taxonomy_get_term($result['tid']);
00051 return panels_context_create('term', $term);
00052 }
00053 }
00054 }
00055
00056
00057
00058
00059 function panels_term_parent_settings_form($conf) {
00060 $form['type'] = array(
00061 '#type' => 'select',
00062 '#title' => t('Relationship type'),
00063 '#options' => array('parent' => t('Immediate parent'), 'top' => t('Top level term')),
00064 '#default_value' => $conf['type'],
00065 );
00066
00067 return $form;
00068 }
00069