From ae56dd4f03759f409dee52761089b9d244d279c4 Mon Sep 17 00:00:00 2001 From: hdl Date: Mon, 30 Apr 2007 14:29:21 +0000 Subject: [PATCH] Commiting necessary subs for bulkedition. --- C4/Koha.pm | 35 ++++++++++++++++++++++++++++ C4/Search.pm | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 3c7164a2df..2da57f336d 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -75,6 +75,8 @@ Koha.pm provides many functions for Koha scripts. &GetAuthorisedValues &FixEncoding &GetKohaAuthorisedValues + &GetManagedTagSubfields + $DEBUG ); @@ -1184,6 +1186,39 @@ sub GetKohaAuthorisedValues { return \%values; } +=head2 GetManagedTagSubfields + +=over 4 + +$res = GetManagedTagSubfields(); + +Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode +$forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones +$frameworkcode : the framework code to read + +=back + +=back + +=cut + +sub GetManagedTagSubfields{ + my $dbh=C4::Context->dbh; + my $rq=$dbh->prepare(qq| +SELECT + DISTINCT CONCAT( marc_subfield_structure.tagfield, tagsubfield ) AS tagsubfield, + marc_subfield_structure.liblibrarian as subfielddesc, + marc_tag_structure.liblibrarian as tagdesc +FROM marc_subfield_structure + LEFT JOIN marc_tag_structure + ON marc_tag_structure.tagfield = marc_subfield_structure.tagfield + AND marc_tag_structure.frameworkcode = marc_subfield_structure.frameworkcode +WHERE marc_subfield_structure.tab>=0 +ORDER BY tagsubfield|); + $rq->execute; + my $data=$rq->fetchall_arrayref({}); + return $data; +} 1; diff --git a/C4/Search.pm b/C4/Search.pm index e8cca04c87..3f29418cba 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -54,6 +54,7 @@ This module provides the searching facilities for the Koha into a zebra catalog. &getRecords &buildQuery &NZgetRecords + &EditBiblios ); # make all your functions, whether exported or not; @@ -831,7 +832,7 @@ sub searchResults { my %subfieldstosearch; while ( ( my $column ) = $sth2->fetchrow ) { my ( $tagfield, $tagsubfield ) = - &GetMarcFromKohaField( $dbh, "items." . $column, "" ); + &GetMarcFromKohaField( "items." . $column, "" ); $subfieldstosearch{$column} = $tagsubfield; } my $times; @@ -1046,6 +1047,69 @@ sub searchResults { } +=head2 EditBiblios + +($countchanged,$listunchanged) = EditBiblios($listbiblios, $tagsubfield,$initvalue,$targetvalue,$test); + +this function changes all the values $initvalue in subfield $tag$subfield in any record in $listbiblios +test parameter if set donot perform change to records in database. + +=over 2 + +=item C + + * $listbiblios is an array ref to marcrecords to be changed + * $tagsubfield is the reference of the subfield to change. + * $initvalue is the value to search the record for + * $targetvalue is the value to set the subfield to + * $test is to be set only not to perform changes in database. + +=item C + * $countchanged counts all the changes performed. + * $listunchanged contains the list of all the biblionumbers of records unchanged. + +=item C + +=back + +my ($countchanged, $listunchanged) = EditBiblios($results->{RECORD}, $tagsubfield,$initvalue,$targetvalue);; +#If one wants to display unchanged records, you should get biblios foreach @$listunchanged +$template->param(countchanged => $countchanged, loopunchanged=>$listunchanged); + +=cut +sub EditBiblios{ + my ($listbiblios,$tagsubfield,$initvalue,$targetvalue,$test)=@_; + my $countmatched; + my @unmatched; + my ($tag,$subfield)=($1,$2) if ($tagsubfield=~/^(\d{1,3})(.)$/); + my ($bntag,$bnsubf) = GetMarcFromKohaField('biblio.biblionumber'); + + foreach my $usmarc (@$listbiblios){ + my $record=MARC::Record->new_from_usmarc($usmarc); + my $biblionumber; + if ($bntag>10){ + $biblionumber = $record->subfield($bntag,$bnsubf); + }else { + $biblionumber=$record->field($bntag)->data; + } + #GetBiblionumber is to be written. + #Could be replaced by TransformMarcToKoha (But Would be longer) + if ($record->field($tag)){ + foreach my $field ($record->field($tag)){ + if ($field->delete_subfield('code' =>$subfield,'match'=>qr($initvalue))){ + $countmatched++; + $field->update($subfield,$targetvalue) if ($targetvalue); + } + } +# warn $record->as_formatted; + ModBiblio($record,$biblionumber,GetFrameworkCode($biblionumber)) unless ($test); + } else { + push @unmatched, $biblionumber; + } + } + return ($countmatched,\@unmatched); +} + #---------------------------------------------------------------------- # # Non-Zebra GetRecords# -- 2.39.5