You are here

function webform_get_submission_count in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform_submissions.inc \webform_get_submission_count()
  2. 6.3 includes/webform.submissions.inc \webform_get_submission_count()
  3. 6.2 webform_submissions.inc \webform_get_submission_count()
  4. 7.3 includes/webform.submissions.inc \webform_get_submission_count()

Return a count of the total number of submissions for a node.

Parameters

$nid: The node ID for which submissions are being fetched.

$uid: Optional; the user ID to filter the submissions by.

$is_draft: Optional; NULL for all, truthy for drafts only, falsy for completed only. The default is completed submissions only.

Return value

int The number of submissions.

7 calls to webform_get_submission_count()
WebformSubmissionTestCase::testWebformSubmission in tests/WebformSubmissionTestCase.test
Test sending a submission and check database integrity.
webform_clear_batch_rows in includes/webform.report.inc
Batch API callback; Write the rows of the export to the export file.
webform_handler_field_submission_count::render in views/webform_handler_field_submission_count.inc
Render the field.
webform_node_view in ./webform.module
Implements hook_node_view().
webform_results_download_range_after_build in includes/webform.report.inc
FormAPI after build function for the download range fieldset.

... See full list

File

includes/webform.submissions.inc, line 961
Submission handling functions.

Code

function webform_get_submission_count($nid, $uid = NULL, $is_draft = 0) {
  $counts =& drupal_static(__FUNCTION__);
  if (!isset($counts[$nid][$uid])) {
    $query = db_select('webform_submissions', 'ws')
      ->addTag('webform_get_submission_count')
      ->condition('ws.nid', $nid);
    if ($uid !== NULL) {
      $query
        ->condition('ws.uid', $uid);
    }
    if ($uid === 0) {
      $submissions = isset($_SESSION['webform_submission']) ? $_SESSION['webform_submission'] : NULL;
      if ($submissions) {
        $query
          ->condition('ws.sid', array_keys($submissions), 'IN');
      }
      else {

        // Intentionally never match anything if the anonymous user has no
        // submissions.
        $query
          ->condition('ws.sid', 0);
      }
    }
    if (isset($is_draft)) {
      $query
        ->condition('ws.is_draft', $is_draft);
    }
    $counts[$nid][$uid] = $query
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  return $counts[$nid][$uid];
}