summaryrefslogtreecommitdiff
path: root/kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc
diff options
context:
space:
mode:
authorTorsten Grote <grote@kolabsys.com>2012-08-14 13:29:52 (GMT)
committerTorsten Grote <grote@kolabsys.com>2012-08-14 13:29:52 (GMT)
commit8a7a4f8e58df35a10fda833a9904eb8fd961a1ca (patch)
tree35e2f907372d637f76c0e3c3ac1c0f27f2dc1391 /kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc
parent146e20fc2d0941a6783641f26b3ea074dc03fc84 (diff)
downloadkolab.org-www-8a7a4f8e58df35a10fda833a9904eb8fd961a1ca.tar.gz
upgrade to drupal 7.15
Diffstat (limited to 'kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc')
-rw-r--r--kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc95
1 files changed, 95 insertions, 0 deletions
diff --git a/kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc b/kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc
new file mode 100644
index 0000000..1855cae
--- /dev/null
+++ b/kolab.org/www/drupal-7.15/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc
@@ -0,0 +1,95 @@
+<?php
+/**
+ * @file
+ * Views' relationship handlers.
+ */
+
+
+/**
+ * Relationship handler to return the taxonomy terms of nodes.
+ *
+ * @ingroup views_relationship_handlers
+ */
+class views_handler_relationship_node_term_data extends views_handler_relationship {
+ function init(&$view, &$options) {
+ parent::init($view, $options);
+
+ // Convert legacy vids option to machine name vocabularies.
+ if (!empty($this->options['vids'])) {
+ $vocabularies = taxonomy_get_vocabularies();
+ foreach ($this->options['vids'] as $vid) {
+ if (isset($vocabularies[$vid], $vocabularies[$vid]->machine_name)) {
+ $this->options['vocabularies'][$vocabularies[$vid]->machine_name] = $vocabularies[$vid]->machine_name;
+ }
+ }
+ }
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+ $options['vocabularies'] = array('default' => array());
+ return $options;
+ }
+
+ function options_form(&$form, &$form_state) {
+ $vocabularies = taxonomy_get_vocabularies();
+ $options = array();
+ foreach ($vocabularies as $voc) {
+ $options[$voc->machine_name] = check_plain($voc->name);
+ }
+
+ $form['vocabularies'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Vocabularies'),
+ '#options' => $options,
+ '#default_value' => $this->options['vocabularies'],
+ '#description' => t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'),
+ );
+ parent::options_form($form, $form_state);
+ }
+
+ /**
+ * Called to implement a relationship in a query.
+ */
+ function query() {
+ $this->ensure_my_table();
+
+ $def = $this->definition;
+ $def['table'] = 'taxonomy_term_data';
+
+ if (!array_filter($this->options['vocabularies'])) {
+ $term_node = $this->query->add_table('taxonomy_index', $this->relationship);
+ $def['left_table'] = 'taxonomy_index';
+ $def['left_field'] = 'tid';
+ $def['field'] = 'tid';
+ $def['type'] = empty($this->options['required']) ? 'LEFT' : 'INNER';
+ }
+ else {
+ // If vocabularies are supplied join a subselect instead
+ $def['left_table'] = $this->table_alias;
+ $def['left_field'] = 'nid';
+ $def['field'] = 'nid';
+ $def['type'] = empty($this->options['required']) ? 'LEFT' : 'INNER';
+
+ $query = db_select('taxonomy_term_data', 'td');
+ $query->addJoin($def['type'], 'taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
+ $query->addJoin($def['type'], 'taxonomy_index', 'tn', 'tn.tid = td.tid');
+ $query->condition('tv.machine_name', array_filter($this->options['vocabularies']));
+ $query->addTag('term_access');
+ $query->fields('td');
+ $query->fields('tn', array('nid'));
+ $def['table formula'] = $query;
+ }
+
+ $join = new views_join();
+
+ $join->definition = $def;
+ $join->construct();
+ $join->adjusted = TRUE;
+
+ // use a short alias for this:
+ $alias = $def['table'] . '_' . $this->table;
+
+ $this->alias = $this->query->add_relationship($alias, $join, 'taxonomy_term_data', $this->relationship);
+ }
+}