From 8b8b48e983f72722fa2eac99225f6ef50abe8067 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 29 Oct 2024 11:37:29 +0000 Subject: [PATCH] enable using announcements to add content to alerts If an announcement has a location of 'alerts' then include that at the top of all alerts. The HTML version either uses "Read more" or the `button_text` property for the link. Announcements are added at the top of the alerts. Part of #1825 --- scripts/alertmailer.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/scripts/alertmailer.php b/scripts/alertmailer.php index 03faba7b63..f252ab051e 100644 --- a/scripts/alertmailer.php +++ b/scripts/alertmailer.php @@ -13,6 +13,20 @@ function mlog($message) { ini_set('memory_limit', -1); include_once INCLUDESPATH . 'easyparliament/member.php'; +$announcement_manager = new \MySociety\TheyWorkForYou\Model\AnnouncementManagement(); +$banner = $announcement_manager->get_random_valid_item('alerts'); + +$text_banner = ''; +$html_banner = ''; +if ($banner) { + $text_banner = $banner->title . "\n\n" . $banner->content . "\n\n" . $banner->url . "\n\n"; + $link_text = "Read more"; + if (property_exists($banner, 'button_text')) { + $link_text = $banner->button_text; + } + $html_banner = '' . $banner->title . "

" . $banner->content . '

' . $link_text . '

'; +} + $global_start = getmicrotime(); $db = new ParlDB(); @@ -211,6 +225,12 @@ function mlog($message) { if ($email != $current['email']) { if ($email_text) { + + if ($banner) { + $email_text = $text_banner . $email_text; + $html_text = $html_banner . $html_text; + } + write_and_send_email($current, $email_text, $html_text, $template); } $current['email'] = $email; @@ -391,6 +411,10 @@ function mlog($message) { } } if ($email_text) { + if ($banner) { + $email_text = $text_banner . $email_text; + $html_text = $html_banner . $html_text; + } write_and_send_email($current, $email_text, $html_text, $template); }