add more fields to towers and sectors, RT#16372
[freeside.git] / FS / FS / tower_sector.pm
1 package FS::tower_sector;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::tower;
7 use FS::svc_broadband;
8
9 =head1 NAME
10
11 FS::tower_sector - Object methods for tower_sector records
12
13 =head1 SYNOPSIS
14
15   use FS::tower_sector;
16
17   $record = new FS::tower_sector \%hash;
18   $record = new FS::tower_sector { 'column' => 'value' };
19
20   $error = $record->insert;
21
22   $error = $new_record->replace($old_record);
23
24   $error = $record->delete;
25
26   $error = $record->check;
27
28 =head1 DESCRIPTION
29
30 An FS::tower_sector object represents an tower sector.  FS::tower_sector
31 inherits from FS::Record.  The following fields are currently supported:
32
33 =over 4
34
35 =item sectornum
36
37 primary key
38
39 =item towernum
40
41 towernum
42
43 =item sectorname
44
45 sectorname
46
47 =item ip_addr
48
49 ip_addr
50
51
52 =back
53
54 =head1 METHODS
55
56 =over 4
57
58 =item new HASHREF
59
60 Creates a new sector.  To add the sector to the database, see L<"insert">.
61
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to.  You can ask the object for a copy with the I<hash> method.
64
65 =cut
66
67 sub table { 'tower_sector'; }
68
69 =item insert
70
71 Adds this record to the database.  If there is an error, returns the error,
72 otherwise returns false.
73
74 =item delete
75
76 Delete this record from the database.
77
78 =cut
79
80 sub delete {
81   my $self = shift;
82
83   #not the most efficient, not not awful, and its not like deleting a sector
84   # with customers is a common operation
85   return "Can't delete a sector with customers" if $self->svc_broadband;
86
87   $self->SUPER::delete;
88 }
89
90 =item replace OLD_RECORD
91
92 Replaces the OLD_RECORD with this one in the database.  If there is an error,
93 returns the error, otherwise returns false.
94
95 =item check
96
97 Checks all fields to make sure this is a valid sector.  If there is
98 an error, returns the error, otherwise returns false.  Called by the insert
99 and replace methods.
100
101 =cut
102
103 sub check {
104   my $self = shift;
105
106   my $error = 
107     $self->ut_numbern('sectornum')
108     || $self->ut_number('towernum', 'tower', 'towernum')
109     || $self->ut_text('sectorname')
110     || $self->ut_textn('ip_addr')
111     || $self->ut_floatn('height')
112     || $self->ut_numbern('freq_mhz')
113     || $self->ut_numbern('direction')
114     || $self->ut_numbern('width')
115     || $self->ut_floatn('range')
116   ;
117   return $error if $error;
118
119   $self->SUPER::check;
120 }
121
122 =item tower
123
124 Returns the tower for this sector, as an FS::tower object (see L<FS::tower>).
125
126 =cut
127
128 sub tower {
129   my $self = shift;
130   qsearchs('tower', { 'towernum'=>$self->towernum } );
131 }
132
133 =item description
134
135 Returns a description for this sector including tower name.
136
137 =cut
138
139 sub description {
140   my $self = shift;
141   if ( $self->sectorname eq '_default' ) {
142     $self->tower->towername
143   }
144   else {
145     $self->tower->towername. ' sector '. $self->sectorname
146   }
147 }
148
149 =item svc_broadband
150
151 Returns the services on this tower sector.
152
153 =cut
154
155 sub svc_broadband {
156   my $self = shift;
157   qsearch('svc_broadband', { 'sectornum' => $self->sectornum });
158 }
159
160 =back
161
162 =head1 BUGS
163
164 =head1 SEE ALSO
165
166 L<FS::tower>, L<FS::Record>, schema.html from the base documentation.
167
168 =cut
169
170 1;
171