typo
[freeside.git] / FS / FS / sb_field.pm
1 package FS::sb_field;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearchs );
6 use FS::part_sb_field;
7
8 use UNIVERSAL qw( can );
9
10 @ISA = qw( FS::Record );
11
12 =head1 NAME
13
14 FS::sb_field - Object methods for sb_field records
15
16 =head1 SYNOPSIS
17
18   use FS::sb_field;
19
20   $record = new FS::sb_field \%hash;
21   $record = new FS::sb_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 See L<FS::part_sb_field> for details on this table's mission in life.
34 FS::sb_field contains the actual values of the xfields defined in
35 part_sb_field.
36
37 The following fields are supported:
38
39 =over 4
40
41 =item sbfieldpart - Type of sb_field as defined by FS::part_sb_field
42
43 =item svcnum - The svc_broadband to which this value belongs.
44
45 =item value - The contents of the field.
46
47 =back
48
49 =head1 METHODS
50
51 =over 4
52
53 =item new HASHREF
54
55 Create a new record.  To add the record to the database, see L<"insert">.
56
57 =cut
58
59 sub table { 'sb_field'; }
60
61 =item insert
62
63 Adds this record to the database.  If there is an error, returns the error,
64 otherwise returns false.
65
66 =item delete
67
68 Deletes this record from the database.  If there is an error, returns the
69 error, otherwise returns false.
70
71 =item replace OLD_RECORD
72
73 Replaces 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 the value against the check_block of the corresponding part_sb_field.
79 Returns whatever the check_block returned (unless the check_block dies, in 
80 which case check returns the die message).  Therefore, if the check_block 
81 wants to allow the value to be stored, it must return false.  See 
82 L<FS::part_sb_field> for details.
83
84 =cut
85
86 sub check {
87   my $self = shift;
88
89   return "svcnum must be defined" unless $self->svcnum;
90   return "sbfieldpart must be defined" unless $self->sbfieldpart;
91
92   my $part_sb_field = $self->part_sb_field;
93
94   $_ = $self->value;
95
96   my $check_block = $self->part_sb_field->check_block;
97   if ($check_block) {
98     $@ = '';
99     my $error = (eval($check_block) or $@); # treat fatal errors as errors
100     return $error if $error;
101     $self->setfield('value' => $_);
102   }
103
104   ''; #no error
105 }
106
107 =item part_sb_field
108
109 Returns a reference to the FS::part_sb_field that defines this FS::sb_field.
110
111 =cut
112
113 sub part_sb_field {
114   my $self = shift;
115
116   return qsearchs('part_sb_field', { sbfieldpart => $self->sbfieldpart });
117 }
118
119 =back
120
121 =item svc_broadband
122
123 Returns a reference to the FS::svc_broadband to which this value is attached.
124 Nobody's ever going to use this function, but here it is anyway.
125
126 =cut
127
128 sub svc_broadband {
129   my $self = shift;
130
131   return qsearchs('svc_broadband', { svcnum => $self->svcnum });
132 }
133
134 =head1 VERSION
135
136 $Id: 
137
138 =head1 BUGS
139
140 =head1 SEE ALSO
141
142 L<FS::svc_broadband>, schema.html
143 from the base documentation.
144
145 =cut
146
147 1;
148