1 package FS::part_virtual_field;
6 use FS::Schema qw( dbdef );
9 @ISA = qw( FS::Record );
13 FS::part_virtual_field - Object methods for part_virtual_field records
17 use FS::part_virtual_field;
19 $record = new FS::part_virtual_field \%hash;
20 $record = new FS::part_virtual_field { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::part_virtual_field object represents the definition of a custom field
33 (see the BACKGROUND section). FS::part_virtual_field contains the name and
34 base table of the field.
36 FS::part_virtual_field inherits from FS::Record. The following fields are
41 =item vfieldpart - primary key (assigned automatically)
43 =item name - name of the field
45 =item dbtable - table for which this virtual field is defined
47 =item length - expected length of the value (UI hint)
49 =item label - descriptive label for the field (UI hint)
59 Create a new record. To add the record to the database, see "insert".
63 sub table { 'part_virtual_field'; }
64 sub virtual_fields { () }
65 sub virtual_fields_hash { () }
67 =item widget UI_TYPE MODE [ VALUE ]
69 Generates UI code for a widget suitable for editing/viewing the field, based on
70 list_source and length.
72 The only UI_TYPE currently supported is 'HTML', and possible MODEs are 'view'
75 In HTML, all widgets are assumed to be table rows. View widgets look like
76 <TR><TD ALIGN="right">Label</TD><TD BGCOLOR="#ffffff">Value</TD></TR>
78 (Most of the display style stuff, such as the colors, should probably go into
79 a separate module specific to the UI. That can wait, though. The API for
80 this function won't change.)
82 VALUE (optional) is the current value of the field.
88 my ($ui_type, $mode, $value, $header_col_type) = @_;
89 $header_col_type = 'TD' unless $header_col_type;
91 my $label = $self->label || $self->name;
93 if ($ui_type eq 'HTML') {
94 if ($mode eq 'view') {
95 $text = q!<TR><!.$header_col_type.q! ALIGN="right">! . encode_entities($label) .
96 q!</!.$header_col_type.q!><TD BGCOLOR="#ffffff">! . encode_entities($value) .
98 } elsif ($mode eq 'edit') {
99 $text = q!<TR><!.$header_col_type.q! ALIGN="right">! . encode_entities($label) .
100 q!</!.$header_col_type.q!><TD>!;
101 $text .= q!<INPUT TYPE=text NAME="! . $self->name .
102 q!" VALUE="! . encode_entities($value) . q!"!;
104 $text .= q! SIZE="! . $self->length . q!"!;
107 $text .= q!</TD></TR>! . "\n";
120 Adds this record to the database. If there is an error, returns the error,
121 otherwise returns false.
125 Deletes this record from the database. If there is an error, returns the
126 error, otherwise returns false.
128 =item replace OLD_RECORD
130 Replaces OLD_RECORD with this one in the database. If there is an error,
131 returns the error, otherwise returns false.
135 If there is an error, returns the error, otherwise returns false.
136 Called by the insert and replace methods.
145 my $error = $self->ut_text('name') ||
146 $self->ut_text('dbtable') ||
147 $self->ut_number('length')
149 return $error if $error;
151 # Make sure it's a real table with a numeric primary key
153 if($table = dbdef->table($self->dbtable)) {
154 if($pkey = $table->primary_key) {
155 if($table->column($pkey)->type =~ /int/i) {
156 # this is what it should be
158 $error = "$table.$pkey is not an integer";
161 $error = "$table does not have a single-field primary key";
164 $error = "$table does not exist in the schema";
166 return $error if $error;