diff options
author | Struan Donald <struan@exo.org.uk> | 2014-03-21 17:30:07 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2014-04-08 13:21:12 +0100 |
commit | 5c871b7093ac2fd137b980979bb210cc1cad59a7 (patch) | |
tree | 6c55c10fe2bf55a6be0f257d7393efc7e3d6be3a /perllib | |
parent | b20cb6576485017970f025e6f294ac8c09f39e69 (diff) |
Add Cobrand config to include update date in email alerts
This is useful for sites where the updates aren't published on the site
so you need a bit more context in the email alerts.
Add inlude_time_in_update_alerts to default cobrand, off as default
If this is set then the date is added after the name string in the
email, passing in 'alert' as the type to dt_prettify in order to allow
the cobrand to format it accordingly.
This does require pulling out the alert confirmed time from the database
in the send_alerts code where it wasn't before.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 60ed216d7..d2af4949e 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -837,6 +837,8 @@ If true then we never send an email to confirm an update sub never_confirm_updates { 0; } +sub include_time_in_update_alerts { 0; } + =head2 prettify_dt my $date = $c->prettify_dt( $datetime ); diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 8e18832a9..545b54c60 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -29,6 +29,7 @@ sub email_alerts ($) { $query .= " $item_table.id as item_id, $item_table.text as item_text, $item_table.name as item_name, $item_table.anonymous as item_anonymous, + $item_table.confirmed as item_confirmed, $head_table.* from alert inner join $item_table on alert.parameter::integer = $item_table.${head_table}_id @@ -114,6 +115,27 @@ sub email_alerts ($) { $data{problem_url} = $url . "/report/" . $row->{id}; } $data{data} .= $row->{item_name} . ' : ' if $row->{item_name} && !$row->{item_anonymous}; + if ( $cobrand->include_time_in_update_alerts ) { + # this is basically recreating the code from the inflate wrapper + # in the database model. + my $tz; + if ( FixMyStreet->config('TIME_ZONE') ) { + $tz = FixMyStreet->config('TIME_ZONE'); + } + + my $parser = DateTime::Format::Pg->new(); + my $dt = $parser->parse_timestamp( $row->{item_confirmed} ); + my $l_tz = DateTime::TimeZone->new( name => "local" ); + # We need to always set this otherwise we end up with the DateTime + # object being in the floating timezone in which case applying a + # subsequent timezone set will have no effect. + $dt->set_time_zone( $l_tz ); + if ( $tz ) { + my $tz_obj = DateTime::TimeZone->new( name => $tz ); + $dt->set_time_zone( $tz_obj ); + } + $data{data} .= $cobrand->prettify_dt( $dt, 'alert' ) . "\n\n"; + } $data{data} .= $row->{item_text} . "\n\n------\n\n"; # this is ward and council problems } else { |