study group bugfixes
This commit is contained in:
@@ -661,6 +661,13 @@ function _booking_process_refund($person)
|
||||
//calculate the refund due
|
||||
//don't include paypal fees in the deposit amount
|
||||
$refund = $paid - _booking_deposit_amount(FALSE);
|
||||
|
||||
//if there is a spouse, subtract their deposit too
|
||||
if (variable_get('booking_enable_combined_pricing', 0) == 1 && $person->booking_partner_id > 0)
|
||||
{
|
||||
$refund = $refund - _booking_deposit_amount(FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
watchdog('booking', "Processing refund due to !first !last. Calculated as $!refund",
|
||||
|
@@ -21,7 +21,7 @@ define('BOOKING_PAYPAL_SUBMIT_URL_SANDBOX', 'https://www.sandbox.paypal.com/cgi-
|
||||
define('BOOKING_PAYPAL_IPN_PATH', 'system/booking_paypal/ipn');
|
||||
define('TIMEZONE', 'Australia/Sydney');
|
||||
define('BOOKING_DEFAULT_STATE', 'NSW');
|
||||
define('CUSTOM_EMAIL_COUNT', 5);
|
||||
define('CUSTOM_EMAIL_COUNT', 10);
|
||||
define('STUDYGROUP_COUNT', 7);
|
||||
|
||||
// Load the include for various constants
|
||||
|
@@ -1043,10 +1043,14 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
|
||||
if (variable_get('booking_enable_studygroups', 0) == 1)
|
||||
{
|
||||
//work out how many study groups there are
|
||||
//$count = db_query("SELECT count(*) as num_groups FROM {booking_studygroup_list} where booking_eventid = :eventid", array(':eventid' => $event->eid))
|
||||
// ->fetchObject();
|
||||
$studygroups = db_query("SELECT count(*) as numgroups from {booking_studygroup_list} s INNER JOIN {booking_event} e ON s.booking_eventid = e.eid WHERE e.booking_event_active = 1")
|
||||
->fetchObject();
|
||||
//$studygroups = db_query("SELECT s.* from {booking_studygroup_list} s INNER JOIN {booking_event} e ON s.booking_eventid = e.eid WHERE e.booking_event_active = 1")
|
||||
// ->fetchAllAssoc('sid');
|
||||
//watchdog('booking', "<pre>Loading node studygroups query output:\n@info</pre>", array('@info' => print_r( $studygroups, true)));
|
||||
|
||||
for ($i = 1; $i <= STUDYGROUP_COUNT; $i++)
|
||||
//for ($i = 1; $i <= STUDYGROUP_COUNT; $i++)
|
||||
for ($i = 1; $i <= $studygroups->numgroups; $i++)
|
||||
{
|
||||
$query->leftJoin('booking_studygroup_mapping', 's' . $i,
|
||||
'p.nid = s' . $i . '.booking_node_id and s' . $i . '.booking_studygroup_id = ' . $i);
|
||||
@@ -1068,8 +1072,9 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
|
||||
|
||||
//now add the study group fields
|
||||
for ($i = 1; $i <= STUDYGROUP_COUNT; $i++)
|
||||
for ($i = 1; $i <= $studygroups->numgroups; $i++)
|
||||
{
|
||||
//$label = "Group_" . $studygroups[$i]->booking_studygroup_descrip;
|
||||
$query->addField('s' . $i, 'booking_session_id', 'session' . $i);
|
||||
$query->addField('s' . $i, 'booking_is_leader', 'session' . $i . '_leader');
|
||||
$query->addField('s' . $i, 'booking_is_reserveleader', 'session' . $i . '_reserveleader');
|
||||
@@ -1095,8 +1100,7 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
|
||||
->fields('pr', array('booking_price', 'booking_price_descrip','booking_late_price'));
|
||||
}
|
||||
|
||||
//get the query result
|
||||
|
||||
//get the query result as either an associative array
|
||||
if ($fetchAssoc == TRUE)
|
||||
{
|
||||
$result = $query->execute()->fetchAllAssoc('nid');
|
||||
@@ -1106,7 +1110,7 @@ function booking_load_query($node_ids = NULL, $fetchAssoc = FALSE)
|
||||
$result = $query->execute();
|
||||
}
|
||||
|
||||
watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
|
||||
//watchdog('booking', "<pre>Loading node query output:\n@info</pre>", array('@info' => print_r( $result, true)));
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -1619,6 +1623,8 @@ function booking_view($node, $view_mode) {
|
||||
array(':eid' => $event->eid));
|
||||
$studygroups = $studygroups_query->fetchAllAssoc('sid');
|
||||
|
||||
watchdog('booking', "<pre>Displaying node studygroups query output:\n@info</pre>", array('@info' => print_r( $studygroups, true)));
|
||||
|
||||
for ($i = 1; $i <= STUDYGROUP_COUNT; $i++)
|
||||
{
|
||||
$role = "";
|
||||
|
@@ -601,6 +601,13 @@ function booking_shuffle_assoc($list) {
|
||||
*/
|
||||
function booking_assign_attendee_group($nid, $session_id, $gender, $age, &$attendee_list, &$session_count)
|
||||
{
|
||||
|
||||
if (empty($nid))
|
||||
{
|
||||
drupal_set_message(t('Attempting to process a non-existent node id.'));
|
||||
return;
|
||||
}
|
||||
|
||||
//mark this person as processed in the working list
|
||||
$attendee_list[$nid]->processed = 1;
|
||||
$attendee_list[$nid]->session = $session_id;
|
||||
@@ -646,7 +653,7 @@ function booking_studygroups_calculate() {
|
||||
$firstgroup = reset($studygroups);
|
||||
$limit = variable_get('booking_regn_limit','500');
|
||||
//add an extra one to the maximum size, to cater for some larger groups when the number of people doesn't divide evenly
|
||||
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 1;
|
||||
$max_people = (int) ($limit / $firstgroup->booking_num_group_sessions) + 2;
|
||||
|
||||
//select all the attendees booked in
|
||||
$query = db_query("SELECT * FROM {booking_person} WHERE booking_event_id = :eid",
|
||||
@@ -693,6 +700,8 @@ function booking_studygroups_calculate() {
|
||||
$person->is_reserveleader = 'N';
|
||||
}
|
||||
|
||||
//watchdog('booking', "<pre>Attendee list:\n@info</pre>", array('@info' => print_r( $attendees, true)));
|
||||
|
||||
//watchdog('booking', "Attendee list: @info", array('@info' => var_export($attendees, TRUE)));
|
||||
|
||||
//process each study group (eg Monday Tuesday Wednesday etc)
|
||||
@@ -762,7 +771,7 @@ function booking_studygroups_calculate() {
|
||||
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end searching for leaders and helpers
|
||||
|
||||
//watchdog('booking', "Attendee list working copy after leader/helper spouse processing: @info", array('@info' => var_export($working_list, TRUE)));
|
||||
//watchdog('booking', "Attendee list session count after leader/helper spouse processing: @info", array('@info' => var_export($session_count, TRUE)));
|
||||
@@ -817,13 +826,13 @@ function booking_studygroups_calculate() {
|
||||
$age_type = 'over25';
|
||||
|
||||
//make sure this person is going to fit in with our calculated gender ratios
|
||||
_booking_loop_carefully($session_count, $gender, $i, $maximums[$gender], $group->booking_num_group_sessions, 2);
|
||||
_booking_loop_carefully($session_count, $gender, $i, $maximums[$gender], $group->booking_num_group_sessions, 3);
|
||||
|
||||
//make sure this person is going to fit in with our calculated age ratios
|
||||
_booking_loop_carefully($session_count, $age_type, $i, $maximums[$age_type], $group->booking_num_group_sessions, 2);
|
||||
_booking_loop_carefully($session_count, $age_type, $i, $maximums[$age_type], $group->booking_num_group_sessions, 3);
|
||||
|
||||
//check for maximum group size
|
||||
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 2);
|
||||
_booking_loop_carefully($session_count, 'total', $i, $max_people, $group->booking_num_group_sessions, 3);
|
||||
|
||||
//assign this attendee to this session if unprocessed so far
|
||||
if ($current->processed == 0)
|
||||
@@ -855,11 +864,12 @@ function booking_studygroups_calculate() {
|
||||
drupal_set_message(t('Assigning bf/gf (id !spouse) of id !id to session !session (currently with !num people).',
|
||||
array('!id' => $it->key(), '!session' => $i, '!spouse' => $current->booking_bf_gf_nid, '!num' => $session_count[$i]['total'])));
|
||||
|
||||
booking_assign_attendee_group($partner_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
booking_assign_attendee_group($bf_gf_id, $i, $working_list[$bf_gf_id]->booking_gender == 'M' ? 'male' : 'female',
|
||||
_booking_get_age_years($working_list[$bf_gf_id]->booking_dob), $working_list, $session_count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//move to the next unprocessed attendee in the list
|
||||
while ($it->valid() && $it->current()->processed == 1)
|
||||
{
|
||||
@@ -875,11 +885,11 @@ function booking_studygroups_calculate() {
|
||||
//iterate over the attendee list and write to the database the session they're assigned to
|
||||
//use the multi-insert query type at https://drupal.org/node/310079
|
||||
$insert_query = db_insert('booking_studygroup_mapping')->fields(array('booking_eventid', 'booking_node_id',
|
||||
'booking_studygroup_id', 'booking_session_id', 'booking_is_leader', 'booking_is_helper'));
|
||||
'booking_studygroup_id', 'booking_session_id', 'booking_is_leader', 'booking_is_helper', 'booking_is_reserveleader'));
|
||||
|
||||
foreach($working_list as $person)
|
||||
{
|
||||
//watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
|
||||
watchdog('booking', "<pre>Working list person:\n@info</pre>", array('@info' => print_r( $person, true)));
|
||||
|
||||
//TODO: a check to update existing records rather than inserting new one
|
||||
// if already in $group_mapping then just run an update query here
|
||||
@@ -916,7 +926,6 @@ function booking_studygroups_calculate() {
|
||||
//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)));
|
||||
|
||||
|
||||
$record = array(
|
||||
'booking_eventid' => $event->eid,
|
||||
'booking_node_id' => $person->nid,
|
||||
@@ -930,14 +939,17 @@ function booking_studygroups_calculate() {
|
||||
}
|
||||
|
||||
}
|
||||
//$insert_query->execute();
|
||||
$insert_query->execute();
|
||||
|
||||
watchdog('booking', "<pre>Attendee 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)));
|
||||
|
||||
//clear the arrays we've been using for this iteration
|
||||
unset($session_count);
|
||||
unset($working_list);
|
||||
|
||||
drupal_set_message(t('Finished processing study group !group.', array('!group' => $group->booking_studygroup_descrip)));
|
||||
|
||||
|
||||
} //finished processing study groups
|
||||
|
||||
//watchdog('booking', "Attendee list final version: @info", array('@info' => var_export($attendees, TRUE)));
|
||||
|
Reference in New Issue
Block a user