/[Frey]/trunk/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

Contents of /trunk/lib/App/RoomReservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1155 - (show annotations)
Thu Jul 2 10:12:54 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 1743 byte(s)
allow users to cancel lecture seat only once
1 package App::RoomReservation::Confirmation;
2 use Moose;
3
4 extends 'App::RoomReservation';
5
6 with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
7
8 has token => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12 );
13
14 sub verify_as_markup {
15 my ($self) = @_;
16
17 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 where
34 md5(id||email) = ?
35 and _confirmed is false
36 and _canceled is false
37 });
38
39 $sth->execute( $self->token );
40
41 if ( $sth->rows == 0 ) {
42 warn "can't confirm ", $self->token, " check if it's allready confirmed";
43 $sth = $dbh->prepare(qq{
44 select 1
45 from reservation
46 where
47 md5(id||email) = ?
48 and _confirmed is true
49 });
50 $sth->execute( $self->token );
51 }
52
53 if ( $sth->rows == 1 ) {
54
55 die "can't find account associated with ", $self->token unless $sth->rows == 1;
56
57 return $self->seat_confirmation_message( token => $self->token );
58
59 } else {
60 die "Problem with confirmation.\n";
61 }
62 }
63
64 sub cancel_as_markup {
65 my ($self) = @_;
66
67 my $dbh = $self->dbh;
68
69 my $sth = $dbh->prepare(qq{
70 update reservation
71 set
72 _canceled = true,
73 _seat_number = null
74 where
75 md5(id||email) = ?
76 -- and _confirmed is true
77 });
78 $sth->execute( $self->token );
79
80 if ( $sth->rows == 1 ) {
81 qq|
82 Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else
83 |;
84 } else {
85 die "Problem with cancelation.\n";
86 }
87 }
88
89 __PACKAGE__->meta->make_immutable;
90 no Moose;
91
92 1;

  ViewVC Help
Powered by ViewVC 1.1.26