/[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

Contents of /branches/zimbardo/lib/App/RoomReservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1181 - (show annotations)
Tue Jul 7 22:07:51 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 1962 byte(s)
 r4308@llin (orig r1175):  dpavlin | 2009-07-06 22:27:57 +0200
 adaptive length of input type=text on form using new form_value_len
 which is implemented by App class
 r4309@llin (orig r1176):  dpavlin | 2009-07-07 14:28:59 +0200
 fix revert and postpone for first file in diff
 r4310@llin (orig r1177):  dpavlin | 2009-07-07 22:11:24 +0200
 take a look at new mst toy (DBIx::Class refactoring into Moose goodness)
 r4311@llin (orig r1178):  dpavlin | 2009-07-07 22:11:44 +0200
 use number of seats from room definition
 r4312@llin (orig r1179):  dpavlin | 2009-07-07 22:12:50 +0200
 wrap title call to application class in eval (sometimes it needs instance of class)
 r4313@llin (orig r1180):  dpavlin | 2009-07-07 22:53:55 +0200
 added mime headers and charset

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 $size = $self->room->seats;
20
21 my $sth = $dbh->prepare(qq{
22 update reservation
23 set
24 _confirmed = true,
25 _seat_number = (
26 select
27 min(seat.nr)
28 from (select generate_series(1,$size) as nr) as seat
29 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 where
36 md5(id||email) = ?
37 and _confirmed is false
38 and _canceled is false
39 });
40
41 my $token = $self->token;
42
43 $sth->execute( $token );
44
45 if ( $sth->rows == 0 ) {
46 warn "can't confirm ", $self->token, " check if it's allready confirmed";
47 $sth = $dbh->prepare(qq{
48 select 1
49 from reservation
50 where
51 md5(id||email) = ?
52 and _confirmed is true
53 });
54 $sth->execute( $token );
55 }
56
57 if ( $sth->rows == 1 ) {
58
59 die qq|<error>can't find account associated with $token</error>| unless $sth->rows == 1;
60
61 return $self->seat_confirmation_message( token => $token );
62
63 } else {
64 die qq|<error>Can't find confirmation $token<br>
65 Did you copy-pasted whole URL in your browser?</error>|;
66 }
67 }
68
69 sub cancel_as_markup {
70 my ($self) = @_;
71
72 my $dbh = $self->dbh;
73
74 my $sth = $dbh->prepare(qq{
75 update reservation
76 set
77 _canceled = true,
78 _seat_number = null
79 where
80 md5(id||email) = ?
81 -- and _confirmed is true
82 });
83 $sth->execute( $self->token );
84
85 if ( $sth->rows == 1 ) {
86 qq|
87 Vaš <em>dolazak je odjavljen</em>.
88
89 Hvala što ste omogućili dolazak nekom drugom!
90 |;
91 } else {
92 die qq|<error>Can't find reservation which you are trying to cancel.<br>
93 Did you copy-pasted whole URL in your browser?</error>|;
94 }
95 }
96
97 __PACKAGE__->meta->make_immutable;
98 no Moose;
99
100 1;

  ViewVC Help
Powered by ViewVC 1.1.26