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 utf8; |
40 |
use utf8; |
40 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
41 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); |
41 |
|
42 |
|
Lines 301-306
sub SimpleSearch {
Link Here
|
301 |
$zoom_query->destroy(); |
302 |
$zoom_query->destroy(); |
302 |
} |
303 |
} |
303 |
|
304 |
|
|
|
305 |
if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) { |
306 |
my @new_results; |
307 |
my $dbh = C4::Context->dbh(); |
308 |
foreach my $result ( @{$results} ) { |
309 |
my $marc_record = MARC::Record->new_from_usmarc($result); |
310 |
my $koha_record = TransformMarcToKoha( $dbh, $marc_record ); |
311 |
my $is_allowed = $koha_record->{branchcode} ? GetIndependentGroupModificationRights( { for => $koha_record->{branchcode} } ) : 1; |
312 |
|
313 |
push( @new_results, $result ) if ( $is_allowed ); |
314 |
} |
315 |
$results = \@new_results; |
316 |
$total_hits = scalar( @new_results ); |
317 |
} |
318 |
|
304 |
return ( undef, $results, $total_hits ); |
319 |
return ( undef, $results, $total_hits ); |
305 |
} |
320 |
} |
306 |
|
321 |
|
Lines 1578-1583
sub buildQuery {
Link Here
|
1578 |
$limit .= "($availability_limit)"; |
1593 |
$limit .= "($availability_limit)"; |
1579 |
} |
1594 |
} |
1580 |
|
1595 |
|
|
|
1596 |
if ( C4::Context->preference('IndependentBranchesRecordsAndItems') ) { |
1597 |
my $search_context = C4::Context->userenv->{type}; |
1598 |
my $IndependentBranchesRecordsAndItems; |
1599 |
if ( $search_context eq 'opac' ) { |
1600 |
# For the OPAC, if IndependentBranchesRecordsAndItems is enabled, |
1601 |
# and BRANCHCODE has been set in the httpd conf, |
1602 |
# we need to filter the items |
1603 |
$IndependentBranchesRecordsAndItems = $ENV{BRANCHCODE}; |
1604 |
} |
1605 |
else { |
1606 |
# For the intranet, if IndependentBranchesRecordsAndItems is enabled, |
1607 |
# and the user is not a superlibrarian, |
1608 |
# we need to filter the items |
1609 |
$IndependentBranchesRecordsAndItems = !C4::Context->IsSuperLibrarian(); |
1610 |
} |
1611 |
my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : (); |
1612 |
|
1613 |
if ( @allowed_branches ) { |
1614 |
$limit .= " and " if ( $query || $limit ); |
1615 |
$limit .= "(" . join( " or ", map { "branch:$_" } @allowed_branches ) . ")"; |
1616 |
} |
1617 |
} |
1618 |
|
1581 |
# Normalize the query and limit strings |
1619 |
# Normalize the query and limit strings |
1582 |
# This is flawed , means we can't search anything with : in it |
1620 |
# This is flawed , means we can't search anything with : in it |
1583 |
# if user wants to do ccl or cql, start the query with that |
1621 |
# if user wants to do ccl or cql, start the query with that |
Lines 1839-1852
sub searchResults {
Link Here
|
1839 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
1877 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
1840 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
1878 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
1841 |
|
1879 |
|
|
|
1880 |
my $IndependentBranchesRecordsAndItems; |
1881 |
if ( $search_context eq 'opac' ) { |
1882 |
# For the OPAC, if IndependentBranchesRecordsAndItems is enabled, |
1883 |
# and BRANCHCODE has been set in the httpd conf, |
1884 |
# we need to filter the items |
1885 |
$IndependentBranchesRecordsAndItems = |
1886 |
C4::Context->preference('IndependentBranchesRecordsAndItems') |
1887 |
&& $ENV{BRANCHCODE}; |
1888 |
} |
1889 |
else { |
1890 |
# For the intranet, if IndependentBranchesRecordsAndItems is enabled, |
1891 |
# and the user is not a superlibrarian, |
1892 |
# we need to filter the items |
1893 |
$IndependentBranchesRecordsAndItems = |
1894 |
C4::Context->preference('IndependentBranchesRecordsAndItems') |
1895 |
&& !C4::Context->IsSuperLibrarian(); |
1896 |
} |
1897 |
my @allowed_branches = $IndependentBranchesRecordsAndItems ? GetIndependentGroupModificationRights() : undef; |
1898 |
|
1842 |
# loop through every item |
1899 |
# loop through every item |
|
|
1900 |
my $index = -1; |
1843 |
foreach my $field (@fields) { |
1901 |
foreach my $field (@fields) { |
|
|
1902 |
$index++; |
1844 |
my $item; |
1903 |
my $item; |
1845 |
|
1904 |
|
1846 |
# populate the items hash |
1905 |
# populate the items hash |
1847 |
foreach my $code ( keys %subfieldstosearch ) { |
1906 |
foreach my $code ( keys %subfieldstosearch ) { |
1848 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
1907 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
1849 |
} |
1908 |
} |
|
|
1909 |
|
1910 |
# if IndependentBranchesRecordsAndItems is enabled, and this record |
1911 |
# isn't allowed to be viewed, remove it from the items list and go |
1912 |
# right to the next item. |
1913 |
if ( $IndependentBranchesRecordsAndItems ) { |
1914 |
if ( none { $_ eq $item->{homebranch} } @allowed_branches ) { |
1915 |
splice(@fields, $index, 1); |
1916 |
$items_count--; |
1917 |
next; |
1918 |
} |
1919 |
} |
1920 |
|
1850 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
1921 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
1851 |
|
1922 |
|
1852 |
# OPAC hidden items |
1923 |
# OPAC hidden items |