|
Lines 31-36
use C4::Branch;
Link Here
|
| 31 |
use C4::Reserves; # GetReserveStatus |
31 |
use C4::Reserves; # GetReserveStatus |
| 32 |
use C4::Debug; |
32 |
use C4::Debug; |
| 33 |
use C4::Charset; |
33 |
use C4::Charset; |
|
|
34 |
use List::MoreUtils qw/any/; |
| 34 |
use YAML; |
35 |
use YAML; |
| 35 |
use URI::Escape; |
36 |
use URI::Escape; |
| 36 |
use Business::ISBN; |
37 |
use Business::ISBN; |
|
Lines 67-72
This module provides searching functions for Koha's bibliographic databases
Link Here
|
| 67 |
&SimpleSearch |
68 |
&SimpleSearch |
| 68 |
&searchResults |
69 |
&searchResults |
| 69 |
&getRecords |
70 |
&getRecords |
|
|
71 |
&getItemSubfieldsToSearch |
| 70 |
&buildQuery |
72 |
&buildQuery |
| 71 |
&AddSearchHistory |
73 |
&AddSearchHistory |
| 72 |
&GetDistinctValues |
74 |
&GetDistinctValues |
|
Lines 340-345
sub getRecords {
Link Here
|
| 340 |
my @results; |
342 |
my @results; |
| 341 |
my $results_hashref = (); |
343 |
my $results_hashref = (); |
| 342 |
|
344 |
|
|
|
345 |
my $opachiddenitems = C4::Context->preference('OpacHiddenItems'); |
| 346 |
my $hidingrules = C4::Items::GetHidingRules(); |
| 347 |
my $ishidingoverridden = C4::Items::isHidingOverridden(); |
| 348 |
|
| 343 |
# Initialize variables for the faceted results objects |
349 |
# Initialize variables for the faceted results objects |
| 344 |
my $facets_counter = (); |
350 |
my $facets_counter = (); |
| 345 |
my $facets_info = (); |
351 |
my $facets_info = (); |
|
Lines 506-511
sub getRecords {
Link Here
|
| 506 |
my $jmax = |
512 |
my $jmax = |
| 507 |
$size > $facets_maxrecs ? $facets_maxrecs : $size; |
513 |
$size > $facets_maxrecs ? $facets_maxrecs : $size; |
| 508 |
for my $facet (@$facets) { |
514 |
for my $facet (@$facets) { |
|
|
515 |
#warn "XXXfacet: ".$facet->{idx}." ".$facet->{label};; |
| 509 |
for ( my $j = 0 ; $j < $jmax ; $j++ ) { |
516 |
for ( my $j = 0 ; $j < $jmax ; $j++ ) { |
| 510 |
|
517 |
|
| 511 |
my $marc_record = new_record_from_zebra ( |
518 |
my $marc_record = new_record_from_zebra ( |
|
Lines 519-528
sub getRecords {
Link Here
|
| 519 |
next; |
526 |
next; |
| 520 |
} |
527 |
} |
| 521 |
|
528 |
|
|
|
529 |
if ($opac) { |
| 530 |
if ($opachiddenitems && !$ishidingoverridden) { |
| 531 |
# TODO: get hidden tag mapping |
| 532 |
#my ($bibliotag,$bibliosubf)=GetMarcFromKohaField('biblio.hidden',''); |
| 533 |
my ($bibliotag,$bibliosubf)=('999','h'); |
| 534 |
my $bibliohidden = $marc_record->field($bibliotag)->subfield($bibliosubf); |
| 535 |
#warn "$i $j bibliohidden:$bibliohidden"; |
| 536 |
if ( $bibliohidden && $bibliohidden == 1 ) { |
| 537 |
next; # this biblio is not part of facets |
| 538 |
} |
| 539 |
|
| 540 |
} |
| 541 |
} |
| 542 |
|
| 522 |
my @used_datas = (); |
543 |
my @used_datas = (); |
| 523 |
|
544 |
|
| 524 |
foreach my $tag ( @{ $facet->{tags} } ) { |
545 |
foreach my $tag ( @{ $facet->{tags} } ) { |
| 525 |
|
|
|
| 526 |
# avoid first line |
546 |
# avoid first line |
| 527 |
my $tag_num = substr( $tag, 0, 3 ); |
547 |
my $tag_num = substr( $tag, 0, 3 ); |
| 528 |
my $subfield_letters = substr( $tag, 3 ); |
548 |
my $subfield_letters = substr( $tag, 3 ); |
|
Lines 532-537
sub getRecords {
Link Here
|
| 532 |
my @fields = $marc_record->field($tag_num); |
552 |
my @fields = $marc_record->field($tag_num); |
| 533 |
foreach my $field (@fields) { |
553 |
foreach my $field (@fields) { |
| 534 |
my $data = $field->as_string( $subfield_letters, $facet->{sep} ); |
554 |
my $data = $field->as_string( $subfield_letters, $facet->{sep} ); |
|
|
555 |
#warn "tagnum:$tag_num tag: $tag data: $data"; |
| 556 |
# ITEMLEVEL handling: |
| 557 |
#NEED TO LOOK AT ITEM IN DB and don't count YAML MATCHING fields tag subfield -> mapping holdingbranch |
| 558 |
# these fields are from marc_record. might need raw as in rebuild_zebra. |
| 559 |
|
| 560 |
#IDEA: |
| 561 |
#TOD GET RID OF hidden library facets do these: (if not patron SEEALL, and patronCategory, and OpacHiddenItems) |
| 562 |
# hide the facet if it's OpacHiddenItems rule hides its items. |
| 563 |
# (because we don't hide biblios if any non-hidden items exists) |
| 564 |
# Could be done for other facets such as authors, locations, itemtypes, series, topics |
| 565 |
# TODO: possibly discern which to hide based on DisplayLibraryFacets syspref from bug 11334 if it gets pushed |
| 566 |
# handle homebranch as well if needed |
| 567 |
if ($opachiddenitems && !$ishidingoverridden) { |
| 568 |
if (any { $data eq $_ } @{$hidingrules->{'holdingbranch'}}) { # see getFacets branch tag995b or 952b |
| 569 |
next; # skip hidden |
| 570 |
} |
| 571 |
} |
| 535 |
|
572 |
|
| 536 |
unless ( $data ~~ @used_datas ) { |
573 |
unless ( $data ~~ @used_datas ) { |
| 537 |
push @used_datas, $data; |
574 |
push @used_datas, $data; |
|
Lines 591-597
sub getRecords {
Link Here
|
| 591 |
$facet_max_length; |
628 |
$facet_max_length; |
| 592 |
|
629 |
|
| 593 |
# if it's a branch, label by the name, not the code, |
630 |
# if it's a branch, label by the name, not the code, |
| 594 |
if ( $link_value =~ /branch/ ) { |
631 |
if ( $link_value =~ /branch/ ) { # see getFacets tag for branch (holdingbranch) |
| 595 |
if ( defined $branches |
632 |
if ( defined $branches |
| 596 |
&& ref($branches) eq "HASH" |
633 |
&& ref($branches) eq "HASH" |
| 597 |
&& defined $branches->{$one_facet} |
634 |
&& defined $branches->{$one_facet} |
|
Lines 606-611
sub getRecords {
Link Here
|
| 606 |
$facet_label_value = "*"; |
643 |
$facet_label_value = "*"; |
| 607 |
} |
644 |
} |
| 608 |
} |
645 |
} |
|
|
646 |
#warn "onefacet: $link_value $number_of_facets $one_facet ^ $facet_link_value ? $facet_label_value =$expanded_facet:$facets_info->{$link_value}->{'expanded'}"; |
| 609 |
|
647 |
|
| 610 |
# if it's a itemtype, label by the name, not the code, |
648 |
# if it's a itemtype, label by the name, not the code, |
| 611 |
if ( $link_value =~ /itype/ ) { |
649 |
if ( $link_value =~ /itype/ ) { |
|
Lines 1682-1697
sub searchResults {
Link Here
|
| 1682 |
my ($itemtag, undef) = &GetMarcFromKohaField( "items.itemnumber", "" ); |
1720 |
my ($itemtag, undef) = &GetMarcFromKohaField( "items.itemnumber", "" ); |
| 1683 |
|
1721 |
|
| 1684 |
## find column names of items related to MARC |
1722 |
## find column names of items related to MARC |
| 1685 |
my $sth2 = $dbh->prepare("SHOW COLUMNS FROM items"); |
1723 |
my $subfieldstosearch_hashref = getItemSubfieldsToSearch(); |
| 1686 |
$sth2->execute; |
1724 |
my %subfieldstosearch = %$subfieldstosearch_hashref; |
| 1687 |
my %subfieldstosearch; |
|
|
| 1688 |
while ( ( my $column ) = $sth2->fetchrow ) { |
| 1689 |
my ( $tagfield, $tagsubfield ) = |
| 1690 |
&GetMarcFromKohaField( "items." . $column, "" ); |
| 1691 |
if ( defined $tagsubfield ) { |
| 1692 |
$subfieldstosearch{$column} = $tagsubfield; |
| 1693 |
} |
| 1694 |
} |
| 1695 |
|
1725 |
|
| 1696 |
# handle which records to actually retrieve |
1726 |
# handle which records to actually retrieve |
| 1697 |
my $times; |
1727 |
my $times; |
|
Lines 1844-1850
sub searchResults {
Link Here
|
| 1844 |
my $other_count = 0; |
1874 |
my $other_count = 0; |
| 1845 |
my $withdrawn_count = 0; |
1875 |
my $withdrawn_count = 0; |
| 1846 |
my $itemlost_count = 0; |
1876 |
my $itemlost_count = 0; |
| 1847 |
my $hideatopac_count = 0; |
|
|
| 1848 |
my $itembinding_count = 0; |
1877 |
my $itembinding_count = 0; |
| 1849 |
my $itemdamaged_count = 0; |
1878 |
my $itemdamaged_count = 0; |
| 1850 |
my $item_in_transit_count = 0; |
1879 |
my $item_in_transit_count = 0; |
|
Lines 1854-1859
sub searchResults {
Link Here
|
| 1854 |
my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults'); |
1883 |
my $maxitems_pref = C4::Context->preference('maxItemsinSearchResults'); |
| 1855 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
1884 |
my $maxitems = $maxitems_pref ? $maxitems_pref - 1 : 1; |
| 1856 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
1885 |
my @hiddenitems; # hidden itemnumbers based on OpacHiddenItems syspref |
|
|
1886 |
my @itemnumbers; # itemnumbers for this biblio |
| 1857 |
|
1887 |
|
| 1858 |
# loop through every item |
1888 |
# loop through every item |
| 1859 |
foreach my $field (@fields) { |
1889 |
foreach my $field (@fields) { |
|
Lines 1864-1882
sub searchResults {
Link Here
|
| 1864 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
1894 |
$item->{$code} = $field->subfield( $subfieldstosearch{$code} ); |
| 1865 |
} |
1895 |
} |
| 1866 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
1896 |
$item->{description} = $itemtypes{ $item->{itype} }{description}; |
|
|
1897 |
push @itemnumbers, $item->{itemnumber}; |
| 1867 |
|
1898 |
|
| 1868 |
# OPAC hidden items |
1899 |
# OPAC hidden items |
| 1869 |
if ($is_opac) { |
1900 |
if ($is_opac) { |
| 1870 |
# hidden because lost |
1901 |
# hidden because lost |
| 1871 |
if ($hidelostitems && $item->{itemlost}) { |
1902 |
if ($hidelostitems && $item->{itemlost}) { |
| 1872 |
$hideatopac_count++; |
|
|
| 1873 |
next; |
1903 |
next; |
| 1874 |
} |
1904 |
} |
| 1875 |
# hidden based on OpacHiddenItems syspref |
1905 |
# hidden based on OpacHiddenItems syspref |
| 1876 |
my @hi = C4::Items::GetHiddenItemnumbers($item); |
1906 |
my @itemnum = ($item->{itemnumber}); |
|
|
1907 |
my @hi = C4::Items::GetHiddenItemnumbersByItemnumbers(@itemnum); |
| 1877 |
if (scalar @hi) { |
1908 |
if (scalar @hi) { |
| 1878 |
push @hiddenitems, @hi; |
1909 |
push @hiddenitems, @hi; |
| 1879 |
$hideatopac_count++; |
|
|
| 1880 |
next; |
1910 |
next; |
| 1881 |
} |
1911 |
} |
| 1882 |
} |
1912 |
} |
|
Lines 2007-2013
sub searchResults {
Link Here
|
| 2007 |
} # notforloan, item level and biblioitem level |
2037 |
} # notforloan, item level and biblioitem level |
| 2008 |
|
2038 |
|
| 2009 |
# if all items are hidden, do not show the record |
2039 |
# if all items are hidden, do not show the record |
| 2010 |
if ($items_count > 0 && $hideatopac_count == $items_count) { |
2040 |
if ( scalar(@itemnumbers) > 0 && scalar(@hiddenitems) == scalar(@itemnumbers) ) { |
|
|
2041 |
# TODO: patron category override |
| 2011 |
next; |
2042 |
next; |
| 2012 |
} |
2043 |
} |
| 2013 |
|
2044 |
|
|
Lines 2094-2099
sub searchResults {
Link Here
|
| 2094 |
return @newresults; |
2125 |
return @newresults; |
| 2095 |
} |
2126 |
} |
| 2096 |
|
2127 |
|
|
|
2128 |
=head2 getItemSubfieldsToSearch |
| 2129 |
Search for the item table related subfield tags |
| 2130 |
=cut |
| 2131 |
sub getItemSubfieldsToSearch { |
| 2132 |
my $dbh = C4::Context->dbh; |
| 2133 |
## find column names of items related to MARC |
| 2134 |
my $sth2 = $dbh->prepare("SHOW COLUMNS FROM items"); |
| 2135 |
$sth2->execute; |
| 2136 |
my %subfieldstosearch; |
| 2137 |
while ( ( my $column ) = $sth2->fetchrow ) { |
| 2138 |
my ( $tagfield, $tagsubfield ) = |
| 2139 |
&GetMarcFromKohaField( "items." . $column, "" ); |
| 2140 |
if ( defined $tagsubfield ) { |
| 2141 |
$subfieldstosearch{$column} = $tagsubfield; |
| 2142 |
} |
| 2143 |
} |
| 2144 |
return \%subfieldstosearch; |
| 2145 |
} |
| 2146 |
|
| 2097 |
=head2 SearchAcquisitions |
2147 |
=head2 SearchAcquisitions |
| 2098 |
Search for acquisitions |
2148 |
Search for acquisitions |
| 2099 |
=cut |
2149 |
=cut |