collect-reminders also contains the year number
[email-reminder.git] / EmailReminder / BirthdayEvent.pm
blob51f04e97540c4e9eb71e49bf4d1447ea27e26928
1 # This file is part of Email-Reminder.
3 # Email-Reminder is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 3 of the
6 # License, or (at your option) any later version.
8 # Email-Reminder is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with Email-Reminder; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 # 02110-1301, USA.
18 package EmailReminder::BirthdayEvent;
20 use strict;
21 use warnings;
22 use overload '""' => \&str;
23 use EmailReminder::Utils;
24 use EmailReminder::YearlyEvent;
26 use base qw(EmailReminder::YearlyEvent);
28 # XML tags
29 __PACKAGE__->mk_accessors(qw(email));
31 sub str {
32 my ($self) = @_;
33 return $self->get_type . ':' . $self->get_id . ') ' . $self->get_name . ' - ' . $self->get_date;
36 # Hard-coded value for this event's type (class method)
37 sub get_type
39 return 'birthday';
42 # Number of fields this event adds to its parent (class method)
43 sub get_nb_fields
45 my ($self) = @_;
46 return $self->SUPER::get_nb_fields() + 1;
49 sub valid_email
51 my ($class, $new_value) = @_;
52 # ToDo: do checking on the email address
53 return $new_value;
56 # Returns the age of the person (starts at 0 years old)
57 sub get_occurence
59 my $self = shift;
61 my $age = $self->EmailReminder::YearlyEvent::get_occurence();
63 return defined($age) ? ($age - 1) : undef;
66 sub get_subject
68 my $self = shift;
70 my $name = $self->get_name();
71 my $age = $self->get_occurence();
72 my $when = $self->{"WHEN"};
74 if ($age and $when eq "today") {
75 return "$name is now $age";
77 else {
78 return "${name}'s birthday";
82 sub get_message_body
84 my $self = shift;
86 # birthday person
87 my $name = $self->get_name();
88 my $email = $self->get_email();
89 my $age = $self->get_occurence();
90 my $when = $self->{"WHEN"};
92 my $age_string = $age ? "turning $age" : "getting one year older";
93 my $email_message = $email ? "\n\nYou can reach $name at $email." : "";
95 my $message = <<"MESSAGEEND";
96 I just want to remind you that $name is $age_string $when.$email_message
97 MESSAGEEND
99 return $message;