1 |
package App::RoomReservation::Reservation; |
2 |
use Moose; |
3 |
|
4 |
extends 'Frey'; |
5 |
with 'Frey::Web'; |
6 |
|
7 |
use DBI; |
8 |
use lib 'lib'; |
9 |
use Frey::PPI; |
10 |
|
11 |
has ime => ( |
12 |
is => 'rw', |
13 |
isa => 'Str', |
14 |
required => 1, |
15 |
); |
16 |
|
17 |
has prezime => ( |
18 |
is => 'rw', |
19 |
isa => 'Str', |
20 |
required => 1, |
21 |
); |
22 |
|
23 |
has institucija => ( |
24 |
is => 'rw', |
25 |
isa => 'Str', |
26 |
required => 1, |
27 |
); |
28 |
|
29 |
has zanimanje => ( |
30 |
is => 'rw', |
31 |
isa => 'Str', |
32 |
required => 1, |
33 |
); |
34 |
|
35 |
has grad => ( |
36 |
is => 'rw', |
37 |
isa => 'Str', |
38 |
required => 1, |
39 |
); |
40 |
|
41 |
has drzava => ( |
42 |
is => 'rw', |
43 |
isa => 'Str', |
44 |
required => 1, |
45 |
); |
46 |
|
47 |
has telefon => ( |
48 |
is => 'rw', |
49 |
isa => 'Str', |
50 |
required => 1, |
51 |
); |
52 |
|
53 |
has mobitel => ( |
54 |
is => 'rw', |
55 |
isa => 'Str', |
56 |
required => 1, |
57 |
); |
58 |
|
59 |
has email => ( |
60 |
is => 'rw', |
61 |
isa => 'Str', |
62 |
required => 1, |
63 |
); |
64 |
|
65 |
has email_verify => ( |
66 |
is => 'rw', |
67 |
isa => 'Str', |
68 |
required => 1, |
69 |
); |
70 |
|
71 |
has _confirmed => ( |
72 |
is => 'rw', |
73 |
isa => 'Bool', |
74 |
required => 1, |
75 |
default => sub { 0 }, |
76 |
); |
77 |
|
78 |
sub dsn { 'DBI:Pg:dbname=room-reservation' } |
79 |
|
80 |
my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; |
81 |
warn "# cols = ",join(',', @cols), $/; |
82 |
|
83 |
sub create_as_markup { |
84 |
my ($self) = @_; |
85 |
|
86 |
my $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr; |
87 |
$dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i; |
88 |
|
89 |
my @vals; |
90 |
my @p; |
91 |
|
92 |
map { |
93 |
push @vals, $self->$_; |
94 |
push @p, '?'; |
95 |
} @cols; |
96 |
|
97 |
my $n = $#cols + 1; |
98 |
|
99 |
my $sql |
100 |
= 'insert into reservation (' |
101 |
. join(',', @cols) |
102 |
. ') values (' |
103 |
. join(',', map { '?' } @cols ) |
104 |
. ')' |
105 |
; |
106 |
|
107 |
warn "sql: $sql\n"; |
108 |
|
109 |
my $sth = $dbh->prepare( $sql ); |
110 |
$sth->execute( @vals ); |
111 |
|
112 |
$sth->rows; |
113 |
} |
114 |
|
115 |
1; |