X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fo2m_Common.pm;h=915393ae9808832d94cff43dcba0617ac3808ccb;hp=0e03b52ee572809c8df4de2dd210c337b46c0b18;hb=389b6f1116c3309c2ee57a6c295ed1a793503095;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984 diff --git a/FS/FS/o2m_Common.pm b/FS/FS/o2m_Common.pm index 0e03b52ee..915393ae9 100644 --- a/FS/FS/o2m_Common.pm +++ b/FS/FS/o2m_Common.pm @@ -35,11 +35,19 @@ Available options: table (required) - Table into which the records are inserted. -num_col (optional) - Column in table which links to the primary key of the base table. If not specified, it is assumed this has the same name. +fields (required) - Arrayref of the field names in the "many" table. -params (required) - Hashref of keys and values, often passed as CVars)> from a form. +params (required) - Hashref of keys and values, often passed as +CVars)> from a form. This will be scanned for keys of the form +"pkeyNN" (where pkey is the primary key column name, and NN is an integer). +Each of these designates one record in the "many" table. The contents of +that record will be taken from other parameters with the names +"pkeyNN_myfield" (where myfield is one of the fields in the 'fields' +array). -fields (required) - Arrayref of field names for each record in table. Pulled from params as "pkeyNN_field" where pkey is table's primary key and NN is the entry's numeric identifier. +num_col (optional) - Name of the foreign key column in the "many" table, which +links to the primary key of the base table. If not specified, it is assumed +this has the same name as in the base table. =cut @@ -87,7 +95,7 @@ sub process_o2m { foreach my $del_obj ( grep { ! $edits{$_->$table_pkey()} } - qsearch( $table, $hashref ) + $self->process_o2m_qsearch( $table, $hashref ) ) { my $error = $del_obj->delete; if ( $error ) { @@ -97,12 +105,13 @@ sub process_o2m { } foreach my $pkey_value ( keys %edits ) { - my $old_obj = qsearchs( $table, { %$hashref, $table_pkey => $pkey_value } ), + my $old_obj = $self->process_o2m_qsearchs( $table, { %$hashref, $table_pkey => $pkey_value } ); my $add_param = $edits{$pkey_value}; my %hash = ( $table_pkey => $pkey_value, map { $_ => $opt{'params'}->{$add_param."_$_"} } @{ $opt{'fields'} } ); + &{ $opt{'hash_callback'} }( \%hash, $old_obj ) if $opt{'hash_callback'}; #next unless grep { $_ =~ /\S/ } values %hash; my $new_obj = "FS::$table"->new( { %$hashref, %hash } ); @@ -117,6 +126,7 @@ sub process_o2m { my %hash = map { $_ => $opt{'params'}->{$add_param."_$_"} } @{ $opt{'fields'} }; + &{ $opt{'hash_callback'} }( \%hash ) if $opt{'hash_callback'}; next unless grep { $_ =~ /\S/ } values %hash; my $add_obj = "FS::$table"->new( { %$hashref, %hash } ); @@ -131,6 +141,9 @@ sub process_o2m { ''; } +sub process_o2m_qsearch { my $self = shift; qsearch( @_ ); } +sub process_o2m_qsearchs { my $self = shift; qsearchs( @_ ); } + sub _load_table { my( $self, $table ) = @_; eval "use FS::$table";