# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. --- views_plugin_argument_validate_taxonomy_term.inc +++ views_plugin_argument_validate_taxonomy_term.inc @@ -56,6 +56,7 @@ 'tids' => t('Term IDs separated by , or +'), 'name' => t('Term name'), 'convert' => t('Term name converted to Term ID'), + 'names_convert' => t('Term names converted to IDs separated by , or + or /') ), '#default_value' => $this->options['type'], '#description' => t('Select the form of this filter value; 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 the filter.'), @@ -182,9 +183,103 @@ return TRUE; } return FALSE; + + case 'names_convert': + // Break up terms into array then convert to IDs + $names_convert = new stdClass(); + $names_convert->value = $argument; + $names_convert = views_break_phrase_string($argument, $names_convert); + if ($names_convert->value == array(-1)) { + return FALSE; } + //convert names to IDs + $namecheck = 0; + foreach ($names_convert->value as $key => $namequery) { + $query = db_select('taxonomy_term_data', 'td'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->fields('td'); + $query->fields('tv', array('machine_name')); + if (!empty($vocabularies)) { + $query->condition('tv.machine_name', $vocabularies); } + if ($transform) { + $query->where("replace(td.name, ' ', '-') = :name", array(':name' => $namequery)); + } + else { + $query->condition('td.name', $namequery); + } + $term = $query->execute()->fetchObject(); + if ($term && (empty($vocabularies) || !empty($vocabularies[$term->machine_name]))) { + if ($type == 'names_convert') { + $this->argument->argument = $term->tid; + $names_convert->value[$key] = $term->tid; + print 'key: ' . $key . '
'; // dev + print 'value: ' . $namequery . '
'; // dev + } + // $this->argument->validated_title = check_plain($term->name); + } + else { + $namecheck++; + } + } + if ($namecheck > 0) { + return FALSE; + } + // end convert + print ('
'); // dev
+        print_r($names_convert); // dev
+        print ('
'); // dev + + $test = drupal_map_assoc($names_convert->value); + $titles = array(); + + // check, if some tids already verified + static $validated_cache = array(); + foreach ($test as $tid) { + if (isset($validated_cache[$tid])) { + if ($validated_cache[$tid] === FALSE) { + return FALSE; + } + else { + $titles[] = $validated_cache[$tid]; + unset($test[$tid]); + } + } + } + + // if unverified tids left - verify them and cache results + if (count($test)) { + $query = db_select('taxonomy_term_data', 'td'); + $query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid'); + $query->fields('td'); + $query->fields('tv', array('machine_name')); + $query->condition('td.tid', $test); + + $result = $query->execute(); + + foreach ($result as $term) { + if ($vocabularies && empty($vocabularies[$term->machine_name])) { + $validated_cache[$term->tid] = FALSE; + return FALSE; + } + + $titles[] = $validated_cache[$term->tid] = check_plain($term->name); + unset($test[$term->tid]); + } + } + + // Remove duplicate titles + $titles = array_unique($titles); + + $this->argument->validated_title = implode($names_convert->operator == 'or' ? ' + ' : ', ', $titles); + // If this is not empty, we did not find a tid. + return empty($test); + + // END names_convert + } + } + function process_summary_arguments(&$args) { $type = $this->options['type']; $transform = $this->options['transform'];