/[Frey]/branches/zimbardo/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

Diff of /branches/zimbardo/lib/App/RoomReservation/Reservation.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/lib/App/RoomReservation/Reservation.pm revision 1095 by dpavlin, Sun Jun 28 18:51:49 2009 UTC branches/zimbardo/lib/App/RoomReservation/Reservation.pm revision 1181 by dpavlin, Tue Jul 7 22:07:51 2009 UTC
# Line 1  Line 1 
1  package App::RoomReservation::Reservation;  package App::RoomReservation::Reservation;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  use Moose::Util::TypeConstraints;
5  with 'Frey::Web';  use Regexp::Common qw[Email::Address];
6    
7    subtype 'Email',
8            as 'Str',
9            where { /^$RE{Email}{Address}$/ },
10            message { qq|<error>$_ nije valjana e-mail adresa / $_ is not valid e-mail address</error>| };
11    
12    extends 'App::RoomReservation';
13    
14    with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
15    
 use DBI;  
16  use lib 'lib';  use lib 'lib';
17  use Frey::PPI;  use Frey::PPI;
18    
# Line 53  has telefon => ( Line 61  has telefon => (
61  has mobitel => (  has mobitel => (
62          is => 'rw',          is => 'rw',
63          isa => 'Str',          isa => 'Str',
64          required => 1,          default => '', # FIXME without this we get undef in form
65  );  );
66    
67  has email => (  has email => (
68          is => 'rw',          is => 'rw',
69          isa => 'Str',          isa => 'Email',
70          required => 1,          required => 1,
71  );  );
72    
73  has email_verify => (  has email_verify => (
74          is => 'rw',          is => 'rw',
75          isa => 'Str',          isa => 'Email',
76          required => 1,          required => 1,
77  );  );
78    
79  has _confirmed => (  has _confirmed => (
80          is => 'rw',          is => 'rw',
81          isa => 'Bool',          isa => 'Bool',
82          required => 1,  #       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 },          default => sub { 0 },
95  );  );
96    
97  sub dsn { 'DBI:Pg:dbname=room-reservation' }  sub form_labels {{
98            ime => 'Ime / Name',
99            prezime => 'Prezime / Surname',
100            institucija => 'Institucija / Institution',
101            zanimanje => 'Zanimanje / Profession',
102            grad => 'Grad / City',
103            drzava => 'Država / Country',
104            telefon => 'Telefon / Phone',
105            mobitel => 'Mobitel / Cellular phone',
106            email => 'e-mail',
107            verify => 'ponovo / again',
108            submit => 'Pošalji / Submit', # 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 $email je već registriran / allready registred</big>
144                            <br><br>
145                    |
146                    . $self->seat_confirmation_message( email => $email )
147                    . qq|
148                            </error>
149                    |
150                    ;
151            }
152    }
153    
154  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
155  warn "# cols = ",join(',', @cols), $/;  warn "# cols = ",join(',', @cols), $/;
# Line 83  warn "# cols = ",join(',', @cols), $/; Line 157  warn "# cols = ",join(',', @cols), $/;
157  sub create_as_markup {  sub create_as_markup {
158          my ($self) = @_;          my ($self) = @_;
159    
         my $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;  
         $dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i;  
   
160          my @vals;          my @vals;
161          my @p;          my @p;
162    
# Line 106  sub create_as_markup { Line 177  sub create_as_markup {
177    
178          warn "sql: $sql\n";          warn "sql: $sql\n";
179    
180          my $sth = $dbh->prepare( $sql );          my $sth = $self->dbh->prepare( $sql );
181          $sth->execute( @vals );          $sth->execute( @vals );
182    
183          $sth->rows;          return $self->seat_confirmation_message( email => $self->email );
184    
185  }  }
186    
187    __PACKAGE__->meta->make_immutable;
188    no Moose;
189    no Moose::Util::TypeConstraints;
190    
191  1;  1;

Legend:
Removed from v.1095  
changed lines
  Added in v.1181

  ViewVC Help
Powered by ViewVC 1.1.26