add CSV report for variety session

This commit is contained in:
Nathan Coad
2018-05-04 22:38:48 +10:00
parent b376faca6f
commit 9a4b327250

View File

@@ -26,6 +26,7 @@ function booking_variety_admin()
'variety_edit' => t('Edit Timeslot'), 'variety_edit' => t('Edit Timeslot'),
'variety_session_list' => t('List Sessions'), 'variety_session_list' => t('List Sessions'),
'variety_session_add' => t('Add Session'), 'variety_session_add' => t('Add Session'),
'variety_session_csv' => t('CSV Report'),
); );
$result = db_query("SELECT * from {booking_variety_timeslots}"); $result = db_query("SELECT * from {booking_variety_timeslots}");
@@ -42,6 +43,7 @@ function booking_variety_admin()
'variety_edit' => l('Edit Timeslot', t('admin/config/booking/variety/!tid/edit', array('!tid' => $data->tid))), 'variety_edit' => l('Edit Timeslot', t('admin/config/booking/variety/!tid/edit', array('!tid' => $data->tid))),
'variety_session_list' => l('List Sessions', t('admin/config/booking/variety/!tid/session/list', array('!tid' => $data->tid))), 'variety_session_list' => l('List Sessions', t('admin/config/booking/variety/!tid/session/list', array('!tid' => $data->tid))),
'variety_session_add' => l('Add Session', t('admin/config/booking/variety/!tid/session/create', array('!tid' => $data->tid))), 'variety_session_add' => l('Add Session', t('admin/config/booking/variety/!tid/session/create', array('!tid' => $data->tid))),
'variety_session_csv' => l('CSV Report', t('admin/config/booking/variety/!tid/csv', array('!tid' => $data->tid))),
); );
} }
@@ -384,14 +386,12 @@ function booking_varietysessions_csv_report($timeslot_id) {
return ""; return "";
} }
// TODO - UPDATE FROM HERE ON! //retrieve the sessions for the specified timeslot
$variety_sessions = db_query("SELECT * FROM {booking_variety_sessions} WHERE booking_eventid = :eid and booking_variety_timeslot_id = :tid",
//retrieve the name of the study group for the specified ID
$variety_session_timeslot = db_query("SELECT * FROM {booking_variety_timeslots} WHERE booking_eventid = :eid and tid = :tid",
array(':eid' => $event->eid, ':tid' => $timeslot_id)) array(':eid' => $event->eid, ':tid' => $timeslot_id))
->fetchObject(); ->fetchObject();
if (! $variety_session_timeslot) { if (! $variety_sessions) {
drupal_set_message("Error: Could not find matching variety session timeslot. Unable to view session membership.", 'error', FALSE); drupal_set_message("Error: Could not find matching variety session timeslot. Unable to view session membership.", 'error', FALSE);
drupal_goto('admin/config/booking/variety'); drupal_goto('admin/config/booking/variety');
return ""; return "";
@@ -409,34 +409,29 @@ function booking_varietysessions_csv_report($timeslot_id) {
$enclosure_esc = preg_quote($enclosure, '/'); $enclosure_esc = preg_quote($enclosure, '/');
//get the list of study group session memberships //get the list of study group session memberships
$session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m $session_members_query = db_query("SELECT r.*, p.* FROM {booking_variety_regn} r
inner join {booking_person} p on p.nid = m.booking_node_id inner join {booking_person} p on p.nid = r.booking_person_nid
WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC, p.booking_lastname", WHERE p.booking_eventid = :eid ORDER BY r.brid",
array(':sid' => $group_id)); array(':eid' => $event->eid));
$session_members = $session_members_query->fetchAll(); $session_members = $session_members_query->fetchAll();
watchdog('booking_debug', 'booking_varietysessions_csv_report session members: <pre>@info</pre>', array('@info' => print_r( $session_members, true)));
//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])) { $session_ids = drupal_json_decode($member->booking_variety_ids);
$data[$member->booking_session_id] = array(); watchdog('booking_debug', 'booking_varietysessions_csv_report person session ids: <pre>@info</pre>', array('@info' => print_r( $session_ids, true)));
//get the session id that matches our timeslot
$sid = $session_ids[$timeslot_id];
if (! isset($data[$sid])) {
$data[$sid] = array();
} }
// lookup the name and role for this entry in the study group session and optionally include age
if (variable_get('booking_studygroup_csv_ages', 0) == 1) {
$text = array($member->booking_firstname, $member->booking_lastname, '[' . _booking_get_age_years($member->booking_dob) .']');
}
else {
$text = array($member->booking_firstname, $member->booking_lastname); $text = array($member->booking_firstname, $member->booking_lastname);
}
//add their role if they're leading/helping etc
if ($member->booking_studygroup_role > 0) {
array_push($text, '(' . _booking_studygroup_role_lookup($member->booking_studygroup_role) . ')');
}
//also tag committee members
if ($member->booking_committee_member == 'Y') {
array_push($text, '(committee)');
}
//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[$sid][] = implode(' ', $text);
} }
//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)));
@@ -448,12 +443,7 @@ function booking_varietysessions_csv_report($timeslot_id) {
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 //make the column headings a bit more user friendly
if ($group->booking_is_readinggroup == 'Y') { $column_headings[] = $variety_sessions[$column]->booking_variety_descrip;
$column_headings[] = _booking_readinggroup_colour_lookup($column);
}
else {
$column_headings[] = "Session " . $column;
}
} }
//add the column headings to the CSV //add the column headings to the CSV