3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 use base qw(Koha::Objects);
32 Koha::News - Koha News object set class
40 =head3 search_for_display
42 my $news = Koha::News->search_for_display({
45 library_id => $branchcode
48 Return Koha::News set for display to user
50 You can limit the results by location, language and library by optional params
52 library_id should be valid branchcode of defined library
55 - slip - for ISSUESLIP notice
57 - opac - for online catalogue
58 - OpacNavRight - Right column in the online catalogue
59 - OpacLoginInstructions
65 lang is language code - it is used only when type is opac or any of OPAC locations
69 sub search_for_display {
70 my ( $self, $params ) = @_;
73 if ($params->{location} ) {
74 if ( $params->{location} eq 'slip' || $params->{location} eq 'koha') {
75 $search_params->{lang} = [ $params->{location}, '' ];
76 } elsif ( $params->{location} eq 'opac' && $params->{lang} ) {
77 $search_params->{lang} = [ $params->{lang}, '' ];
78 } elsif ( $params->{lang} ) {
79 $search_params->{lang} = $params->{location} . '_' . $params->{lang};
81 Koha::Exceptions::BadParameter->throw("The location ($params->{location}) and lang ($params->{lang}) parameters combination is not valid");
85 $search_params->{branchcode} = [ $params->{library_id}, undef ] if $params->{library_id};
86 $search_params->{published_on} = { '<=' => \'NOW()' };
87 $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
88 expirationdate => undef ];
90 return $self->SUPER::search($search_params, { order_by => 'number' });
106 return 'Koha::NewsItem';
111 Kyle M Hall <kyle@bywatersolutions.com>