From 89c062c44b2835f2c6ccb27c761bc0ed7d4b45d9 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 23 Mar 2009 17:15:27 +0100 Subject: [PATCH] (bug #3053) extract ISBD view generator, and permit to display valuecode in ISBD view 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. Signed-off-by: Galen Charlton --- 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 0613e42e4c..60823a0aab 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -54,6 +54,8 @@ BEGIN { &GetBiblioItemInfosOf &GetBiblioItemByBiblioNumber &GetBiblioFromItemNumber + + &GetISBDView &GetMarcNotes &GetMarcSubjects @@ -612,6 +614,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//g; + + # remove empty () + $res =~ s/\(\)//g; + + return $res; +} + =head2 GetBiblio =over 4 diff --git a/catalogue/ISBDdetail.pl b/catalogue/ISBDdetail.pl index 250fda6c9e..d9eea6df64 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//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 e679ed8ffc..38896eecf6 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -67,8 +67,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $biblionumber = $query->param('biblionumber'); -my $itemtype = &GetFrameworkCode($biblionumber); -my $tagslib = &GetMarcStructure( 1, $itemtype ); my $marcflavour = C4::Context->preference("marcflavour"); my $record = GetMarcBiblio($biblionumber); @@ -117,124 +115,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//g; - -# remove empty () -$res =~ s/\(\)//g; +my $res = GetISBDView($biblionumber); my $reviews = getreviews( $biblionumber, 1 ); foreach ( @$reviews ) { -- 2.39.5