1 package FS::svc_Tower_Mixin;
7 =item tower_sector_sql HASHREF
9 Class method which returns a list of WHERE clause fragments to
10 search for services with tower/sector given by HASHREF. Can
11 contain 'towernum' and 'sectornum' keys, either of which can be
12 an arrayref or a single value. To use this, the search needs to
15 towernum or sectornum can also contain 'none' to allow null values.
19 sub tower_sector_sql {
20 my( $class, $params ) = @_;
21 return () unless keys %$params;
24 for my $field (qw(towernum sectornum)) {
25 my $value = $params->{$field} or next;
26 if ( ref $value and grep { $_ } @$value ) {
27 my $in = join(',', map { /^(\d+)$/ ? $1 : () } @$value);
29 push @orwhere, "tower_sector.$field IN ($in)" if $in;
30 if ( grep /^none$/, @$value ) {
31 # then allow this field to be null
32 push @orwhere, "tower_sector.$field IS NULL";
33 # and if this field is the sector, also allow the default sector
35 push @orwhere, "sectorname = '_default'" if $field eq 'sectornum';
37 push @where, '( '.join(' OR ', @orwhere).' )';
39 elsif ( $value =~ /^(\d+)$/ ) {
40 push @where, "tower_sector.$field = $1";
42 elsif ( $value eq 'none' ) {
43 push @where, "tower_sector.$field IS NULL";