/[Frey]/trunk/lib/App/RoomReservation/Reservation/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/Reservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1121 - (show annotations)
Tue Jun 30 13:24:03 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 1617 byte(s)
allocate seat number after confirmation
1 package App::RoomReservation::Reservation::Confirmation;
2 use Moose;
3
4 extends 'App::RoomReservation';
5
6 has token => (
7 is => 'ro',
8 isa => 'Str',
9 required => 1,
10 );
11
12 sub verify_as_markup {
13 my ($self) = @_;
14
15 my $dbh = $self->dbh;
16
17 my $sth = $dbh->prepare(qq{
18 update reservation
19 set
20 _confirmed = true,
21 _seat_number = (
22 select
23 min(seat.nr)
24 from (select generate_series(1,600) as nr) as seat
25 full join reservation on reservation._seat_number = seat.nr
26 where id is null
27 group by seat.nr
28 order by seat.nr asc
29 limit 1
30 )
31 where md5(id||email) = ? and _confirmed is false
32 });
33
34 $sth->execute( $self->token );
35
36 if ( $sth->rows == 1 ) {
37
38 $sth = $dbh->prepare(qq{
39 select ime||' '||prezime,_seat_number
40 from reservation
41 where md5(id||email) = ? and _confirmed is true and _seat_number is not null
42 });
43
44 $sth->execute( $self->token );
45 my ($name, $seat) = $sth->fetchrow_array;
46
47 qq|
48 $name, <em>reservation has been confirmed</em> and seat number <big>$seat</big> is waiting for you.
49 <br>
50 Please print this notice and show it when entering lecture.
51 |;
52 } else {
53 die "Problem with confirmation.\n";
54 }
55 }
56
57 sub cancel_as_markup {
58 my ($self) = @_;
59
60 my $dbh = $self->dbh;
61
62 my $sth = $dbh->prepare(qq{
63 update reservation
64 set
65 _confirmed = false,
66 _seat_number = null
67 where md5(id||email) = ? and _confirmed is true
68 });
69 $sth->execute( $self->token );
70
71 if ( $sth->rows == 1 ) {
72 qq|Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else|;
73 } else {
74 die "Problem with cancelation.\n";
75 }
76 }
77
78 1;

  ViewVC Help
Powered by ViewVC 1.1.26