Projet

Général

Profil

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

root / drupal7 / sites / all / modules / webform / views / webform_handler_field_submission_count.inc @ feca1e4a

1
<?php
2

    
3
/**
4
 * @file
5
 * Views handler to display the number of submissions in a webform.
6
 */
7

    
8
/**
9
 * Field handler to present the submission count of a node to the user.
10
 */
11
class webform_handler_field_submission_count extends views_handler_field {
12

    
13
  /**
14
   *
15
   */
16
  public function construct() {
17
    parent::construct();
18
    $this->count_type = $this->definition['count_type'];
19

    
20
    if ($this->count_type == 'node') {
21
      $this->additional_fields['nid'] = 'nid';
22
      $this->additional_fields['type'] = 'type';
23
    }
24
    elseif ($this->count_type == 'users') {
25
      $this->additional_fields['uid'] = 'uid';
26
    }
27
  }
28

    
29
  /**
30
   *
31
   */
32
  public function option_definition() {
33
    $options = parent::option_definition();
34
    $options['label'] = array('default' => '# of Submissions', 'translatable' => TRUE);
35
    return $options;
36
  }
37

    
38
  /**
39
   *
40
   */
41
  public function query() {
42
    $this->ensure_my_table();
43
    $this->add_additional_fields();
44
  }
45

    
46
  /**
47
   *
48
   */
49
  public function render($values) {
50
    global $user;
51

    
52
    $output = NULL;
53
    if ($this->count_type == 'node' && variable_get('webform_node_' . $values->{$this->aliases['type']}, FALSE)) {
54
      module_load_include('inc', 'webform', 'includes/webform.submissions');
55
      $node = node_load($values->{$this->aliases['nid']});
56
      if (webform_results_access($node, $user)) {
57
        $count = webform_get_submission_count($node->nid);
58
        $output = l($count, "node/$node->nid/webform-results");
59
      }
60
      elseif (webform_submission_access($node, NULL, 'list', $user)) {
61
        $count = webform_get_submission_count($node->nid, $user->uid);
62
        $output = l($count, "node/$node->nid/submissions");
63
      }
64
      else {
65
        $output = webform_get_submission_count($node->nid);
66
      }
67
    }
68
    elseif ($this->count_type == 'users') {
69
      $output = db_select('webform_submissions')
70
        ->condition('uid', $values->{$this->aliases['uid']})
71
        ->countQuery()->execute()->fetchField();
72
    }
73

    
74
    return $output;
75
  }
76

    
77
}