torrus, RT#10574
[freeside.git] / FS / FS / svc_port.pm
1 package FS::svc_port;
2
3 use strict;
4 use base qw( FS::svc_Common );
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::cust_svc;
7
8 =head1 NAME
9
10 FS::svc_port - Object methods for svc_port records
11
12 =head1 SYNOPSIS
13
14   use FS::svc_port;
15
16   $record = new FS::svc_port \%hash;
17   $record = new FS::svc_port { '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   $error = $record->suspend;
28
29   $error = $record->unsuspend;
30
31   $error = $record->cancel;
32
33 =head1 DESCRIPTION
34
35 An FS::svc_port object represents a router port.  FS::table_name inherits from
36 FS::svc_Common.  The following fields are currently supported:
37
38 =over 4
39
40 =item svcnum - 
41
42 =item serviceid - Torrus serviceid (in srvexport and reportfields tables)
43
44 =back
45
46 =head1 METHODS
47
48 =over 4
49
50 =item new HASHREF
51
52 Creates a new port.  To add the port to the database, see L<"insert">.
53
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to.  You can ask the object for a copy with the I<hash> method.
56
57 =cut
58
59 sub table { 'svc_port'; }
60
61 sub table_info {
62   {
63     'name' => 'Port',
64     #'name_plural' => 'Ports', #optional,
65     #'longname_plural' => 'Ports', #optional
66     'sorts' => [ 'svcnum', 'serviceid' ], # optional sort field (or arrayref of sort fields, main first)
67     'display_weight' => 75,
68     'cancel_weight'  => 10,
69     'fields' => {
70       'serviceid'         => 'Torrus serviceid',
71     },
72   };
73 }
74
75 =item search_sql STRING
76
77 Class method which returns an SQL fragment to search for the given string.
78
79 =cut
80
81 #or something more complicated if necessary
82 sub search_sql {
83   my($class, $string) = @_;
84   $class->search_sql_field('serviceid', $string);
85 }
86
87 =item label
88
89 Returns a meaningful identifier for this port
90
91 =cut
92
93 sub label {
94   my $self = shift;
95   $self->serviceid; #or something more complicated if necessary
96 }
97
98 =item insert
99
100 Adds this record to the database.  If there is an error, returns the error,
101 otherwise returns false.
102
103 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be 
104 defined.  An FS::cust_svc record will be created and inserted.
105
106 =cut
107
108 sub insert {
109   my $self = shift;
110   my $error;
111
112   $error = $self->SUPER::insert;
113   return $error if $error;
114
115   '';
116 }
117
118 =item delete
119
120 Delete this record from the database.
121
122 =cut
123
124 sub delete {
125   my $self = shift;
126   my $error;
127
128   $error = $self->SUPER::delete;
129   return $error if $error;
130
131   '';
132 }
133
134
135 =item replace OLD_RECORD
136
137 Replaces the OLD_RECORD with this one in the database.  If there is an error,
138 returns the error, otherwise returns false.
139
140 =cut
141
142 sub replace {
143   my ( $new, $old ) = ( shift, shift );
144   my $error;
145
146   $error = $new->SUPER::replace($old);
147   return $error if $error;
148
149   '';
150 }
151
152 =item suspend
153
154 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
155
156 =item unsuspend
157
158 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
159
160 =item cancel
161
162 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
163
164 =item check
165
166 Checks all fields to make sure this is a valid port.  If there is
167 an error, returns the error, otherwise returns false.  Called by the insert
168 and repalce methods.
169
170 =cut
171
172 sub check {
173   my $self = shift;
174
175   my $x = $self->setfixed;
176   return $x unless ref($x);
177   my $part_svc = $x;
178
179   my $error = $self->ut_textn('serviceid'); #too lenient?
180   return $error if $error;
181
182   $self->SUPER::check;
183 }
184
185 =item
186
187 Returns a PNG graph for this port.
188
189 XXX Options
190
191 =cut
192
193 sub graph_png {
194   my $self = shift;
195   my $serviceid = $self->serviceid;
196
197
198 }
199
200 =back
201
202 =head1 BUGS
203
204 =head1 SEE ALSO
205
206 L<FS::svc_Common>, L<FS::Record>, L<FS::cust_svc>, L<FS::part_svc>,
207 L<FS::cust_pkg>, schema.html from the base documentation.
208
209 =cut
210
211 1;
212