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