koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 Search.pm Koha.pm


From: Henri-Damien LAURENT
Subject: [Koha-cvs] koha/C4 Search.pm Koha.pm
Date: Mon, 30 Apr 2007 14:29:21 +0000

CVSROOT:        /cvsroot/koha
Module name:    koha
Changes by:     Henri-Damien LAURENT <hdl>      07/04/30 14:29:21

Modified files:
        C4             : Search.pm Koha.pm 

Log message:
        Commiting necessary subs for bulkedition.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&r1=1.132&r2=1.133
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Koha.pm?cvsroot=koha&r1=1.52&r2=1.53

Patches:
Index: Search.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Search.pm,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -b -r1.132 -r1.133
--- Search.pm   27 Apr 2007 19:57:12 -0000      1.132
+++ Search.pm   30 Apr 2007 14:29:21 -0000      1.133
@@ -25,7 +25,7 @@
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.132 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.133 $' =~ /\d+/g;
     shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
 };
 
@@ -54,6 +54,7 @@
   &getRecords
   &buildQuery
   &NZgetRecords
+  &EditBiblios
 );
 
 # make all your functions, whether exported or not;
@@ -831,7 +832,7 @@
     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 @@
 }
 
 
+=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<input arg:>
+
+    * $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<Output arg:>
+    * $countchanged counts all the changes performed.
+    * $listunchanged contains the list of all the biblionumbers of records 
unchanged.
+
+=item C<usage in the script:>
+
+=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)address@hidden;
+  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,address@hidden);
+}
+
 #----------------------------------------------------------------------
 #
 # Non-Zebra GetRecords#

Index: Koha.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Koha.pm,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -b -r1.52 -r1.53
--- Koha.pm     18 Apr 2007 17:00:14 -0000      1.52
+++ Koha.pm     30 Apr 2007 14:29:21 -0000      1.53
@@ -17,7 +17,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Koha.pm,v 1.52 2007/04/18 17:00:14 tipaul Exp $
+# $Id: Koha.pm,v 1.53 2007/04/30 14:29:21 hdl Exp $
 
 use strict;
 require Exporter;
@@ -25,7 +25,7 @@
 use C4::Output;
 use vars qw($VERSION @ISA @EXPORT);
 
-$VERSION = do { my @v = '$Revision: 1.52 $' =~ /\d+/g; shift(@v) . "." . join( 
"_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.53 $' =~ /\d+/g; shift(@v) . "." . join( 
"_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -75,6 +75,8 @@
   &GetAuthorisedValues
   &FixEncoding
   &GetKohaAuthorisedValues
+  &GetManagedTagSubfields
+
   $DEBUG
   );
 
@@ -1184,6 +1186,39 @@
   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;
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]