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

(-)a/C4/Letters.pm (-5 / +158 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 33-43 use C4::Debug; Link Here
33
use Koha::DateUtils;
38
use Koha::DateUtils;
34
use Koha::SMS::Providers;
39
use Koha::SMS::Providers;
35
40
36
use Date::Calc qw( Add_Delta_Days );
37
use Encode;
38
use Carp;
39
use Koha::Email;
41
use Koha::Email;
40
use Koha::DateUtils qw( format_sqldatetime );
42
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
43
42
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
44
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
43
45
Lines 717-724 sub GetPreparedLetter { Link Here
717
        }
719
        }
718
    }
720
    }
719
721
722
    $letter->{content} = _process_tt(
723
        {
724
            content => $letter->{content},
725
            tables  => $tables,
726
        }
727
    );
728
720
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
729
    $letter->{content} =~ s/<<\S*>>//go; #remove any stragglers
721
#   $letter->{content} =~ s/<<[^>]*>>//go;
722
730
723
    return $letter;
731
    return $letter;
724
}
732
}
Lines 1376-1381 sub _set_message_status { Link Here
1376
    return $result;
1384
    return $result;
1377
}
1385
}
1378
1386
1387
sub _process_tt {
1388
    my ( $params ) = @_;
1389
1390
    my $content = $params->{content};
1391
    my $tables = $params->{tables};
1392
1393
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1394
    my $template           = Template->new(
1395
        {
1396
            EVAL_PERL    => 1,
1397
            ABSOLUTE     => 1,
1398
            PLUGIN_BASE  => 'Koha::Template::Plugin',
1399
            COMPILE_EXT  => $use_template_cache ? '.ttc' : '',
1400
            COMPILE_DIR  => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1401
            FILTERS      => {},
1402
            ENCODING     => 'UTF-8',
1403
        }
1404
    ) or die Template->error();
1405
1406
    my $tt_params = _get_tt_params( $tables );
1407
1408
    my $output;
1409
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
1410
1411
    return $output;
1412
}
1413
1414
sub _get_tt_params {
1415
    my ($tables) = @_;
1416
1417
    my $params;
1418
1419
    my $config = {
1420
        biblio => {
1421
            module   => 'Koha::Biblios',
1422
            singular => 'biblio',
1423
            plural   => 'biblios',
1424
            pk       => 'biblionumber',
1425
        },
1426
        borrowers => { #FIXME: Bug 15548 will require this to be updated
1427
            module   => 'Koha::Borrowers', # to Koha::Patrons
1428
            singular => 'borrower',
1429
            plural   => 'borrowers',
1430
            pk       => 'borrowernumber',
1431
        },
1432
        branches => {
1433
            module   => 'Koha::Libraries',
1434
            singular => 'branch',
1435
            plural   => 'branches',
1436
            pk       => 'branchcode',
1437
        },
1438
        items => {
1439
            module   => 'Koha::Items',
1440
            singular => 'item',
1441
            plural   => 'items',
1442
            pk       => 'itemnumber',
1443
        },
1444
        opac_news => {
1445
            module   => 'Koha::News',
1446
            singular => 'news',
1447
            plural   => 'news',
1448
            pk       => 'idnew',
1449
        },
1450
        reserves => {
1451
            module   => 'Koha::Holds',
1452
            singular => 'hold',
1453
            plural   => 'holds',
1454
            fk       => [ 'borrowernumber', 'biblionumber' ],
1455
        },
1456
        serial => {
1457
            module   => 'Koha::Serials',
1458
            singular => 'serial',
1459
            plural   => 'serials',
1460
            pk       => 'serialid',
1461
        },
1462
        subscription => {
1463
            module   => 'Koha::Subscriptions',
1464
            singular => 'subscription',
1465
            plural   => 'subscriptions',
1466
            pk       => 'subscriptionid',
1467
        },
1468
        suggestions => {
1469
            module   => 'Koha::Suggestions',
1470
            singular => 'suggestion',
1471
            plural   => 'suggestions',
1472
            pk       => 'suggestionid',
1473
        },
1474
        issues => {
1475
            module   => 'Koha::Checkouts',
1476
            singular => 'checkout',
1477
            plural   => 'checkouts',
1478
            fk       => 'itemnumber',
1479
        },
1480
        borrower_modifications => {
1481
            module   => 'Koha::Borrower::Modifications',
1482
            singular => 'patron_modification',
1483
            plural   => 'patron_modifications',
1484
            fk       => 'verification_token',
1485
        },
1486
    };
1487
1488
    foreach my $table ( keys %$tables ) {
1489
        next unless $config->{$table};
1490
1491
        my $ref = ref( $tables->{$table} ) || q{};
1492
        my $module = $config->{$table}->{module};
1493
1494
        if ( can_load( modules => { $module => undef } ) ) {
1495
            my $pk = $config->{$table}->{pk};
1496
            my $fk = $config->{$table}->{fk};
1497
1498
            if ( $ref eq q{} || $ref eq 'HASH' ) {
1499
                my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table};
1500
                my $object;
1501
                if ( $fk ) { # Using a foreign key for lookup
1502
                    $object = $module->search( { $fk => $id } )->next();
1503
                } else { # using the table's primary key for lookup
1504
                    $object = $module->find($id);
1505
                }
1506
                $params->{ $config->{$table}->{singular} } = $object;
1507
            }
1508
            else {    # $ref eq 'ARRAY'
1509
                my $object;
1510
                if ( @{ $tables->{$table} } == 1 ) {    # Param is a single key
1511
                    $object = $module->search( { $pk => $tables->{$table} } )->next();
1512
                }
1513
                else {                                  # Params are mutliple foreign keys
1514
                    my @values = @{ $tables->{$table} };
1515
                    my @keys   = @{ $config->{$table}->{fk} };
1516
                    my %params = map { $_ => shift(@values) } @keys;
1517
                    $object = $module->search( \%params )->next();
1518
                }
1519
                $params->{ $config->{$table}->{singular} } = $object;
1520
            }
1521
        }
1522
        else {
1523
            croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR";
1524
        }
1525
    }
