Projet

Général

Profil

Paste
Télécharger (2,86 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / webform / views / webform_handler_field_submission_link.inc @ 8c72e82a

1
<?php
2

    
3
/**
4
 * @file
5
 * Views handler to display links to a submission.
6
 */
7

    
8
/**
9
 * Field handler to present a link to the user.
10
 */
11
class webform_handler_field_submission_link extends views_handler_field {
12
  var $link_type;
13

    
14
  function construct() {
15
    // 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
    $this->additional_fields['serial'] = 'serial';
23
    $this->additional_fields['is_draft'] = 'is_draft';
24
  }
25

    
26
  function allow_advanced_render() {
27
    return FALSE;
28
  }
29

    
30
  function option_definition() {
31
    $options = parent::option_definition();
32
    $options['label'] = array('default' => '', 'translatable' => TRUE);
33
    $options['text'] = array('default' => $this->link_type, 'translatable' => TRUE);
34
    $options['access_check'] = array('default' => TRUE);
35
    return $options;
36
  }
37

    
38
  function options_form(&$form, &$form_state) {
39
    parent::options_form($form, $form_state);
40
    $form['text'] = array(
41
      '#type' => 'textfield',
42
      '#title' => t('Text to display'),
43
      '#default_value' => $this->options['text'],
44
      '#description' => t('The token [serial] will be replaced with the serial number and draft indication.'),
45
    );
46
    $form['access_check'] = array(
47
      '#type' => 'checkbox',
48
      '#title' => t('Verify submission access for each link'),
49
      '#default_value' => $this->options['access_check'],
50
    );
51
  }
52

    
53
  function render($values) {
54
    $sid = $values->{$this->aliases['sid']};
55
    $nid = $values->{$this->aliases['nid']};
56
    $serial = $values->{$this->aliases['serial']};
57
    $is_draft = $values->{$this->aliases['is_draft']};
58

    
59
    $text = str_ireplace('[serial]',
60
                          $serial . ($is_draft ? ' (' . t('draft') . ')' : ''),
61
                          $this->options['text']);
62
    switch ($this->link_type) {
63
      case 'view':
64
        $text = !empty($text) ? $text : t('view');
65
        $link = l($text, "node/$nid/submission/$sid");
66
        break;
67
      case 'edit':
68
        $text = !empty($text) ? $text : t('edit');
69
        $link = l($text, "node/$nid/submission/$sid/edit");
70
        break;
71
      case 'delete':
72
        $text = !empty($text) ? $text : t('delete');
73
        $path = drupal_get_path_alias($_GET['q']);
74
        $link = l($text, "node/$nid/submission/$sid/delete", array('query' => array('destination' => $path)));
75
        break;
76
      default:
77
        return;
78
    }
79

    
80
    if ($this->options['access_check']) {
81
      module_load_include('inc', 'webform', 'includes/webform.submissions');
82
      $node = node_load($nid);
83
      $submission = webform_get_submission($nid, $sid);
84
      if (!webform_submission_access($node, $submission, $this->link_type)) {
85
        return;
86
      }
87
    }
88

    
89
    return $link;
90
  }
91
}