1 |
dpavlin |
1122 |
package App::RoomReservation::Confirmation; |
2 |
dpavlin |
1098 |
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 |
dpavlin |
1121 |
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 |
dpavlin |
1098 |
where md5(id||email) = ? and _confirmed is false |
32 |
|
|
}); |
33 |
dpavlin |
1121 |
|
34 |
dpavlin |
1098 |
$sth->execute( $self->token ); |
35 |
|
|
|
36 |
|
|
if ( $sth->rows == 1 ) { |
37 |
dpavlin |
1121 |
|
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 |
dpavlin |
1098 |
} else { |
53 |
dpavlin |
1121 |
die "Problem with confirmation.\n"; |
54 |
dpavlin |
1098 |
} |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
sub cancel_as_markup { |
58 |
|
|
my ($self) = @_; |
59 |
|
|
|
60 |
dpavlin |
1121 |
my $dbh = $self->dbh; |
61 |
|
|
|
62 |
|
|
my $sth = $dbh->prepare(qq{ |
63 |
|
|
update reservation |
64 |
|
|
set |
65 |
|
|
_confirmed = false, |
66 |
|
|
_seat_number = null |
67 |
dpavlin |
1098 |
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 |
dpavlin |
1121 |
die "Problem with cancelation.\n"; |
75 |
dpavlin |
1098 |
} |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
1; |