3 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;
#use HTML::Template::Compiled;
#use DBI;
use Data::Dumper;
package Unit;
use Moose;
has 'begin' => ( is => 'rw' );
has 'end' => ( is => 'rw' );
has 'person' => ( is => 'rw' );
has 'task' => ( is => 'rw' );
has 'position' => ( is => 'ro' );
sub as_html {
my $self = shift;
my $o = '';
$o .= '<td class="event">'. $self->begin .'-'. $self->end .'<br />';
$o .= '<span class="person">' . $self->person . '</span><br />';
$o .= '<span class="task">' . $self->task . '</span><br />';;
$o .= '<a href="event.pl?pos=' . $self->position . '">edit</a>';
$o .= '</td>' . "\n";
return $o;
}
package TimeSlot;
use Moose;
has 'units' => ( isa => 'ArrayRef', is => 'rw' );
has 'day' => ( is => 'rw' );
has 'position' => ( is => 'ro' );
sub as_html {
my $self = shift;
my $o = '';
$o .= '<table class="days" border="1">' . "\n";
$o .= '<tr><th class="day">' . $self-> day . '</th></tr>' . "\n";
$o .= "<tr>\n" . $_->as_html . "</tr>\n" for @{$self->{units}};
$o .= '</table>' . "\n";
return $o;
}
package TimeTable;
use Moose;
has 'weekdays' => ( isa => 'ArrayRef', is => 'rw' );
sub create_week {
my $self = shift;
my @days = @_;
@days = qw/ MO DI MI DO FR SA SO / unless @days;
@{$self->{weekdays}} = map { TimeSlot->new(day => $_) } @days;
$self->{weekdays}->[$_]->{position}=$_ for 0 .. $#{$self->{weekdays}};
}
sub populate_units {
my $self = shift;
die "TimeTable->populate_units needs weekdays to add on!"
unless @{$self->{weekdays}};
my @start_end = @_;
@start_end = qw/ 08:00 09:30 09:45 11:15 11:30 13:00 / unless @start_end;
die "TimeTable->populate_units needs an even list to work on!"
unless @start_end %2 == 0;
my $i = 0;
while (my ($s, $e) = splice @start_end, 0, 2) {
push @{$self->{weekdays}->[$_]->{units}},
Unit->new( begin => $s, end => $e, position => $i)
for 0..$#{$self->{weekdays}};
$i++;
}
}
sub as_html {
my $self = shift;
my $o = '';
$o .= '<div class="weekday" style="float: left;">' . "\n"
. $_->as_html
. '</div>' . "\n" for @{$self->{weekdays}};;
return $o;
}
sub add_task {
my $self = shift;
my $d_pos = shift;
my $u_pos = shift;
my $task = shift || '';
$self->{weekdays}->[$d_pos]->{units}->[$u_pos]->task($task);
}
sub add_person {
my $self = shift;
my $d_pos = shift;
my $u_pos = shift;
my $person = shift || '';
$self->{weekdays}->[$d_pos]->{units}->[$u_pos]->person($person);
}
package main;
my $q = CGI->new;
my $tt = TimeTable->new;
$tt->create_week;
$tt->populate_units;
$tt->add_task(0, 1, 'use templating!');
$tt->add_person(0, 1, 'Foo Bar Buz');
print $q->header, $q->start_html, $tt->as_html, $q->end_html;
3 Einträge, 1 Seite |