Projet

Général

Profil

Paste
Télécharger (2,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / advanced_forum / includes / views / advanced_forum_plugin_style_forum_topic_list.inc @ 74f6bef0

1
<?php
2
/**
3
 * @file
4
 * Contains the topic list style plugin.
5
 */
6

    
7
/**
8
 * Style plugin to render each item as a row in a table.
9
 *
10
 * @ingroup views_style_plugins
11
 */
12
class advanced_forum_plugin_style_forum_topic_list extends views_plugin_style_table {
13
  function option_definition() {
14
    $options = parent::option_definition();
15
    $options['tid'] = array('default' => '');
16
    return $options;
17
  }
18

    
19
  function options_form(&$form, &$form_state) {
20
    parent::options_form($form, $form_state);
21
    $options = array('' => t('None'));
22

    
23
    $arguments = $this->display->handler->get_handlers('argument');
24
    foreach ($arguments as $id => $argument) {
25
      $options['argument.' . $id] = $argument->ui_name();
26

    
27
    }
28
    $filters = $this->display->handler->get_handlers('filter');
29
    foreach ($filters as $id => $filter) {
30
      $options['filter.' . $id] = $filter->ui_name();
31
    }
32

    
33
    $form['tid'] = array(
34
      '#type' => 'select',
35
      '#title' => t('Source of forum ID'),
36
      '#options' => $options,
37
      '#default_value' => $this->options['tid'],
38
    );
39
  }
40

    
41
  /**
42
   * Add a couple of fields to the query that we can later use. We are going to
43
   * specificly alias them because this style is not meant to be used on relationships.
44
   */
45
  function query() {
46
    $this->view->query->add_field('node', 'sticky', 'topic_is_sticky');
47
    $this->view->query->add_field('forum', 'tid', 'topic_actual_forum');
48
  }
49

    
50
  /**
51
   * Figure out what the forum ID is. It could have come from an argument
52
   * or a filter or nowhere. This source would be set by the user in the
53
   * options.
54
   */
55
  function get_forum_ids() {
56
    $where = $this->options['tid'];
57
    if (empty($where)) {
58
      return;
59
    }
60

    
61
    $term = '';
62

    
63
    list($type, $id) = explode('.', $where, 2);
64
    $handler = $this->display->handler->get_handler($type, $id);
65
    if ($type == 'argument') {
66
      return empty($handler->argument) ? array() : array($handler->argument);
67
    }
68
    else {
69
      $terms = is_array($handler->value) ? $handler->value : array($handler->value) ;
70
      if (isset($handler->options['depth'])) {
71
        foreach ($terms as $tid) {
72
          $term = taxonomy_term_load($tid);
73
          $tree = taxonomy_get_tree($term->vid, $tid, -1, $handler->options['depth']);
74
          $terms = array_merge($terms, array_map('_taxonomy_get_tid_from_term', $tree));
75
        }
76
      }
77
      return $terms;
78
    }
79
  }
80
}