code refactor

This commit is contained in:
2016-06-28 21:48:55 +10:00
parent a1c091a03c
commit a4da6d2d93

View File

@@ -1538,58 +1538,35 @@ function _booking_leader_helper_email_summary($node) {
$found = FALSE; $found = FALSE;
//display study session data if enabled //display study session data if enabled
if (variable_get('booking_enable_studygroups', 0) == 1) if (variable_get('booking_enable_studygroups', 0) == 1) {
{
//look up the titles of the study groups //look up the titles of the study groups
$studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid", $studygroups_query = db_query("SELECT * FROM {booking_studygroup_list} WHERE booking_eventid = :eid",
array(':eid' => $event->eid)); array(':eid' => $event->eid));
$studygroups = $studygroups_query->fetchAllAssoc('sid'); $studygroups = $studygroups_query->fetchAllAssoc('sid');
//for ($i = 1; $i <= variable_get('booking_studygroup_count','0'); $i++) foreach ($studygroups as $studygroup) {
//for ($i = 1; $i <= count($studygroups); $i++)
foreach ($studygroups as $studygroup)
{
//don't print info about the readings groups //don't print info about the readings groups
//if ($i == variable_get('booking_readinggroup_id','7')) if ($studygroup->booking_is_readinggroup == 'Y') {
// continue;
//if ($studygroups[$i]->booking_is_readinggroup == 'Y')
// continue;
if ($studygroup->booking_is_readinggroup == 'Y')
continue; continue;
}
//calculate the session references //calculate the session references
//$sessionid = "session" . $i;
$sessionid = "session" . $studygroup->sid; $sessionid = "session" . $studygroup->sid;
$roleid = $sessionid . "_role"; $roleid = $sessionid . "_role";
$otherperson_name = "TBA"; $otherperson_name = "TBA";
$otherperson_email = ""; $otherperson_email = "";
$otherperson_phone = ""; $otherperson_phone = "";
//check that this study group session has been defined for this attendee and that they //check that this study group session has been defined for this attendee and that they have a role to perform
if (!empty($node->$sessionid) && $node->$roleid > 0) 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 they're a leader or reserver leader, then the matching person is the helper
if ($node->$roleid == 1 || $node->$roleid == 3) if ($node->$roleid == 1 || $node->$roleid == 3) {
{
$role = "Leader"; $role = "Leader";
$otherrole = "Helper"; $otherrole = "Helper";
$otherrole_id = 2; $otherrole_id = 2;
} }
//otherwise the matching person is the leader //otherwise the matching person is the leader
else else {
{
$role = "Helper"; $role = "Helper";
$otherrole = "Leader"; $otherrole = "Leader";
$otherrole_id = 1; $otherrole_id = 1;
@@ -1606,9 +1583,9 @@ function _booking_leader_helper_email_summary($node) {
//watchdog('booking', "<pre>Other person for studygroup !group and role !role result:\n@info</pre>", //watchdog('booking', "<pre>Other person for studygroup !group and role !role result:\n@info</pre>",
// array('!group' => $studygroup->sid, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true))); // array('!group' => $studygroup->sid, '!role' => $otherrole_id, '@info' => print_r( $otherperson, true)));
foreach ($otherperson as $other) //create the text for the token
{ foreach ($otherperson as $other) {
$otherperson_name = $other->booking_firstname . ' ' . $other->booking_lastname; $otherperson_name = $other->booking_firstname . ' ' . $other->booking_lastname;
$otherperson_email = $other->booking_email; $otherperson_email = $other->booking_email;
$otherperson_phone = $other->booking_mobile; $otherperson_phone = $other->booking_mobile;
@@ -1618,14 +1595,14 @@ function _booking_leader_helper_email_summary($node) {
array('!role' => $role, '!id' => $studygroup->sid, '!descrip' => $studygroup->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, '!otherrole' => $otherrole, '!other' => $otherperson_name, '!phone' => $otherperson_phone, '!email' => $otherperson_email,
)); ));
} }
} }
} }
foreach ($rows as $key => $value) //format the output to be used in an email
foreach ($rows as $key => $value) {
$rows[$key] = wordwrap($value); $rows[$key] = wordwrap($value);
}
return implode("\n", $rows); return implode("\n", $rows);
} }