aboutsummaryrefslogtreecommitdiff
path: root/finder_menu.module
blob: 9eb17b62a8758c77916b45ff6ed7937b45d4fbba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
// $Id$

/**
 * Implementation of hook_block();
 */
function finder_taxonomy_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0]['info']  = t('Finder Menu');
      $blocks[0]['cache'] = BLOCK_NO_CACHE;
      return $blocks;

    case 'configure':
      $form['finder_taxonomy_vid'] = array(
        '#type'          => 'radios',
        '#title'         => t('Select the vocabulary to list'),
        '#default_value' => variable_get('finder_taxonomy_vid', 1),
        '#options'       => finder_taxonomy_get_vocabularies(),
      );
      return $form;

    case 'save':
      variable_set('finder_taxonomy_vid', (int) $edit['finder_taxonomy_vid']);
      break;

    case 'view':
      $vid              = variable_get('finder_taxonomy_vid', 1);
      $tree             = finder_taxonomy_get_terms($vid);
      $block['content'] = theme('item_list', $tree);
      return $block;
  }
}

/**
 * Get all vocabularies;
 */
function finder_taxonomy_get_vocabularies() {
  $result = db_query('SELECT vid, name from {vocabulary}');
  while ($item = db_fetch_object($result)) {
    $items[$item->vid] = $item->name;
  }
  return $items;
}

function finder_taxonomy_get_terms($vid = null) {
  if ($vid != null) {
    $tree = taxonomy_get_tree($vid);
    foreach ($tree as $term) {
      $items[$term->tid] = $term->name;
    }
    return $items;
  }
  return null;
}