Bug 22435: Fix _set_found_trigger
[koha.git] / Koha / NewsItem.pm
1 package Koha::NewsItem;
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
23 use Koha::Database;
24 use Koha::DateUtils qw( dt_from_string );
25 use Koha::Libraries;
26 use Koha::Patrons;
27
28 use base qw(Koha::Object);
29
30 =head1 NAME
31
32 Koha::NewsItem - Koha News Item object class
33
34 Koha::NewsItem represents a single piece of news from the opac_news table
35
36 =head1 API
37
38 =head2 Class Methods
39
40 =cut
41
42 =head3 author
43
44     $newsitem->author;
45
46 Return the Koha::Patron object for the patron who authored this news item
47
48 =cut
49
50 sub author {
51     my ($self) = @_;
52     my $author_rs = $self->_result->borrowernumber;
53     return unless $author_rs;
54     return Koha::Patron->_new_from_dbic($author_rs);
55 }
56
57 =head3 is_expired
58
59 my $is_expired = $news_item->is_expired;
60
61 Returns 1 if the news item is expired or 0;
62
63 =cut
64
65 sub is_expired {
66     my ( $self ) = @_;
67
68     return 0 unless $self->expirationdate;
69     return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' );
70     return 0;
71 }
72
73 =head3 library
74
75 my $library = $news_item->library;
76
77 Returns Koha::Library object or undef
78
79 =cut
80
81 sub library {
82     my ( $self ) = @_;
83
84     my $library_rs = $self->_result->branchcode;
85     return unless $library_rs;
86     return Koha::Library->_new_from_dbic( $library_rs );
87 }
88
89
90 =head3 _type
91
92 =cut
93
94 sub _type {
95     return 'OpacNews';
96 }
97
98 =head1 AUTHOR
99
100 Kyle M Hall <kyle@bywatersolutions.com>
101
102 =cut
103
104 1;