1 package Koha::AdditionalContent;
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
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.
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.
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>.
23 use Koha::DateUtils qw( dt_from_string );
26 use Koha::AdditionalContentsLocalizations;
28 use base qw(Koha::Object);
32 Koha::AdditionalContent - Koha Additional content object class
42 $additional_content->author;
44 Return the Koha::Patron object for the patron who authored this additional content
50 my $author_rs = $self->_result->borrowernumber;
51 return unless $author_rs;
52 return Koha::Patron->_new_from_dbic($author_rs);
57 my $is_expired = $additional_content->is_expired;
59 Returns 1 if the additional content is expired or 0;
66 return 0 unless $self->expirationdate;
67 return 1 if dt_from_string( $self->expirationdate ) < dt_from_string->truncate( to => 'day' );
73 my $library = $additional_content->library;
75 Returns Koha::Library object or undef
82 my $library_rs = $self->_result->branchcode;
83 return unless $library_rs;
84 return Koha::Library->_new_from_dbic($library_rs);
87 =head3 translated_contents
89 my $translated_contents = $additional_content->translated_contents;
90 $additional_content->translated_contents(\@contents)
94 sub translated_contents {
95 my ( $self, $localizations ) = @_;
97 my $schema = $self->_result->result_source->schema;
100 $self->translated_contents->delete;
102 for my $localization (@$localizations) {
103 $self->_result->add_to_additional_contents_localizations($localization);
109 my $rs = $self->_result->additional_contents_localizations;
110 return Koha::AdditionalContentsLocalizations->_new_from_dbic($rs);
113 =head3 default_localization
115 my $default_content = $additional_content->default_localization;
117 Return the default content.
121 sub default_localization {
123 my $rs = $self->_result->additional_contents_localizations->find( { lang => 'default' } );
124 return Koha::AdditionalContentsLocalization->_new_from_dbic($rs);
127 =head3 translated_content
129 my $translated_content = $additional_content->translated_content($lang);
131 Return the translated content for a given language. The default is returned if none exist.
135 sub translated_content {
136 my ( $self, $lang ) = @_;
138 my $content = $self->translated_contents->search(
139 { lang => [ 'default', $lang ] },
140 { order_by => { -asc => [ \'lang="default"', 'id' ] } }
150 return 'AdditionalContent';
155 Kyle M Hall <kyle@bywatersolutions.com>