Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Patches from Cliff

  • Loading branch information...
commit 604df6fca6babfb7e447a4c59a2e0305d4260156 1 parent 6fbaf19
@pudge pudge authored
View
30 plugins/ScheduleShifts/ScheduleShifts.pm
@@ -46,6 +46,23 @@ sub new {
$self->{virtual_user} = $user;
$self->sqlConnect;
+ my $static_shift_defs = getCurrentStatic('shift_definitions');
+
+ # What about error handling for bad shift definitions?
+ #
+ # How about warnings for overlapping shifts, or should that
+ # be allowed? Hmmmm..... - Cliff
+ for (split /:/, $static_shift_defs) {
+ my($s_name, $s_times) = split /,/, $_;
+ my($start, $len) = split /=/, $s_times;
+
+ $self->{shift_defs}{$s_name} = {
+ start => $start,
+ 'length' => $len,
+ };
+ }
+ $self->{shift_types} = [ keys %{ $self->{shift_defs} } ];
+
return $self;
}
@@ -367,11 +384,13 @@ sub getShift {
my($self, $when) = @_;
my $constants = getCurrentStatic();
- my $shift_types = [ split /,/, $constants->{shift_shift_types} ];
my $tzcode = $constants->{shift_shifts_tz};
# hr begin in our defined TZ, length in hours
my @shifts = map { [ split /=/ ] } split /,/, $constants->{shift_shifts};
+ my @shifts = map {
+ [ @{ %{ $self->{shift_defs}{$_} } }{qw(start length)} ]
+ } @{ $self->{shift_types} };
# we only need to find out needed week, day of week, and hour
# if we need today/tomorrow/$x days, don't need hour
@@ -417,7 +436,7 @@ sub getShift {
$dow = $time[6];
$day = $self->getDayOfWeekOffset($dow);
}
- @slots = 0 .. $#{$shift_types};
+ @slots = 0 .. $#{ $self->{shift_types} };
} else {
my $slot;
my $hr = $time[2];
@@ -448,7 +467,7 @@ sub getShift {
if ($when eq 'now') {
# we have it
} elsif ($when eq 'next') {
- if (++$slot > $#{$shift_types}) {
+ if (++$slot > $#{ $self->{shift_types} }) {
$time += 86400;
@time = localtime($time);
$dow = $time[6];
@@ -475,8 +494,6 @@ sub getDaddy {
my $constants = getCurrentStatic();
my $slashdb = getCurrentDB();
- my $shift_types = [ split /,/, $constants->{shift_shift_types} ];
-
my($time, $day, $slots) = $self->getShift($when);
my $default = $self->getCurrentDefaultShifts;
@@ -496,7 +513,8 @@ sub getDaddy {
}
$data;
} map {
- $current->{$week}{$day}{$shift_types->[$_]} || $default->{$day}{$shift_types->[$_]}
+ $current->{$week}{$day}{ $self->{shift_types}[$_] } ||
+ $default->{$day}{ $self->{shift_types}[$_] }
} @$slots;
return \@daddies;
View
3  plugins/ScheduleShifts/mysql_dump
@@ -4,6 +4,5 @@ INSERT INTO message_codes (code, type, seclev) VALUES (17, 'Schedule Change Noti
INSERT INTO vars (name, value, description) VALUES ('shift_change_managers', '', 'Comma separated list of user IDs that have been designated as "Shift Change Managers," who will receive a copy of all shift change notices');
INSERT INTO vars (name, value, description) VALUES ('shift_change_message_users', '1', 'Send messages to users who gain/lose shifts');
INSERT INTO vars (name, value, description) VALUES ('shift_schedule_weeks', 5, 'Number of weeks in advance in which shifts can be schedules');
-INSERT INTO vars (name, value, description) VALUES ('shift_shift_types', 'morning,afternoon,evening', 'Names of the shift types, comma separated');
-INSERT INTO vars (name, value, description) VALUES ('shift_shifts', '6=6,12=6,16=6', 'The shift schedule: begin hour=length in hours, for each shift, comma separated');
INSERT INTO vars (name, value, description) VALUES ('shift_shifts_tz', 'EST', 'Time zone that the shifts are in');
+INSERT INTO vars (name, value, description) VALUES ('shift_definitions', 'morning,6=6:afternoon,12=6:evening,18=6', 'Shift descriptions which contain colon separated triplets of "<shiftname>, <shift start>=<shift length>"');
View
6 plugins/ScheduleShifts/shifts.pl
@@ -70,7 +70,7 @@ sub getDaddyList {
my $link = "$gSkin->{absolutedir}/admin.pl";
my $shift_types = @$daddies > 1
- ? [ split /,/, $constants->{shift_shift_types} ]
+ ? $schedule->{shift_types}
: [ $when ];
my $editors = $schedule->getEditors;
@@ -121,8 +121,6 @@ sub showShifts {
my $num_weeks = $constants->{shift_schedule_weeks};
my $shifts = $schedule->getCurrentShifts($num_weeks);
- my $shift_types = [ split /,/, $constants->{shift_shift_types} ];
-
my $schedule_weeks;
my $cur_week = $schedule->getCurrentGregorianWeek;
for (0 .. $num_weeks) {
@@ -142,7 +140,7 @@ sub showShifts {
days_of_week => \@dow,
default_shifts => $defaults,
shifts => $shifts,
- shift_types => $shift_types,
+ shift_types => $schedule->{shift_types},
weeks => $schedule_weeks,
curr_day => $day,
});
Please sign in to comment.
Something went wrong with that request. Please try again.