Bugzilla – Attachment 3491 Details for
Bug 5984
OPAC: Hide items using a systempreferces to determine what to hide
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed Patch
0001-Bug-5984-Allowing-the-librarians-to-hide-items-in-th.patch (text/plain), 10.41 KB, created by
Chris Cormack
on 2011-03-29 02:50:50 UTC
(
hide
)
Description:
Proposed Patch
Filename:
MIME Type:
Creator:
Chris Cormack
Created:
2011-03-29 02:50:50 UTC
Size:
10.41 KB
patch
obsolete
>From 675c88edd567bdd47db762a877fab269fac58170 Mon Sep 17 00:00:00 2001 >From: Chris Cormack <chrisc@catalyst.net.nz> >Date: Tue, 29 Mar 2011 15:46:29 +1300 >Subject: [PATCH] Bug 5984 : Allowing the librarians to hide items in the Opac using a system preference > >Squashed commit of the following: > >commit 72b578928b287ba3b5fa8965e42ff1ccbdf9013a >Author: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Wed Oct 20 11:26:46 2010 +0200 > > Bug 5984 : MT4587, Follow-up: Hiding rules are now in a syspref > >commit d95329955f976900afdafa82fe0a1699e8e892dc >Author: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Tue Oct 19 15:19:16 2010 +0200 > > Bug 5984 : MT4587, Follow-up: Adds yaml config file for custom opac items hiding > >commit 6777c1a97700b77095e4e499ca73040bf94271e2 >Author: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Mon Oct 18 11:14:03 2010 +0200 > > Bug 5984 : MT4587 : Adds yaml config file for custom opac items hiding >--- > C4/Items.pm | 53 ++++++++++++++++++++ > C4/Search.pm | 25 ++++++--- > docs/opac/OpacHiddenItems.txt | 12 +++++ > installer/data/mysql/updatedatabase.pl | 9 +++ > .../opac-tmpl/prog/en/modules/opac-results.tmpl | 3 +- > opac/opac-detail.pl | 22 +++++++-- > 6 files changed, 111 insertions(+), 13 deletions(-) > create mode 100644 docs/opac/OpacHiddenItems.txt > >diff --git a/C4/Items.pm b/C4/Items.pm >index d293608..b9cb3f1 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -33,6 +33,7 @@ use C4::Branch; > require C4::Reserves; > use C4::Charset; > use C4::Acquisition; >+use List::MoreUtils qw/any/; > > use vars qw($VERSION @ISA @EXPORT); > >@@ -68,6 +69,7 @@ BEGIN { > get_itemnumbers_of > GetItemnumberFromBarcode > GetBarcodeFromItemnumber >+ GetHiddenItemnumbers > > DelItemCheck > MoveItemFromBiblio >@@ -1467,6 +1469,57 @@ sub GetBarcodeFromItemnumber { > return ($result); > } > >+=head2 GetHiddenItemnumbers >+ >+=over 4 >+ >+$result = GetHiddenItemnumbers(@items); >+ >+=back >+ >+=cut >+ >+sub GetHiddenItemnumbers { >+ my (@items) = @_; >+ my @resultitems; >+ >+ my $yaml = C4::Context->preference('OpacHiddenItems'); >+ my $hidingrules; >+ eval { >+ $hidingrules = YAML::Load($yaml); >+ }; >+ if ($@) { >+ warn "Unable to parse OpacHiddenItems syspref : $@"; >+ return (); >+ } else { >+ my $dbh = C4::Context->dbh; >+ >+ # For each item >+ foreach my $item (@items) { >+ >+ # We check each rule >+ foreach my $field (keys %$hidingrules) { >+ my $query = "SELECT $field from items where itemnumber = ?"; >+ my $sth = $dbh->prepare($query); >+ $sth->execute($item->{'itemnumber'}); >+ my ($result) = $sth->fetchrow; >+ >+ # If the results matches the values in the yaml file >+ if (any { $result eq $_ } @{$hidingrules->{$field}}) { >+ >+ # We add the itemnumber to the list >+ push @resultitems, $item->{'itemnumber'}; >+ >+ # If at least one rule matched for an item, no need to test the others >+ last; >+ } >+ } >+ } >+ return @resultitems; >+ } >+ >+ } >+ > =head3 get_item_authorised_values > > find the types and values for all authorised values assigned to this item. >diff --git a/C4/Search.pm b/C4/Search.pm >index b698a93..f05d29a 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -29,6 +29,8 @@ use C4::XSLT; > use C4::Branch; > use C4::Reserves; # CheckReserves > use C4::Debug; >+use C4::Items; >+use YAML; > use URI::Escape; > > use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); >@@ -1581,8 +1583,14 @@ sub searchResults { > $item->{$code} = $field->subfield( $subfieldstosearch{$code} ); > } > >- my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; >- my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; >+ # Hidden items >+ my @items = ($item); >+ my (@hiddenitems) = GetHiddenItemnumbers(@items); >+ $item->{'hideatopac'} = 1 if (@hiddenitems); >+ >+ my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; >+ my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; >+ > # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one > if ($item->{$hbranch}) { > $item->{'branchname'} = $branches{$item->{$hbranch}}; >@@ -1654,6 +1662,7 @@ sub searchResults { > || $item->{itemlost} > || $item->{damaged} > || $item->{notforloan} > 0 >+ || $item->{hideatopac} > || $reservestatus eq 'Waiting' > || ($transfertwhen ne '')) > { >@@ -1665,11 +1674,11 @@ sub searchResults { > $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan}; > $other_count++; > >- my $key = $prefix . $item->{status}; >- foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) { >- $other_items->{$key}->{$_} = $item->{$_}; >- } >- $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0; >+ my $key = $prefix . $item->{status}; >+ foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber hideatopac)) { >+ $other_items->{$key}->{$_} = $item->{$_}; >+ } >+ $other_items->{$key}->{intransit} = ( $transfertwhen ne '' ) ? 1 : 0; > $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0; > $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value; > $other_items->{$key}->{count}++ if $item->{$hbranch}; >@@ -1681,7 +1690,7 @@ sub searchResults { > $can_place_holds = 1; > $available_count++; > $available_items->{$prefix}->{count}++ if $item->{$hbranch}; >- foreach (qw(branchname itemcallnumber)) { >+ foreach (qw(branchname itemcallnumber hideatopac)) { > $available_items->{$prefix}->{$_} = $item->{$_}; > } > $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; >diff --git a/docs/opac/OpacHiddenItems.txt b/docs/opac/OpacHiddenItems.txt >new file mode 100644 >index 0000000..625d465 >--- /dev/null >+++ b/docs/opac/OpacHiddenItems.txt >@@ -0,0 +1,12 @@ >+The OpacHiddenItems syspref allow the user to define custom rules >+for hiding specific items at opac. >+ >+YAML syntax is used for defining such rules. >+ >+Items can be hidden according to values from the items table: >+ >+field: [value1, value2, ...] >+ >+Example : >+wthdrawn: [0, 1] >+homebranch: [homebranch1, homebranch2] >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 23b5d67..f584c03 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -4134,6 +4134,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > SetVersion ($DBversion); > } > >+$DBversion = "3.03.00.XXX"; >+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { >+ $dbh->do(" >+ INSERT IGNORE INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHiddenItems','','This syspref allows to define custom rules for hiding specific items at opac. See docs/opac/OpacHiddenItems.txt for more informations.','','Textarea'); >+ "); >+ print "Upgrade to $DBversion done (Adding OpacHiddenItems syspref)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 DropAllForeignKeys($table) >diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl >index d7aff2e..83641fc 100644 >--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl >+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-results.tmpl >@@ -431,7 +431,7 @@ $(document).ready(function(){ > <!-- TMPL_IF NAME="available_items_loop" --> > <span class="available"><strong>Copies available:</strong> > <!-- TMPL_LOOP NAME="available_items_loop" --> >- >+ <!-- TMPL_UNLESS NAME="hideatopac" --> > <!-- TMPL_IF NAME="singleBranchMode" --> > <!-- TMPL_VAR NAME="location" --> > <!-- TMPL_ELSE --> >@@ -443,6 +443,7 @@ $(document).ready(function(){ > <!-- TMPL_IF NAME="itemcallnumber" -->[<a href="/cgi-bin/koha/opac-search.pl?q=callnum:<!-- TMPL_VAR NAME="itemcallnumber" ESCAPE="URL" -->"><!-- TMPL_VAR NAME="itemcallnumber" --></a>]<!-- /TMPL_IF --> > <!-- /TMPL_IF --> > (<!-- TMPL_VAR NAME="count" -->), >+ <!-- /TMPL_UNLESS --> > <!-- /TMPL_LOOP --> > </span> > <!-- TMPL_ELSE --> >diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl >index 1015e54..d54543f 100755 >--- a/opac/opac-detail.pl >+++ b/opac/opac-detail.pl >@@ -41,6 +41,7 @@ use C4::Members; > use C4::VirtualShelves; > use C4::XSLT; > use C4::ShelfBrowser; >+use List::MoreUtils qw/any none/; > > BEGIN { > if (C4::Context->preference('BakerTaylorEnabled')) { >@@ -80,14 +81,27 @@ $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowChec > # change back when ive fixed request.pl > my @all_items = &GetItemsInfo( $biblionumber, 'opac' ); > my @items; >-@items = @all_items unless C4::Context->preference('hidelostitems'); > >-if (C4::Context->preference('hidelostitems')) { >- # Hide host items >+# Getting items to be hidden >+my @hiddenitems = GetHiddenItemnumbers(@all_items); >+ >+# Are there items to hide? >+my $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; >+ >+# Hide items >+if ($hideitems) { > for my $itm (@all_items) { >- push @items, $itm unless $itm->{itemlost}; >+ if ( C4::Context->preference('hidelostitems') ) { >+ push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems; >+ } else { >+ push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems; > } > } >+} else { >+ # Or not >+ @items = @all_items; >+} >+ > my $dat = &GetBiblioData($biblionumber); > > my $itemtypes = GetItemTypes(); >-- >1.7.1 >
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 5984
:
3491
|
3492
|
3493
|
3644
|
3691
|
3692
|
3693
|
3694
|
3700
|
3701
|
3702
|
3703
|
3704
|
3705
|
3706