typo
[freeside.git] / FS / FS / router_field.pm
1 package FS::router_field;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::part_router_field;
7 use FS::router;
8
9
10 @ISA = qw( FS::Record );
11
12 =head1 NAME
13
14 FS::router_field - Object methods for router_field records
15
16 =head1 SYNOPSIS
17
18   use FS::router_field;
19
20   $record = new FS::router_field \%hash;
21   $record = new FS::router_field { 'column' => 'value' };
22
23   $error = $record->insert;
24
25   $error = $new_record->replace($old_record);
26
27   $error = $record->delete;
28
29   $error = $record->check;
30
31 =head1 DESCRIPTION
32
33 FS::router_field contains values of router xfields.  See FS::part_sb_field 
34 for details on the xfield mechanism.
35
36 =over 4
37
38 =item routerfieldpart - Type of router_field as defined by 
39 FS::part_router_field
40
41 =item routernum - The FS::router to which this value belongs.
42
43 =item value - The contents of the field.
44
45 =back
46
47 =head1 METHODS
48
49
50 =over 4
51
52 =item new HASHREF
53
54 Create a new record.  To add the record to the database, see "insert".
55
56 =cut
57
58 sub table { 'router_field'; }
59
60 =item insert
61
62 Adds this record to the database.  If there is an error, returns the error,
63 otherwise returns false.
64
65 =item delete
66
67 Deletes this record from the database.  If there is an error, returns the
68 error, otherwise returns false.
69
70 =item replace OLD_RECORD
71
72 Replaces OLD_RECORD with this one in the database.  If there is an error,
73 returns the error, otherwise returns false.
74
75 =item check
76
77 Checks all fields to make sure this is a valid record.  If there is an error,
78 returns the error, otherwise returns false.  Called by the insert and replace
79 methods.
80
81 =cut
82
83 sub check {
84   my $self = shift;
85
86   return "routernum must be defined" unless $self->routernum;
87   return "routerfieldpart must be defined" unless $self->routerfieldpart;
88
89   my $part_router_field = $self->part_router_field;
90   $_ = $self->value;
91
92   my $check_block = $part_router_field->check_block;
93   if ($check_block) {
94     $@ = '';
95     my $error = (eval($check_block) or $@);
96     return $error if $error;
97     $self->setfield('value' => $_);
98   }
99
100   ''; #no error
101 }
102
103 =item part_router_field
104
105 Returns a reference to the FS:part_router_field that defines this 
106 FS::router_field
107
108 =cut
109
110 sub part_router_field {
111   my $self = shift;
112
113   return qsearchs('part_router_field', 
114     { routerfieldpart => $self->routerfieldpart });
115 }
116
117 =item router
118
119 Returns a reference to the FS::router to which this FS::router_field 
120 belongs.
121
122 =cut
123
124 sub router {
125   my $self = shift;
126
127   return qsearchs('router', { routernum => $self->routernum });
128 }
129
130 =back
131
132 =head1 VERSION
133
134 $Id: 
135
136 =head1 BUGS
137
138 =head1 SEE ALSO
139
140 FS::svc_broadband, FS::router, FS::router_block, FS::router_field,  
141 schema.html from the base documentation.
142
143 =cut
144
145 1;
146