/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1098 - (hide annotations)
Sun Jun 28 22:14:22 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 1867 byte(s)
added verification and cancelation of reservation
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     <h2>Prijava za predavanje profesora Phillipa 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 dpavlin 1098 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 dpavlin 1086
42 dpavlin 1098 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 dpavlin 1086 sub seats_left {
55     my ($self) = @_;
56 dpavlin 1098 $self->seats - $self->seats_confirmed - $self->seats_tentative;
57 dpavlin 1086 }
58    
59     sub room_markup {
60     my ($self) = @_;
61    
62 dpavlin 1098 my $size = 100; # %
63 dpavlin 1086
64 dpavlin 1098 sub calc {
65     my ( $self, $name ) = @_;
66     int( 100 * ( $self->$name / $self->seats ) );
67     }
68 dpavlin 1086
69 dpavlin 1098 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 dpavlin 1086 $self->description
86     . qq|
87 dpavlin 1098 <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 dpavlin 1086 | . $self->seats_left . qq|
96     </td></tr>
97     </table>
98     |
99     }
100    
101     1;

  ViewVC Help
Powered by ViewVC 1.1.26