summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Taranyuk2011-05-11 03:39:52 (GMT)
committer Artem Taranyuk2011-05-11 03:39:52 (GMT)
commitcbbc9de407ef7f6017e8bf2b641897935d12c0ef (patch)
tree20a2c03343e31309d010e3ad9302ca1782495896
parent1c7d9dbd32c3331e0205295a292a6c53938ceed7 (diff)
Added delta for relationships in views6.x-2.x
-rw-r--r--content_taxonomy.module3
-rw-r--r--includes/views/content_taxonomy.views.inc3
-rw-r--r--includes/views/content_taxonomy_handler_relationship.inc72
3 files changed, 77 insertions, 1 deletions
diff --git a/content_taxonomy.module b/content_taxonomy.module
index 08982d5..6832b72 100644
--- a/content_taxonomy.module
+++ b/content_taxonomy.module
@@ -135,10 +135,11 @@ function content_taxonomy_field_settings($op, $field) {
// Add a relation to the taxonomy term table.
$data[$table_alias][$field['field_name'] .'_value']['relationship'] = array(
- 'handler' => 'views_handler_relationship',
+ 'handler' => 'content_taxonomy_handler_relationship',
'base' => 'term_data',
'field' => 'tid',
'label' => t('@field-title term', array('@field-title' => check_plain(t($field['widget']['label'])))),
+ 'content_field_name' => $field['field_name'],
);
// Swap the filter handler to the 'in' operator.
diff --git a/includes/views/content_taxonomy.views.inc b/includes/views/content_taxonomy.views.inc
index 81b12b0..07a49b3 100644
--- a/includes/views/content_taxonomy.views.inc
+++ b/includes/views/content_taxonomy.views.inc
@@ -12,6 +12,9 @@ function content_taxonomy_views_handlers() {
'content_taxonomy_handler_filter_many_to_one' => array(
'parent' => 'content_handler_filter_many_to_one',
),
+ 'content_taxonomy_handler_relationship' => array(
+ 'parent' => 'views_handler_relationship',
+ ),
),
);
}
diff --git a/includes/views/content_taxonomy_handler_relationship.inc b/includes/views/content_taxonomy_handler_relationship.inc
new file mode 100644
index 0000000..a09b93b
--- /dev/null
+++ b/includes/views/content_taxonomy_handler_relationship.inc
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @file
+ * Handles content relationships and deals properly with multiple
+ * values by allowing the views administrator to select deltas.
+ */
+class content_taxonomy_handler_relationship extends views_handler_relationship {
+ var $content_field;
+
+ function construct() {
+ parent::construct();
+
+ $this->content_field = content_fields($this->definition['content_field_name']);
+ }
+
+ function option_definition() {
+ $options = parent::option_definition();
+ $options['delta'] = array('default' => -1);
+
+ return $options;
+ }
+
+ /**
+ * Add a delta selector for multiple fields.
+ */
+ function options_form(&$form, &$form_state) {
+ $field = $this->content_field;
+ parent::options_form($form, $form_state);
+
+ // Only add the form gadget if the field is multiple.
+ if ($field['multiple']) {
+ $max_delta = $field['multiple'];
+ // 1 means unlimited.
+ if ($max_delta == 1) {
+ $max_delta = 10;
+ }
+
+ $options = array('-1' => t('All'));
+ for ($i = 0; $i < $max_delta; $i++) {
+ $options[$i] = $i + 1;
+ }
+ $form['delta'] = array(
+ '#type' => 'select',
+ '#options' => $options,
+ '#default_value' => $this->options['delta'],
+ '#title' => t('Delta'),
+ '#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'),
+ );
+ }
+ }
+
+ function ensure_my_table() {
+ if (!isset($this->table_alias)) {
+ $join = $this->get_join();
+ if (!isset($join->extra)) {
+ $join->extra = array();
+ }
+ $delta = isset($this->options['delta']) ? $this->options['delta'] : -1;
+ if ($delta != -1) {
+ $join->extra[] = array(
+ 'field' => 'delta',
+ 'value' => $delta,
+ 'numeric' => TRUE,
+ );
+ }
+
+ $this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
+ }
+ return $this->table_alias;
+ }
+} \ No newline at end of file