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

Diff of /trunk/lib/App/RoomReservation/Reservation.pm

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

revision 1086 by dpavlin, Sun Jun 28 14:21:10 2009 UTC revision 1164 by dpavlin, Thu Jul 2 17:59:56 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  #with 'Frey::Storage';  
7    subtype 'Email',
8            as 'Str',
9            where { /^$RE{Email}{Address}$/ },
10            message { "$_ is not valid e-mail" };
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 => (  has ime => (
20          is => 'rw',          is => 'rw',
# Line 50  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 },          default => sub { 0 },
84  );  );
85    
86  sub as_markup {  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 BUILD {
112            my $self = shift;
113            my $email = $self->email;
114            die "e-mail not verified\n" unless $email eq $self->email_verify;
115            my $sth = $self->dbh->prepare(qq{
116                    select count(*) from reservation where email = ?
117            });
118            $sth->execute( $email );
119            my ($registred) = $sth->fetchrow_array;
120            if ( $registred ) {
121                    die qq|
122                            <big>e-mail address $email allready registred</big>
123                    | . $self->seat_confirmation_message( email => $email )
124                    ;
125            }
126    }
127    
128    my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
129    warn "# cols = ",join(',', @cols), $/;
130    
131    sub create_as_markup {
132          my ($self) = @_;          my ($self) = @_;
133    
134          $self->ime;          my @vals;
135            my @p;
136    
137            map {
138                    push @vals, $self->$_;
139                    push @p, '?';
140            } @cols;
141    
142            my $n = $#cols + 1;
143    
144            my $sql
145                    = 'insert into reservation ('
146                    . join(',', @cols)
147                    . ') values ('
148                    . join(',', map { '?' } @cols )
149                    . ')'
150                    ;
151    
152            warn "sql: $sql\n";
153    
154            my $sth = $self->dbh->prepare( $sql );
155            $sth->execute( @vals );
156    
157            return $self->seat_confirmation_message( email => $self->email );
158    
159  }  }
160    
161    __PACKAGE__->meta->make_immutable;
162    no Moose;
163    no Moose::Util::TypeConstraints;
164    
165  1;  1;

Legend:
Removed from v.1086  
changed lines
  Added in v.1164

  ViewVC Help
Powered by ViewVC 1.1.26