diff options
author | Ivan Kohler <ivan@freeside.biz> | 2016-04-25 11:53:45 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2016-04-25 11:53:45 -0700 |
commit | 09aa2b55432181f5ddc6bac532b17809c530f3a9 (patch) | |
tree | b1bfb7ee695c234e4c0fe87ab6067d70ad4d0e76 | |
parent | 8b4fe72cbd3b29445e336cc3e8cc5dbf5ff02185 (diff) | |
parent | fdb8784fc81fc5c809a8c2e495a9dfa5b30f0d91 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
-rw-r--r-- | FS/FS/part_event/Condition/day_of_week.pm | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/FS/FS/part_event/Condition/day_of_week.pm b/FS/FS/part_event/Condition/day_of_week.pm new file mode 100644 index 000000000..6b8431097 --- /dev/null +++ b/FS/FS/part_event/Condition/day_of_week.pm @@ -0,0 +1,49 @@ +package FS::part_event::Condition::day_of_week; + +use strict; +use base qw( FS::part_event::Condition ); +use FS::Record qw( dbh ); + +tie my %dayofweek, 'Tie::IxHash', + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', +; + +sub description { + "Run only on certain days of the week", +} + +sub option_fields { + ( + 'dayofweek' => { + label => 'Days to run', + type => 'checkbox-multiple', + options => [ values %dayofweek ], + option_labels => { map { $_ => $_ } values %dayofweek }, + }, + ); +} + +sub condition { # is this even necessary? condition_sql is exact. + my( $self, $object, %opt ) = @_; + + my $today = $dayofweek{(localtime($opt{'time'}))[6]}; + if (grep { $_ eq $today } (keys %{$self->option('dayofweek')})) { + return 1; + } + ''; +} + +sub condition_sql { + my( $class, $table, %opt ) = @_; + my $today = $dayofweek{(localtime($opt{'time'}))[6]}; + my $day = $class->condition_sql_option_option('dayofweek'); + return dbh->quote($today) . " IN $day"; +} + +1; |