Projet

Général

Profil

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

root / drupal7 / sites / all / modules / webform / views / webform_handler_field_submission_link.inc @ 01f36513

1
<?php
2

    
3
/**
4
 * Views handler to display links to a submission.
5
 *
6
 * Field handler to present a link to the user.
7
 */
8
class webform_handler_field_submission_link extends views_handler_field {
9
  public $link_type;
10

    
11
  /**
12
   *
13
   */
14
  public 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
  /**
27
   *
28
   */
29
  public function allow_advanced_render() {
30
    return FALSE;
31
  }
32

    
33
  /**
34
   *
35
   */
36
  public function option_definition() {
37
    $options = parent::option_definition();
38
    $options['label'] = array('default' => '', 'translatable' => TRUE);
39
    $options['text'] = array('default' => $this->link_type, 'translatable' => TRUE);
40
    $options['access_check'] = array('default' => TRUE);
41
    return $options;
42
  }
43

    
44
  /**
45
   *
46
   */
47
  public function options_form(&$form, &$form_state) {
48
    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
      '#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
    );
60
  }
61

    
62
  /**
63
   *
64
   */
65
  public function render($values) {
66
    $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

    
71
    $text = str_ireplace('[serial]',
72
                          $serial . ($is_draft ? ' (' . t('draft') . ')' : ''),
73
                          $this->options['text']);
74
    switch ($this->link_type) {
75
      case 'view':
76
        $text = !empty($text) ? $text : t('view');
77
        $link = l($text, "node/$nid/submission/$sid");
78
        break;
79

    
80
      case 'edit':
81
        $text = !empty($text) ? $text : t('edit');
82
        $link = l($text, "node/$nid/submission/$sid/edit");
83
        break;
84

    
85
      case 'delete':
86
        $text = !empty($text) ? $text : t('delete');
87
        $path = drupal_get_path_alias($_GET['q']);
88
        $link = l($text, "node/$nid/submission/$sid/delete", array('query' => array('destination' => $path)));
89
        break;
90

    
91
      default:
92
        return;
93
    }
94

    
95
    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
    }
103

    
104
    return $link;
105
  }
106

    
107
}