/[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 1186 - (hide annotations)
Mon Sep 21 21:29:38 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 2033 byte(s)
assign seat numbers to _confirmed reservation without _seat_number
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 dpavlin 1181 my $size = $self->room->seats;
20    
21 dpavlin 1121 my $sth = $dbh->prepare(qq{
22     update reservation
23     set
24     _confirmed = true,
25     _seat_number = (
26     select
27     min(seat.nr)
28 dpavlin 1181 from (select generate_series(1,$size) as nr) as seat
29 dpavlin 1121 full join reservation on reservation._seat_number = seat.nr
30     where id is null
31     group by seat.nr
32     order by seat.nr asc
33     limit 1
34     )
35 dpavlin 1151 where
36     md5(id||email) = ?
37 dpavlin 1155 and _canceled is false
38 dpavlin 1186 and (
39     _confirmed is false
40     or
41     ( _confirmed is true and _seat_number is null )
42     )
43 dpavlin 1098 });
44 dpavlin 1121
45 dpavlin 1165 my $token = $self->token;
46 dpavlin 1098
47 dpavlin 1165 $sth->execute( $token );
48    
49 dpavlin 1151 if ( $sth->rows == 0 ) {
50     warn "can't confirm ", $self->token, " check if it's allready confirmed";
51     $sth = $dbh->prepare(qq{
52     select 1
53     from reservation
54     where
55     md5(id||email) = ?
56     and _confirmed is true
57     });
58 dpavlin 1165 $sth->execute( $token );
59 dpavlin 1151 }
60    
61 dpavlin 1098 if ( $sth->rows == 1 ) {
62 dpavlin 1121
63 dpavlin 1165 die qq|<error>can't find account associated with $token</error>| unless $sth->rows == 1;
64 dpavlin 1134
65 dpavlin 1165 return $self->seat_confirmation_message( token => $token );
66 dpavlin 1147
67 dpavlin 1098 } else {
68 dpavlin 1165 die qq|<error>Can't find confirmation $token<br>
69     Did you copy-pasted whole URL in your browser?</error>|;
70 dpavlin 1098 }
71     }
72    
73     sub cancel_as_markup {
74     my ($self) = @_;
75    
76 dpavlin 1121 my $dbh = $self->dbh;
77    
78     my $sth = $dbh->prepare(qq{
79     update reservation
80     set
81 dpavlin 1155 _canceled = true,
82 dpavlin 1121 _seat_number = null
83 dpavlin 1151 where
84     md5(id||email) = ?
85     -- and _confirmed is true
86 dpavlin 1098 });
87     $sth->execute( $self->token );
88    
89     if ( $sth->rows == 1 ) {
90 dpavlin 1151 qq|
91 dpavlin 1173 Vaš <em>dolazak je odjavljen</em>.
92    
93     Hvala što ste omogućili dolazak nekom drugom!
94 dpavlin 1151 |;
95 dpavlin 1098 } else {
96 dpavlin 1165 die qq|<error>Can't find reservation which you are trying to cancel.<br>
97     Did you copy-pasted whole URL in your browser?</error>|;
98 dpavlin 1098 }
99     }
100    
101 dpavlin 1133 __PACKAGE__->meta->make_immutable;
102     no Moose;
103    
104 dpavlin 1098 1;

  ViewVC Help
Powered by ViewVC 1.1.26