/** * Sends a notification that a match has been modified by a public user * * @param Match $o_match * @param User $o_user * @param bool $b_is_new_match * @param bool $b_is_deleted_match */ public function MatchUpdated(Match $o_match, User $o_user, $b_is_new_match = false, $b_is_deleted_match = false) { # Don't send email if match added by a trusted administrator if ($o_user->Permissions()->HasPermission(PermissionType::MANAGE_MATCHES)) { return; } # Match may have been added to multiple seasons (though this is theoretical because at the time # of writing only an admin can add to multiple seasons... and they don't generate emails.) # Nevertheless the object model is geared to that possibility and this way the code makes sense # of the object model. if ($o_match->Seasons()->GetCount()) { $emails_to_send = array(); foreach ($o_match->Seasons() as $season) { /* @var $season Season */ ### Find the email address to notify for this season. ### # If the competition has a manager, use their email address... $email = ''; if (!is_null($season->GetCompetition()) and $season->GetCompetition()->GetNotificationEmail()) { # ...but don't email the competition manager if they're adding/updating the match! if ($season->GetCompetition()->GetNotificationEmail() == $o_user->GetEmail()) { continue; } $email = $season->GetCompetition()->GetNotificationEmail(); } else { # If there's no competition manager, send to backup email address $email = $this->settings->GetMatchUpdatesEmail(); } # Add the current season to the list of seasons to notify that email address about if ($email) { if (!isset($emails_to_send[$email])) { $emails_to_send[$email] = array(); } $emails_to_send[$email][] = $season; } } # And now send an email to each address, listing the change for all the seasons they represent foreach ($emails_to_send as $email => $seasons) { $this->SendMatchUpdatedEmail($o_match, $o_user, $b_is_new_match, $b_is_deleted_match, $email, $seasons); } } else { # If there's no season there's no competition manager, send to backup email address $this->SendMatchUpdatedEmail($o_match, $o_user, $b_is_new_match, $b_is_deleted_match, $this->settings->GetMatchUpdatesEmail()); } }