Bug 22544: Clarify documentation and change param 'type' to 'location'
[koha-ffzg.git] / Koha / NewsItem.pm
index 75dc787..cd33b51 100644 (file)
@@ -22,6 +22,8 @@ use Modern::Perl;
 use Carp;
 
 use Koha::Database;
+use Koha::DateUtils;
+use Koha::Libraries;
 use Koha::Patrons;
 
 use base qw(Koha::Object);
@@ -53,6 +55,39 @@ sub author {
     return Koha::Patron->_new_from_dbic($author_rs);
 }
 
+=head3 is_expired
+
+my $is_expired = $news_item->is_expired;
+
+Returns 1 if the news item is expired or 0;
+
+=cut
+
+sub is_expired {
+    my ( $self ) = @_;
+
+    return 0 unless $self->expirationdate;
+    return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' );
+    return 0;
+}
+
+=head3 library
+
+my $library = $news_item->library;
+
+Returns Koha::Library object or undef
+
+=cut
+
+sub library {
+    my ( $self ) = @_;
+
+    my $library_rs = $self->_result->branchcode;
+    return unless $library_rs;
+    return Koha::Library->_new_from_dbic( $library_rs );
+}
+
+
 =head3 _type
 
 =cut