function similarterms_handler_argument_node_nid::validate_arg in Similar By Terms 7.2
Same name and namespace in other branches
- 6.2 views/similarterms_handler_argument_node_nid.inc \similarterms_handler_argument_node_nid::validate_arg()
Validate that this argument works. By default, all arguments are valid.
Overrides views_handler_argument::validate_arg
File
- views/
similarterms_handler_argument_node_nid.inc, line 73
Class
- similarterms_handler_argument_node_nid
- Argument handler to accept a node id. based on node_handler_argument_node_nid except that it doesn't add a where clause to the query.
Code
function validate_arg($arg) {
// first run the inherited arg validation
if (!parent::validate_arg($arg)) {
return FALSE;
}
if (!empty($this->options['break_phrase'])) {
views_break_phrase($this->argument, $this);
}
else {
$this->value = array(
$this->argument,
);
}
// $vocabulary_vids is array of vocabulary ids (a.k.a. vids, confusing right?)
$vocabulary_vids = empty($this->options['vocabularies']) ? array() : $this->options['vocabularies'];
foreach ($vocabulary_vids as $key => $val) {
if ($val === 0) {
unset($vocabulary_vids[$key]);
}
}
$select = db_select('taxonomy_index', 'ti');
$select
->addField('ti', 'tid');
if (count($vocabulary_vids)) {
$select
->join('taxonomy_term_data', 'td', 'ti.tid = td.tid');
$select
->join('taxonomy_vocabulary', 'tv', 'tv.vid = td.vid');
$select
->condition('tv.machine_name', $vocabulary_vids, 'IN');
}
$select
->condition('ti.nid', $this->value, 'IN');
$result = $select
->execute();
$this->tids = array();
foreach ($result as $row) {
$this->tids[$row->tid] = $row->tid;
}
$this->view->tids = $this->tids;
if (count($this->tids) == 0) {
// there are no terms ... we need to cancel the query and bail out
return FALSE;
}
return TRUE;
}