/[Frey]/trunk/lib/App/RoomReservation/Room.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

Contents of /trunk/lib/App/RoomReservation/Room.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1150 - (show annotations)
Wed Jul 1 18:41:28 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 1915 byte(s)
mis-named room_markup renamed to room_as_makrup
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 <h2>Prijava za predavanje profesora Philipa Zimbarda "The Lucifer Effect"</h2>
19 <h3>28. 9. 2009. u 12 sati </h3>
20 |,
21 );
22
23 has seats => (
24 is => 'rw',
25 isa => 'Int',
26 required => 1,
27 default => 600,
28 );
29
30 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 {
55 my ($self) = @_;
56 $self->seats - $self->seats_confirmed - $self->seats_tentative;
57 }
58
59 sub room_as_markup {
60 my ($self) = @_;
61
62 my $size = 100; # %
63
64 sub calc {
65 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
86 . qq|
87 <table>
88 <tr><th colspan=3>seats in room</th></tr>
89 <tr><th>confirmed</th><th>tentative</th><th>left</th></tr>
90 <tr><td class=confirmed width=$confirmed%>
91 | . $self->seats_confirmed . qq|
92 </td><td class=tentative width=$tentative%>
93 | . $self->seats_tentative . qq|
94 </td><td class=left width=$left%>
95 | . $self->seats_left . qq|
96 </td></tr>
97 </table>
98 |
99 }
100
101 __PACKAGE__->meta->make_immutable;
102 no Moose;
103
104 1;

  ViewVC Help
Powered by ViewVC 1.1.26