|
Lines 31-36
use C4::Reserves;
Link Here
|
| 31 |
use C4::ClassSource qw( GetClassSort ); |
31 |
use C4::ClassSource qw( GetClassSort ); |
| 32 |
use C4::Log qw( logaction ); |
32 |
use C4::Log qw( logaction ); |
| 33 |
|
33 |
|
|
|
34 |
use Koha::AuthorisedValues; |
| 34 |
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; |
35 |
use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; |
| 35 |
use Koha::Biblio::ItemGroups; |
36 |
use Koha::Biblio::ItemGroups; |
| 36 |
use Koha::Checkouts; |
37 |
use Koha::Checkouts; |
|
Lines 58-63
use Koha::StockRotationItem;
Link Here
|
| 58 |
use Koha::StockRotationRotas; |
59 |
use Koha::StockRotationRotas; |
| 59 |
use Koha::TrackedLinks; |
60 |
use Koha::TrackedLinks; |
| 60 |
use Koha::Policy::Holds; |
61 |
use Koha::Policy::Holds; |
|
|
62 |
use Koha::DisplayItems; |
| 61 |
|
63 |
|
| 62 |
use base qw(Koha::Object); |
64 |
use base qw(Koha::Object); |
| 63 |
|
65 |
|
|
Lines 412-417
Returns the itemtype for the item based on whether item level itemtypes are set
Link Here
|
| 412 |
sub effective_itemtype { |
414 |
sub effective_itemtype { |
| 413 |
my ($self) = @_; |
415 |
my ($self) = @_; |
| 414 |
|
416 |
|
|
|
417 |
if ( C4::Context->preference('UseDisplayModule') ) { |
| 418 |
if ( my $display = $self->active_display ) { |
| 419 |
my $display_itype = $display->get_column('display_itype'); |
| 420 |
return $display_itype if $display_itype; |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 415 |
return $self->_result()->effective_itemtype(); |
424 |
return $self->_result()->effective_itemtype(); |
| 416 |
} |
425 |
} |
| 417 |
|
426 |
|
|
Lines 778-783
sub check_booking {
Link Here
|
| 778 |
return $bookings_count ? 0 : 1; |
787 |
return $bookings_count ? 0 : 1; |
| 779 |
} |
788 |
} |
| 780 |
|
789 |
|
|
|
790 |
=head3 active_display_item |
| 791 |
|
| 792 |
my $display_item = $item->active_display_item; |
| 793 |
|
| 794 |
Returns the Koha::DisplayItem object if this item is part of an active display, undef otherwise. |
| 795 |
An active display is one where enabled = 1 and the current date falls within the start_date and end_date range (if set). |
| 796 |
|
| 797 |
=cut |
| 798 |
|
| 799 |
sub active_display_item { |
| 800 |
my ($self) = @_; |
| 801 |
|
| 802 |
return unless C4::Context->preference('UseDisplayModule'); |
| 803 |
|
| 804 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 805 |
my $today = dt_from_string(); |
| 806 |
|
| 807 |
my $display_item = Koha::DisplayItems->search( |
| 808 |
{ |
| 809 |
itemnumber => $self->itemnumber, |
| 810 |
'display.enabled' => 1, |
| 811 |
-and => [ |
| 812 |
-or => [ |
| 813 |
{ 'display.start_date' => undef }, |
| 814 |
{ 'display.start_date' => { '<=' => $dtf->format_date($today) } } |
| 815 |
], |
| 816 |
-or => [ |
| 817 |
{ 'display.end_date' => undef }, |
| 818 |
{ 'display.end_date' => { '>=' => $dtf->format_date($today) } } |
| 819 |
] |
| 820 |
] |
| 821 |
}, |
| 822 |
{ join => 'display' } |
| 823 |
)->next; |
| 824 |
|
| 825 |
return $display_item; |
| 826 |
} |
| 827 |
|
| 781 |
=head3 request_transfer |
828 |
=head3 request_transfer |
| 782 |
|
829 |
|
| 783 |
my $transfer = $item->request_transfer( |
830 |
my $transfer = $item->request_transfer( |
|
Lines 1949-1954
sub to_api {
Link Here
|
| 1949 |
$overrides->{effective_item_type_id} = $self->effective_itemtype; |
1996 |
$overrides->{effective_item_type_id} = $self->effective_itemtype; |
| 1950 |
$overrides->{effective_not_for_loan_status} = $self->effective_not_for_loan_status; |
1997 |
$overrides->{effective_not_for_loan_status} = $self->effective_not_for_loan_status; |
| 1951 |
$overrides->{effective_bookable} = $self->effective_bookable; |
1998 |
$overrides->{effective_bookable} = $self->effective_bookable; |
|
|
1999 |
$overrides->{effective_location} = $self->effective_location; |
| 2000 |
$overrides->{effective_collection_code} = $self->effective_collection_code; |
| 2001 |
$overrides->{effective_home_library_id} = $self->effective_homebranch; |
| 2002 |
$overrides->{effective_holding_library_id} = $self->effective_holdingbranch; |
| 1952 |
|
2003 |
|
| 1953 |
return { %$response, %$overrides }; |
2004 |
return { %$response, %$overrides }; |
| 1954 |
} |
2005 |
} |
|
Lines 2069-2074
sub effective_bookable {
Link Here
|
| 2069 |
return $self->bookable // $self->itemtype->bookable; |
2120 |
return $self->bookable // $self->itemtype->bookable; |
| 2070 |
} |
2121 |
} |
| 2071 |
|
2122 |
|
|
|
2123 |
=head3 effective_location |
| 2124 |
|
| 2125 |
my $location = $item->effective_location; |
| 2126 |
|
| 2127 |
Returns the effective location of the item. If the item is on an active display |
| 2128 |
with a display_location, returns the display_location. Otherwise, returns |
| 2129 |
the item's location. |
| 2130 |
|
| 2131 |
=cut |
| 2132 |
|
| 2133 |
sub effective_location { |
| 2134 |
my ($self) = @_; |
| 2135 |
|
| 2136 |
return $self->location unless C4::Context->preference('UseDisplayModule'); |
| 2137 |
|
| 2138 |
if ( my $display = $self->active_display ) { |
| 2139 |
if ( $display->display_location ) { |
| 2140 |
return $display->display_location; |
| 2141 |
} |
| 2142 |
return "DISPLAY: " . $display->display_name; |
| 2143 |
} |
| 2144 |
|
| 2145 |
return $self->location; |
| 2146 |
} |
| 2147 |
|
| 2148 |
=head3 effective_collection_code |
| 2149 |
|
| 2150 |
my $ccode = $item->effective_collection_code; |
| 2151 |
|
| 2152 |
Returns the effective collection code for the item. If the item is part of an active display |
| 2153 |
with a display_code set, returns that code. Otherwise returns the item's regular ccode. |
| 2154 |
|
| 2155 |
=cut |
| 2156 |
|
| 2157 |
sub effective_collection_code { |
| 2158 |
my ($self) = @_; |
| 2159 |
|
| 2160 |
return $self->ccode unless C4::Context->preference('UseDisplayModule'); |
| 2161 |
|
| 2162 |
if ( my $display = $self->active_display ) { |
| 2163 |
my $display_code = $display->get_column('display_code'); |
| 2164 |
return $display_code if $display_code; |
| 2165 |
} |
| 2166 |
|
| 2167 |
return $self->ccode; |
| 2168 |
} |
| 2169 |
|
| 2170 |
=head3 effective_homebranch |
| 2171 |
|
| 2172 |
my $homebranch = $item->effective_homebranch; |
| 2173 |
|
| 2174 |
Returns the effective home branch for the item. If the item is part of an active display |
| 2175 |
with a display_branch set, returns that branch. Otherwise returns the item's regular homebranch. |
| 2176 |
|
| 2177 |
=cut |
| 2178 |
|
| 2179 |
sub effective_homebranch { |
| 2180 |
my ($self) = @_; |
| 2181 |
|
| 2182 |
return $self->get_column('homebranch') unless C4::Context->preference('UseDisplayModule'); |
| 2183 |
|
| 2184 |
if ( my $display = $self->active_display ) { |
| 2185 |
my $display_branch = $display->get_column('display_branch'); |
| 2186 |
return $display_branch if $display_branch; |
| 2187 |
} |
| 2188 |
|
| 2189 |
return $self->get_column('homebranch'); |
| 2190 |
} |
| 2191 |
|
| 2192 |
=head3 effective_holdingbranch |
| 2193 |
|
| 2194 |
my $holdingbranch = $item->effective_holdingbranch; |
| 2195 |
|
| 2196 |
Returns the effective holding branch for the item. If the item is part of an active display |
| 2197 |
with a display_holding_branch set, returns that branch. Otherwise returns the item's regular holdingbranch. |
| 2198 |
|
| 2199 |
=cut |
| 2200 |
|
| 2201 |
sub effective_holdingbranch { |
| 2202 |
my ($self) = @_; |
| 2203 |
|
| 2204 |
return $self->get_column('holdingbranch') unless C4::Context->preference('UseDisplayModule'); |
| 2205 |
|
| 2206 |
if ( my $display = $self->active_display ) { |
| 2207 |
my $display_holding_branch = $display->get_column('display_holding_branch'); |
| 2208 |
return $display_holding_branch if $display_holding_branch; |
| 2209 |
} |
| 2210 |
|
| 2211 |
return $self->get_column('holdingbranch'); |
| 2212 |
} |
| 2213 |
|
| 2214 |
=head3 active_display |
| 2215 |
|
| 2216 |
my $display = $item->active_display; |
| 2217 |
|
| 2218 |
Returns the active display for this item, if any. Returns undef if the item is not |
| 2219 |
currently in an active display. |
| 2220 |
|
| 2221 |
An active display is one that: |
| 2222 |
- Is enabled |
| 2223 |
- Has a start_date that is today or in the past (or no start_date) |
| 2224 |
- Has an end_date that is today or in the future (or no end_date) |
| 2225 |
- Has a date_remove on the display_item that is today or in the future (or no date_remove) |
| 2226 |
|
| 2227 |
=cut |
| 2228 |
|
| 2229 |
sub active_display { |
| 2230 |
my ($self) = @_; |
| 2231 |
|
| 2232 |
return unless C4::Context->preference('UseDisplayModule'); |
| 2233 |
|
| 2234 |
my $display_item_rs = $self->_result->display_items( |
| 2235 |
{ |
| 2236 |
'display.enabled' => 1, |
| 2237 |
'-or' => [ |
| 2238 |
'display.start_date' => { '<=', \'CURDATE()' }, |
| 2239 |
'display.start_date' => undef |
| 2240 |
], |
| 2241 |
'-and' => [ |
| 2242 |
'-or' => [ |
| 2243 |
'display.end_date' => { '>=', \'CURDATE()' }, |
| 2244 |
'display.end_date' => undef |
| 2245 |
], |
| 2246 |
'-or' => [ |
| 2247 |
'date_remove' => { '>=', \'CURDATE()' }, |
| 2248 |
'date_remove' => undef |
| 2249 |
] |
| 2250 |
] |
| 2251 |
}, |
| 2252 |
{ |
| 2253 |
join => 'display', |
| 2254 |
order_by => { -desc => 'date_added' } |
| 2255 |
} |
| 2256 |
); |
| 2257 |
|
| 2258 |
if ( my $display_item = $display_item_rs->first ) { |
| 2259 |
return $display_item->display; |
| 2260 |
} |
| 2261 |
|
| 2262 |
return; |
| 2263 |
} |
| 2264 |
|
| 2265 |
=head3 location_description |
| 2266 |
|
| 2267 |
my $description = $item->location_description(); |
| 2268 |
|
| 2269 |
Returns the human-readable description for the item's location from authorised values. |
| 2270 |
|
| 2271 |
=cut |
| 2272 |
|
| 2273 |
sub location_description { |
| 2274 |
my ($self) = @_; |
| 2275 |
|
| 2276 |
return '' unless $self->location; |
| 2277 |
|
| 2278 |
my $av = Koha::AuthorisedValues->get_description_by_koha_field( |
| 2279 |
{ kohafield => 'items.location', authorised_value => $self->location } ); |
| 2280 |
return $av->{lib} || $self->location; |
| 2281 |
} |
| 2282 |
|
| 2072 |
=head3 orders |
2283 |
=head3 orders |
| 2073 |
|
2284 |
|
| 2074 |
my $orders = $item->orders(); |
2285 |
my $orders = $item->orders(); |
|
Lines 2759-2764
sub strings_map {
Link Here
|
| 2759 |
} |
2970 |
} |
| 2760 |
} |
2971 |
} |
| 2761 |
|
2972 |
|
|
|
2973 |
if ( my $effective_loc = $self->effective_location ) { |
| 2974 |
my $description; |
| 2975 |
|
| 2976 |
# Handle display locations that start with "DISPLAY:" |
| 2977 |
if ( $effective_loc =~ /^DISPLAY:/ ) { |
| 2978 |
$description = $effective_loc; |
| 2979 |
} else { |
| 2980 |
|
| 2981 |
# Look up authorized value for regular locations |
| 2982 |
my $av = Koha::AuthorisedValues->get_description_by_koha_field( |
| 2983 |
{ kohafield => 'items.location', authorised_value => $effective_loc } ); |
| 2984 |
$description = $av->{lib} || $effective_loc; |
| 2985 |
} |
| 2986 |
$strings->{effective_location} = { |
| 2987 |
category => 'LOC', |
| 2988 |
str => $description, |
| 2989 |
type => 'av', |
| 2990 |
}; |
| 2991 |
} |
| 2992 |
|
| 2762 |
return $strings; |
2993 |
return $strings; |
| 2763 |
} |
2994 |
} |
| 2764 |
|
2995 |
|