Bug 22544: Clarify documentation and change param 'type' to 'location'

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Josef Moravec 2021-01-18 10:33:21 +01:00 committed by Jonathan Druart
parent ec6d2900b4
commit 98392c82ee
7 changed files with 26 additions and 26 deletions

View File

@ -589,7 +589,7 @@ sub IssueSlip {
};
}
my $news = Koha::News->search_for_display({
type => 'slip',
location => 'slip',
library_id => $branch,
});
my @news;

View File

@ -40,14 +40,14 @@ Koha::News - Koha News object set class
=head3 search_for_display
my $news = Koha::News->search_for_display({
type => 'slip',
location => 'slip',
lang => 'en',
library_id => $branchcode
})
Return Koha::News set for display to user
You can limit the results by type(lang) and library by optional params
You can limit the results by location, language and library by optional params
library_id should be valid branchcode of defined library
@ -62,7 +62,7 @@ type is one of this:
- opacheader
- opaccredits
lang is language code - it is used only when type is opac or OpacNavRight
lang is language code - it is used only when type is opac or any of OPAC locations
=cut
@ -70,15 +70,15 @@ sub search_for_display {
my ( $self, $params ) = @_;
my $search_params;
if ($params->{type} ) {
if ( $params->{type} eq 'slip' || $params->{type} eq 'koha') {
$search_params->{lang} = [ $params->{type}, '' ];
} elsif ( $params->{type} eq 'opac' && $params->{lang} ) {
if ($params->{location} ) {
if ( $params->{location} eq 'slip' || $params->{location} eq 'koha') {
$search_params->{lang} = [ $params->{location}, '' ];
} elsif ( $params->{location} eq 'opac' && $params->{lang} ) {
$search_params->{lang} = [ $params->{lang}, '' ];
} elsif ( $params->{lang} ) {
$search_params->{lang} = $params->{type} . '_' . $params->{lang};
$search_params->{lang} = $params->{location} . '_' . $params->{lang};
} else {
Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid");
Koha::Exceptions::BadParameter->throw("The location and lang parameters combination is not valid");
}
}

View File

@ -37,7 +37,7 @@ sub get {
my $library = $params->{library};
my $content = Koha::News->search_for_display({
type => $display_location,
location => $display_location,
lang => $lang,
library_id => $library,
});

View File

@ -50,7 +50,7 @@ if (C4::Context->userenv) {
$homebranch = C4::Context->userenv->{'branch'};
}
my $koha_news = Koha::News->search_for_display({
type => 'koha',
location => 'koha',
library_id => $homebranch
});

View File

@ -71,7 +71,7 @@ if (defined $news_id){
}
} else {
$koha_news = Koha::News->search_for_display({
type => 'opac',
location => 'opac',
lang => $template->lang,
library_id => $homebranch,
});

View File

@ -44,7 +44,7 @@ my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Con
my $branchcode = $input->param('branchcode');
my $koha_news = Koha::News->search_for_display({
type => 'opac',
location => 'opac',
lang => $news_lang,
library_id => $branchcode,
});

View File

@ -220,22 +220,22 @@ subtest '->search_for_display' => sub {
is($news->count, 4, 'Active and not expired news');
is($news->next->number, 2, 'News items are returned in correct order');
$news = Koha::News->search_for_display({ type => 'slip'});
is($news->count, 2, 'Slip and all type returned');
$news = Koha::News->search_for_display({ location => 'slip'});
is($news->count, 2, 'Slip and "all" locations returned');
$news = Koha::News->search_for_display({ type => 'koha'});
is($news->count, 3, 'Intranet and all');
$news = Koha::News->search_for_display({ location => 'koha'});
is($news->count, 3, 'Intranet and "all"');
$new_not_expired->lang('OpacNavRight_en')->store;
$news = Koha::News->search_for_display({ type => 'OpacNavRight', lang => 'en'});
$news = Koha::News->search_for_display({ location => 'OpacNavRight', lang => 'en'});
is($news->count, 1, 'OpacNavRight');
is($news->next->idnew, $new_not_expired->idnew, 'Returned the right new item');
$new_intra->lang('')->store;
$news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
is($news->count, 1, 'Only all type is returned');
$news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
is($news->count, 1, 'Only opac news are returned');
$new_not_expired->lang('en')->store;
$news = Koha::News->search_for_display({ type => 'opac', lang => 'en'});
$news = Koha::News->search_for_display({ location => 'opac', lang => 'en'});
is($news->count, 2, 'Opac en and all is returned');
$news = Koha::News->search_for_display({ library_id => $library1->branchcode });
@ -248,11 +248,11 @@ subtest '->search_for_display' => sub {
$news = Koha::News->search_for_display({ library_id => $library2->branchcode});
is($news->count, 2, 'Filtering by library returns right number of news items');
$news = Koha::News->search_for_display({ type => 'NonExistantType', lang => 'en'});
is($news->count, 0, 'Non-existant type is searched, but should not find any item');
$news = Koha::News->search_for_display({ location => 'NonExistantType', lang => 'en'});
is($news->count, 0, 'Non-existant location is searched, but should not find any item');
throws_ok { Koha::News->search_for_display({type => 'opac'}) } 'Koha::Exceptions::BadParameter',
'Exception raised when type is opac and no language given';
throws_ok { Koha::News->search_for_display({ location => 'opac'}) } 'Koha::Exceptions::BadParameter',
'Exception raised when location is opac and no language given';
$schema->storage->txn_rollback;
};