enable CardFortress in test database, #71513
[freeside.git] / FS / FS / sector_coverage.pm
1 package FS::sector_coverage;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6 use Cpanel::JSON::XS;
7
8 =head1 NAME
9
10 FS::sector_coverage - Object methods for sector_coverage records
11
12 =head1 SYNOPSIS
13
14   use FS::sector_coverage;
15
16   $record = new FS::sector_coverage \%hash;
17   $record = new FS::sector_coverage { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::sector_coverage object represents a coverage map for a sector at
30 a specific signal strength level.  FS::sector_coverage inherits from
31 FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item coveragenum
36
37 primary key
38
39 =item sectornum
40
41 L<FS::tower_sector> foreign key
42
43 =item db_loss
44
45 The maximum path loss shown on this map, in dB.
46
47 =item geometry
48
49 A GeoJSON Geometry object for the area covered at this level.
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new map.  To add the example to the database, see L<"insert">.
60
61 Note that this stores the hash reference, not a distinct copy of the hash it
62 points to.  You can ask the object for a copy with the I<hash> method.
63
64 =cut
65
66 # the new method can be inherited from FS::Record, if a table method is defined
67
68 sub table { 'sector_coverage'; }
69
70 =item insert
71
72 Adds this record to the database.  If there is an error, returns the error,
73 otherwise returns false.
74
75 =item delete
76
77 Delete this record from the database.
78
79 =item replace OLD_RECORD
80
81 Replaces the OLD_RECORD with this one in the database.  If there is an error,
82 returns the error, otherwise returns false.
83
84 =cut
85
86 # the replace method can be inherited from FS::Record
87
88 =item check
89
90 Checks all fields to make sure this is a valid example.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert
92 and replace methods.
93
94 =cut
95
96 # the check method should currently be supplied - FS::Record contains some
97 # data checking routines
98
99 sub check {
100   my $self = shift;
101
102   my $error = 
103     $self->ut_numbern('coveragenum')
104     || $self->ut_number('sectornum')
105     || $self->ut_number('db_loss')
106   ;
107   return $error if $error;
108
109   if ( length($self->geometry) ) {
110     # make sure it parses at least
111     local $@;
112     my $data = eval { decode_json($self->geometry) };
113     if ( $@ ) {
114       # limit the length, in case it decides to return a large chunk of data
115       return "Error parsing coverage geometry: ".substr($@, 0, 100);
116     }
117   }
118
119   $self->SUPER::check;
120 }
121
122 =back
123
124 =head1 BUGS
125
126 =head1 SEE ALSO
127
128 L<FS::Record>
129
130 =cut
131
132 1;
133