You are here

function webform_download_latest_start_sid in Webform 7.4

Get an SID based a requested latest count.

Parameters

int $nid: The webform NID.

int $latest_count: The latest count on which the SID will be retrieved.

string $completion_type: The completion type, either "finished", "draft", or "all".

Return value

int The submission ID that starts the latest sequence of submissions.

1 call to webform_download_latest_start_sid()
webform_download_sids_query in includes/webform.report.inc
Given a set of range options, return an unexecuted select query.

File

includes/webform.report.inc, line 2111
This file includes helper functions for creating reports for webform.module.

Code

function webform_download_latest_start_sid($nid, $latest_count, $completion_type = 'all') {

  // @todo Find a more efficient DBTNG query to retrieve this number.
  $query = db_select('webform_submissions', 'ws')
    ->fields('ws', array(
    'sid',
  ))
    ->condition('nid', $nid)
    ->orderBy('ws.sid', 'DESC')
    ->range(0, $latest_count)
    ->addTag('webform_download_latest_start_sid');
  if ($completion_type !== 'all') {
    $query
      ->condition('is_draft', (int) ($completion_type === 'draft'));
  }
  $latest_sids = $query
    ->execute()
    ->fetchCol();
  return $latest_sids ? min($latest_sids) : 1;
}