1 |
package App::RoomReservation::Room; |
2 |
use Moose; |
3 |
|
4 |
extends 'App::RoomReservation'; |
5 |
|
6 |
has room => ( |
7 |
is => 'rw', |
8 |
isa => 'Str', |
9 |
required => 1, |
10 |
default => 'zimbardo', |
11 |
); |
12 |
|
13 |
has description => ( |
14 |
is => 'rw', |
15 |
isa => 'Str', |
16 |
required => 1, |
17 |
default => q| |
18 |
<h3>Prijava za predavanje profesora Philipa Zimbarda "The Lucifer Effect" 28. 9. 2009. u 12 sati</h3> |
19 |
<h3>Registration for the lecture by professor Philip Zimbardo “The Lucifer Effect” that will take place on 28th Sept 2009 at 12h.</h3> |
20 |
<hr> |
21 |
<br><br> |
22 |
|, |
23 |
); |
24 |
|
25 |
has seats => ( |
26 |
is => 'rw', |
27 |
isa => 'Int', |
28 |
required => 1, |
29 |
default => 580, |
30 |
); |
31 |
|
32 |
has seats_confirmed => ( |
33 |
is => 'ro', |
34 |
isa => 'Int', |
35 |
lazy => 1, |
36 |
default => sub { |
37 |
my $self = shift; |
38 |
$self->dbh->selectrow_array(qq{ |
39 |
select count(*) from reservation where _confirmed is true group by _confirmed |
40 |
}) || 0; |
41 |
}, |
42 |
); |
43 |
|
44 |
has seats_tentative => ( |
45 |
is => 'ro', |
46 |
isa => 'Int', |
47 |
lazy => 1, |
48 |
default => sub { |
49 |
my $self = shift; |
50 |
$self->dbh->selectrow_array(qq{ |
51 |
select count(*) from reservation where _confirmed is false group by _confirmed |
52 |
}) || 0; |
53 |
}, |
54 |
); |
55 |
|
56 |
sub seats_left { |
57 |
my ($self) = @_; |
58 |
$self->seats - $self->seats_confirmed - $self->seats_tentative; |
59 |
} |
60 |
|
61 |
sub room_as_markup { |
62 |
my ($self) = @_; |
63 |
|
64 |
my $size = 100; # % |
65 |
|
66 |
sub calc { |
67 |
my ( $self, $name ) = @_; |
68 |
int( 100 * ( $self->$name / $self->seats ) ); |
69 |
} |
70 |
|
71 |
my $confirmed = $self->calc( 'seats_confirmed' ); |
72 |
my $tentative = $self->calc( 'seats_tentative' ); |
73 |
my $left = $self->calc( 'seats_left' ); |
74 |
|
75 |
$self->add_css(qq| |
76 |
td.confirmed { |
77 |
background: #fcc; |
78 |
} |
79 |
td.tentative { |
80 |
background: #ffc; |
81 |
} |
82 |
td.left { |
83 |
background: #cfc; |
84 |
} |
85 |
|); |
86 |
|
87 |
$self->description |
88 |
. qq| |
89 |
<table> |
90 |
<tr><th colspan=3>seats in room</th></tr> |
91 |
<tr><th>confirmed</th><th>tentative</th><th>left</th></tr> |
92 |
<tr><td class=confirmed width=$confirmed%> |
93 |
| . $self->seats_confirmed . qq| |
94 |
</td><td class=tentative width=$tentative%> |
95 |
| . $self->seats_tentative . qq| |
96 |
</td><td class=left width=$left%> |
97 |
| . $self->seats_left . qq| |
98 |
</td></tr> |
99 |
</table> |
100 |
| |
101 |
} |
102 |
|
103 |
__PACKAGE__->meta->make_immutable; |
104 |
no Moose; |
105 |
|
106 |
1; |