Bug 30459: Make BatchDeleteAuthority update the index in one request
[koha.git] / Koha / AdditionalContents.pm
1 package Koha::AdditionalContents;
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 Koha::Database;
23 use Koha::Exceptions;
24 use Koha::AdditionalContent;
25
26 use base qw(Koha::Objects);
27
28 =head1 NAME
29
30 Koha::AdditionalContents - Koha Additional content object set class
31
32 =head1 API
33
34 =head2 Class Methods
35
36 =cut
37
38 =head3 search_for_display
39
40 my $contents = Koha::AdditionalContents->search_for_display({
41     category => 'news', # news or html_customizations
42     location => 'slip',
43     lang => 'es-ES',
44     library_id => $branchcode
45 })
46
47 Return Koha::AdditionalContents 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 location is one of this:
54 - slip - for ISSUESLIP notice
55 - staff_only - for intranet
56 - opac_only - for OPAC
57 - staff_and_opac - for intranet and online catalogue
58 - OpacNavRight - Right column in the online catalogue
59 - opacheader
60 - OpacCustomSearch
61 - OpacMainUserBlock
62 - opaccredits
63 - OpacLoginInstructions
64 - OpacSuggestionInstructions
65 - ArticleRequestsDisclaimerText
66
67 =cut
68
69 sub search_for_display {
70     my ( $self, $params ) = @_;
71
72     my $search_params;
73     $search_params->{location} = $params->{location};
74     $search_params->{branchcode} = $params->{library_id} ? [ $params->{library_id}, undef ] : undef;
75     $search_params->{published_on} = { '<=' => \'CAST(NOW() AS DATE)' };
76     $search_params->{-or} = [ expirationdate => { '>=' => \'CAST(NOW() AS DATE)' },
77                               expirationdate => undef ];
78
79     if ( $params->{lang} ) {
80         # FIXME I am failing to translate the following query
81         # SELECT   a1.category,   a1.code,   COALESCE(a2.title, a1.title)
82         # FROM additional_contents a1
83         # LEFT JOIN additional_contents a2 on a1.code=a2.code AND a2.lang="es-ES"
84         # WHERE a1.lang = 'default';
85
86         # So we are retrieving the code with a translated content, then the other ones
87         my $translated_contents =
88           $self->SUPER::search( { %$search_params, lang => $params->{lang} } );
89         my $default_contents = $self->SUPER::search(
90             {
91                 %$search_params,
92                 lang => 'default',
93                 code =>
94                   { '-not_in' => [ $translated_contents->get_column('code') ] }
95             }
96         );
97
98         return $self->SUPER::search(
99             {
100                 idnew => [
101                     $translated_contents->get_column('idnew'),
102                     $default_contents->get_column('idnew')
103                 ]
104             },
105             { order_by => 'number' }
106         );
107     }
108
109     return $self->SUPER::search({%$search_params, lang => 'default'}, { order_by => 'number'});
110 }
111
112 =head3 _type
113
114 =cut
115
116 sub _type {
117     return 'AdditionalContent';
118 }
119
120 =head3 object_class
121
122 =cut
123
124 sub object_class {
125     return 'Koha::AdditionalContent';
126 }
127
128 =head1 AUTHOR
129
130 Kyle M Hall <kyle@bywatersolutions.com>
131
132 =cut
133
134 1;