Skip to content

Commit

Permalink
enable using announcements to add content to alerts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
struan committed Oct 29, 2024
1 parent 97614fa commit ee57a75
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scripts/alertmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<strong>' . $banner->title . "</strong><p>" . $banner->content . '</p><p><a href="' . $banner->url . '">' . $link_text . '</a></p>';
}

$global_start = getmicrotime();
$db = new ParlDB();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ee57a75

Please sign in to comment.