Lines 22-28
use Modern::Perl;
Link Here
|
22 |
use Carp; |
22 |
use Carp; |
23 |
|
23 |
|
24 |
use Koha::Database; |
24 |
use Koha::Database; |
25 |
|
25 |
use Koha::Exceptions; |
26 |
use Koha::NewsItem; |
26 |
use Koha::NewsItem; |
27 |
|
27 |
|
28 |
use base qw(Koha::Objects); |
28 |
use base qw(Koha::Objects); |
Lines 37-42
Koha::News - Koha News object set class
Link Here
|
37 |
|
37 |
|
38 |
=cut |
38 |
=cut |
39 |
|
39 |
|
|
|
40 |
=head3 search_for_display |
41 |
|
42 |
my $news = Koha::News->search_for_display({ |
43 |
type => '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 type(lang) 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 |
- OpanNavRight - Right column in the online catalogue |
59 |
|
60 |
lang is language code - it is used only when type is opac or OpacNavRight |
61 |
|
62 |
=cut |
63 |
|
64 |
sub search_for_display { |
65 |
my ( $self, $params ) = @_; |
66 |
|
67 |
my $search_params; |
68 |
if ($params->{type} ) { |
69 |
if ( $params->{type} eq 'slip' || $params->{type} eq 'koha') { |
70 |
$search_params->{lang} = [ $params->{type}, '' ]; |
71 |
} elsif ( $params->{type} eq 'opac' && $params->{lang} ) { |
72 |
$search_params->{lang} = [ $params->{lang}, '' ]; |
73 |
} elsif ( $params->{type} eq 'OpacNavRight' && $params->{lang} ) { |
74 |
$search_params->{lang} = $params->{type} . '_' . $params->{lang}; |
75 |
} else { |
76 |
Koha::Exceptions::BadParameter->throw("The type and lang parameters combination is not valid"); |
77 |
} |
78 |
} |
79 |
|
80 |
$search_params->{branchcode} = [ $params->{library_id}, undef ] if $params->{library_id}; |
81 |
$search_params->{timestamp} = { '<=' => \'NOW()' }; |
82 |
$search_params->{-or} = [ expirationdate => { '>=' => \'NOW()' }, |
83 |
expirationdate => undef ]; |
84 |
|
85 |
return $self->SUPER::search($search_params, { order_by => 'number' }); |
86 |
} |
87 |
|
40 |
=head3 type |
88 |
=head3 type |
41 |
|
89 |
|
42 |
=cut |
90 |
=cut |