X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fpart_event_condition.pm;h=16f84fa77899cc3b6ad393c73b38e50b75dc4312;hp=32f19a3aead0db1ae516354fd08f8ff7f0de6e4b;hb=8d0e8149e7b19ad8543ac6c8c663be63dbc34762;hpb=8e0d6410715c534f2994167c83e319a625b2ee0d diff --git a/FS/FS/part_event_condition.pm b/FS/FS/part_event_condition.pm index 32f19a3ae..16f84fa77 100644 --- a/FS/FS/part_event_condition.pm +++ b/FS/FS/part_event_condition.pm @@ -1,13 +1,11 @@ package FS::part_event_condition; +use base qw( FS::option_Common ); use strict; -use vars qw( @ISA $DEBUG @SKIP_CONDITION_SQL ); +use vars qw( $DEBUG @SKIP_CONDITION_SQL ); use FS::UID qw( dbh driver_name ); -use FS::Record qw( qsearch qsearchs ); -use FS::option_Common; use FS::part_event; #for order_conditions_sql... -@ISA = qw( FS::option_Common ); # FS::Record ); $DEBUG = 0; @SKIP_CONDITION_SQL = (); @@ -185,6 +183,10 @@ foreach my $INC ( @INC ) { }; my $mod = $1; my $fullmod = "FS::part_event::Condition::$mod"; + if ( $fullmod =~ /_(Mixin|Common)$/ ) { + #warn "skipping $1 class $fullmod\n"; + next; + } eval "use $fullmod;"; if ( $@ ) { die "error using $fullmod (skipping): $@\n" if $@; @@ -220,8 +222,7 @@ sub conditions { my( $class, $eventtable ) = @_; ( map { $_ => $conditions{$_} } -# sort { $conditions{$a}->{'default_weight'}<=>$conditions{$b}->{'default_weight'} } -# sort by ? + sort {$conditions{$a}->{'description'} cmp $conditions{$b}->{'description'}} $class->all_conditionnames( $eventtable ) ); @@ -240,17 +241,17 @@ sub all_conditionnames { keys %conditions } -=item join_conditions_sql [ EVENTTABLE ] +=item join_conditions_sql [ EVENTTABLE [, OPTIONS ] ] Returns an SQL fragment selecting joining all condition options for an event as tables titled "cond_I". Typically used in conjunction with -B. +B. OPTIONS should include 'time', the time to use +in testing event conditions. =cut sub join_conditions_sql { - my ( $class, $eventtable ) = @_; - my %conditions = $class->conditions( $eventtable ); + my ( $class, $eventtable, %options ) = @_; join(' ', map { @@ -259,7 +260,8 @@ sub join_conditions_sql { " AND cond_$_.conditionname = ". dbh->quote($_). " )"; } - keys %conditions + map $_->[0], $class->_where_conditions( $eventtable, %options ) + ); } @@ -277,27 +279,38 @@ as passed to freeside-daily), as a UNIX timestamp. sub where_conditions_sql { my ( $class, $eventtable, %options ) = @_; + join(' AND ', + map { my $conditionname = $_->[0]; + my $sql = $_->[1]; + "( cond_$conditionname.conditionname IS NULL OR $sql )"; + } + $class->_where_conditions( $eventtable, %options ) + ); +} + +sub _where_conditions { + my ( $class, $eventtable, %options ) = @_; + my $time = $options{'time'}; my %conditions = $class->conditions( $eventtable ); - my $where = join(' AND ', + grep { $_->[1] !~ /^\s*true\s*$/i + || $conditions{ $_->[0] }->{order_sql} + } map { my $conditionname = $_; my $coderef = $conditions{$conditionname}->{condition_sql}; + #die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE'; my $sql = &$coderef( $eventtable, 'time' => $time, 'driver_name' => driver_name(), ); - die "$coderef is not a CODEREF" unless ref($coderef) eq 'CODE'; - "( cond_$conditionname.conditionname IS NULL OR $sql )"; + [ $_, $sql ]; } - grep { my $cond = $_; - ! grep { $_ eq $cond } @SKIP_CONDITION_SQL - } - keys %conditions - ); - - $where; + grep { my $cond = $_; + ! grep { $_ eq $cond } @SKIP_CONDITION_SQL + } + keys %conditions; } =item order_conditions_sql [ EVENTTABLE ]