X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Tower_Mixin.pm;h=3da07c1cd0d3e3b5d812bf902dabcbd859d0302c;hb=dd268209494ce9fc3491d02b8c3034a7dffc84e4;hp=8caef6dc88b5063fd75a9f8ba3bdaa134ddc87ca;hpb=fc2bc78541d1c8c0f1f0570b55e41ac032d03e65;p=freeside.git diff --git a/FS/FS/svc_Tower_Mixin.pm b/FS/FS/svc_Tower_Mixin.pm index 8caef6dc8..3da07c1cd 100644 --- a/FS/FS/svc_Tower_Mixin.pm +++ b/FS/FS/svc_Tower_Mixin.pm @@ -14,4 +14,40 @@ sub tower_sector { qsearchs('tower_sector', { sectornum => $self->sectornum }); } +=item tower_sector_sql HASHREF + +Class method which returns a list of WHERE clause fragments to +search for services with tower/sector given by HASHREF. Can +contain 'towernum' and 'sectornum' keys, either of which can be +an arrayref or a single value. To use this, the search needs to +join to tower_sector. + +towernum or sectornum can also contain 'none' to allow null values. + +=cut + +sub tower_sector_sql { + my( $class, $params ) = @_; + return () unless keys %$params; + + my @where = (); + for my $field (qw(towernum sectornum)) { + my $value = $params->{$field} or next; + if ( ref $value and grep { $_ } @$value ) { + my $in = join(',', map { /^(\d+)$/ ? $1 : () } @$value); + my @orwhere; + push @orwhere, "tower_sector.$field IN ($in)" if $in; + push @orwhere, "tower_sector.$field IS NULL" if grep /^none$/, @$value; + push @where, '( '.join(' OR ', @orwhere).' )'; + } + elsif ( $value =~ /^(\d+)$/ ) { + push @where, "tower_sector.$field = $1"; + } + elsif ( $value eq 'none' ) { + push @where, "tower_sector.$field IS NULL"; + } + } + @where; +} + 1;