/[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 1151 - (show annotations)
Wed Jul 1 21:47:04 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 2093 byte(s)
split out messages to user (html+email) to separate class
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 });
37
38 $sth->execute( $self->token );
39
40 if ( $sth->rows == 0 ) {
41 warn "can't confirm ", $self->token, " check if it's allready confirmed";
42 $sth = $dbh->prepare(qq{
43 select 1
44 from reservation
45 where
46 md5(id||email) = ?
47 and _confirmed is true
48 });
49 $sth->execute( $self->token );
50 }
51
52 if ( $sth->rows == 1 ) {
53
54 $sth = $dbh->prepare(qq{
55 select
56 ime||' '||prezime,
57 _seat_number,
58 email
59 from reservation
60 where
61 _confirmed is true
62 -- and _seat_number is not null
63 and md5(id||email) = ?
64 });
65
66 $sth->execute( $self->token );
67
68 die "can't find account associated with ", $self->token unless $sth->rows == 1;
69
70 my @reservation = $sth->fetchrow_array;
71 push @reservation,
72 $self->url_for( 'Confirmation/cancel_as_markup?token=' . $self->token );
73
74 return $self->seat_confirmation_message( @reservation );
75
76 } else {
77 die "Problem with confirmation.\n";
78 }
79 }
80
81 sub cancel_as_markup {
82 my ($self) = @_;
83
84 my $dbh = $self->dbh;
85
86 my $sth = $dbh->prepare(qq{
87 update reservation
88 set
89 _confirmed = false,
90 _seat_number = null
91 where
92 md5(id||email) = ?
93 -- and _confirmed is true
94 });
95 $sth->execute( $self->token );
96
97 if ( $sth->rows == 1 ) {
98 qq|
99 Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else
100 |;
101 } else {
102 die "Problem with cancelation.\n";
103 }
104 }
105
106 __PACKAGE__->meta->make_immutable;
107 no Moose;
108
109 1;

  ViewVC Help
Powered by ViewVC 1.1.26