View | Details | Raw Unified | Return to bug 14757
Collapse All | Expand All

(-)a/C4/Letters.pm (-5 / +131 lines)
Lines 22-27 use warnings; Link Here
22
22
23
use MIME::Lite;
23
use MIME::Lite;
24
use Mail::Sendmail;
24
use Mail::Sendmail;
25
use Date::Calc qw( Add_Delta_Days );
26
use Encode;
27
use Carp;
28
use Template;
29
use Module::Load::Conditional qw(can_load);
25
30
26
use C4::Koha qw(GetAuthorisedValueByCode);
31
use C4::Koha qw(GetAuthorisedValueByCode);
27
use C4::Members;
32
use C4::Members;
Lines 31-41 use C4::Log; Link Here
31
use C4::SMS;
36
use C4::SMS;
32
use C4::Debug;
37
use C4::Debug;
33
use Koha::DateUtils;
38
use Koha::DateUtils;
34
use Date::Calc qw( Add_Delta_Days );
35
use Encode;
36
use Carp;
37
use Koha::Email;
39
use Koha::Email;
38
use Koha::DateUtils qw( format_sqldatetime );
40
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
39
41
40
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
42
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
41
43
Lines 715-722 sub GetPreparedLetter { Link Here
715
        }
717
        }
716
    }
718
    }
717
719
720
    $letter->{content} = _process_tt(
721
        {
722
            content => $letter->{content},
723
            tables  => $tables,
724
        }
725
    );
726
718
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
727
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
719
#   $letter->{content} =~ s/<<[^>]*>>//go;
720
728
721
    return $letter;
729
    return $letter;
722
}
730
}
Lines 1316-1321 sub _set_message_status { Link Here
1316
    return $result;
1324
    return $result;
1317
}
1325
}
1318
1326
1327
sub _process_tt {
1328
    my ( $params ) = @_;
1329
1330
    my $content = $params->{content};
1331
    my $tables = $params->{tables};
1332
1333
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1334
    my $template           = Template->new(
1335
        {
1336
            EVAL_PERL    => 1,
1337
            ABSOLUTE     => 1,
1338
            PLUGIN_BASE  => 'Koha::Template::Plugin',
1339
            COMPILE_EXT  => $use_template_cache ? '.ttc' : '',
1340
            COMPILE_DIR  => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1341
            FILTERS      => {},
1342
            ENCODING     => 'UTF-8',
1343
        }
1344
    ) or die Template->error();
1345
1346
    my $tt_params = _get_tt_params( $tables );
1347
1348
    my $output;
1349
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
1350
1351
    return $output;
1352
}
1353
1354
sub _get_tt_params {
1355
    my ($tables) = @_;
1356
1357
    my $params;
1358
1359
    my $config = {
1360
        biblio => {
1361
            module   => 'Koha::Biblios',
1362
            singular => 'biblio',
1363
            plural   => 'biblios',
1364
            pk       => 'biblionumber',
1365
        },
1366
        borrowers => { #FIXME: Bug 15548 will require this to be updated
1367
            module   => 'Koha::Borrowers', # to Koha::Patrons
1368
            singular => 'borrower',
1369
            plural   => 'borrowers',
1370
            pk       => 'borrowernumber',
1371
        },
1372
        branches => {
1373
            module   => 'Koha::Libraries',
1374
            singular => 'branch',
1375
            plural   => 'branches',
1376
            pk       => 'branchcode',
1377
        },
1378
        items => {
1379
            module   => 'Koha::Items',
1380
            singular => 'item',
1381
            plural   => 'items',
1382
            pk       => 'itemnumber',
1383
        },
1384
        opac_news => {
1385
            module   => 'Koha::News',
1386
            singular => 'news',
1387
            plural   => 'news',
1388
            pk       => 'idnew',
1389
        },
1390
        reserves => {
1391
            module   => 'Koha::Holds',
1392
            singular => 'hold',
1393
            plural   => 'holds',
1394
            pk       => 'reserve_id',
1395
        },
1396
        serial => {
1397
            module   => 'Koha::Serials',
1398
            singular => 'serial',
1399
            plural   => 'serials',
1400
            pk       => 'serialid',
1401
        },
1402
        subscription => {
1403
            module   => 'Koha::Subscriptions',
1404
            singular => 'subscription',
1405
            plural   => 'subscriptions',
1406
            pk       => 'subscriptionid',
1407
        },
1408
        suggestions => {
1409
            module   => 'Koha::Suggestions',
1410
            singular => 'suggestion',
1411
            plural   => 'suggestions',
1412
            pk       => 'suggestionid',
1413
        },
1414
    };
1415
1416
    foreach my $table ( keys %$tables ) {
1417
        next unless $config->{$table};
1418
1419
        my $ref = ref( $tables->{$table} ) || q{};
1420
        my $module = $config->{$table}->{module};
1421
1422
        if ( can_load( modules => { $module => undef } ) ) {
1423
            my $pk = $config->{$table}->{pk};
1424
1425
            if ( $ref eq q{} || $ref eq 'HASH' ) {
1426
                my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table};
1427
                my $object = $module->find($id);
1428
                $params->{ $config->{$table}->{singular} } = $object;
1429
            }
1430
            else {    # $ref eq 'ARRAY'
1431
                my $objects = $module->search( { $pk => $tables->{$table} } );
1432
                $params->{ $config->{$table}->{plural} } = $objects;
1433
            }
1434
        }
1435
        else {
1436
            croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR";
1437
        }
1438
    }
1439
1440
    $params->{today} = dt_from_string();
1441
1442
    return $params;
1443
}
1444
1319
1445
1320
1;
1446
1;
1321
__END__
1447
__END__
(-)a/Koha/News.pm (+62 lines)
Line 0 Link Here
1
package Koha::News;
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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::NewsItem;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::News - Koha News object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'OpacNews';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::NewsItem';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
(-)a/Koha/NewsItem.pm (+56 lines)
Line 0 Link Here
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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Branches;
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 type
43
44
=cut
45
46
sub type {
47
    return 'OpacNews';
48
}
49
50
=head1 AUTHOR
51
52
Kyle M Hall <kyle@bywatersolutions.com>
53
54
=cut
55
56
1;
(-)a/Koha/Suggestion.pm (+54 lines)
Line 0 Link Here
1
package Koha::Suggestion;
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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Branches;
27
28
use base qw(Koha::Object);
29
30
=head1 NAME
31
32
Koha::Suggestion - Koha Suggestion object class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'Suggestion';
46
}
47
48
=head1 AUTHOR
49
50
Kyle M Hall <kyle@bywatersolutions.com>
51
52
=cut
53
54
1;
(-)a/Koha/Suggestions.pm (-1 / +62 lines)
Line 0 Link Here
0
- 
1
package Koha::Suggestions;
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 under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use Carp;
23
24
use Koha::Database;
25
26
use Koha::Suggestion;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Suggestions - Koha Suggestion object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=cut
39
40
=head3 type
41
42
=cut
43
44
sub type {
45
    return 'Suggestion';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Suggestion';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;

Return to bug 14757