function webform_get_submissions_load in Webform 7.4
Retrieve and load the submissions for the specified submissions query.
This is an internal routine and not intended for use by other modules.
@params object $pager_query A select or extended select query containing the needed fields: webform_submissions: all fields user: name
Return value
array An array of loaded webform submissions.
2 calls to webform_get_submissions_load()
- webform_get_submissions in includes/
webform.submissions.inc - Return all the submissions for a particular node.
- webform_results_batch_rows in includes/
webform.report.inc - Batch API callback; Write the rows of the export to the export file.
File
- includes/
webform.submissions.inc, line 876 - Submission handling functions.
Code
function webform_get_submissions_load($pager_query) {
// If the "$pager_query" is actually an unextended select query, then instead
// of querying the webform_submissions_data table with a potentially huge
// array of sids in an IN clause, use the select query directly as this will
// be much faster. Extended queries don't work in join clauses. The query
// is assumed to include the sid.
if ($pager_query instanceof SelectQuery) {
$submissions_query = clone $pager_query;
}
// Extract any filter on node id to use in an optimization below.
foreach ($pager_query
->conditions() as $index => $condition) {
if ($index !== '#conjunction' && $condition['operator'] === '=' && ($condition['field'] === 'nid' || $condition['field'] === 'ws.nid')) {
$nid = $condition['value'];
break;
}
}
$result = $pager_query
->execute();
$submissions = $result
->fetchAllAssoc('sid');
// If there are no submissions being retrieved, return an empty array.
if (!$submissions) {
return $submissions;
}
foreach ($submissions as $sid => $submission) {
$submissions[$sid]->preview = FALSE;
$submissions[$sid]->data = array();
}
// Query the required submission data.
$query = db_select('webform_submitted_data', 'sd');
$query
->addTag('webform_get_submissions_data')
->fields('sd', array(
'sid',
'cid',
'no',
'data',
))
->orderBy('sd.sid', 'ASC')
->orderBy('sd.cid', 'ASC')
->orderBy('sd.no', 'ASC');
if (isset($submissions_query)) {
// If available, prefer joining on the subquery as it is much faster than an
// IN clause on a large array. A subquery with the IN operator doesn't work
// when the subquery has a LIMIT clause, requiring an inner join instead.
$query
->innerJoin($submissions_query, 'ws2', 'sd.sid = ws2.sid');
}
else {
$query
->condition('sd.sid', array_keys($submissions), 'IN');
}
// By adding the NID to this query we allow MySQL to use the primary key on
// in webform_submitted_data for sorting (nid_sid_cid_no).
if (isset($nid)) {
$query
->condition('sd.nid', $nid);
}
$result = $query
->execute();
// Convert the queried rows into submission data.
foreach ($result as $row) {
$submissions[$row->sid]->data[$row->cid][$row->no] = $row->data;
}
foreach (module_implements('webform_submission_load') as $module) {
$function = $module . '_webform_submission_load';
$function($submissions);
}
return $submissions;
}