RT# 31208 Docs $FS::Record::qsearch_qualify_columns
[freeside.git] / FS / FS / fiber_olt.pm
1 package FS::fiber_olt;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6 use FS::svc_fiber;
7 use FS::olt_site;
8
9 =head1 NAME
10
11 FS::fiber_olt - Object methods for fiber_olt records
12
13 =head1 SYNOPSIS
14
15   use FS::fiber_olt;
16
17   $record = new FS::fiber_olt \%hash;
18   $record = new FS::fiber_olt { '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::fiber_olt object represents an Optical Line Terminal that fiber
31 connections (L<FS::svc_fiber>) connect to.  FS::fiber_olt inherits from
32 FS::Record.  The following fields are currently supported:
33
34 =over 4
35
36 =item oltnum - primary key
37
38 =item oltname - name of this device
39
40 =item serial - serial number
41
42 =item sitenum - the L<FS::olt_site> where this OLT is installed
43
44 =item disabled - set to 'Y' to make this OLT unavailable for new connections
45
46 =back
47
48 =head1 METHODS
49
50 =over 4
51
52 =item new HASHREF
53
54 Creates a new fiber_olt record.  To add it to the database, see L<"insert">.
55
56 =cut
57
58 # the new method can be inherited from FS::Record, if a table method is defined
59
60 sub table { 'fiber_olt'; }
61
62 =item insert
63
64 Adds this record to the database.  If there is an error, returns the error,
65 otherwise returns false.
66
67 =item delete
68
69 Delete this record from the database.
70
71 =item replace OLD_RECORD
72
73 Replaces the OLD_RECORD with this one in the database.  If there is an error,
74 returns the error, otherwise returns false.
75
76 =item check
77
78 Checks all fields to make sure this is a valid example.  If there is
79 an error, returns the error, otherwise returns false.  Called by the insert
80 and replace methods.
81
82 =cut
83
84 # the check method should currently be supplied - FS::Record contains some
85 # data checking routines
86
87 sub check {
88   my $self = shift;
89
90   my $error = 
91     $self->ut_numbern('oltnum')
92     || $self->ut_text('oltname')
93     || $self->ut_text('serial')
94     || $self->ut_foreign_keyn('sitenum', 'olt_site', 'sitenum')
95     || $self->ut_flag('disabled')
96   ;
97   return $error if $error;
98
99   $self->SUPER::check;
100 }
101
102 =item site_description
103
104 Returns the OLT's site description.
105
106 =cut
107
108 sub site_description {
109   my $self = shift;
110   return '' if !$self->sitenum;
111   my $olt_site = FS::olt_site->by_key($self->sitenum);
112   return $olt_site->description;
113 }
114
115 =item description
116
117 Returns the OLT's site name and unit name.
118
119 =cut
120
121 sub description {
122   my $self = shift;
123   my $desc = $self->oltname;
124   $desc = $self->site_description . '/' . $desc if $self->sitenum;
125   return $desc;
126 }
127
128 # 3.x stub
129
130 sub svc_fiber {
131   my $self = shift;
132   qsearch('svc_fiber', { 'oltnum' => $self->get('oltnum') });
133 }
134
135 =back
136
137 =head1 SEE ALSO
138
139 L<FS::svc_fiber>, L<FS::olt_site>, L<FS::Record>
140
141 =cut
142
143 1;
144