You are here

class views_handler_field_term_regcode_tid in Registration codes 6.2

Same name and namespace in other branches
  1. 7.2 includes/views_handler_field_term_regcode_tid.inc \views_handler_field_term_regcode_tid
  2. 7 includes/views_handler_field_term_regcode_tid.inc \views_handler_field_term_regcode_tid

Field handler for terms.

This code is all taken from views_handler_field_term_node_tid.inc

Hierarchy

Expanded class hierarchy of views_handler_field_term_regcode_tid

1 string reference to 'views_handler_field_term_regcode_tid'
regcode_views_data in ./regcode.views.inc
Implements hook_views_data().

File

includes/views_handler_field_term_regcode_tid.inc, line 8

View source
class views_handler_field_term_regcode_tid extends views_handler_field_prerender_list {

  /**
   * Implement option_definition.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['link_to_taxonomy'] = array(
      'default' => TRUE,
    );
    $options['limit'] = array(
      'default' => FALSE,
    );
    $options['vids'] = array(
      'default' => array(),
    );
    return $options;
  }

  /**
   * Provide "link to term" option.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['link_to_taxonomy'] = array(
      '#title' => t('Link this field to its term page'),
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['link_to_taxonomy']),
    );
  }

  /**
   * Add this term to the query
   */
  function query() {
    $this
      ->add_additional_fields();
  }
  function pre_render($values) {
    $this->aliases['vid'] = 'rid';
    $this->field_alias = $this->aliases['vid'];
    $vids = array();
    foreach ($values as $result) {
      if (!empty($result->{$this->aliases['vid']})) {
        $vids[] = $result->{$this->aliases['vid']};
      }
    }
    if ($vids) {
      $result = db_query("SELECT tn.rid AS node_vid, td.*, v.name as vocabulary FROM {term_data} td INNER JOIN {regcode_term} tn ON td.tid = tn.tid INNER JOIN {vocabulary} v ON v.vid = td.vid WHERE tn.rid IN (%s) AND td.vid = %d ORDER BY td.weight, td.name", implode(', ', $vids), variable_get('regcode_vocabulary', 1));
      while ($term = db_fetch_object($result)) {
        $this->items[$term->node_vid][$term->tid]['name'] = check_plain($term->name);
        $this->items[$term->node_vid][$term->tid]['tid'] = $term->tid;
        $this->items[$term->node_vid][$term->tid]['vid'] = $term->vid;
        $this->items[$term->node_vid][$term->tid]['vocabulary'] = check_plain($term->vocabulary);
        if (!empty($this->options['link_to_taxonomy'])) {
          $this->items[$term->node_vid][$term->tid]['make_link'] = TRUE;
          $this->items[$term->node_vid][$term->tid]['path'] = taxonomy_term_path($term);
        }
      }
    }
  }
  function render_item($count, $item) {
    return $item['name'];
  }

}

Members