From 4fcd741e97b094558708ded192d085c6a0ff4633 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 20 Jan 2016 10:03:30 +1100 Subject: [PATCH] Fixed study group matching leader/helper calculations --- booking.helper.inc | 6 +++--- booking.studygroup_leaders.inc | 34 ++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/booking.helper.inc b/booking.helper.inc index 18f0a5d..4955781 100644 --- a/booking.helper.inc +++ b/booking.helper.inc @@ -1502,12 +1502,12 @@ function _booking_leader_helper_email_summary($node) { " INNER JOIN {booking_person} p on m.booking_node_id = p.nid " . " WHERE booking_eventid = :eid " . " AND booking_studygroup_id = :group AND booking_studygroup_role = :role AND booking_session_id = :session", - array(':eid' => $event->eid, ':group' => $i, ':role' => $otherrole_id, ':session' => $node->$sessionid, + array(':eid' => $event->eid, ':group' => $studygroup->sid, ':role' => $otherrole_id, ':session' => $node->$sessionid, )); $otherperson = $otherperson_query->fetchAll(); watchdog('booking', "
Other person for studygroup !group and role !role result:\n@info
", - array('!group' => $i, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true))); + array('!group' => $studygroup->sid, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true))); foreach ($otherperson as $other) { @@ -1517,7 +1517,7 @@ function _booking_leader_helper_email_summary($node) { } $rows[] = t('!role for !descrip (section !id). Your !otherrole is !other. You can contact them on !phone or !email.', - array('!role' => $role, '!id' => $studygroups[$i]->sid, '!descrip' => $studygroups[$i]->booking_studygroup_descrip, + array('!role' => $role, '!id' => $studygroup->sid, '!descrip' => $studygroup->booking_studygroup_descrip, '!otherrole' => $otherrole, '!other' => $otherperson_name, '!phone' => $otherperson_phone, '!email' => $otherperson_email, )); diff --git a/booking.studygroup_leaders.inc b/booking.studygroup_leaders.inc index a699327..cb4cbfa 100644 --- a/booking.studygroup_leaders.inc +++ b/booking.studygroup_leaders.inc @@ -28,16 +28,30 @@ function booking_studygroups_leaders_calculate() { $calculation_messages[] = t('Processing eligible Leader/helper with id !id and age !age', array('!id' => $person->nid, '!age' => $age) ); + + foreach ($groups as $studygroup) + { + //watchdog('booking_debug', "
Study Group Element\n@info
", array('@info' => print_r( $studygroup, true))); + if ($age >= 22 && $studygroup->leader_nid == 0) + { + $studygroup->leader_nid = $person->nid; + $calculation_messages[] = t("Study Group Assignment as leader for nid !nid to group !descrip at session id !sid", + array('!nid' => $person->nid, '!descrip' => $studygroup->booking_studygroup_descrip, '!sid' => $studygroup->session_id, '@info' => print_r( $studygroup, true))); + break; + } + elseif ($age < 22 && $studygroup->helper_nid == 0) + { + $studygroup->helper_nid = $person->nid; + $calculation_messages[] = t("Study Group Assignment as helper for nid !nid to group !descrip at session id !sid", + array('!nid' => $person->nid, '!descrip' => $studygroup->booking_studygroup_descrip, '!sid' => $studygroup->session_id, '@info' => print_r( $studygroup, true))); + break; + } + } //if someone is 22 or over, they're a leader - if ($age >= 22) - { - $next_group_index = $groups[_booking_get_next_studygroup('leader_nid', $groups)]; - $calculation_messages[] = t('Assigning id !id to study group !group as a leader', - array('!id' => $person->nid, '!group' => $next_group_index) - ); - $groups[$next_group_index]->leader_nid = $person->nid; - } + //$next_group_index = $groups[_booking_get_next_studygroup('leader_nid', $groups)]; + + //$groups[$next_group_index]->leader_nid = $person->nid; //if someone is under 22, they're a helper //left over people become a reserve leader @@ -152,7 +166,7 @@ function _booking_studygroups_retrieve_groups() { $new_group = clone $group; $new_group->session_id = $i; - $new_group->leader_nid = -1; + $new_group->leader_nid = 0; $new_group->helper_nid = 0; $new_group->reserve_nid = 0; $new_group->processed = 0; @@ -161,7 +175,7 @@ function _booking_studygroups_retrieve_groups() { } } - watchdog('booking', "
Study Group Sessions:\n@info
", array('@info' => print_r( $groups, true))); + //watchdog('booking', "
Study Group Sessions:\n@info
", array('@info' => print_r( $groups, true))); return $groups; } \ No newline at end of file