Bug 27883: Add ability to preserve patron field from being overwritten by import
[koha.git] / 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 use Carp;
23
24 use Koha::Database;
25 use Koha::Exceptions;
26 use Koha::NewsItem;
27
28 use base qw(Koha::Objects);
29
30 =head1 NAME
31
32 Koha::News - Koha News object set class
33
34 =head1 API
35
36 =head2 Class Methods
37
38 =cut
39
40 =head3 search_for_display
41
42 my $news = Koha::News->search_for_display({
43     location => 'slip',
44     lang => 'en',
45     library_id => $branchcode
46 })
47
48 Return Koha::News set for display to user
49
50 You can limit the results by location, language and library by optional params
51
52 library_id should be valid branchcode of defined library
53
54 type is one of this:
55 - slip - for ISSUESLIP notice
56 - koha - for intranet
57 - opac - for online catalogue
58 - OpacNavRight - Right column in the online catalogue
59 - OpacLoginInstructions
60 - OpacMainUserBlock
61 - OpacCustomSearch
62 - opacheader
63 - opaccredits
64
65 lang is language code - it is used only when type is opac or any of OPAC locations
66
67 =cut
68
69 sub search_for_display {
70     my ( $self, $params ) = @_;
71
72     my $search_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};
80         } else {
81             Koha::Exceptions::BadParameter->throw("The location ($params->{location}) and lang ($params->{lang}) parameters combination is not valid");
82         }
83     }
84
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 ];
89
90     return $self->SUPER::search($search_params, { order_by => 'number' });
91 }
92
93 =head3 _type
94
95 =cut
96
97 sub _type {
98     return 'OpacNews';
99 }
100
101 =head3 object_class
102
103 =cut
104
105 sub object_class {
106     return 'Koha::NewsItem';
107 }
108
109 =head1 AUTHOR
110
111 Kyle M Hall <kyle@bywatersolutions.com>
112
113 =cut
114
115 1;