@@ -, +, @@ slips and notices ---- ---- --- C4/Letters.pm | 136 +++++++++++++++++++++++++++++++++++++++++++++++-- Koha/News.pm | 62 ++++++++++++++++++++++ Koha/NewsItem.pm | 56 ++++++++++++++++++++ Koha/Serial.pm | 54 ++++++++++++++++++++ Koha/Serials.pm | 62 ++++++++++++++++++++++ Koha/Subscription.pm | 54 ++++++++++++++++++++ Koha/Subscriptions.pm | 62 ++++++++++++++++++++++ Koha/Suggestion.pm | 54 ++++++++++++++++++++ Koha/Suggestions.pm | 62 ++++++++++++++++++++++ 9 files changed, 597 insertions(+), 5 deletions(-) create mode 100644 Koha/News.pm create mode 100644 Koha/NewsItem.pm create mode 100644 Koha/Serial.pm create mode 100644 Koha/Serials.pm create mode 100644 Koha/Subscription.pm create mode 100644 Koha/Subscriptions.pm create mode 100644 Koha/Suggestion.pm create mode 100644 Koha/Suggestions.pm --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -22,6 +22,11 @@ use warnings; use MIME::Lite; use Mail::Sendmail; +use Date::Calc qw( Add_Delta_Days ); +use Encode; +use Carp; +use Template; +use Module::Load::Conditional qw(can_load); use C4::Koha qw(GetAuthorisedValueByCode); use C4::Members; @@ -31,11 +36,8 @@ use C4::Log; use C4::SMS; use C4::Debug; use Koha::DateUtils; -use Date::Calc qw( Add_Delta_Days ); -use Encode; -use Carp; use Koha::Email; -use Koha::DateUtils qw( format_sqldatetime ); +use Koha::DateUtils qw( format_sqldatetime dt_from_string ); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -713,8 +715,14 @@ sub GetPreparedLetter { } } + $letter->{content} = _process_tt( + { + content => $letter->{content}, + tables => $tables, + } + ); + $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers -# $letter->{content} =~ s/<<[^>]*>>//go; return $letter; } @@ -1310,6 +1318,124 @@ sub _set_message_status { return $result; } +sub _process_tt { + my ( $params ) = @_; + + my $content = $params->{content}; + my $tables = $params->{tables}; + + my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; + my $template = Template->new( + { + EVAL_PERL => 1, + ABSOLUTE => 1, + PLUGIN_BASE => 'Koha::Template::Plugin', + COMPILE_EXT => $use_template_cache ? '.ttc' : '', + COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', + FILTERS => {}, + ENCODING => 'UTF-8', + } + ) or die Template->error(); + + my $tt_params = _get_tt_params( $tables ); + + my $output; + $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); + + return $output; +} + +sub _get_tt_params { + my ($tables) = @_; + + my $params; + + my $config = { + biblio => { + module => 'Koha::Biblios', + singular => 'biblio', + plural => 'biblios', + pk => 'biblionumber', + }, + borrowers => { + module => 'Koha::Borrowers', + singular => 'borrower', + plural => 'borrowers', + pk => 'borrowernumber', + }, + branches => { + module => 'Koha::Branches', + singular => 'branch', + plural => 'branches', + pk => 'branchcode', + }, + items => { + module => 'Koha::Items', + singular => 'item', + plural => 'items', + pk => 'itemnumber', + }, + opac_news => { + module => 'Koha::News', + singular => 'news', + plural => 'news', + pk => 'idnew', + }, + reserves => { + module => 'Koha::Holds', + singular => 'hold', + plural => 'holds', + pk => 'reserve_id', + }, + serial => { + module => 'Koha::Serials', + singular => 'serial', + plural => 'serials', + pk => 'serialid', + }, + subscription => { + module => 'Koha::Subscriptions', + singular => 'subscription', + plural => 'subscriptions', + pk => 'subscriptionid', + }, + suggestions => { + module => 'Koha::Suggestions', + singular => 'suggestion', + plural => 'suggestions', + pk => 'suggestionid', + }, + }; + + foreach my $table ( keys %$tables ) { + next unless $config->{$table}; + + my $ref = ref( $tables->{$table} ) || q{}; + my $module = $config->{$table}->{module}; + + if ( can_load( modules => { $module => undef } ) ) { + my $pk = $config->{$table}->{pk}; + + if ( $ref eq q{} || $ref eq 'HASH' ) { + my $id = ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; + my $object = $module->find($id); + $params->{ $config->{$table}->{singular} } = $object; + } + else { # $ref eq 'ARRAY' + my $objects = $module->search( { $pk => $tables->{$table} } ); + $params->{ $config->{$table}->{plural} } = $objects; + } + } + else { + croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR"; + } + } + + $params->{today} = dt_from_string(); + + return $params; +} + 1; __END__ --- a/Koha/News.pm +++ a/Koha/News.pm @@ -0,0 +1,62 @@ +package Koha::News; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::NewsItem; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::News - Koha News object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'OpacNews'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::NewsItem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/NewsItem.pm +++ a/Koha/NewsItem.pm @@ -0,0 +1,56 @@ +package Koha::NewsItem; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Branches; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::NewsItem - Koha News Item object class + +Koha::NewsItem represents a single piece of news from the opac_news table + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'OpacNews'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Serial.pm +++ a/Koha/Serial.pm @@ -0,0 +1,54 @@ +package Koha::Serial; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Branches; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Serial - Koha Serial object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Serial'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Serials.pm +++ a/Koha/Serials.pm @@ -0,0 +1,62 @@ +package Koha::Serials; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Serial; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Serials - Koha Serial object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Serial'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Serial'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Subscription.pm +++ a/Koha/Subscription.pm @@ -0,0 +1,54 @@ +package Koha::Subscription; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Branches; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Subscription - Koha Subscription object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Subscription'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Subscriptions.pm +++ a/Koha/Subscriptions.pm @@ -0,0 +1,62 @@ +package Koha::Subscriptions; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Subscription; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Subscriptions - Koha Subscription object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Subscription'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Subscription'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Suggestion.pm +++ a/Koha/Suggestion.pm @@ -0,0 +1,54 @@ +package Koha::Suggestion; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Branches; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Suggestion - Koha Suggestion object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Suggestion'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --- a/Koha/Suggestions.pm +++ a/Koha/Suggestions.pm @@ -0,0 +1,62 @@ +package Koha::Suggestions; + +# Copyright ByWater Solutions 2015 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Suggestion; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Suggestions - Koha Suggestion object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Suggestion'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Suggestion'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; --