You are here

function _webform_report_get_data in Webform Report 5

Same name and namespace in other branches
  1. 6 webform_report.inc \_webform_report_get_data()

Get date data for the specified webform

Parameters

node is an object of type node:

Return value

a database query result set

2 calls to _webform_report_get_data()
webform_report_csv in ./webform_report.module
Output a webform report in CSV format
webform_report_view in ./webform_report.module
Implementation of hook_view

File

./webform_report.module, line 531

Code

function _webform_report_get_data($node) {
  $result = NULL;
  if (is_array($node->components) and count($node->components) > 0) {

    // build a subquery for the specified components
    $query = "c.cid = '";
    $count = 0;
    foreach ($node->components as $component) {
      $query .= $component;
      if ($count < count($node->components) - 1) {
        $query .= "' OR c.cid = '";
      }
      $count++;
    }
    $query .= "'";
    $result = db_query("SELECT w.nid, c.name, c.cid, c.type, d.nid, d.sid, d.data, s.uid, u.name as user, s.submitted, s.remote_addr\n                        FROM {webform} w\n                        LEFT JOIN {webform_submitted_data} d ON w.nid = d.nid\n                        LEFT JOIN {webform_component} c ON d.cid = c.cid AND d.nid = c.nid\n                        LEFT JOIN {webform_submissions} s ON d.sid = s.sid\n                        LEFT JOIN {users} u ON s.uid = u.uid\n                        WHERE w.nid = %d\n                        AND (" . $query . ")\n                        ORDER BY d.sid, c.cid, c.name, d.data", $node->wnid);
  }
  return $result;
}