Lines 36-41
use URI::Escape;
Link Here
|
36 |
use Business::ISBN; |
36 |
use Business::ISBN; |
37 |
use MARC::Record; |
37 |
use MARC::Record; |
38 |
use MARC::Field; |
38 |
use MARC::Field; |
|
|
39 |
use List::MoreUtils qw(none); |
39 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
40 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
40 |
|
41 |
|
41 |
# set the version for version checking |
42 |
# set the version for version checking |
Lines 303-308
sub SimpleSearch {
Link Here
|
303 |
$zoom_query->destroy(); |
304 |
$zoom_query->destroy(); |
304 |
} |
305 |
} |
305 |
|
306 |
|
|
|
307 |
if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) { |
308 |
my @new_results; |
309 |
my $dbh = C4::Context->dbh(); |
310 |
foreach my $result ( @{$results} ) { |
311 |
my $marc_record = MARC::Record->new_from_usmarc($result); |
312 |
my $koha_record = TransformMarcToKoha( $dbh, $marc_record ); |
313 |
my $is_allowed = $koha_record->{branchcode} ? GetIndependentGroupModificationRights( { for => $koha_record->{branchcode} } ) : 1; |
314 |
|
315 |
push( @new_results, $result ) if ( $is_allowed ); |
316 |
} |
317 |
$results = \@new_results; |
318 |
$total_hits = scalar( @new_results ); |
319 |
} |
320 |
|
306 |
return ( undef, $results, $total_hits ); |
321 |
return ( undef, $results, $total_hits ); |
307 |
} |
322 |
} |
308 |
|
323 |
|
Lines 1741-1746
sub buildQuery {
Link Here
|
1741 |
$limit .= "($availability_limit)"; |
1756 |
$limit .= "($availability_limit)"; |
1742 |
} |
1757 |
} |
1743 |
|
1758 |
|
|
|
1759 |
if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) { |
1760 |
my $search_context = C4::Context->userenv->{type}; |
1761 |
my $IndependentBranchesRecordsAndItems; |
1762 |
if ( $search_context eq 'opac' ) { |
1763 |
# For the OPAC, if IndependentBranchesRecordsAndItems is enabled, |
1764 |
# and BRANCHCODE has been set in the httpd conf, |
1765 |
# we need to filter the items |
1766 |
$IndependentBranchesRecordsAndItems = $ENV{BRANCHCODE}; |
1767 |
} |
1768 |
else { |
1769 |
# For the intranet, if IndependentBranchesRecordsAndItems is enabled, |
1770 |
# and the user is not a superlibrarian, |
1771 |
# we need to filter the items |
1772 |
$IndependentBranchesRecordsAndItems = !C4::Context->IsSuperLibrarian(); |
1773 |
} |
1774 |
my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : (); |
1775 |
|
1776 |
if ( @allowed_branches ) { |
1777 |
$limit .= " and " if ( $query || $limit ); |
1778 |
$limit .= "(" . join( " or ", map { "branch:$_" } @allowed_branches ) . ")"; |
1779 |
} |
1780 |
} |
1781 |
|
1744 |
# Normalize the query and limit strings |
1782 |
# Normalize the query and limit strings |
1745 |
# This is flawed , means we can't search anything with : in it |
1783 |
# This is flawed , means we can't search anything with : in it |
1746 |
# if user wants to do ccl or cql, start the query with that |
1784 |
# if user wants to do ccl or cql, start the query with that |
Lines 2052-2065
sub searchResults {
Link Here
|
2052 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
2090 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
2053 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
2091 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
2054 |
|
2092 |
|
|
|
2093 |
my $IndependentBranchesRecordsAndItems; |
2094 |
if ( $search_context eq 'opac' ) { |
2095 |
# For the OPAC, if IndependentBranchesRecordsAndItems is enabled, |
2096 |
# and BRANCHCODE has been set in the httpd conf, |
2097 |
# we need to filter the items |
2098 |
$IndependentBranchesRecordsAndItems = |
2099 |
C4::Context->preference('IndependentBranchesRecordsAndItems') |
2100 |
&& $ENV{BRANCHCODE}; |
2101 |
} |
2102 |
else { |
2103 |
# For the intranet, if IndependentBranchesRecordsAndItems is enabled, |
2104 |
# and the user is not a superlibrarian, |
2105 |
# we need to filter the items |
2106 |
$IndependentBranchesRecordsAndItems = |
2107 |
C4::Context->preference('IndependentBranchesRecordsAndItems') |
2108 |
&& !C4::Context->IsSuperLibrarian(); |
2109 |
} |
2110 |
my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : undef; |
2111 |
|
2055 |
# loop through every item |
2112 |
# loop through every item |
|
|
2113 |
my $index = -1; |
2056 |
foreach my $field (@fields) { |
2114 |
foreach my $field (@fields) { |
|
|
2115 |
$index++; |
2057 |
my $item; |
2116 |
my $item; |
2058 |
|
2117 |
|
2059 |
# populate the items hash |
2118 |
# populate the items hash |
2060 |
foreach my $code ( keys %subfieldstosearch ) { |
2119 |
foreach my $code ( keys %subfieldstosearch ) { |
2061 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
2120 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
2062 |
} |
2121 |
} |
|
|
2122 |
|
2123 |
# if IndependentBranchesRecordsAndItems is enabled, and this record |
2124 |
# isn't allowed to be viewed, remove it from the items list and go |
2125 |
# right to the next item. |
2126 |
if ( $IndependentBranchesRecordsAndItems ) { |
2127 |
if ( none { $_ eq $item->{homebranch} } @allowed_branches ) { |
2128 |
splice(@fields, $index, 1); |
2129 |
$items_count--; |
2130 |
next; |
2131 |
} |
2132 |
} |
2133 |
|
2063 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
2134 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
2064 |
|
2135 |
|
2065 |
# OPAC hidden items |
2136 |
# OPAC hidden items |