diff options
author | pezholio <pezholio@gmail.com> | 2017-05-05 15:20:31 +0100 |
---|---|---|
committer | pezholio <pezholio@gmail.com> | 2017-05-05 15:24:12 +0100 |
commit | 77ff26ef363a54f0c550649d2a02bad0f449b926 (patch) | |
tree | 4092f1d31577fdef3cc303bc6836042129466b91 /perllib/FixMyStreet/DB/Result/User.pm | |
parent | 1c07eca3d6e8cea5d70c043de02d30bd7cdc5630 (diff) |
Move alert signup logic out of controller
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index cf6de9a76..8385d2eea 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -204,6 +204,27 @@ sub alert_for_problem { } ); } +=head2 create_alert + +Sign a user up to receive alerts on a given problem + +=cut + +sub create_alert { + my ( $self, $id, $options ) = @_; + my $alert = $self->alert_for_problem($id); + + unless ( $alert ) { + $alert = $self->alerts->create({ + %$options, + alert_type => 'new_updates', + parameter => $id, + }); + } + + $alert->confirm(); +} + sub body { my $self = shift; return '' unless $self->from_body; |