1 |
package App::RoomReservation::Room; |
package App::RoomReservation::Room; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
use Frey; |
extends 'App::RoomReservation'; |
|
with 'Frey::Web'; |
|
5 |
|
|
6 |
has room => ( |
has room => ( |
7 |
is => 'rw', |
is => 'rw', |
27 |
default => 600, |
default => 600, |
28 |
); |
); |
29 |
|
|
30 |
sub seats_full { 42 } |
has seats_confirmed => ( |
31 |
|
is => 'ro', |
32 |
|
isa => 'Int', |
33 |
|
lazy => 1, |
34 |
|
default => sub { |
35 |
|
my $self = shift; |
36 |
|
$self->dbh->selectrow_array(qq{ |
37 |
|
select count(*) from reservation where _confirmed is true group by _confirmed |
38 |
|
}) || 0; |
39 |
|
}, |
40 |
|
); |
41 |
|
|
42 |
|
has seats_tentative => ( |
43 |
|
is => 'ro', |
44 |
|
isa => 'Int', |
45 |
|
lazy => 1, |
46 |
|
default => sub { |
47 |
|
my $self = shift; |
48 |
|
$self->dbh->selectrow_array(qq{ |
49 |
|
select count(*) from reservation where _confirmed is false group by _confirmed |
50 |
|
}) || 0; |
51 |
|
}, |
52 |
|
); |
53 |
|
|
54 |
sub seats_left { |
sub seats_left { |
55 |
my ($self) = @_; |
my ($self) = @_; |
56 |
$self->seats - $self->seats_full; |
$self->seats - $self->seats_confirmed - $self->seats_tentative; |
57 |
} |
} |
58 |
|
|
59 |
sub room_markup { |
sub room_markup { |
60 |
my ($self) = @_; |
my ($self) = @_; |
61 |
|
|
62 |
my $size = 50; # % |
my $size = 100; # % |
63 |
|
|
64 |
my $full = int( $size * ( $self->seats_full / $self->seats ) ); |
sub calc { |
65 |
my $left = int( $size * ( $self->seats_left / $self->seats ) ); |
my ( $self, $name ) = @_; |
66 |
|
int( 100 * ( $self->$name / $self->seats ) ); |
67 |
|
} |
68 |
|
|
69 |
|
my $confirmed = $self->calc( 'seats_confirmed' ); |
70 |
|
my $tentative = $self->calc( 'seats_tentative' ); |
71 |
|
my $left = $self->calc( 'seats_left' ); |
72 |
|
|
73 |
|
$self->add_css(qq| |
74 |
|
td.confirmed { |
75 |
|
background: #fcc; |
76 |
|
} |
77 |
|
td.tentative { |
78 |
|
background: #ffc; |
79 |
|
} |
80 |
|
td.left { |
81 |
|
background: #cfc; |
82 |
|
} |
83 |
|
|); |
84 |
|
|
85 |
$self->description |
$self->description |
86 |
. qq| |
. qq| |
87 |
<table width=$size%> |
<table> |
88 |
<tr><th colspan=2>seats</th></tr> |
<tr><th colspan=3>seats in room</th></tr> |
89 |
<tr><th>full</th><th>left</th> |
<tr><th>confirmed</th><th>tentative</th><th>left</th></tr> |
90 |
<tr><td width=$full%> |
<tr><td class=confirmed width=$confirmed%> |
91 |
| . $self->seats_full . qq| |
| . $self->seats_confirmed . qq| |
92 |
</td><td width=$left%> |
</td><td class=tentative width=$tentative%> |
93 |
|
| . $self->seats_tentative . qq| |
94 |
|
</td><td class=left width=$left%> |
95 |
| . $self->seats_left . qq| |
| . $self->seats_left . qq| |
96 |
</td></tr> |
</td></tr> |
97 |
</table> |
</table> |