1526
1527
    $params->{today} = dt_from_string();
1528
1529
    return $params;
1530
}
1531
1379
1532
1380
1;
1533
1;
1381
__END__
1534
__END__
(-)a/Koha/Borrower/Modification.pm (+52 lines)
Line 0 Link Here
1
package Koha::Borrower::Modification;
2
3
# Copyright ByWater Solutions 2014
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 base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Item - Koha Item object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'BorrowerModification';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Checkout.pm (+52 lines)
Line 0 Link Here
1
package Koha::Checkout;
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 base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Checkout - Koha Checkout object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'Issue';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
1;
(-)a/Koha/Checkouts.pm (+62 lines)
Line 0 Link Here
1
package Koha::Checkouts;
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::Checkout;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Checkouts - Koha Checkout 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 'Issue';
46
}
47
48
=head3 object_class
49
50
=cut
51
52
sub object_class {
53
    return 'Koha::Checkout';
54
}
55
56
=head1 AUTHOR
57
58
Kyle M Hall <kyle@bywatersolutions.com>
59
60
=cut
61
62
1;
(-)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 (+54 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 base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::NewsItem - Koha News Item object class
31
32
Koha::NewsItem represents a single piece of news from the opac_news table
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
=head1 AUTHOR
49
50
Kyle M Hall <kyle@bywatersolutions.com>
51
52
=cut
53
54
1;
(-)a/Koha/Patron/Modifications.pm (-2 / +22 lines)
Lines 27-36 use Modern::Perl; Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Debug;
28
use C4::Debug;
29
29
30
use base qw(Koha::Objects);
31
30
sub new {
32
sub new {
31
    my ( $class, %args ) = @_;
33
    my ( $self, %args ) = @_;
34
35
    $self = $self->SUPER::new(@_);
36
37
    foreach my $key ( keys %args ) {
38
        $self->{$key} = $args{$key};
39
    }
32
40
33
    return bless( \%args, $class );
41
    return $self;
34
}
42
}
35
43
36
=head2 AddModifications
44
=head2 AddModifications
Lines 304-307 sub GetModifications { Link Here
304
    return $data;
312
    return $data;
305
}
313
}
306
314
315
sub type {
316
    return 'BorrowerModification';
317
}
318
319
=head3 object_class
320
321
=cut
322
323
sub object_class {
324
    return 'Koha::Borrower::Modification';
325
}
326
307
1;
327
1;
(-)a/Koha/Suggestion.pm (+52 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 base qw(Koha::Object);
27
28
=head1 NAME
29
30
Koha::Suggestion - Koha Suggestion object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 type
39
40
=cut
41
42
sub type {
43
    return 'Suggestion';
44
}
45
46
=head1 AUTHOR
47
48
Kyle M Hall <kyle@bywatersolutions.com>
49
50
=cut
51
52
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