2
// $Id: views_plugin_argument_validate_taxonomy_term.inc,v 1.4 2009/04/08 05:10:07 merlinofchaos Exp $
5
* Contains the 'taxonomy term' argument validator plugin.
9
* Validate whether an argument is an acceptable node.
11
class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument_validate {
12
function validate_form(&$form, &$form_state) {
13
$vocabularies = taxonomy_get_vocabularies();
15
foreach ($vocabularies as $voc) {
16
$options[$voc->vid] = check_plain($voc->name);
19
$form['validate_argument_vocabulary'] = array(
20
'#type' => 'checkboxes',
21
'#prefix' => '<div id="edit-options-validate-argument-vocabulary-wrapper">',
22
'#suffix' => '</div>',
23
'#title' => t('Vocabularies'),
24
'#options' => $options,
25
'#default_value' => isset($this->argument->options['validate_argument_vocabulary']) ? $this->argument->options['validate_argument_vocabulary'] : array(),
26
'#description' => t('If you wish to validate for specific vocabularies, check them; if none are checked, all terms will pass.'),
27
'#process' => array('expand_checkboxes', 'views_process_dependency'),
28
'#dependency' => array('edit-options-validate-type' => array($this->id)),
31
$form['validate_argument_type'] = array(
33
'#title' => t('Argument type'),
35
'tid' => t('Term ID'),
36
'tids' => t('Term IDs separated by , or +'),
37
'name' => t('Term name or synonym'),
38
'convert' => t('Term name/synonym converted to Term ID'),
40
'#default_value' => isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid',
41
'#description' => t('Select the form of this argument; if using term name, it is generally more efficient to convert it to a term ID and use Taxonomy: Term ID rather than Taxonomy: Term Name" as an argument.'),
42
'#process' => array('views_process_dependency'),
43
'#dependency' => array('edit-options-validate-type' => array($this->id)),
46
$form['validate_argument_transform'] = array(
47
'#type' => 'checkbox',
48
'#title' => t('Transform dashes in URL to spaces in term name arguments'),
49
'#default_value' => isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE,
50
'#process' => array('views_process_dependency'),
51
'#dependency' => array('edit-options-validate-type' => array($this->id)),
55
function validate_argument($argument) {
56
$vids = isset($this->argument->options['validate_argument_vocabulary']) ? array_filter($this->argument->options['validate_argument_vocabulary']) : array();
57
$type = isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid';
58
$transform = isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE;
62
if (!is_numeric($argument)) {
66
$result = db_fetch_object(db_query("SELECT * FROM {term_data} WHERE tid = %d", $argument));
71
return empty($vids) || !empty($vids[$result->vid]);
73
$tids = new stdClass();
74
$tids->value = $argument;
75
$tids = views_break_phrase($argument, $tids);
76
if ($tids->value == array(-1)) {
80
$placeholders = implode(', ', array_fill(0, sizeof($tids->value), '%d'));
82
$test = drupal_map_assoc($tids->value);
85
$result = db_query("SELECT * FROM {term_data} WHERE tid IN ($placeholders)", $tids->value);
86
while ($term = db_fetch_object($result)) {
87
if ($vids && empty($vids[$term->vid])) {
91
$titles[] = check_plain($term->name);
92
unset($test[$term->tid]);
95
$this->argument->validated_title = implode($tids->operator == 'or' ? ' + ' : ', ', $titles);
96
// If this is not empty, we did not find a tid.
102
$and = " AND td.vid IN(" . implode(', ', $vids) . ')';
105
$argument = str_replace('-', ' ', $argument);
107
$result = db_fetch_object(db_query("SELECT td.* FROM {term_data} td LEFT JOIN {term_synonym} ts ON ts.tid = td.tid WHERE (td.name = '%s' OR ts.name = '%s')$and", $argument, $argument));
112
if ($type == 'convert') {
113
$this->argument->argument = $result->tid;
114
$this->argument->validated_title = check_plain($result->name);