Add token for leader-helper pairs

This commit is contained in:
2014-06-20 13:07:46 +10:00
parent 1293dae510
commit e83db04800
5 changed files with 147 additions and 9 deletions

View File

@@ -1180,6 +1180,92 @@ function _booking_studygroup_email_summary($node) {
return implode("\n", $rows);
}
/**
* Helper function to format information matching leaders and helpers, to be used as a token
*/
function _booking_leader_helper_email_summary($node) {
global $event;
$rows = array();
$found = FALSE;
//display study session data if enabled
if (variable_get('booking_enable_studygroups', 0) == 1)
{
//look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid');
for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++)
{
//don't print info about the readings groups
if ($i == variable_get('booking_readinggroup_id','7'))
continue;
//calculate the session references
$sessionid = "session" . $i;
$roleid = $sessionid . "_role";
$otherperson_name = "TBA";
//check that this study group session has been defined for this attendee and that they
if (!empty($node->$sessionid) && $node->$roleid > 0)
{
//make sure we only add this prefix text once, as soon as we've found a matching role
if ($found == FALSE)
{
$found = TRUE;
$rows[] = t("You have been assigned to perform the following roles for study groups:");
}
//TODO: use a function for this.
//if they're a leader or reserver leader, then the matching person is the helper
if ($node->$roleid == 1 || $node->$roleid == 3)
{
$role = "Leader";
$otherrole = "Helper";
$otherrole_id = 2;
}
//otherwise the matching person is the leader
else
{
$role = "Helper";
$otherrole = "Leader";
$otherrole_id = 1;
}
//find the other person
$otherperson_query = db_query("SELECT m.*, p.booking_firstname, p.booking_lastname FROM {booking_studygroup_mapping} m " .
" 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,
));
$otherperson = $otherperson_query->fetchAll();
watchdog('booking', "<pre>Other person for studygroup !group and role !role result:\n@info</pre>",
array('!group' => $i, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true)));
foreach ($otherperson as $other)
{
$otherperson_name = $other->booking_firstname . ' ' . $other->booking_lastname;
}
$rows[] = t('!role for !descrip (section !id). Your !otherrole is !other.',
array('!role' => $role, '!id' => $studygroups[$i]->sid, '!descrip' => $studygroups[$i]->booking_studygroup_descrip,
'!otherrole' => $otherrole, '!other' => $otherperson_name,
));
}
}
}
foreach ($rows as $key => $value)
$rows[$key] = wordwrap($value);
return implode("\n", $rows);
}
/**
* Helper function to format summary of room allocation to be used as a token
*/