--- trunk/lib/App/RoomReservation/Room.pm 2009/06/28 18:51:49 1095 +++ trunk/lib/App/RoomReservation/Room.pm 2009/06/28 22:14:22 1098 @@ -1,8 +1,7 @@ package App::RoomReservation::Room; use Moose; -use Frey; -with 'Frey::Web'; +extends 'App::RoomReservation'; has room => ( is => 'rw', @@ -28,29 +27,71 @@ default => 600, ); -sub seats_full { 42 } +has seats_confirmed => ( + is => 'ro', + isa => 'Int', + lazy => 1, + default => sub { + my $self = shift; + $self->dbh->selectrow_array(qq{ + select count(*) from reservation where _confirmed is true group by _confirmed + }) || 0; + }, +); + +has seats_tentative => ( + is => 'ro', + isa => 'Int', + lazy => 1, + default => sub { + my $self = shift; + $self->dbh->selectrow_array(qq{ + select count(*) from reservation where _confirmed is false group by _confirmed + }) || 0; + }, +); sub seats_left { my ($self) = @_; - $self->seats - $self->seats_full; + $self->seats - $self->seats_confirmed - $self->seats_tentative; } sub room_markup { my ($self) = @_; - my $size = 50; # % + my $size = 100; # % - my $full = int( $size * ( $self->seats_full / $self->seats ) ); - my $left = int( $size * ( $self->seats_left / $self->seats ) ); + sub calc { + my ( $self, $name ) = @_; + int( 100 * ( $self->$name / $self->seats ) ); + } + + my $confirmed = $self->calc( 'seats_confirmed' ); + my $tentative = $self->calc( 'seats_tentative' ); + my $left = $self->calc( 'seats_left' ); + + $self->add_css(qq| + td.confirmed { + background: #fcc; + } + td.tentative { + background: #ffc; + } + td.left { + background: #cfc; + } + |); $self->description . qq| - - - -
seats
fullleft
- | . $self->seats_full . qq| - + + + +
seats in room
confirmedtentativeleft
+ | . $self->seats_confirmed . qq| + + | . $self->seats_tentative . qq| + | . $self->seats_left . qq|