X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=af8c101960ccbf9ba237eab1d51ae2363c434308;hb=0df2eac272aa26a62431f5cd830c1cb7b1018e32;hp=2bffdc3772e5caef043c03762fb81097403c4dbc;hpb=a1cb420e2647d8b78d7169694145c2dd3b660448;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 2bffdc377..af8c10196 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -4,7 +4,7 @@ use strict; use charnames ':full'; use vars qw( $AUTOLOAD @ISA @EXPORT_OK $DEBUG %virtual_fields_cache - $money_char $lat_lower $lon_upper + %virtual_fields_hash_cache $money_char $lat_lower $lon_upper $me $nowarn_identical $nowarn_classload $no_update_diff $no_history $qsearch_qualify_columns @@ -1621,6 +1621,41 @@ sub virtual_fields { } +=item virtual_fields_hash [ TABLE ] + +Returns a list of virtual field records as a hash defined for the table. This should not +be exported, and should only be called as an instance or class method. + +=cut + +sub virtual_fields_hash { + my $self = shift; + my $table; + $table = $self->table or confess "virtual_fields called on non-table"; + + confess "Unknown table $table" unless dbdef->table($table); + + return () unless dbdef->table('part_virtual_field'); + + unless ( $virtual_fields_hash_cache{$table} ) { + $virtual_fields_hash_cache{$table} = []; + my $concat = [ "'cf_'", "name" ]; + my $select = concat_sql($concat).' as name, label, length'; + my @vfields = qsearch({ + select => $select, + table => 'part_virtual_field', + hashref => { 'dbtable' => $table, }, + }); + + foreach (@vfields) { + push @{ $virtual_fields_hash_cache{$table} }, $_->{Hash}; + } + } + + @{$virtual_fields_hash_cache{$table}}; + +} + =item process_batch_import JOB OPTIONS_HASHREF PARAMS Processes a batch import as a queued JSRPC job