Fix up studygroups update functions

This commit is contained in:
2014-06-19 09:37:18 +10:00
parent 781acbd9de
commit 478d093bb9
4 changed files with 70 additions and 20 deletions

View File

@@ -242,6 +242,13 @@ function booking_admin() {
'#maxlength' => 3, '#maxlength' => 3,
'#default_value' => variable_get('booking_readinggroup_id','0'), '#default_value' => variable_get('booking_readinggroup_id','0'),
); );
$form['misc']['booking_publish_readinggroups'] = array (
'#type' => 'radios',
'#title' => t('Display reading group colours on the Who\'s Coming page?'),
'#description' => t('Select whether to publish reading group colours.'),
'#options' => array (0 => t('No'), t('Yes')),
'#default_value' => variable_get('booking_publish_readinggroups', 0),
);
$form['misc']['booking_csv_exclude_fields'] = array ( $form['misc']['booking_csv_exclude_fields'] = array (
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Fields to exclude from CSV report'), '#title' => t('Fields to exclude from CSV report'),

View File

@@ -395,13 +395,35 @@ function _booking_shuffle_assoc($list) {
*/ */
function _booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count) function _booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count)
{ {
$previous_session = 0;
//check for valid attendee
if (empty($nid)) if (empty($nid))
{ {
drupal_set_message(t('Attempting to process a non-existent node id.')); drupal_set_message(t('Attempting to process a non-existent node id.'));
return; return;
} }
//check if this person had already been processsed
if ($attendee_list[$nid]->processed == 1 && $attendee_list[$nid]->session > 0)
{
drupal_set_message(t('Detected re-assignment of id !id previously assigned to session !session.',
array('!id' => $nid, '!session' => $attendee_list[$nid]->session)
));
$previous_session = $attendee_list[$nid]->session;
//update previous session totals
$session_count[$previous_session][$gender]--;
$session_count[$previous_session]['total']--;
if ($age < 20)
$session_count[$previous_session]['under20']--;
elseif($age >= 20 && $age < 25)
$session_count[$previous_session]['20to25']--;
else
$session_count[$previous_session]['over25']--;
}
//mark this person as processed in the working list //mark this person as processed in the working list
$attendee_list[$nid]->processed = 1; $attendee_list[$nid]->processed = 1;
$attendee_list[$nid]->session = $session_id; $attendee_list[$nid]->session = $session_id;
@@ -410,9 +432,7 @@ function _booking_assign_attendee_group($nid, $session_id, $gender, $age, &$atte
$session_count[$session_id][$gender]++; $session_count[$session_id][$gender]++;
$session_count[$session_id]['total']++; $session_count[$session_id]['total']++;
//record the age bracket //process ages
//$age = _booking_get_age_years($attendee_list[$nid]->booking_dob);
if ($age < 20) if ($age < 20)
$session_count[$session_id]['under20']++; $session_count[$session_id]['under20']++;
elseif($age >= 20 && $age < 25) elseif($age >= 20 && $age < 25)

View File

@@ -284,11 +284,19 @@ function booking_coming_page() {
global $event; global $event;
$output = ""; $output = "";
$table = ""; $table = "";
//$header = array('Name', 'Team Colour', 'State');
$header = array('Name', 'State');
$booking_limit = variable_get('booking_regn_limit','350'); $booking_limit = variable_get('booking_regn_limit','350');
$rows = array(); $rows = array();
//work out whether to include the team colour in this page
if (variable_get('booking_publish_readinggroups', 0) == 1)
{
$header = array('Name', 'Team Colour', 'State');
}
else
{
$header = array('Name', 'State');
}
if (variable_get('booking_auto_show_on_lists', 1) == 1) if (variable_get('booking_auto_show_on_lists', 1) == 1)
{ {
$or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1); $or = db_or()->condition('p.booking_status', 0)->condition('p.booking_status', 1);
@@ -333,14 +341,29 @@ function booking_coming_page() {
//watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE))); //watchdog('booking', "Who's coming query: @info", array('@info' => var_export($result, TRUE)));
foreach ($result as $person) { foreach ($result as $person)
$rows[] = array( {
t('!first !last', array('!first' => ucwords($person->booking_firstname), $state = $person->booking_country === variable_get('booking_default_country') ? $person->booking_state : $person->booking_country;
'!last' => ucwords($person->booking_lastname))),
//only for when we have readings groups //if we're allowed to publish reading groups, specify them in the array element
//t('!group',array('!group' => $person->booking_readinggroup)), if (variable_get('booking_publish_readinggroups', 0) == 1)
t('!state', array('!state' => ($person->booking_country === variable_get('booking_default_country')) ? $person->booking_state : $person->booking_country)), {
); $rows[] = array(
t('!first !last', array('!first' => ucwords($person->booking_firstname),
'!last' => ucwords($person->booking_lastname))),
t('!group',array('!group' => $person->booking_readinggroup)),
t('!state', array('!state' => $state)),
);
}
//don't publish reading group information
else
{
$rows[] = array(
t('!first !last', array('!first' => ucwords($person->booking_firstname),
'!last' => ucwords($person->booking_lastname))),
t('!state', array('!state' => $state)),
);
}
} }
//watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE))); //watchdog('booking', "Who's coming formatted: @info", array('@info' => var_export($rows, TRUE)));

View File

@@ -965,7 +965,7 @@ function booking_studygroups_update() {
$firstgroup = reset($studygroups); $firstgroup = reset($studygroups);
$limit = variable_get('booking_regn_limit','500'); $limit = variable_get('booking_regn_limit','500');
//be a bit more lenient with maximums to avoid excessive re-arrangement of groups //be a bit more lenient with maximums to avoid excessive re-arrangement of groups
$fudge_factor = 3; $fudge_factor = 1;
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + $fudge_factor; $max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + $fudge_factor;
//select all the attendees booked in //select all the attendees booked in
@@ -1272,7 +1272,7 @@ function booking_studygroups_update() {
'!role' => $person->booking_studygroup_role))); '!role' => $person->booking_studygroup_role)));
//update the entry //update the entry
/*
db_update('booking_studygroup_mapping') db_update('booking_studygroup_mapping')
->fields(array( ->fields(array(
'booking_session_id' => $person->session, 'booking_session_id' => $person->session,
@@ -1280,7 +1280,7 @@ function booking_studygroups_update() {
)) ))
->condition('sid', $mapping->sid) ->condition('sid', $mapping->sid)
->execute(); ->execute();
*/
} }
else else
{ {
@@ -1296,8 +1296,8 @@ function booking_studygroups_update() {
//if we didn't find an existing record, add it to the list to insert //if we didn't find an existing record, add it to the list to insert
if (! $found && $person->session <> 0) if (! $found && $person->session <> 0)
{ {
//drupal_set_message(t('Found no existing study group session for user id !id. Adding to list of inserts.', drupal_set_message(t('Found no existing study group session for user id !id. Adding to list of inserts.',
// array('!id' => $person->nid, '!sid' => $mapping->sid, '!session' => $person->session))); array('!id' => $person->nid, '!sid' => $mapping->sid, '!session' => $person->session)));
$record = array( $record = array(
'booking_eventid' => $event->eid, 'booking_eventid' => $event->eid,
@@ -1310,7 +1310,7 @@ function booking_studygroups_update() {
} }
} }
//$insert_query->execute(); $insert_query->execute();
//watchdog('booking', "<pre>Session statistics list:\n@info</pre>", array('@info' => print_r( $session_count, true))); //watchdog('booking', "<pre>Session statistics list:\n@info</pre>", array('@info' => print_r( $session_count, true)));