Bug 17600: Standardize our EXPORT_OK
[srvgit] / Koha / News.pm
1 package Koha::News;
2
3 # Copyright ByWater Solutions 2015
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22
23 use Koha::Database;
24 use Koha::Exceptions;
25 use Koha::NewsItem;
26
27 use base qw(Koha::Objects);
28
29 =head1 NAME
30
31 Koha::News - Koha News object set class
32
33 =head1 API
34
35 =head2 Class Methods
36
37 =cut
38
39 =head3 search_for_display
40
41 my $news = Koha::News->search_for_display({
42     location => 'slip',
43     lang => 'en',
44     library_id => $branchcode
45 })
46
47 Return Koha::News set for display to user
48
49 You can limit the results by location, language and library by optional params
50
51 library_id should be valid branchcode of defined library
52
53 type is one of this:
54 - slip - for ISSUESLIP notice
55 - koha - for intranet
56 - opac - for online catalogue
57 - OpacNavRight - Right column in the online catalogue
58 - OpacLoginInstructions
59 - OpacMainUserBlock
60 - OpacCustomSearch
61 - opacheader
62 - opaccredits
63
64 lang is language code - it is used only when type is opac or any of OPAC locations
65
66 =cut
67
68 sub search_for_display {
69     my ( $self, $params ) = @_;
70
71     my $search_params;
72     if ($params->{location} ) {
73         if ( $params->{location} eq 'slip' || $params->{location} eq 'koha') {
74             $search_params->{lang} = [ $params->{location}, '' ];
75         } elsif ( $params->{location} eq 'opac' && $params->{lang} ) {
76             $search_params->{lang} = [ $params->{lang}, '' ];
77         } elsif ( $params->{lang} ) {
78             $search_params->{lang} = $params->{location} . '_' . $params->{lang};
79         } else {
80             Koha::Exceptions::BadParameter->throw("The location ($params->{location}) and lang ($params->{lang}) parameters combination is not valid");
81         }
82     }
83
84     $search_params->{branchcode} = [ $params->{library_id}, undef ] if $params->{library_id};
85     $search_params->{published_on} = { '<=' => \'NOW()' };
86     $search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' },
87                               expirationdate => undef ];
88
89     return $self->SUPER::search($search_params, { order_by => 'number' });
90 }
91
92 =head3 _type
93
94 =cut
95
96 sub _type {
97     return 'OpacNews';
98 }
99
100 =head3 object_class
101
102 =cut
103
104 sub object_class {
105     return 'Koha::NewsItem';
106 }
107
108 =head1 AUTHOR
109
110 Kyle M Hall <kyle@bywatersolutions.com>
111
112 =cut
113
114 1;