add CSV report for variety session
This commit is contained in:
@@ -26,6 +26,7 @@ function booking_variety_admin()
|
||||
'variety_edit' => t('Edit Timeslot'),
|
||||
'variety_session_list' => t('List Sessions'),
|
||||
'variety_session_add' => t('Add Session'),
|
||||
'variety_session_csv' => t('CSV Report'),
|
||||
);
|
||||
|
||||
$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_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_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 "";
|
||||
}
|
||||
|
||||
// TODO - UPDATE FROM HERE ON!
|
||||
|
||||
//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",
|
||||
//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",
|
||||
array(':eid' => $event->eid, ':tid' => $timeslot_id))
|
||||
->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_goto('admin/config/booking/variety');
|
||||
return "";
|
||||
@@ -409,34 +409,29 @@ function booking_varietysessions_csv_report($timeslot_id) {
|
||||
$enclosure_esc = preg_quote($enclosure, '/');
|
||||
|
||||
//get the list of study group session memberships
|
||||
$session_members_query = db_query("SELECT m.*, p.* FROM {booking_studygroup_mapping} m
|
||||
inner join {booking_person} p on p.nid = m.booking_node_id
|
||||
WHERE m.booking_studygroup_id = :sid ORDER BY m.booking_session_id, m.booking_studygroup_role DESC, p.booking_lastname",
|
||||
array(':sid' => $group_id));
|
||||
$session_members_query = db_query("SELECT r.*, p.* FROM {booking_variety_regn} r
|
||||
inner join {booking_person} p on p.nid = r.booking_person_nid
|
||||
WHERE p.booking_eventid = :eid ORDER BY r.brid",
|
||||
array(':eid' => $event->eid));
|
||||
$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
|
||||
foreach ($session_members as $member) {
|
||||
if (! isset($data[$member->booking_session_id])) {
|
||||
$data[$member->booking_session_id] = array();
|
||||
$session_ids = drupal_json_decode($member->booking_variety_ids);
|
||||
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);
|
||||
}
|
||||
//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
|
||||
$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)));
|
||||
@@ -448,16 +443,11 @@ function booking_varietysessions_csv_report($timeslot_id) {
|
||||
foreach ($header_array as $column) {
|
||||
$maximums[] = count($data[$column]);
|
||||
//make the column headings a bit more user friendly
|
||||
if ($group->booking_is_readinggroup == 'Y') {
|
||||
$column_headings[] = _booking_readinggroup_colour_lookup($column);
|
||||
}
|
||||
else {
|
||||
$column_headings[] = "Session " . $column;
|
||||
}
|
||||
$column_headings[] = $variety_sessions[$column]->booking_variety_descrip;
|
||||
}
|
||||
|
||||
//add the column headings to the CSV
|
||||
$header = implode( $delimiter, $column_headings );
|
||||
$header = implode($delimiter, $column_headings);
|
||||
$csv .= $header . "\n";
|
||||
|
||||
//generate each row for the CSV
|
||||
|
Reference in New Issue
Block a user