/[Frey]/branches/zimbardo/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

Annotation of /branches/zimbardo/lib/App/RoomReservation/Room.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1173 - (hide annotations)
Sun Jul 5 21:40:54 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 2058 byte(s)
translation

1 dpavlin 1086 package App::RoomReservation::Room;
2 dpavlin 1095 use Moose;
3 dpavlin 1086
4 dpavlin 1098 extends 'App::RoomReservation';
5 dpavlin 1095
6 dpavlin 1086 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 dpavlin 1173 <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 dpavlin 1086 |,
23     );
24    
25     has seats => (
26     is => 'rw',
27     isa => 'Int',
28     required => 1,
29     default => 600,
30     );
31    
32 dpavlin 1098 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 dpavlin 1086
44 dpavlin 1098 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 dpavlin 1086 sub seats_left {
57     my ($self) = @_;
58 dpavlin 1098 $self->seats - $self->seats_confirmed - $self->seats_tentative;
59 dpavlin 1086 }
60    
61 dpavlin 1150 sub room_as_markup {
62 dpavlin 1086 my ($self) = @_;
63    
64 dpavlin 1098 my $size = 100; # %
65 dpavlin 1086
66 dpavlin 1098 sub calc {
67     my ( $self, $name ) = @_;
68     int( 100 * ( $self->$name / $self->seats ) );
69     }
70 dpavlin 1086
71 dpavlin 1098 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 dpavlin 1086 $self->description
88     . qq|
89 dpavlin 1098 <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 dpavlin 1086 | . $self->seats_left . qq|
98     </td></tr>
99     </table>
100     |
101     }
102    
103 dpavlin 1133 __PACKAGE__->meta->make_immutable;
104     no Moose;
105    
106 dpavlin 1086 1;

  ViewVC Help
Powered by ViewVC 1.1.26