views_handler_field_term_regcode_tid.inc in Registration codes 6.2
File
includes/views_handler_field_term_regcode_tid.inc
View source
<?php
class views_handler_field_term_regcode_tid extends views_handler_field_prerender_list {
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;
}
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']),
);
}
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'];
}
}