tidy up column headings
This commit is contained in:
@@ -37,17 +37,6 @@ function booking_studygroups_csv_report($group_id) {
|
|||||||
$delimiter_esc = preg_quote($delimiter, '/');
|
$delimiter_esc = preg_quote($delimiter, '/');
|
||||||
$enclosure_esc = preg_quote($enclosure, '/');
|
$enclosure_esc = preg_quote($enclosure, '/');
|
||||||
|
|
||||||
//is this study group a readings group?
|
|
||||||
// @todo do we even care?
|
|
||||||
/*
|
|
||||||
if ($group_id == variable_get('booking_readinggroup_id','7')) {
|
|
||||||
$is_reading_group = TRUE;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$is_reading_group = FALSE;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
//get the list of study group session memberships
|
//get the list of study group session memberships
|
||||||
$session_members_query = db_query("SELECT m.*, p.booking_firstname, p.booking_lastname FROM {booking_studygroup_mapping} m
|
$session_members_query = db_query("SELECT m.*, p.booking_firstname, p.booking_lastname FROM {booking_studygroup_mapping} m
|
||||||
inner join {booking_person} p on p.nid = m.booking_node_id
|
inner join {booking_person} p on p.nid = m.booking_node_id
|
||||||
@@ -55,12 +44,6 @@ function booking_studygroups_csv_report($group_id) {
|
|||||||
array(':sid' => $group_id));
|
array(':sid' => $group_id));
|
||||||
$session_members = $session_members_query->fetchAll();
|
$session_members = $session_members_query->fetchAll();
|
||||||
|
|
||||||
/*
|
|
||||||
$session_members_query = db_query("SELECT * FROM {booking_studygroup_mapping} WHERE booking_studygroup_id = :sid ORDER BY booking_session_id",
|
|
||||||
array(':sid' => $group_id));
|
|
||||||
$session_members = $session_members_query->fetchAll();
|
|
||||||
*/
|
|
||||||
|
|
||||||
//generate the row data
|
//generate the row data
|
||||||
foreach ($session_members as $member) {
|
foreach ($session_members as $member) {
|
||||||
if (! isset($data[$member->booking_session_id])) {
|
if (! isset($data[$member->booking_session_id])) {
|
||||||
@@ -74,20 +57,22 @@ function booking_studygroups_csv_report($group_id) {
|
|||||||
}
|
}
|
||||||
//add the spaces and put this element in the right array
|
//add the spaces and put this element in the right array
|
||||||
$data[$member->booking_session_id][] = implode(' ', $text);
|
$data[$member->booking_session_id][] = implode(' ', $text);
|
||||||
|
|
||||||
//$data[$member->booking_session_id][] = $member->booking_node_id;
|
|
||||||
}
|
}
|
||||||
watchdog('booking_debug', "<pre>Study Group CSV Report\n@info</pre>", array('@info' => print_r( $data_array, true)));
|
watchdog('booking_debug', "<pre>Study Group CSV Report\n@info</pre>", array('@info' => print_r( $data_array, true)));
|
||||||
|
|
||||||
//calculate the CSV layout
|
//calculate the CSV layout
|
||||||
$header_array = array_keys($data);
|
$header_array = array_keys($data);
|
||||||
$maximums = array();
|
$maximums = array();
|
||||||
|
$column_headings = array();
|
||||||
foreach ($header_array as $column) {
|
foreach ($header_array as $column) {
|
||||||
$maximums[] = count($data[$column]);
|
$maximums[] = count($data[$column]);
|
||||||
|
//make the column headings a bit more user friendly
|
||||||
|
$column_headings[] = "Session " . $column;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the column headings to the CSV
|
//add the column headings to the CSV
|
||||||
$header = implode( $delimiter, $header_array );
|
$header = implode( $delimiter, $column_headings );
|
||||||
$csv .= $header . "\n";
|
$csv .= $header . "\n";
|
||||||
|
|
||||||
//generate each row for the CSV
|
//generate each row for the CSV
|
||||||
@@ -114,26 +99,4 @@ function booking_studygroups_csv_report($group_id) {
|
|||||||
drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
|
drupal_add_http_header("Content-Disposition", "attachment; filename=" . $name . ".csv");
|
||||||
print $csv;
|
print $csv;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function taken from http://php.net/manual/en/function.fputcsv.php#87120
|
|
||||||
*/
|
|
||||||
function fputcsv2 ($fh, array $fields, $delimiter = ',', $enclosure = '"', $mysql_null = false) {
|
|
||||||
$delimiter_esc = preg_quote($delimiter, '/');
|
|
||||||
$enclosure_esc = preg_quote($enclosure, '/');
|
|
||||||
|
|
||||||
$output = array();
|
|
||||||
foreach ($fields as $field) {
|
|
||||||
if ($field === null && $mysql_null) {
|
|
||||||
$output[] = 'NULL';
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field) ? (
|
|
||||||
$enclosure . str_replace($enclosure, $enclosure . $enclosure, $field) . $enclosure
|
|
||||||
) : $field;
|
|
||||||
}
|
|
||||||
|
|
||||||
fwrite($fh, join($delimiter, $output) . "\n");
|
|
||||||
}
|
|
Reference in New Issue
Block a user