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 . '
'; +} + $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); }