View source
<?php
class webform_handler_relationship_submission_data extends views_handler_relationship {
public function option_definition() {
$options = parent::option_definition();
$options['webform_nid'] = array(
'default' => NULL,
);
$options['webform_cid'] = array(
'default' => NULL,
);
$options['webform_form_key'] = array(
'default' => NULL,
);
$options['webform_join_by'] = array(
'default' => 'nid_cid',
);
return $options;
}
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
form_load_include($form_state, 'inc', 'webform', 'views/webform.views');
$nid = (int) $this->options['webform_nid'];
$cid = (int) $this->options['webform_cid'];
_webform_views_options_form($form, $form_state, $nid, $cid);
$form['webform_join_by'] = array(
'#type' => 'select',
'#title' => t('Relate using'),
'#default_value' => $this->options['webform_join_by'],
'#options' => array(
'nid_cid' => t('Node and Component ID'),
'cid' => t('Component ID'),
'form_key' => t('Component Form Key'),
),
'#description' => t('Choose <em>Node and Component ID</em> when this view will display data from only this webform.</br>Choose <em>Component ID</em> when this view will display data from other webforms and where the Component ID is identical.</br>Choose <em>Component Form Key</em> when this view will display data from other webforms with varying Component IDs.'),
);
}
public function options_validate(&$form, &$form_state) {
parent::options_validate($form, $form_state);
_webform_views_options_validate($form, $form_state);
}
public function options_submit(&$form, &$form_state) {
parent::options_submit($form, $form_state);
_webform_views_options_submit($form, $form_state);
$options =& $form_state['values']['options'];
$options['webform_form_key'] = $options['webform_join_by'] == 'form_key' && ($node = node_load($options['webform_nid'])) ? $node->webform['components'][$options['webform_cid']]['form_key'] : NULL;
unset($options);
}
public function query() {
switch ($this->options['webform_join_by']) {
case 'form_key':
$form_key = $this->options['webform_form_key'];
$join_type = $this->options['required'] ? 'INNER' : 'LEFT';
$this
->ensure_my_table();
$join = new views_join();
$join
->construct('webform_component', $this->table, 'nid', 'nid', array(
array(
'field' => 'form_key',
'value' => $form_key,
),
), $join_type);
$alias = $this->query
->add_relationship('webform_component_' . $form_key, $join, $this->table_alias, $this->relationship);
$this->definition['extra'][] = "%alias.cid = {$alias}.cid";
break;
case 'nid_cid':
$this->definition['extra'][] = array(
'field' => "nid",
'value' => $this->options['webform_nid'],
);
case 'cid':
$this->definition['extra'][] = array(
'field' => "cid",
'value' => $this->options['webform_cid'],
);
break;
}
parent::query();
}
}