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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1175 - (show annotations)
Mon Jul 6 20:27:57 2009 UTC (13 years, 6 months ago) by dpavlin
File size: 3181 byte(s)
adaptive length of input type=text on form using new form_value_len
which is implemented by App class
1 package App::RoomReservation::Reservation;
2 use Moose;
3
4 use Moose::Util::TypeConstraints;
5 use Regexp::Common qw[Email::Address];
6
7 subtype 'Email',
8 as 'Str',
9 where { /^$RE{Email}{Address}$/ },
10 message { qq|<error>$_ is not valid e-mail address</error>| };
11
12 extends 'App::RoomReservation';
13
14 with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
15
16 use lib 'lib';
17 use Frey::PPI;
18
19 has ime => (
20 is => 'rw',
21 isa => 'Str',
22 required => 1,
23 );
24
25 has prezime => (
26 is => 'rw',
27 isa => 'Str',
28 required => 1,
29 );
30
31 has institucija => (
32 is => 'rw',
33 isa => 'Str',
34 required => 1,
35 );
36
37 has zanimanje => (
38 is => 'rw',
39 isa => 'Str',
40 required => 1,
41 );
42
43 has grad => (
44 is => 'rw',
45 isa => 'Str',
46 required => 1,
47 );
48
49 has drzava => (
50 is => 'rw',
51 isa => 'Str',
52 required => 1,
53 );
54
55 has telefon => (
56 is => 'rw',
57 isa => 'Str',
58 required => 1,
59 );
60
61 has mobitel => (
62 is => 'rw',
63 isa => 'Str',
64 default => '', # FIXME without this we get undef in form
65 );
66
67 has email => (
68 is => 'rw',
69 isa => 'Email',
70 required => 1,
71 );
72
73 has email_verify => (
74 is => 'rw',
75 isa => 'Email',
76 required => 1,
77 );
78
79 has _confirmed => (
80 is => 'rw',
81 isa => 'Bool',
82 # required => 1,
83 default => sub { 0 },
84 );
85
86 has _seat_number => (
87 is => 'rw',
88 isa => 'Int',
89 );
90
91 has _canceled => (
92 is => 'rw',
93 isa => 'Bool',
94 default => sub { 0 },
95 );
96
97 sub form_labels {{
98 ime => 'Ime',
99 prezime => 'Prezime',
100 institucija => 'Institucija',
101 zanimanje => 'Zanimanje',
102 grad => 'Grad',
103 drzava => 'Država',
104 telefon => 'Telefon',
105 mobitel => 'Mobitel',
106 email => 'e-mail adresa',
107 verify => 'unesite ponovo',
108 submit => 'Pošalji', # submit button
109 }}
110
111 sub form_value_len {
112 my $self = shift;
113 my $sth = $self->dbh->prepare(qq{
114 select * from reservation limit 1
115 });
116 $sth->execute;
117 my @columns = $sth->fetchrow_array;
118
119 $sth = $self->dbh->prepare(qq{
120 select
121 } . join(',', map { "max(length($_)) as $_" } grep { !/^_/ && !/id/ } @{ $sth->{NAME} } ) . qq{
122 from reservation
123 });
124 $sth->execute;
125 my $max_len = $sth->fetchrow_hashref;
126 warn "# max_len = ", $self->dump( $max_len );
127 return $max_len;
128 }
129
130 sub BUILD {
131 my $self = shift;
132 my $email = $self->email;
133 die qq|<error>e-mail addresses not same</error>| unless $email eq $self->email_verify;
134 my $sth = $self->dbh->prepare(qq{
135 select count(*) from reservation where email = ?
136 });
137 $sth->execute( $email );
138 my ($registred) = $sth->fetchrow_array;
139 if ( $registred ) {
140 die
141 qq|
142 <error>
143 <big>e-mail address $email allready registred</big>
144 |
145 . $self->seat_confirmation_message( email => $email )
146 . qq|
147 </error>
148 |
149 ;
150 }
151 }
152
153 my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
154 warn "# cols = ",join(',', @cols), $/;
155
156 sub create_as_markup {
157 my ($self) = @_;
158
159 my @vals;
160 my @p;
161
162 map {
163 push @vals, $self->$_;
164 push @p, '?';
165 } @cols;
166
167 my $n = $#cols + 1;
168
169 my $sql
170 = 'insert into reservation ('
171 . join(',', @cols)
172 . ') values ('
173 . join(',', map { '?' } @cols )
174 . ')'
175 ;
176
177 warn "sql: $sql\n";
178
179 my $sth = $self->dbh->prepare( $sql );
180 $sth->execute( @vals );
181
182 return $self->seat_confirmation_message( email => $self->email );
183
184 }
185
186 __PACKAGE__->meta->make_immutable;
187 no Moose;
188 no Moose::Util::TypeConstraints;
189
190 1;

  ViewVC Help
Powered by ViewVC 1.1.26