blob: 2555b9e506ce3100a82d7bbd87754b8c28a3590d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
package FS::svc_Tower_Mixin;
use strict;
=item tower_sector
=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;
|