/[Frey]/branches/zimbardo/lib/App/RoomReservation/Confirmation.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /branches/zimbardo/lib/App/RoomReservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1172 - (hide annotations)
Sun Jul 5 21:40:16 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 1933 byte(s)
branch for localisation

1 dpavlin 1122 package App::RoomReservation::Confirmation;
2 dpavlin 1098 use Moose;
3    
4     extends 'App::RoomReservation';
5    
6 dpavlin 1151 with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
7 dpavlin 1134
8 dpavlin 1098 has token => (
9     is => 'ro',
10     isa => 'Str',
11     required => 1,
12     );
13    
14     sub verify_as_markup {
15     my ($self) = @_;
16    
17 dpavlin 1121 my $dbh = $self->dbh;
18    
19     my $sth = $dbh->prepare(qq{
20     update reservation
21     set
22     _confirmed = true,
23     _seat_number = (
24     select
25     min(seat.nr)
26     from (select generate_series(1,600) as nr) as seat
27     full join reservation on reservation._seat_number = seat.nr
28     where id is null
29     group by seat.nr
30     order by seat.nr asc
31     limit 1
32     )
33 dpavlin 1151 where
34     md5(id||email) = ?
35     and _confirmed is false
36 dpavlin 1155 and _canceled is false
37 dpavlin 1098 });
38 dpavlin 1121
39 dpavlin 1165 my $token = $self->token;
40 dpavlin 1098
41 dpavlin 1165 $sth->execute( $token );
42    
43 dpavlin 1151 if ( $sth->rows == 0 ) {
44     warn "can't confirm ", $self->token, " check if it's allready confirmed";
45     $sth = $dbh->prepare(qq{
46     select 1
47     from reservation
48     where
49     md5(id||email) = ?
50     and _confirmed is true
51     });
52 dpavlin 1165 $sth->execute( $token );
53 dpavlin 1151 }
54    
55 dpavlin 1098 if ( $sth->rows == 1 ) {
56 dpavlin 1121
57 dpavlin 1165 die qq|<error>can't find account associated with $token</error>| unless $sth->rows == 1;
58 dpavlin 1134
59 dpavlin 1165 return $self->seat_confirmation_message( token => $token );
60 dpavlin 1147
61 dpavlin 1098 } else {
62 dpavlin 1165 die qq|<error>Can't find confirmation $token<br>
63     Did you copy-pasted whole URL in your browser?</error>|;
64 dpavlin 1098 }
65     }
66    
67     sub cancel_as_markup {
68     my ($self) = @_;
69    
70 dpavlin 1121 my $dbh = $self->dbh;
71    
72     my $sth = $dbh->prepare(qq{
73     update reservation
74     set
75 dpavlin 1155 _canceled = true,
76 dpavlin 1121 _seat_number = null
77 dpavlin 1151 where
78     md5(id||email) = ?
79     -- and _confirmed is true
80 dpavlin 1098 });
81     $sth->execute( $self->token );
82    
83     if ( $sth->rows == 1 ) {
84 dpavlin 1151 qq|
85     Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else
86     |;
87 dpavlin 1098 } else {
88 dpavlin 1165 die qq|<error>Can't find reservation which you are trying to cancel.<br>
89     Did you copy-pasted whole URL in your browser?</error>|;
90 dpavlin 1098 }
91     }
92    
93 dpavlin 1133 __PACKAGE__->meta->make_immutable;
94     no Moose;
95    
96 dpavlin 1098 1;

  ViewVC Help
Powered by ViewVC 1.1.26