You are here

public function webform_handler_field_submission_count::render in Webform 7.3

Same name and namespace in other branches
  1. 6.3 views/webform_handler_field_submission_count.inc \webform_handler_field_submission_count::render()
  2. 7.4 views/webform_handler_field_submission_count.inc \webform_handler_field_submission_count::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

views/webform_handler_field_submission_count.inc, line 49
Views handler to display the number of submissions in a webform.

Class

webform_handler_field_submission_count
Field handler to present the submission count of a node to the user.

Code

public function render($values) {
  global $user;
  $output = NULL;
  if ($this->count_type == 'node' && in_array($values->{$this->aliases['type']}, webform_variable_get('webform_node_types'))) {
    module_load_include('inc', 'webform', 'includes/webform.submissions');
    $node = node_load($values->{$this->aliases['nid']});
    if (webform_results_access($node, $user)) {
      $count = webform_get_submission_count($node->nid);
      $output = l($count, "node/{$node->nid}/webform-results");
    }
    else {
      $count = webform_get_submission_count($node->nid, $user->uid);
      $output = l($count, "node/{$node->nid}/submissions");
    }
  }
  elseif ($this->count_type == 'users') {
    $output = db_select('webform_submissions')
      ->condition('uid', $values->{$this->aliases['uid']})
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  return $output;
}