vocabulary_terms.inc

Go to the documentation of this file.
00001 <?php
00002 // $Id: vocabulary_terms.inc,v 1.1.2.6 2008/10/29 20:47:19 merlinofchaos Exp $
00003 
00004 
00005 /**
00006  * Callback function to supply a list of content types.
00007  */
00008 function panels_vocabulary_terms_panels_content_types() {
00009   if (module_exists('taxonomy')) {
00010     $items['vocabulary_terms'] = array(
00011       'title' => t('Term description'),
00012       'content_types' => 'panels_admin_content_types_vocabulary_terms',
00013       'single' => TRUE,
00014       'render callback' => 'panels_content_vocabulary_terms',
00015       'add callback' => 'panels_admin_edit_vocabulary_terms',
00016       'edit callback' => 'panels_admin_edit_vocabulary_terms',
00017       'title callback' => 'panels_admin_title_vocabulary_terms',
00018     );
00019     return $items;
00020   }
00021 }
00022 
00023 /**
00024  * Output function for the 'vocabulary terms' content type. Outputs a
00025  * list of terms for the input vocabulary.
00026  */
00027 function panels_content_vocabulary_terms($conf, $panel_args, $context) {
00028   $vocab = isset($context->data) ? drupal_clone($context->data) : NULL;
00029   $max_depth = (!empty($conf['max_depth']) ? (int)$conf['max_depth'] : NULL);
00030   if ($conf['tree'] == FALSE) {
00031     $terms = taxonomy_get_tree($vocab->vid, 0, -1, $max_depth);
00032     $items = array();
00033     foreach ($terms as $term) {
00034       $items[] = l($term->name, 'taxonomy/term/'. $term->tid);
00035     }
00036     $output = theme('item_list', $items);
00037   }
00038   else {
00039     $output = theme('item_list', _panels_content_vocabulary_terms($vocab->vid, $max_depth));
00040   }
00041 
00042   $block = new stdClass();
00043   $block->module  = 'node_type';
00044   $block->subject = $vocab->name;
00045   $block->content = $output;
00046   $block->delta   = $vocab->tid;
00047 
00048   return $block;
00049 }
00050 
00051 function _panels_content_vocabulary_terms($vid, $max_depth, $depth = -1, $tid = 0) {
00052   $depth++;
00053   if ($max_depth != NULL && $depth == $max_depth) {
00054     return array();
00055   }
00056   $return = array();
00057   $query = db_query('SELECT t.name, t.tid FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d AND h.parent = %d ORDER BY t.weight ASC, t.name ASC', $vid, $tid);
00058   while ($result = db_fetch_object($query)) {
00059     $return[] = array(
00060       'data' => l($result->name, 'taxonomy/term/'. $result->tid),
00061       'children' => _panels_content_vocabulary_terms($vid, $max_depth, $depth, $result->tid),
00062     );
00063   }
00064   return $return;
00065 }
00066 
00067 /**
00068  * Return all content types available.
00069  */
00070 function panels_admin_content_types_vocabulary_terms() {
00071   return array(
00072     'description' => array(
00073       'title' => t('Vocabulary terms'),
00074       'icon' => 'icon_node.png',
00075       'path' => panels_get_path('content_types/node'),
00076       'description' => t('All the terms in a vocabulary.'),
00077       'required context' => new panels_required_context(t('Vocabulary'), 'vocabulary'),
00078       'category' => array(t('Vocabulary context'), -9),
00079     ),
00080   );
00081 }
00082 
00083 function panels_admin_title_vocabulary_terms($conf, $context) {
00084   return t('"@s" terms', array('@s' => $context->identifier));
00085 }
00086 
00087 function panels_admin_edit_vocabulary_terms($id, $parents, $conf = array()) {
00088   // Apply defaults
00089   if (empty($conf)) {
00090     $conf = array('max_depth' => 0, 'tree' => 1);
00091   }
00092 
00093   $form['max_depth'] = array(
00094     '#type' => 'select',
00095     '#title' => t('Maximum depth'),
00096     '#options' => array_merge(array(t('unlimited')), range(1, 9)),
00097     '#default_value' => $conf['max_depth'],
00098     '#description' => t('Define the maximum depth of terms being displayed.'),
00099   );
00100 
00101   $form['tree'] = array(
00102     '#type' => 'checkbox',
00103     '#title' => t('Display as tree'),
00104     '#default_value' => $conf['tree'],
00105     '#description' => t('If checked, the terms are displayed in a tree, otherwise in a flat list.'),
00106   );
00107 
00108   return $form;
00109 }
00110 

Generated on Thu Jul 29 05:00:14 2010 for Panels 2 by  doxygen 1.5.6