1 package Koha::AdditionalContents;
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>.
24 use Koha::AdditionalContent;
26 use base qw(Koha::Objects);
30 Koha::AdditionalContents - Koha Additional content object set class
38 =head3 search_for_display
40 my $contents = Koha::AdditionalContents->search_for_display({
41 category => 'news', # news or html_customizations
44 library_id => $branchcode
47 Return Koha::AdditionalContents set for display to user
49 You can limit the results by location, language and library by optional params
51 library_id should be valid branchcode of defined library
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
63 - OpacLoginInstructions
64 - OpacSuggestionInstructions
65 - ArticleRequestsDisclaimerText
69 sub search_for_display {
70 my ( $self, $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 $search_params->{category} = $params->{category} if $params->{category};
80 if ( $params->{lang} ) {
81 # FIXME I am failing to translate the following query
82 # SELECT a1.category, a1.code, COALESCE(a2.title, a1.title)
83 # FROM additional_contents a1
84 # LEFT JOIN additional_contents a2 on a1.code=a2.code AND a2.lang="es-ES"
85 # WHERE a1.lang = 'default';
87 # So we are retrieving the code with a translated content, then the other ones
88 my $translated_contents =
89 $self->SUPER::search( { %$search_params, lang => $params->{lang} } );
90 my $default_contents = $self->SUPER::search(
95 { '-not_in' => [ $translated_contents->get_column('code') ] }
99 return $self->SUPER::search(
102 $translated_contents->get_column('idnew'),
103 $default_contents->get_column('idnew')
106 { order_by => 'number' }
110 return $self->SUPER::search({%$search_params, lang => 'default'}, { order_by => 'number'});
113 =head3 find_best_match
115 Koha::AdditionalContents->find_best_match({
116 category => , location => , lang => , library_id =>
119 When choosing the best match, a match on lang and library is preferred.
120 Next a match on library and default lang. Then match on All libs and lang.
121 Finally a match with All libs and default lang.
125 sub find_best_match {
126 my ( $self, $params ) = @_;
127 my $library_id = $params->{library_id};
128 my $lang = $params->{lang};
130 my $rs = $self->SUPER::search({
131 category => $params->{category},
132 location => $params->{location},
133 lang => [ $lang, 'default' ],
134 branchcode => [ $library_id, undef ],
138 my ( $alt1, $alt2, $alt3 );
139 while( my $rec = $rs->next ) {
140 return $rec if $library_id && $rec->branchcode && $rec->branchcode eq $library_id && $lang && $rec->lang eq $lang;
141 $alt1 = $rec if !$alt1 && $library_id && $rec->branchcode && $rec->branchcode eq $library_id;
142 $alt2 = $rec if !$alt2 && $lang && $rec->lang eq $lang;
143 $alt3 = $rec if !$alt3;
145 return $alt1 // $alt2 // $alt3;
153 return 'AdditionalContent';
161 return 'Koha::AdditionalContent';
166 Kyle M Hall <kyle@bywatersolutions.com>