Bug 22544: Clarify documentation and change param 'type' to 'location'
[koha-ffzg.git] / Koha / NewsItem.pm
index d2fbcc0..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);
@@ -47,10 +49,45 @@ Return the Koha::Patron object for the patron who authored this news item
 =cut
 
 sub author {
+    my ($self) = @_;
+    my $author_rs = $self->_result->borrowernumber;
+    return unless $author_rs;
+    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 ) = @_;
-    return Koha::Patron->_new_from_dbic($self->_result->borrowernumber);
+
+    my $library_rs = $self->_result->branchcode;
+    return unless $library_rs;
+    return Koha::Library->_new_from_dbic( $library_rs );
 }
 
+
 =head3 _type
 
 =cut