[Koha-patches] [PATCH] [3.0.x] (bug #3053) extract ISBD view generator, and permit to display valuecode in ISBD view
Nahuel ANGELINETTI
nahuel.angelinetti at biblibre.com
Mon Mar 23 17:15:27 CET 2009
this patch extract the generator of ISBD view in a C4 function, because it's used in intranet AND in OPAC but with 2 separate codes.
Now it's more reusable.
---
C4/Biblio.pm | 134 +++++++++++++++++++++++++++++++++++++++++++++++
catalogue/ISBDdetail.pl | 113 +---------------------------------------
opac/opac-ISBDdetail.pl | 119 +-----------------------------------------
3 files changed, 136 insertions(+), 230 deletions(-)
diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index e911713..495cae1 100755
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -57,6 +57,8 @@ BEGIN {
&GetBiblioItemInfosOf
&GetBiblioItemByBiblioNumber
&GetBiblioFromItemNumber
+
+ &GetISBDView
&GetMarcNotes
&GetMarcSubjects
@@ -609,6 +611,138 @@ sub GetBiblioFromItemNumber {
return ($data);
}
+=head2 GetISBDView
+
+=over 4
+
+$isbd = &GetISBDView($biblionumber);
+
+Return the ISBD view which can be included in opac and intranet
+
+=back
+
+=cut
+
+sub GetISBDView {
+ my $biblionumber = shift;
+ my $record = GetMarcBiblio($biblionumber);
+ my $itemtype = &GetFrameworkCode($biblionumber);
+ my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
+ my $tagslib = &GetMarcStructure( 1, $itemtype );
+
+ my $ISBD = C4::Context->preference('ISBD');
+ my $bloc = $ISBD;
+ my $res;
+ my $blocres;
+
+ foreach my $isbdfield ( split (/#/, $bloc) ) {
+
+ # $isbdfield= /(.?.?.?)/;
+ $isbdfield =~ /(\d\d\d)([^\|])?\|(.*)\|(.*)\|(.*)/;
+ my $fieldvalue = $1 || 0;
+ my $subfvalue = $2 || "";
+ my $textbefore = $3;
+ my $analysestring = $4;
+ my $textafter = $5;
+
+ # warn "==> $1 / $2 / $3 / $4";
+ # my $fieldvalue=substr($isbdfield,0,3);
+ if ( $fieldvalue > 0 ) {
+ my $hasputtextbefore = 0;
+ my @fieldslist = $record->field($fieldvalue);
+ @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
+
+ # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
+ # warn "FV : $fieldvalue";
+ if ($subfvalue ne ""){
+ foreach my $field ( @fieldslist ) {
+ foreach my $subfield ($field->subfield($subfvalue)){
+ my $calculated = $analysestring;
+ my $tag = $field->tag();
+ if ( $tag < 10 ) {
+ }
+ else {
+ my $subfieldvalue =
+ GetAuthorisedValueDesc( $tag, $subfvalue,
+ $subfield, '', $tagslib );
+ my $tagsubf = $tag . $subfvalue;
+ $calculated =~
+ s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
+ $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
+
+ # field builded, store the result
+ if ( $calculated && !$hasputtextbefore )
+ { # put textbefore if not done
+ $blocres .= $textbefore;
+ $hasputtextbefore = 1;
+ }
+
+ # remove punctuation at start
+ $calculated =~ s/^( |;|:|\.|-)*//g;
+ $blocres .= $calculated;
+
+ }
+ }
+ }
+ $blocres .= $textafter if $hasputtextbefore;
+ } else {
+ foreach my $field ( @fieldslist ) {
+ my $calculated = $analysestring;
+ my $tag = $field->tag();
+ if ( $tag < 10 ) {
+ }
+ else {
+ my @subf = $field->subfields;
+ for my $i ( 0 .. $#subf ) {
+ my $valuecode = $subf[$i][1];
+ my $subfieldcode = $subf[$i][0];
+ my $subfieldvalue =
+ GetAuthorisedValueDesc( $tag, $subf[$i][0],
+ $subf[$i][1], '', $tagslib );
+ my $tagsubf = $tag . $subfieldcode;
+
+ $calculated =~ s/ # replace all {{}} codes by the value code.
+ \{\{$tagsubf\}\} # catch the {{actualcode}}
+ /
+ $valuecode # replace by the value code
+ /gx;
+
+ $calculated =~
+ s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
+ $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
+ }
+
+ # field builded, store the result
+ if ( $calculated && !$hasputtextbefore )
+ { # put textbefore if not done
+ $blocres .= $textbefore;
+ $hasputtextbefore = 1;
+ }
+
+ # remove punctuation at start
+ $calculated =~ s/^( |;|:|\.|-)*//g;
+ $blocres .= $calculated;
+ }
+ }
+ $blocres .= $textafter if $hasputtextbefore;
+ }
+ }
+ else {
+ $blocres .= $isbdfield;
+ }
+ }
+ $res .= $blocres;
+
+ $res =~ s/\{(.*?)\}//g;
+ $res =~ s/\\n/\n/g;
+ $res =~ s/\n/<br\/>/g;
+
+ # remove empty ()
+ $res =~ s/\(\)//g;
+
+ return $res;
+}
+
=head2 GetBiblio
=over 4
diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl
index 250fda6..d9eea6d 100755
--- a/catalogue/ISBDdetail.pl
+++ b/catalogue/ISBDdetail.pl
@@ -54,10 +54,6 @@ my $query = new CGI;
my $dbh = C4::Context->dbh;
my $biblionumber = $query->param('biblionumber');
-my $itemtype = &GetFrameworkCode($biblionumber);
-my $tagslib = &GetMarcStructure( 1, $itemtype );
-
-my $record = GetMarcBiblio($biblionumber);
# open template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -70,117 +66,10 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
}
);
-my $ISBD = C4::Context->preference('ISBD');
-
# my @blocs = split /\@/,$ISBD;
# my @fields = $record->fields();
-my $res;
-
-# foreach my $bloc (@blocs) {
-# $bloc =~ s/\n//g;
-my $bloc = $ISBD;
-my $blocres;
-
-my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
-# @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
-
-foreach my $isbdfield ( split /#/, $bloc ) {
-
- $isbdfield =~ /(\d\d\d)([^\|])?\|(.*)\|(.*)\|(.*)/;
- my $fieldvalue = $1;
- my $subfvalue = $2;
- my $textbefore = $3;
- my $analysestring = $4;
- my $textafter = $5;
-
- # warn "==> $1 / $2 / $3 / $4";
- # my $fieldvalue=substr($isbdfield,0,3);
- if ( $fieldvalue > 0 ) {
- my $hasputtextbefore = 0;
- my @fieldslist = $record->field($fieldvalue);
- @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
-
- # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
- # warn "FV : $fieldvalue";
- if ($subfvalue ne ""){
- foreach my $field ( @fieldslist ) {
- foreach my $subfield ($field->subfield($subfvalue)){
- warn $fieldvalue."$subfvalue";
- my $calculated = $analysestring;
- my $tag = $field->tag();
- if ( $tag < 10 ) {
- }
- else {
- my $subfieldvalue =
- GetAuthorisedValueDesc( $tag, $subfvalue,
- $subfield, '', $tagslib );
- my $tagsubf = $tag . $subfvalue;
- $calculated =~
- s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
-# $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
-
- # field builded, store the result
- if ( $calculated && !$hasputtextbefore )
- { # put textbefore if not done
- $blocres .= $textbefore;
- $hasputtextbefore = 1;
- }
-
- # remove punctuation at start
- $calculated =~ s/^( |;|:|\.|-)*//g;
- $blocres .= $calculated;
-
- }
- }
- }
- $blocres .= $textafter if $hasputtextbefore;
- } else {
- foreach my $field ( @fieldslist ) {
- my $calculated = $analysestring;
- my $tag = $field->tag();
- if ( $tag < 10 ) {
- }
- else {
- my @subf = $field->subfields;
- for my $i ( 0 .. $#subf ) {
- my $subfieldcode = $subf[$i][0];
- my $subfieldvalue =
- GetAuthorisedValueDesc( $tag, $subf[$i][0],
- $subf[$i][1], '', $tagslib );
- my $tagsubf = $tag . $subfieldcode;
- $calculated =~
- s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
-# $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
- }
-
- # field builded, store the result
- if ( $calculated && !$hasputtextbefore )
- { # put textbefore if not done
- $blocres .= $textbefore;
- $hasputtextbefore = 1;
- }
-
- # remove punctuation at start
- $calculated =~ s/^( |;|:|\.|-)*//g;
- $blocres .= $calculated;
- }
- }
- $blocres .= $textafter if $hasputtextbefore;
- }
- }
- else {
- $blocres .= $isbdfield;
- }
-}
-$res .= $blocres;
-
-# }
-$res =~ s/\{(.*?)\}//g;
-$res =~ s/\\n/\n/g;
-$res =~ s/\n/<br\/>/g;
+my $res = GetISBDView($biblionumber);
-# remove empty ()
-$res =~ s/\(\)//g;
# count of item linked with biblio
my $itemcount = GetItemsCount($biblionumber);
$template->param( count => $itemcount);
diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl
index 2a57604..87284fc 100755
--- a/opac/opac-ISBDdetail.pl
+++ b/opac/opac-ISBDdetail.pl
@@ -59,8 +59,6 @@ my $query = new CGI;
my $dbh = C4::Context->dbh;
my $biblionumber = $query->param('biblionumber');
-my $itemtype = &GetFrameworkCode($biblionumber);
-my $tagslib = &GetMarcStructure( 1, $itemtype );
my $marcflavour = C4::Context->preference("marcflavour");
my $record = GetMarcBiblio($biblionumber);
@@ -98,124 +96,9 @@ $template->param(
subscriptionsnumber => $subscriptionsnumber,
);
-my $ISBD = C4::Context->preference('ISBD');
-
# my @blocs = split /\@/,$ISBD;
# my @fields = $record->fields();
-my $res;
-
-# foreach my $bloc (@blocs) {
-# $bloc =~ s/\n//g;
-my $bloc = $ISBD;
-my $blocres;
-my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype);
-
-foreach my $isbdfield ( split /#/, $bloc ) {
-
- # $isbdfield= /(.?.?.?)/;
- $isbdfield =~ /(\d\d\d)([^\|])?\|(.*)\|(.*)\|(.*)/;
- my $fieldvalue = $1;
- my $subfvalue = $2;
- my $textbefore = $3;
- my $analysestring = $4;
- my $textafter = $5;
-
- # warn "==> $1 / $2 / $3 / $4";
- # my $fieldvalue=substr($isbdfield,0,3);
- if ( $fieldvalue > 0 ) {
- my $hasputtextbefore = 0;
- my @fieldslist = $record->field($fieldvalue);
- @fieldslist = sort {$a->subfield($holdingbrtagsubf) cmp $b->subfield($holdingbrtagsubf)} @fieldslist if ($fieldvalue eq $holdingbrtagf);
-
- # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
- # warn "FV : $fieldvalue";
- if ($subfvalue ne ""){
- foreach my $field ( @fieldslist ) {
- foreach my $subfield ($field->subfield($subfvalue)){
- warn $fieldvalue."$subfvalue";
- my $calculated = $analysestring;
- my $tag = $field->tag();
- if ( $tag < 10 ) {
- }
- else {
- my $subfieldvalue =
- GetAuthorisedValueDesc( $tag, $subfvalue,
- $subfield, '', $tagslib );
- my $tagsubf = $tag . $subfvalue;
- $calculated =~
- s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
- $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
-
- # field builded, store the result
- if ( $calculated && !$hasputtextbefore )
- { # put textbefore if not done
- $blocres .= $textbefore;
- $hasputtextbefore = 1;
- }
-
- # remove punctuation at start
- $calculated =~ s/^( |;|:|\.|-)*//g;
- $blocres .= $calculated;
-
- }
- }
- }
- $blocres .= $textafter if $hasputtextbefore;
- } else {
- foreach my $field ( @fieldslist ) {
- my $calculated = $analysestring;
- my $tag = $field->tag();
- if ( $tag < 10 ) {
- }
- else {
- my @subf = $field->subfields;
- for my $i ( 0 .. $#subf ) {
- my $valuecode = $subf[$i][1];
- my $subfieldcode = $subf[$i][0];
- my $subfieldvalue =
- GetAuthorisedValueDesc( $tag, $subf[$i][0],
- $subf[$i][1], '', $tagslib );
- my $tagsubf = $tag . $subfieldcode;
-
- $calculated =~ s/ # replace all {{}} codes by the value code.
- \{\{$tagsubf\}\} # catch the {{actualcode}}
- /
- $valuecode # replace by the value code
- /gx;
-
- $calculated =~
- s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
- $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g;
- }
-
- # field builded, store the result
- if ( $calculated && !$hasputtextbefore )
- { # put textbefore if not done
- $blocres .= $textbefore;
- $hasputtextbefore = 1;
- }
-
- # remove punctuation at start
- $calculated =~ s/^( |;|:|\.|-)*//g;
- $blocres .= $calculated;
- }
- }
- $blocres .= $textafter if $hasputtextbefore;
- }
- }
- else {
- $blocres .= $isbdfield;
- }
-}
-$res .= $blocres;
-
-# }
-$res =~ s/\{(.*?)\}//g;
-$res =~ s/\\n/\n/g;
-$res =~ s/\n/<br\/>/g;
-
-# remove empty ()
-$res =~ s/\(\)//g;
+my $res = GetISBDView($biblionumber);
my $reviews = getreviews( $biblionumber, 1 );
foreach ( @$reviews ) {
--
1.5.6.3
More information about the Koha-patches
mailing list