@@ -, +, @@ Category --- C4/Items.pm | 20 ++++++++++++++++++-- installer/data/mysql/sysprefs.sql | 2 ++ installer/data/mysql/updatedatabase.pl | 16 ++++++++++++++++ .../prog/en/modules/admin/preferences/opac.pref | 8 ++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -1635,6 +1635,14 @@ sub GetHiddenItemnumbers { return (); } my $dbh = C4::Context->dbh; + my $userid = C4::Context->userenv->{'id'} || q{}; + my $homebranch = C4::Context->userenv->{'branch'} || q{}; + my $categorycode = q{}; + if ($userid) { + my $sth = $dbh->prepare("SELECT categorycode FROM borrowers WHERE userid=?;"); + $sth->execute($userid); + $categorycode = $sth->fetchrow; + } # For each item foreach my $item (@items) { @@ -1654,8 +1662,16 @@ sub GetHiddenItemnumbers { # If the results matches the values in the yaml file if (any { $val eq $_ } @{$hidingrules->{$field}}) { - # We add the itemnumber to the list - push @resultitems, $item->{'itemnumber'}; + my $override = 0; + if ( ($homebranch eq $item->{'homebranch'} && + $categorycode eq C4::Context->preference('PatronSingleBranch') ) || + $categorycode eq C4::Context->preference('PatronEveryBranch') ) { + $override = 1; + } + if ($override==0) { + # We add the itemnumber to the hidden list + push @resultitems, $item->{'itemnumber'}; + } # If at least one rule matched for an item, no need to test the others last; --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -428,3 +428,5 @@ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) V INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AcqWarnOnDuplicateInvoice','0','Warn librarians when they try to create a duplicate invoice', '', 'YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('PatronEveryBranch','PTEB','The patron category code which allows viewing hidden items for every branch','',''); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('PatronSingleBranch','PTSB',"The patron category code which allows viewing hidden items for only the patron's home branch",'',''); --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7044,6 +7044,22 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do( + q{ +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('PatronEveryBranch','PTEB',"The patron category code which allows viewing hidden items for every branch",'',''); +} + ); + $dbh->do( + q{ +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('PatronSingleBranch','PTSB',"The patron category code which allows viewing hidden items for only the patron's home branch",'',''); +} + ); + print "Upgrade to $DBversion done (Bug filtering: Patron Category to override OPACHiddenItems)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -497,6 +497,14 @@ OPAC: class: code - Allows to define custom rules for hiding specific items at opac. See docs/opac/OpacHiddenItems.txt for more informations - + - pref: PatronSingleBranch + class: short + - Patrons matching this patron category overrides OpacHiddenItems for their home branch only. + - + - pref: PatronEveryBranch + class: short + - Patrons matching this patron category overrides OpacHiddenItems for their every branch. + - - pref: OpacAllowPublicListCreation default: 1 choices: --