Bugzilla – Attachment 51314 Details for
Bug 11592
opac detail scripts do not respect MARC tag visibility
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11592 - Add should_hide_marc method to filter
Bug-11592---Add-shouldhidemarc-method-to-filter.patch (text/plain), 6.92 KB, created by
Mark Tompsett
on 2016-05-09 01:43:10 UTC
(
hide
)
Description:
Bug 11592 - Add should_hide_marc method to filter
Filename:
MIME Type:
Creator:
Mark Tompsett
Created:
2016-05-09 01:43:10 UTC
Size:
6.92 KB
patch
obsolete
>From 585a24e390b85215b73a9d4b9e1cbfcf1c993eea Mon Sep 17 00:00:00 2001 >From: Mark Tompsett <mtompset@hotmail.com> >Date: Wed, 16 Mar 2016 17:10:02 -0400 >Subject: [PATCH] Bug 11592 - Add should_hide_marc method to filter > >Add should_hide_marc to ViewPolicy filter >Add should_hide_marc tests to t/db_dependent/Filter_MARC_ViewPolicy.t > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/Filter/MARC/ViewPolicy.pm | 59 +++++++++++++++++++++++++++++++++ > t/db_dependent/Filter_MARC_ViewPolicy.t | 54 ++++++++++++++++++++++-------- > 2 files changed, 99 insertions(+), 14 deletions(-) > >diff --git a/Koha/Filter/MARC/ViewPolicy.pm b/Koha/Filter/MARC/ViewPolicy.pm >index 98df72d..69a144c 100644 >--- a/Koha/Filter/MARC/ViewPolicy.pm >+++ b/Koha/Filter/MARC/ViewPolicy.pm >@@ -215,6 +215,65 @@ sub _should_hide_on_interface { > return $hide; > } > >+=head2 should_hide_marc >+ >+Return a hash reference of whether a field, built from >+kohafield and tag, is hidden (1) or not (0) for a given >+interface >+ >+ my $OpacHideMARC = >+ should_hide_marc( { >+ frameworkcode => $frameworkcode, >+ interface => 'opac', >+ } ); >+ >+ if ($OpacHideMARC->{'stocknumber'}==1) { >+ print "Hidden!\n"; >+ } >+ >+C<$OpacHideMARC> is a ref to a hash which contains a series >+of key value pairs indicating if that field (key) is >+hidden (value == 1) or not (value == 0). >+ >+C<$frameworkcode> is the framework code. >+ >+C<$interface> is the interface. It defaults to 'opac' if >+nothing is passed. Valid values include 'opac' or 'intranet'. >+ >+=cut >+ >+sub should_hide_marc { >+ my ( $self, $parms ) = @_; >+ my $frameworkcode = $parms->{frameworkcode} // q{}; >+ my $interface = $parms->{interface} // 'opac'; >+ my $hide = _should_hide_on_interface(); >+ >+ my %shouldhidemarc; >+ my $marc_subfield_structure = GetMarcStructure( 0, $frameworkcode ); >+ foreach my $tag ( keys %{$marc_subfield_structure} ) { >+ foreach my $subtag ( keys %{ $marc_subfield_structure->{$tag} } ) { >+ my $subfield_record = $marc_subfield_structure->{$tag}->{$subtag}; >+ if ( ref $subfield_record eq 'HASH' ) { >+ my $kohafield = $subfield_record->{'kohafield'}; >+ if ($kohafield) { >+ my @tmpsplit = split /[.]/xsm, $kohafield; >+ my $field = $tmpsplit[-1]; >+ my $hidden = $subfield_record->{'hidden'}; >+ my $shouldhide = $hide->{$interface}->{$hidden}; >+ if ($shouldhide) { >+ $shouldhidemarc{$field} = 1; >+ } >+ elsif ( !exists $shouldhidemarc{$field} ) { >+ $shouldhidemarc{$field} = 0; >+ } >+ } >+ } >+ } >+ } >+ >+ return \%shouldhidemarc; >+} >+ > =head1 DIAGNOSTICS > > $ prove -v t/RecordProcessor.t >diff --git a/t/db_dependent/Filter_MARC_ViewPolicy.t b/t/db_dependent/Filter_MARC_ViewPolicy.t >index ba446bc..0c757e5 100644 >--- a/t/db_dependent/Filter_MARC_ViewPolicy.t >+++ b/t/db_dependent/Filter_MARC_ViewPolicy.t >@@ -30,7 +30,7 @@ use MARC::Record; > use MARC::Field; > use C4::Context; > use C4::Biblio; >-use Koha::Cache qw/flush_all/; >+use Koha::Cache qw/get_instance flush_all/; > use Koha::Database; > > BEGIN { >@@ -60,13 +60,8 @@ sub run_hiding_tests { > > my ( $isbn_field, $isbn_subfield ) = > GetMarcFromKohaField( 'biblioitems.isbn', q{} ); >- my $update_sql = >- q{UPDATE marc_subfield_structure SET hidden=? } >- . q{WHERE tagfield='} >- . $isbn_field >- . q{' OR } >- . q{ tagfield='008';}; >- my $sth = $dbh->prepare($update_sql); >+ my $update_sql = q{UPDATE marc_subfield_structure SET hidden=? }; >+ my $sth = $dbh->prepare($update_sql); > foreach my $hidden_value (@valid_hidden_values) { > > $sth->execute($hidden_value); >@@ -99,10 +94,10 @@ sub run_hiding_tests { > if ( any { $_ == $hidden_value } @{ $hidden->{$interface} } ) { > > # Subfield and controlfield are set to be hidden >- is( $filtered_record->field('020'), >+ is( $filtered_record->field($isbn_field), > undef, > "Data field has been deleted because of hidden=$hidden_value" ); >- isnt( $unfiltered_record->field('020'), undef, >+ isnt( $unfiltered_record->field($isbn_field), undef, > "Data field has been deleted in the original record because of hidden=$hidden_value" > ); > >@@ -118,10 +113,10 @@ sub run_hiding_tests { > > } > else { >- isnt( $filtered_record->field('020'), undef, >+ isnt( $filtered_record->field($isbn_field), undef, > "Data field hasn't been deleted because of hidden=$hidden_value" > ); >- isnt( $unfiltered_record->field('020'), undef, >+ isnt( $unfiltered_record->field($isbn_field), undef, > "Data field hasn't been deleted in the original record because of hidden=$hidden_value" > ); > >@@ -133,11 +128,42 @@ sub run_hiding_tests { > "Control field hasn't been deleted in the original record because of hidden=$hidden_value" > ); > >+ # force all the hidden values the same, so filtered and unfiltered >+ # records should be identical. > is_deeply( $filtered_record, $unfiltered_record, > 'Records are the same' ); > } > > } >+ >+ $sth->execute(-1); # -1 is visible in opac and intranet. >+ >+ my $cache = Koha::Cache->get_instance(); >+ $cache->flush_all(); # easy way to ensure DB is queried again. >+ >+ my $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc( >+ { >+ frameworkcode => q{}, >+ interface => $interface >+ } >+ ); >+ my @hiddenfields = grep { $shouldhidemarc->{$_}==1 } keys %{$shouldhidemarc}; >+ >+ $sth->execute(8); # 8 is invisible in opac and intranet. >+ >+ $cache->flush_all(); # easy way to ensure DB is queried again. >+ >+ $shouldhidemarc = Koha::Filter::MARC::ViewPolicy->should_hide_marc( >+ { >+ frameworkcode => q{}, >+ interface => $interface >+ } >+ ); >+ my @keyvalues = keys %{$shouldhidemarc}; >+ my @visiblefields = grep { $shouldhidemarc->{$_}==1 } @keyvalues; >+ >+ is(scalar @hiddenfields,0,'Should Hide MARC - Full Visibility'); >+ is_deeply(\@visiblefields,\@keyvalues,'Should Hide MARC - No Visibility'); > return; > } > >@@ -164,7 +190,7 @@ sub create_marc_record { > > subtest 'Koha::Filter::MARC::ViewPolicy opac tests' => sub { > >- plan tests => 102; >+ plan tests => 104; > > $schema->storage->txn_begin(); > run_hiding_tests('opac'); >@@ -173,7 +199,7 @@ subtest 'Koha::Filter::MARC::ViewPolicy opac tests' => sub { > > subtest 'Koha::Filter::MARC::ViewPolicy intranet tests' => sub { > >- plan tests => 102; >+ plan tests => 104; > > $schema->storage->txn_begin(); > run_hiding_tests('intranet'); >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11592
:
24600
|
24601
|
24611
|
24629
|
24654
|
24655
|
24657
|
24658
|
24659
|
24660
|
24661
|
24662
|
24663
|
24664
|
24875
|
24876
|
24952
|
24953
|
28002
|
28003
|
28477
|
28478
|
28479
|
28480
|
28724
|
31356
|
32382
|
32383
|
33356
|
33357
|
33358
|
33689
|
35855
|
35856
|
35857
|
35858
|
47993
|
47996
|
47997
|
48001
|
49288
|
49289
|
49290
|
49291
|
49612
|
49613
|
49614
|
49615
|
50484
|
50485
|
50486
|
50489
|
50542
|
50550
|
50551
|
50552
|
50553
|
50554
|
51313
|
51314
|
51315
|
51316
|
51317
|
51318
|
51326
|
53440
|
53441
|
53442
|
53443
|
53444
|
55040
|
55041
|
55042
|
55043
|
55044
|
55045
|
55046
|
55184
|
55185