|
Lines 46-51
use C4::XSLT qw( XSLTParse4Display );
Link Here
|
| 46 |
use C4::Reserves qw( GetReserveStatus ); |
46 |
use C4::Reserves qw( GetReserveStatus ); |
| 47 |
use C4::Charset qw( SetUTF8Flag ); |
47 |
use C4::Charset qw( SetUTF8Flag ); |
| 48 |
use Koha::AuthorisedValues; |
48 |
use Koha::AuthorisedValues; |
|
|
49 |
use Koha::Displays; |
| 50 |
use Koha::Items; |
| 49 |
use Koha::ItemTypes; |
51 |
use Koha::ItemTypes; |
| 50 |
use Koha::Libraries; |
52 |
use Koha::Libraries; |
| 51 |
use Koha::Logger; |
53 |
use Koha::Logger; |
|
Lines 1683-1693
sub searchResults {
Link Here
|
| 1683 |
# FIXME - We build an authorised values hash here, using the default framework |
1685 |
# FIXME - We build an authorised values hash here, using the default framework |
| 1684 |
# though it is possible to have different authvals for different fws. |
1686 |
# though it is possible to have different authvals for different fws. |
| 1685 |
|
1687 |
|
|
|
1688 |
## get metadatas |
| 1689 |
my $collections = { |
| 1690 |
map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( |
| 1691 |
{ frameworkcode => '', kohafield => 'items.ccode' } |
| 1692 |
) |
| 1693 |
}; |
| 1686 |
my $shelflocations = { |
1694 |
my $shelflocations = { |
| 1687 |
map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( |
1695 |
map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( |
| 1688 |
{ frameworkcode => '', kohafield => 'items.location' } |
1696 |
{ frameworkcode => '', kohafield => 'items.location' } |
| 1689 |
) |
1697 |
) |
| 1690 |
}; |
1698 |
}; |
|
|
1699 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 1700 |
my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed }; |
| 1701 |
|
| 1702 |
# Cache for display lookups to avoid repeated queries |
| 1703 |
my $display_cache = {}; |
| 1704 |
|
| 1705 |
# Helper function to get effective location for search results |
| 1706 |
my $get_effective_collection_code = sub { |
| 1707 |
my ($item) = @_; |
| 1708 |
return $collections->{ $item->{ccode} } unless C4::Context->preference('UseDisplayModule'); |
| 1709 |
|
| 1710 |
my $item_obj = Koha::Items->find( $item->{itemnumber} ); |
| 1711 |
return $collections->{ $item->{ccode} } unless $item_obj; |
| 1712 |
|
| 1713 |
my $effective_collection_code = $item_obj->effective_collection_code; |
| 1714 |
|
| 1715 |
# If it starts with "DISPLAY:", validate against displays table |
| 1716 |
if ( $effective_collection_code =~ /^DISPLAY:\s*(.+)$/ ) { |
| 1717 |
my $display_name = $1; |
| 1718 |
|
| 1719 |
# Use cache to avoid repeated database queries |
| 1720 |
if ( !exists $display_cache->{$display_name} ) { |
| 1721 |
my $display = Koha::Displays->search( { display_name => $display_name } )->next; |
| 1722 |
$display_cache->{$display_name} = $display ? $display->display_name : undef; |
| 1723 |
} |
| 1724 |
return $display_cache->{$display_name} |
| 1725 |
? "DISPLAY: " . $display_cache->{$display_name} |
| 1726 |
: $effective_collection_code; |
| 1727 |
} else { |
| 1728 |
return $collections->{$effective_collection_code}; |
| 1729 |
} |
| 1730 |
}; |
| 1731 |
my $get_effective_itemtype = sub { |
| 1732 |
my ($item) = @_; |
| 1733 |
return $itemtypes{ $item->{itype} }{translated_description} unless C4::Context->preference('UseDisplayModule'); |
| 1734 |
|
| 1735 |
my $item_obj = Koha::Items->find( $item->{itemnumber} ); |
| 1736 |
return $itemtypes{ $item->{itype} }{translated_description} unless $item_obj; |
| 1737 |
|
| 1738 |
my $effective_itemtype = $item_obj->effective_itemtype; |
| 1739 |
|
| 1740 |
# If it starts with "DISPLAY:", validate against displays table |
| 1741 |
if ( $effective_itemtype =~ /^DISPLAY:\s*(.+)$/ ) { |
| 1742 |
my $display_name = $1; |
| 1743 |
|
| 1744 |
# Use cache to avoid repeated database queries |
| 1745 |
if ( !exists $display_cache->{$display_name} ) { |
| 1746 |
my $display = Koha::Displays->search( { display_name => $display_name } )->next; |
| 1747 |
$display_cache->{$display_name} = $display ? $display->display_name : undef; |
| 1748 |
} |
| 1749 |
return $display_cache->{$display_name} |
| 1750 |
? "DISPLAY: " . $display_cache->{$display_name} |
| 1751 |
: $effective_itemtype; |
| 1752 |
} else { |
| 1753 |
return $itemtypes{$effective_itemtype}{translated_description}; |
| 1754 |
} |
| 1755 |
}; |
| 1756 |
my $get_effective_location = sub { |
| 1757 |
my ($item) = @_; |
| 1758 |
return $shelflocations->{ $item->{location} } unless C4::Context->preference('UseDisplayModule'); |
| 1759 |
|
| 1760 |
my $item_obj = Koha::Items->find( $item->{itemnumber} ); |
| 1761 |
return $shelflocations->{ $item->{location} } unless $item_obj; |
| 1762 |
|
| 1763 |
my $effective_loc = $shelflocations->{ $item_obj->effective_location }; |
| 1764 |
|
| 1765 |
# If it starts with "DISPLAY:", validate against displays table |
| 1766 |
if ( $effective_loc =~ /^DISPLAY:\s*(.+)$/ ) { |
| 1767 |
my $display_name = $1; |
| 1768 |
|
| 1769 |
# Use cache to avoid repeated database queries |
| 1770 |
if ( !exists $display_cache->{$display_name} ) { |
| 1771 |
my $display = Koha::Displays->search( { display_name => $display_name } )->next; |
| 1772 |
$display_cache->{$display_name} = $display ? $display->display_name : undef; |
| 1773 |
} |
| 1774 |
return $display_cache->{$display_name} ? "DISPLAY: " . $display_cache->{$display_name} : $effective_loc; |
| 1775 |
} else { |
| 1776 |
return $effective_loc; |
| 1777 |
} |
| 1778 |
}; |
| 1779 |
my $get_effective_homebranch = sub { |
| 1780 |
my ($item) = @_; |
| 1781 |
return $item->{homebranch} unless C4::Context->preference('UseDisplayModule'); |
| 1782 |
|
| 1783 |
my $item_obj = Koha::Items->find( $item->{itemnumber} ); |
| 1784 |
return $item->{homebranch} unless $item_obj; |
| 1785 |
|
| 1786 |
my $effective_homebranch = $item_obj->effective_homebranch->branchcode; |
| 1787 |
|
| 1788 |
# If it starts with "DISPLAY:", validate against displays table |
| 1789 |
if ( $effective_homebranch =~ /^DISPLAY:\s*(.+)$/ ) { |
| 1790 |
my $display_name = $1; |
| 1791 |
|
| 1792 |
# Use cache to avoid repeated database queries |
| 1793 |
if ( !exists $display_cache->{$display_name} ) { |
| 1794 |
my $display = Koha::Displays->search( { display_name => $display_name } )->next; |
| 1795 |
$display_cache->{$display_name} = $display ? $display->display_name : undef; |
| 1796 |
} |
| 1797 |
return $display_cache->{$display_name} |
| 1798 |
? "DISPLAY: " . $display_cache->{$display_name} |
| 1799 |
: $effective_homebranch; |
| 1800 |
} else { |
| 1801 |
return $effective_homebranch; |
| 1802 |
} |
| 1803 |
}; |
| 1804 |
my $get_effective_holdingbranch = sub { |
| 1805 |
my ($item) = @_; |
| 1806 |
return $item->{holdingbranch} unless C4::Context->preference('UseDisplayModule'); |
| 1807 |
|
| 1808 |
my $item_obj = Koha::Items->find( $item->{itemnumber} ); |
| 1809 |
return $item->{holdingbranch} unless $item_obj; |
| 1810 |
|
| 1811 |
my $effective_holdingbranch = $item_obj->effective_holdingbranch->branchcode; |
| 1812 |
|
| 1813 |
# If it starts with "DISPLAY:", validate against displays table |
| 1814 |
if ( $effective_holdingbranch =~ /^DISPLAY:\s*(.+)$/ ) { |
| 1815 |
my $display_name = $1; |
| 1816 |
|
| 1817 |
# Use cache to avoid repeated database queries |
| 1818 |
if ( !exists $display_cache->{$display_name} ) { |
| 1819 |
my $display = Koha::Displays->search( { display_name => $display_name } )->next; |
| 1820 |
$display_cache->{$display_name} = $display ? $display->display_name : undef; |
| 1821 |
} |
| 1822 |
return $display_cache->{$display_name} |
| 1823 |
? "DISPLAY: " . $display_cache->{$display_name} |
| 1824 |
: $effective_holdingbranch; |
| 1825 |
} else { |
| 1826 |
return $effective_holdingbranch; |
| 1827 |
} |
| 1828 |
}; |
| 1691 |
|
1829 |
|
| 1692 |
# get notforloan authorised value list (see $shelflocations FIXME) |
1830 |
# get notforloan authorised value list (see $shelflocations FIXME) |
| 1693 |
my $av = Koha::MarcSubfieldStructures->search( |
1831 |
my $av = Koha::MarcSubfieldStructures->search( |
|
Lines 1698-1707
sub searchResults {
Link Here
|
| 1698 |
); |
1836 |
); |
| 1699 |
my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef; |
1837 |
my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef; |
| 1700 |
|
1838 |
|
| 1701 |
#Get itemtype hash |
|
|
| 1702 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 1703 |
my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed }; |
| 1704 |
|
| 1705 |
#search item field code |
1839 |
#search item field code |
| 1706 |
my ( $itemtag, undef ) = &GetMarcFromKohaField("items.itemnumber"); |
1840 |
my ( $itemtag, undef ) = &GetMarcFromKohaField("items.itemnumber"); |
| 1707 |
|
1841 |
|
|
Lines 1866-1872
sub searchResults {
Link Here
|
| 1866 |
next; |
2000 |
next; |
| 1867 |
} |
2001 |
} |
| 1868 |
|
2002 |
|
| 1869 |
$item->{description} = $itemtypes{ $item->{itype} }{translated_description} if $item->{itype}; |
2003 |
$item->{collectioncode} = $get_effective_collection_code->($item) if $item->{ccode}; |
|
|
2004 |
$item->{description} = $get_effective_itemtype->($item) if $item->{itype}; |
| 2005 |
$item->{location} = $get_effective_location->($item) if $item->{location}; |
| 2006 |
|
| 2007 |
$item->{homebranch} = $get_effective_homebranch->($item) if $item->{homebranch}; |
| 2008 |
$item->{holdingbranch} = $get_effective_holdingbranch->($item) if $item->{holdingbranch}; |
| 1870 |
|
2009 |
|
| 1871 |
# OPAC hidden items |
2010 |
# OPAC hidden items |
| 1872 |
if ($is_opac) { |
2011 |
if ($is_opac) { |
|
Lines 1893-1898
sub searchResults {
Link Here
|
| 1893 |
$item->{'branchcode'} = $item->{$otherbranch}; |
2032 |
$item->{'branchcode'} = $item->{$otherbranch}; |
| 1894 |
} |
2033 |
} |
| 1895 |
|
2034 |
|
|
|
2035 |
if ( C4::Context->preference('UseDisplayModule') ) { |
| 2036 |
my @displays; |
| 2037 |
my @display_items = Koha::DisplayItems->search( |
| 2038 |
{ itemnumber => $item->{itemnumber} }, |
| 2039 |
{ |
| 2040 |
order_by => { '-desc' => 'date_added' }, |
| 2041 |
} |
| 2042 |
)->as_list; |
| 2043 |
|
| 2044 |
foreach my $display_item (@display_items) { |
| 2045 |
push @displays, $display_item->display; |
| 2046 |
} |
| 2047 |
|
| 2048 |
$item->{display_items} = \@display_items if @display_items; |
| 2049 |
$item->{displays} = \@displays if @displays; |
| 2050 |
} |
| 2051 |
|
| 1896 |
my $prefix = |
2052 |
my $prefix = |
| 1897 |
( $item->{$hbranch} ? $item->{$hbranch} . '--' : q{} ) |
2053 |
( $item->{$hbranch} ? $item->{$hbranch} . '--' : q{} ) |
| 1898 |
. ( $item->{location} ? $item->{location} : q{} ) |
2054 |
. ( $item->{location} ? $item->{location} : q{} ) |
|
Lines 1914-1928
sub searchResults {
Link Here
|
| 1914 |
$onloan_items->{$key}->{count}++ if $item->{$hbranch}; |
2070 |
$onloan_items->{$key}->{count}++ if $item->{$hbranch}; |
| 1915 |
$onloan_items->{$key}->{branchname} = $item->{branchname}; |
2071 |
$onloan_items->{$key}->{branchname} = $item->{branchname}; |
| 1916 |
$onloan_items->{$key}->{branchcode} = $item->{branchcode}; |
2072 |
$onloan_items->{$key}->{branchcode} = $item->{branchcode}; |
| 1917 |
$onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location}; |
2073 |
$onloan_items->{$key}->{location} = $item->{location}; |
| 1918 |
$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber}; |
2074 |
$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber}; |
| 1919 |
$onloan_items->{$key}->{description} = $item->{description}; |
2075 |
$onloan_items->{$key}->{description} = $item->{description}; |
| 1920 |
$onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( |
2076 |
$onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( |
| 1921 |
$search_context->{'interface'}, |
2077 |
$search_context->{'interface'}, |
| 1922 |
$itemtypes{ $item->{itype} }->{imageurl} |
2078 |
$itemtypes{ $item->{itype} }->{imageurl} |
| 1923 |
); |
2079 |
); |
| 1924 |
$onloan_items->{$key}->{collectioncode} = |
2080 |
$onloan_items->{$key}->{collectioncode} = $item->{collectioncode}; |
| 1925 |
GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); |
2081 |
$onloan_items->{$key}->{displays} = $item->{displays}; |
| 1926 |
|
2082 |
|
| 1927 |
# if something's checked out and lost, mark it as 'long overdue' |
2083 |
# if something's checked out and lost, mark it as 'long overdue' |
| 1928 |
if ( $item->{itemlost} ) { |
2084 |
if ( $item->{itemlost} ) { |
|
Lines 2032-2045
sub searchResults {
Link Here
|
| 2032 |
GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value ) |
2188 |
GetAuthorisedValueDesc( '', '', $item->{notforloan}, '', '', $notforloan_authorised_value ) |
| 2033 |
if $notforloan_authorised_value and $item->{notforloan}; |
2189 |
if $notforloan_authorised_value and $item->{notforloan}; |
| 2034 |
$other_items->{$key}->{count}++ if $item->{$hbranch}; |
2190 |
$other_items->{$key}->{count}++ if $item->{$hbranch}; |
| 2035 |
$other_items->{$key}->{location} = $shelflocations->{ $item->{location} } if $item->{location}; |
2191 |
$other_items->{$key}->{location} = $item->{location}; |
| 2036 |
$other_items->{$key}->{description} = $item->{description}; |
2192 |
$other_items->{$key}->{description} = $item->{description}; |
| 2037 |
$other_items->{$key}->{imageurl} = getitemtypeimagelocation( |
2193 |
$other_items->{$key}->{imageurl} = getitemtypeimagelocation( |
| 2038 |
$search_context->{'interface'}, |
2194 |
$search_context->{'interface'}, |
| 2039 |
$itemtypes{ $item->{itype} // q{} }->{imageurl} |
2195 |
$itemtypes{ $item->{itype} // q{} }->{imageurl} |
| 2040 |
); |
2196 |
); |
| 2041 |
$other_items->{$key}->{collectioncode} = |
2197 |
$other_items->{$key}->{collectioncode} = $item->{collectioncode}; |
| 2042 |
GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); |
2198 |
$other_items->{$key}->{displays} = $item->{displays}; |
| 2043 |
} |
2199 |
} |
| 2044 |
|
2200 |
|
| 2045 |
# item is available |
2201 |
# item is available |
|
Lines 2053-2066
sub searchResults {
Link Here
|
| 2053 |
} |
2209 |
} |
| 2054 |
$available_items->{$prefix}->{branchavailablecount} = $branch_available_count; |
2210 |
$available_items->{$prefix}->{branchavailablecount} = $branch_available_count; |
| 2055 |
$available_items->{$prefix}->{branchcode} = $item->{branchcode}; |
2211 |
$available_items->{$prefix}->{branchcode} = $item->{branchcode}; |
| 2056 |
$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} } |
2212 |
$available_items->{$prefix}->{location} = $item->{location}; |
| 2057 |
if $item->{location}; |
2213 |
$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( |
| 2058 |
$available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( |
|
|
| 2059 |
$search_context->{'interface'}, |
2214 |
$search_context->{'interface'}, |
| 2060 |
$itemtypes{ $item->{itype} // q{} }->{imageurl} |
2215 |
$itemtypes{ $item->{itype} // q{} }->{imageurl} |
| 2061 |
); |
2216 |
); |
| 2062 |
$available_items->{$prefix}->{collectioncode} = |
2217 |
$available_items->{$prefix}->{collectioncode} = $item->{collectioncode}; |
| 2063 |
GetAuthorisedValueDesc( '', '', $item->{ccode}, '', '', 'CCODE' ); |
2218 |
$available_items->{$prefix}->{displays} = $item->{displays}; |
| 2064 |
} |
2219 |
} |
| 2065 |
} |
2220 |
} |
| 2066 |
} # notforloan, item level and biblioitem level |
2221 |
} # notforloan, item level and biblioitem level |