1 |
a45e4bc1
|
Assos Assos
|
<?php
|
2 |
feca1e4a
|
Assos Assos
|
|
3 |
a45e4bc1
|
Assos Assos
|
/**
|
4 |
|
|
* Views' relationship handlers.
|
5 |
|
|
*/
|
6 |
feca1e4a
|
Assos Assos
|
class webform_handler_relationship_submission_data extends views_handler_relationship {
|
7 |
a45e4bc1
|
Assos Assos
|
|
8 |
feca1e4a
|
Assos Assos
|
/**
|
9 |
76bdcd04
|
Assos Assos
|
* {@inheritdoc}
|
10 |
feca1e4a
|
Assos Assos
|
*/
|
11 |
|
|
public function option_definition() {
|
12 |
a45e4bc1
|
Assos Assos
|
$options = parent::option_definition();
|
13 |
|
|
$options['webform_nid'] = array('default' => NULL);
|
14 |
|
|
$options['webform_cid'] = array('default' => NULL);
|
15 |
c5920ca5
|
Assos Assos
|
$options['webform_form_key'] = array('default' => NULL);
|
16 |
|
|
$options['webform_join_by'] = array('default' => 'nid_cid');
|
17 |
a45e4bc1
|
Assos Assos
|
return $options;
|
18 |
|
|
}
|
19 |
|
|
|
20 |
feca1e4a
|
Assos Assos
|
/**
|
21 |
76bdcd04
|
Assos Assos
|
* {@inheritdoc}
|
22 |
feca1e4a
|
Assos Assos
|
*/
|
23 |
|
|
public function options_form(&$form, &$form_state) {
|
24 |
a45e4bc1
|
Assos Assos
|
parent::options_form($form, $form_state);
|
25 |
|
|
form_load_include($form_state, 'inc', 'webform', 'views/webform.views');
|
26 |
|
|
|
27 |
|
|
$nid = (int) $this->options['webform_nid'];
|
28 |
|
|
$cid = (int) $this->options['webform_cid'];
|
29 |
|
|
|
30 |
|
|
// Helper function provides webform_nid and webform_cid options.
|
31 |
|
|
_webform_views_options_form($form, $form_state, $nid, $cid);
|
32 |
c5920ca5
|
Assos Assos
|
|
33 |
|
|
$form['webform_join_by'] = array(
|
34 |
|
|
'#type' => 'select',
|
35 |
|
|
'#title' => t('Relate using'),
|
36 |
|
|
'#default_value' => $this->options['webform_join_by'],
|
37 |
|
|
'#options' => array(
|
38 |
|
|
'nid_cid' => t('Node and Component ID'),
|
39 |
|
|
'cid' => t('Component ID'),
|
40 |
|
|
'form_key' => t('Component Form Key'),
|
41 |
|
|
),
|
42 |
|
|
'#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.'),
|
43 |
|
|
);
|
44 |
|
|
|
45 |
a45e4bc1
|
Assos Assos
|
}
|
46 |
|
|
|
47 |
feca1e4a
|
Assos Assos
|
/**
|
48 |
76bdcd04
|
Assos Assos
|
* {@inheritdoc}
|
49 |
feca1e4a
|
Assos Assos
|
*/
|
50 |
|
|
public function options_validate(&$form, &$form_state) {
|
51 |
a45e4bc1
|
Assos Assos
|
parent::options_validate($form, $form_state);
|
52 |
|
|
_webform_views_options_validate($form, $form_state);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
feca1e4a
|
Assos Assos
|
/**
|
56 |
76bdcd04
|
Assos Assos
|
* {@inheritdoc}
|
57 |
feca1e4a
|
Assos Assos
|
*/
|
58 |
|
|
public function options_submit(&$form, &$form_state) {
|
59 |
a45e4bc1
|
Assos Assos
|
parent::options_submit($form, $form_state);
|
60 |
|
|
_webform_views_options_submit($form, $form_state);
|
61 |
c5920ca5
|
Assos Assos
|
$options =& $form_state['values']['options'];
|
62 |
389fb945
|
Assos Assos
|
$options['webform_form_key'] = $options['webform_join_by'] == 'form_key' && ($node = node_load($options['webform_nid']))
|
63 |
c5920ca5
|
Assos Assos
|
? $node->webform['components'][$options['webform_cid']]['form_key']
|
64 |
|
|
: NULL;
|
65 |
|
|
// Drop PHP reference.
|
66 |
|
|
unset($options);
|
67 |
a45e4bc1
|
Assos Assos
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Called to implement a relationship in a query.
|
71 |
|
|
*
|
72 |
|
|
* It respects the given component ids, provided via options form.
|
73 |
|
|
*/
|
74 |
feca1e4a
|
Assos Assos
|
public function query() {
|
75 |
c5920ca5
|
Assos Assos
|
// When defining extra clauses, the 'table' key can be used to specify the
|
76 |
|
|
// alias of another table. If NULL is specified, then the field is not
|
77 |
|
|
// qualified with a table. Therefore, do NOT specify "'table' => NULL".
|
78 |
|
|
switch ($this->options['webform_join_by']) {
|
79 |
|
|
case 'form_key':
|
80 |
|
|
$form_key = $this->options['webform_form_key'];
|
81 |
|
|
$join_type = $this->options['required'] ? 'INNER' : 'LEFT';
|
82 |
|
|
|
83 |
|
|
$this->ensure_my_table();
|
84 |
|
|
$join = new views_join();
|
85 |
|
|
|
86 |
|
|
$join->construct(
|
87 |
|
|
// The table to be joined.
|
88 |
|
|
'webform_component',
|
89 |
|
|
// The left table (i.e. this table, webform_submission).
|
90 |
|
|
$this->table,
|
91 |
|
|
// The left field (i.e. the webform node id).
|
92 |
|
|
'nid',
|
93 |
|
|
// The field (i.e. webform_components.nid).
|
94 |
|
|
'nid',
|
95 |
|
|
// Extra array of additional conditions.
|
96 |
|
|
array(
|
97 |
|
|
array(
|
98 |
|
|
// Extra join of form_key.
|
99 |
|
|
'field' => 'form_key',
|
100 |
|
|
// ... = $form_key (operator '=' is default)
|
101 |
|
|
'value' => $form_key,
|
102 |
|
|
),
|
103 |
|
|
),
|
104 |
|
|
// Join type is the same as this relationship's join type.
|
105 |
|
|
$join_type);
|
106 |
|
|
|
107 |
|
|
$alias = $this->query->add_relationship(
|
108 |
|
|
// Requested alias for new reliationship.
|
109 |
|
|
'webform_component_' . $form_key,
|
110 |
|
|
// Addition join to be added to this relatinship.
|
111 |
|
|
$join,
|
112 |
|
|
// Base table (i.e. drivingevals_submission)
|
113 |
|
|
$this->table_alias,
|
114 |
|
|
// Add the view to this relationship.
|
115 |
|
|
$this->relationship);
|
116 |
|
|
|
117 |
|
|
// The actual alias for this relationship's join is not known yet. Becasue
|
118 |
|
|
// of name conflicts, it may have a number appended to the end. %alias is
|
119 |
|
|
// substitued when the query is build with the actual alias name.
|
120 |
|
|
$this->definition['extra'][] = "%alias.cid = {$alias}.cid";
|
121 |
|
|
break;
|
122 |
|
|
|
123 |
|
|
case 'nid_cid':
|
124 |
|
|
$this->definition['extra'][] = array(
|
125 |
|
|
'field' => "nid",
|
126 |
|
|
'value' => $this->options['webform_nid'],
|
127 |
|
|
);
|
128 |
|
|
// FALL THROUGH.
|
129 |
|
|
case 'cid':
|
130 |
|
|
$this->definition['extra'][] = array(
|
131 |
|
|
'field' => "cid",
|
132 |
|
|
'value' => $this->options['webform_cid'],
|
133 |
|
|
);
|
134 |
|
|
break;
|
135 |
|
|
}
|
136 |
a45e4bc1
|
Assos Assos
|
|
137 |
|
|
// The rest of building the join is performed by the parent.
|
138 |
|
|
parent::query();
|
139 |
|
|
}
|
140 |
feca1e4a
|
Assos Assos
|
|
141 |
a45e4bc1
|
Assos Assos
|
} |