Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created January 4, 2017 16:10
Show Gist options
  • Save lkacenja/0399831c7cc18aed868fdcd35743960f to your computer and use it in GitHub Desktop.
Save lkacenja/0399831c7cc18aed868fdcd35743960f to your computer and use it in GitHub Desktop.
<?php
function foop($class_date_nid, $webform_nid) {
$sub_query = db_select('webform_submitted_data', 'w');
$sub_query->fields('w', array('sid'));
$sub_query->join('webform_component', 'webform_component', 'w.cid=webform_component.cid');
$sub_query->condition('form_key', 'ssl_date_nid', '=');
$sub_query->condition('webform_component.nid', $webform_nid, '=');
$sub_query->condition('data', $class_date_nid, '=');
$query = db_select('webform_submitted_data', 'w');
$query->fields('w', array());
$query->addField('webform_component', 'name', 'name');
$query ->join('webform_component', 'webform_component', 'w.cid=webform_component.cid');
$query->condition('sid', $sub_query, 'IN');
$query->condition('webform_component.nid', $webform_nid, '=');
$query->condition('form_key', 'ssl_date_nid', '!=');
$resource = $query->execute();
$output = array();
while ($row = $resource->fetchObject()) {
$output[$row->sid] = !empty($output[$row->sid]) ? $output[$row->sid] : array();
$output[$row->sid][] = $row;
}
return array_values($output);
}
$z = foop(213, 211);
$headers = array();
$rows = array();
function ywca_api_get_headers_from_submission($item) {
return $item->name;
}
function ywca_api_get_rows_from_submission($item) {
return $item->data;
}
foreach($z AS $item) {
if (empty($headers)) {
$headers = array_map('ywca_api_get_headers_from_submission', $item);
}
$rows[] = array_map('ywca_api_get_rows_from_submission', $item);
}
$render = array(
'#theme' => 'table',
'#header' => $headers,
'#rows' => $rows
);
dsm(render($render));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment