Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable using announcements to add content to alerts #1842

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we only output the second p if link_text isn't blank? People could put their own links inside the content presumably, and then not need a "Read more"? e.g. the last time we did this manually, the added text was:

 <p style="font-size: 16px;">
The UK Parliament is back – read our blog post on
<a href="https://www.mysociety.org/2024/07/04/theyworkforyou-understanding-the-new-parliament/">resources to help you understand the new Parliament</a>,
and if you enjoy your alerts,
<a href="https://www.theyworkforyou.com/support-us/">donate to support our work</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
Loading