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 1326-1331 sub _set_message_status { Link Here
1326
    return $result;
1334
    return $result;
1327
}
1335
}
1328
1336
1337
sub _process_tt {
1338
    my ( $params ) = @_;
1339
1340
    my $content = $params->{content};
1341
    my $tables = $params->{tables};
1342
1343
    my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
1344
    my $template           = Template->new(
1345
        {
1346
            EVAL_PERL    => 1,
1347
            ABSOLUTE     => 1,
1348
            PLUGIN_BASE  => 'Koha::Template::Plugin',
1349
            COMPILE_EXT  => $use_template_cache ? '.ttc' : '',
1350
            COMPILE_DIR  => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
1351
            FILTERS      => {},
1352
            ENCODING     => 'UTF-8',
1353
        }
1354
    ) or die Template->error();
1355
1356
    my $tt_params = _get_tt_params( $tables );
1357
1358
    my $output;
1359
    $template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error();
1360
1361
    return $output;
1362
}
1363
1364
sub _get_tt_params {
1365
    my ($tables) = @_;
1366
1367
    my $params;
1368
1369
    my $config = {
1370
        biblio => {
1371
            module   => 'Koha::Biblios',
1372
            singular => 'biblio',
1373
            plural   => 'biblios',
1374
            pk       => 'biblionumber',
1375
        },
1376
        borrowers => { #FIXME: Bug 15548 will require this to be updated
1377
            module   => 'Koha::Borrowers', # to Koha::Patrons
1378
            singular => 'borrower',
1379
            plural   => 'borrowers',
1380
            pk       => 'borrowernumber',
1381
        },
1382
        branches => {
1383
            module   => 'Koha::Libraries',
1384
            singular => 'branch',
1385
            plural   => 'branches',
1386
            pk       => 'branchcode',
1387
        },
1388
        items => {
1389
            module   => 'Koha::Items',
1390
            singular => 'item',
1391
            plural   => 'items',
1392
            pk       => 'itemnumber',
1393
        },
1394
        opac_news => {
1395
            module   => 'Koha::News',
1396
            singular => 'news',
1397
            plural   => 'news',
1398
            pk       => 'idnew',
1399
        },
1400
        reserves => {
1401
            module   => 'Koha::Holds',
1402
            singular => 'hold',
1403
            plural   => 'holds',
1404
            fk       => [ 'borrowernumber', 'biblionumber' ],
1405
        },
1406
        serial => {
1407
            module   => 'Koha::Serials',
1408
            singular => 'serial',
1409
            plural   => 'serials',
1410
            pk       => 'serialid',
1411
        },
1412
        subscription => {
1413
            module   => 'Koha::Subscriptions',
1414
            singular => 'subscription',
1415
            plural   => 'subscriptions',
1416
            pk       => 'subscriptionid',
1417
        },
1418
        suggestions => {
1419
            module   => 'Koha::Suggestions',
1420
            singular => 'suggestion',
1421
            plural   => 'suggestions',
1422
            pk       => 'suggestionid',
1423
        },
1424
        issues => {
1425
            module   => 'Koha::Checkouts',
1426
            singular => 'checkout',
1427
            plural   => 'checkouts',
1428
            fk       => 'itemnumber',
1429
        },
1430
        borrower_modifications => {
1431
            module   => 'Koha::Borrower::Modifications',
1432
            singular => 'patron_modification',
1433
            plural   => 'patron_modifications',
1434
            fk       => 'verification_token',
1435
        },
1436
    };
1437
1438
    foreach my $table ( keys %$tables ) {
1439
        next unless $config->{$table};
1440
1441
        my $ref = ref( $tables->{$table} ) || q{};
1442
        my $module = $config->{$table}->{module};
1443
1444
        if ( can_load( modules => { $module => undef } ) ) {
1445
            my $pk = $config->{$table}->{pk};
1446
            my $fk = $config->{$table}->{fk};
1447
1448
            if ( $ref eq q{} || $ref eq 'HASH' ) {
1449
                my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table};
1450
                my $object;
1451
                if ( $fk ) { # Using a foreign key for lookup
1452
                    $object = $module->search( { $fk => $id } )->next();
1453
                } else { # using the table's primary key for lookup
1454
                    $object = $module->find($id);
1455
                }
1456
                $params->{ $config->{$table}->{singular} } = $object;
1457
            }
1458
            else {    # $ref eq 'ARRAY'
1459
                my $object;
1460
                if ( @{ $tables->{$table} } == 1 ) {    # Param is a single key
1461
                    $object = $module->search( { $pk => $tables->{$table} } )->next();
1462
                }
1463
                else {                                  # Params are mutliple foreign keys
1464
                    my @values = @{ $tables->{$table} };
1465
                    my @keys   = @{ $config->{$table}->{fk} };
1466
                    my %params = map { $_ => shift(@values) } @keys;
1467
                    $object = $module->search( \%params )->next();
1468
                }
1469
                $params->{ $config->{$table}->{singular} } = $object;
1470
            }
1471
        }
1472
        else {
1473
            croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR";
1474
        }
1475
    }
1476
1477
    $params->{today} = dt_from_string();
1478
1479
    return $params;
1480
}
1481
1329
1482
1330
1;
1483
1;
1331
__END__
1484
__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/Borrower/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/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/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