1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Views handler to display links to a submission.
|
5 |
01f36513
|
Assos Assos
|
*
|
6 |
85ad3d82
|
Assos Assos
|
* Field handler to present a link to the user.
|
7 |
|
|
*/
|
8 |
|
|
class webform_handler_field_submission_link extends views_handler_field {
|
9 |
feca1e4a
|
Assos Assos
|
public $link_type;
|
10 |
85ad3d82
|
Assos Assos
|
|
11 |
feca1e4a
|
Assos Assos
|
/**
|
12 |
|
|
*
|
13 |
|
|
*/
|
14 |
|
|
public function construct() {
|
15 |
85ad3d82
|
Assos Assos
|
// We need to set this property before calling the construct() chain
|
16 |
|
|
// as we use it in the option_definintion() call.
|
17 |
|
|
$this->link_type = $this->definition['link_type'];
|
18 |
|
|
|
19 |
|
|
parent::construct();
|
20 |
|
|
$this->additional_fields['sid'] = 'sid';
|
21 |
|
|
$this->additional_fields['nid'] = 'nid';
|
22 |
a45e4bc1
|
Assos Assos
|
$this->additional_fields['serial'] = 'serial';
|
23 |
|
|
$this->additional_fields['is_draft'] = 'is_draft';
|
24 |
85ad3d82
|
Assos Assos
|
}
|
25 |
|
|
|
26 |
feca1e4a
|
Assos Assos
|
/**
|
27 |
|
|
*
|
28 |
|
|
*/
|
29 |
|
|
public function allow_advanced_render() {
|
30 |
85ad3d82
|
Assos Assos
|
return FALSE;
|
31 |
|
|
}
|
32 |
|
|
|
33 |
feca1e4a
|
Assos Assos
|
/**
|
34 |
|
|
*
|
35 |
|
|
*/
|
36 |
|
|
public function option_definition() {
|
37 |
85ad3d82
|
Assos Assos
|
$options = parent::option_definition();
|
38 |
|
|
$options['label'] = array('default' => '', 'translatable' => TRUE);
|
39 |
|
|
$options['text'] = array('default' => $this->link_type, 'translatable' => TRUE);
|
40 |
a45e4bc1
|
Assos Assos
|
$options['access_check'] = array('default' => TRUE);
|
41 |
85ad3d82
|
Assos Assos
|
return $options;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
feca1e4a
|
Assos Assos
|
/**
|
45 |
|
|
*
|
46 |
|
|
*/
|
47 |
|
|
public function options_form(&$form, &$form_state) {
|
48 |
85ad3d82
|
Assos Assos
|
parent::options_form($form, $form_state);
|
49 |
|
|
$form['text'] = array(
|
50 |
|
|
'#type' => 'textfield',
|
51 |
|
|
'#title' => t('Text to display'),
|
52 |
|
|
'#default_value' => $this->options['text'],
|
53 |
a45e4bc1
|
Assos Assos
|
'#description' => t('The token [serial] will be replaced with the serial number and draft indication.'),
|
54 |
|
|
);
|
55 |
|
|
$form['access_check'] = array(
|
56 |
|
|
'#type' => 'checkbox',
|
57 |
|
|
'#title' => t('Verify submission access for each link'),
|
58 |
|
|
'#default_value' => $this->options['access_check'],
|
59 |
85ad3d82
|
Assos Assos
|
);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
feca1e4a
|
Assos Assos
|
/**
|
63 |
|
|
*
|
64 |
|
|
*/
|
65 |
|
|
public function render($values) {
|
66 |
a45e4bc1
|
Assos Assos
|
$sid = $values->{$this->aliases['sid']};
|
67 |
|
|
$nid = $values->{$this->aliases['nid']};
|
68 |
|
|
$serial = $values->{$this->aliases['serial']};
|
69 |
|
|
$is_draft = $values->{$this->aliases['is_draft']};
|
70 |
85ad3d82
|
Assos Assos
|
|
71 |
a45e4bc1
|
Assos Assos
|
$text = str_ireplace('[serial]',
|
72 |
|
|
$serial . ($is_draft ? ' (' . t('draft') . ')' : ''),
|
73 |
|
|
$this->options['text']);
|
74 |
85ad3d82
|
Assos Assos
|
switch ($this->link_type) {
|
75 |
|
|
case 'view':
|
76 |
a45e4bc1
|
Assos Assos
|
$text = !empty($text) ? $text : t('view');
|
77 |
|
|
$link = l($text, "node/$nid/submission/$sid");
|
78 |
85ad3d82
|
Assos Assos
|
break;
|
79 |
feca1e4a
|
Assos Assos
|
|
80 |
85ad3d82
|
Assos Assos
|
case 'edit':
|
81 |
a45e4bc1
|
Assos Assos
|
$text = !empty($text) ? $text : t('edit');
|
82 |
|
|
$link = l($text, "node/$nid/submission/$sid/edit");
|
83 |
85ad3d82
|
Assos Assos
|
break;
|
84 |
feca1e4a
|
Assos Assos
|
|
85 |
85ad3d82
|
Assos Assos
|
case 'delete':
|
86 |
a45e4bc1
|
Assos Assos
|
$text = !empty($text) ? $text : t('delete');
|
87 |
85ad3d82
|
Assos Assos
|
$path = drupal_get_path_alias($_GET['q']);
|
88 |
a45e4bc1
|
Assos Assos
|
$link = l($text, "node/$nid/submission/$sid/delete", array('query' => array('destination' => $path)));
|
89 |
85ad3d82
|
Assos Assos
|
break;
|
90 |
feca1e4a
|
Assos Assos
|
|
91 |
85ad3d82
|
Assos Assos
|
default:
|
92 |
a45e4bc1
|
Assos Assos
|
return;
|
93 |
85ad3d82
|
Assos Assos
|
}
|
94 |
|
|
|
95 |
a45e4bc1
|
Assos Assos
|
if ($this->options['access_check']) {
|
96 |
|
|
module_load_include('inc', 'webform', 'includes/webform.submissions');
|
97 |
|
|
$node = node_load($nid);
|
98 |
|
|
$submission = webform_get_submission($nid, $sid);
|
99 |
|
|
if (!webform_submission_access($node, $submission, $this->link_type)) {
|
100 |
|
|
return;
|
101 |
|
|
}
|
102 |
85ad3d82
|
Assos Assos
|
}
|
103 |
|
|
|
104 |
|
|
return $link;
|
105 |
|
|
}
|
106 |
feca1e4a
|
Assos Assos
|
|
107 |
85ad3d82
|
Assos Assos
|
} |