CLeanups in invitations handling

master
Daniel Berteaud 10 years ago
parent f8bd8daa50
commit 55832c26d4
  1. 34
      vroom.pl

@ -665,26 +665,23 @@ helper get_invitation_by_token => sub {
WHERE `token`=? WHERE `token`=?
AND `processed`=\'0\''); AND `processed`=\'0\'');
}; };
$sth->execute($id); $sth->execute($token);
return $sth->fetchall_hashref('token')->{$token}; return $sth->fetchall_hashref('token')->{$token};
}; };
# Find invitations which have a unprocessed repsponse # Find invitations which have a unprocessed repsponse
helper find_invitations => sub { helper get_invitation_list => sub {
my $self = shift; my $self = shift;
my ($session) = @_;
my $sth = eval { my $sth = eval {
$self->db->prepare('SELECT `token` $self->db->prepare('SELECT *
FROM `email_invitations` FROM `email_invitations`
WHERE `from`=? WHERE `from`=?
AND `response` IS NOT NULL AND `response` IS NOT NULL
AND `processed`=\'0\''); AND `processed`=\'0\'');
} || return undef; };
$sth->execute($self->session('name')) || return undef; $sth->execute($session);
my @res; return $sth->fetchall_hashref('id');
while(my $invit = $sth->fetchrow_array){
push @res, $invit;
}
return @res;
}; };
helper respond_invitation => sub { helper respond_invitation => sub {
@ -1234,24 +1231,21 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
$status = 'success'; $status = 'success';
$msg = ''; $msg = '';
} }
my @invitations = $self->find_invitations(); my $invitations = $self->get_invitation_list($self->session('name'));
if (scalar @invitations > 0){
$msg = ''; $msg = '';
foreach my $id (@invitations){ foreach my $invit (keys %{$invitations}){
my $invit = $self->get_invitation_by_token($id); $msg .= sprintf($self->l('INVITE_REPONSE_FROM_s'), $invitations->{$invit}->{email}) . "\n" ;
$msg .= sprintf($self->l('INVITE_REPONSE_FROM_s'), $invit->{email}) . "\n" ; if ($invitations->{$invit}->{response} && $invitations->{$invit}->{response} eq 'later'){
if ($invit->{response} && $invit->{response} eq 'later'){
$msg .= $self->l('HE_WILL_TRY_TO_JOIN_LATER'); $msg .= $self->l('HE_WILL_TRY_TO_JOIN_LATER');
} }
else{ else{
$msg .= $self->l('HE_WONT_JOIN'); $msg .= $self->l('HE_WONT_JOIN');
} }
if ($invit->{message} && $invit->{message} ne ''){ if ($invitations->{$invit}->{message} && $invitations->{$invit}->{message} ne ''){
$msg .= "\n" . $self->l('MESSAGE') . ":\n" . $invit->{message} . "\n"; $msg .= "\n" . $self->l('MESSAGE') . ":\n" . $invitations->{$invit}->{message} . "\n";
} }
$msg .= "\n"; $msg .= "\n";
$self->processed_invitation($id); $self->processed_invitation($invitations->{$invit}->{token});
}
} }
return $self->render( return $self->render(
json => { json => {

Loading…
Cancel
Save