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

(-)a/C4/SIP/ILS/Patron.pm (-7 / +40 lines)
Lines 15-21 use Carp; Link Here
15
use Sys::Syslog qw(syslog);
15
use Sys::Syslog qw(syslog);
16
use Data::Dumper;
16
use Data::Dumper;
17
17
18
use C4::SIP::Sip qw(add_field);
18
use C4::SIP::Sip qw(add_field maybe_add);
19
19
20
use C4::Debug;
20
use C4::Debug;
21
use C4::Context;
21
use C4::Context;
Lines 212-218 sub AUTOLOAD { Link Here
212
    }
212
    }
213
}
213
}
214
214
215
sub name {
215
=head2 format
216
217
This method uses a template to build a string from a Koha::Patron object
218
If errors are encountered in processing template we log them and return nothing
219
220
=cut
221
222
sub format {
216
    my ( $self, $template ) = @_;
223
    my ( $self, $template ) = @_;
217
224
218
    if ($template) {
225
    if ($template) {
Lines 224-235 sub name { Link Here
224
        my $patron = Koha::Patrons->find( $self->{borrowernumber} );
231
        my $patron = Koha::Patrons->find( $self->{borrowernumber} );
225
232
226
        my $output;
233
        my $output;
227
        $tt->process( \$template, { patron => $patron }, \$output );
234
        eval {
235
            $tt->process( \$template, { patron => $patron }, \$output );
236
        };
237
        if ( $@ ){
238
            syslog("LOG_DEBUG", "Error processing template: $template");
239
            return "";
240
        }
228
        return $output;
241
        return $output;
229
    }
242
    }
230
    else {
231
        return $self->{name};
232
    }
233
}
243
}
234
244
235
sub check_password {
245
sub check_password {
Lines 524-530 sub build_patron_attributes_string { Link Here
524
    my ( $self, $server ) = @_;
534
    my ( $self, $server ) = @_;
525
535
526
    my $string = q{};
536
    my $string = q{};
527
528
    if ( $server->{account}->{patron_attribute} ) {
537
    if ( $server->{account}->{patron_attribute} ) {
529
        my @attributes_to_send =
538
        my @attributes_to_send =
530
          ref $server->{account}->{patron_attribute} eq "ARRAY"
539
          ref $server->{account}->{patron_attribute} eq "ARRAY"
Lines 549-554 sub build_patron_attributes_string { Link Here
549
    return $string;
558
    return $string;
550
}
559
}
551
560
561
562
=head2 build_custom_field_string
563
564
This method builds the part of the sip message for custom patron fields as defined in the sip config
565
566
=cut
567
568
sub build_custom_field_string {
569
    my ( $self, $server ) = @_;
570
571
    my $string = q{};
572
573
    if ( $server->{account}->{custom_patron_field} ) {
574
        my @custom_fields =
575
            ref $server->{account}->{custom_patron_field} eq "ARRAY"
576
            ? @{ $server->{account}->{custom_patron_field} }
577
            : $server->{account}->{custom_patron_field};
578
        foreach my $custom_field ( @custom_fields ) {
579
            $string .= maybe_add( $custom_field->{field}, $self->format( $custom_field->{template} ) ) if defined $custom_field->{field};
580
        }
581
    }
582
    return $string;
583
}
584
552
1;
585
1;
553
__END__
586
__END__
554
587
(-)a/C4/SIP/Sip.pm (-1 lines)
Lines 108-114 sub maybe_add { Link Here
108
            $value =~ s/$regex->{find}/$regex->{replace}/g;
108
            $value =~ s/$regex->{find}/$regex->{replace}/g;
109
        }
109
        }
110
    }
110
    }
111
112
    return (defined($value) && $value) ? add_field($fid, $value) : '';
111
    return (defined($value) && $value) ? add_field($fid, $value) : '';
113
}
112
}
114
113
(-)a/C4/SIP/Sip/MsgType.pm (-3 / +14 lines)
Lines 435-441 sub build_patron_status { Link Here
435
435
436
        $resp .= patron_status_string($patron);
436
        $resp .= patron_status_string($patron);
437
        $resp .= $lang . timestamp();
437
        $resp .= $lang . timestamp();
438
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
438
        if ( defined $server->{account}->{ae_field_template} ) {
439
            $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template}, $server ) );
440
        } else {
441
            $resp .= add_field( FID_PERSONAL_NAME, $patron->name, $server );
442
        }
443
439
444
440
        # while the patron ID we got from the SC is valid, let's
445
        # while the patron ID we got from the SC is valid, let's
441
        # use the one returned from the ILS, just in case...
446
        # use the one returned from the ILS, just in case...
Lines 458-463 sub build_patron_status { Link Here
458
          if ( $server->{account}->{send_patron_home_library_in_af} );
463
          if ( $server->{account}->{send_patron_home_library_in_af} );
459
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
464
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
460
465
466
        $resp .= $patron->build_custom_field_string( $server );
461
        $resp .= $patron->build_patron_attributes_string( $server );
467
        $resp .= $patron->build_patron_attributes_string( $server );
462
468
463
    } else {
469
    } else {
Lines 971-977 sub handle_patron_info { Link Here
971
        # while the patron ID we got from the SC is valid, let's
977
        # while the patron ID we got from the SC is valid, let's
972
        # use the one returned from the ILS, just in case...
978
        # use the one returned from the ILS, just in case...
973
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
979
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
974
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
980
        if ( defined $server->{account}->{ae_field_template} ) {
981
            $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template} ), $server );
982
        } else {
983
            $resp .= add_field( FID_PERSONAL_NAME, $patron->name, $server );
984
        }
975
985
976
        # TODO: add code for the fields
986
        # TODO: add code for the fields
977
        #   hold items limit
987
        #   hold items limit
Lines 1026-1031 sub handle_patron_info { Link Here
1026
        }
1036
        }
1027
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
1037
        $resp .= maybe_add( FID_PRINT_LINE, $patron->print_line, $server );
1028
1038
1039
        $resp .= $patron->build_custom_field_string( $server );
1029
        $resp .= $patron->build_patron_attributes_string( $server );
1040
        $resp .= $patron->build_patron_attributes_string( $server );
1030
    } else {
1041
    } else {
1031
1042
Lines 1274-1280 sub handle_patron_enable { Link Here
1274
        $resp .= $patron->language . timestamp();
1285
        $resp .= $patron->language . timestamp();
1275
1286
1276
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
1287
        $resp .= add_field( FID_PATRON_ID,     $patron->id, $server );
1277
        $resp .= add_field( FID_PERSONAL_NAME, $patron->name( $server->{account}->{ae_field_template} ), $server );
1288
        $resp .= add_field( FID_PERSONAL_NAME, $patron->format( $server->{account}->{ae_field_template} ), $server );
1278
        if ( defined($patron_pwd) ) {
1289
        if ( defined($patron_pwd) ) {
1279
            $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ), $server );
1290
            $resp .= add_field( FID_VALID_PATRON_PWD, sipbool( $patron->check_password($patron_pwd) ), $server );
1280
        }
1291
        }
(-)a/etc/SIPconfig.xml (+1 lines)
Lines 64-69 Link Here
64
          <syspref_overrides>
64
          <syspref_overrides>
65
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
65
              <AllFinesNeedOverride>0</AllFinesNeedOverride>
66
          </syspref_overrides>
66
          </syspref_overrides>
67
          <custom_patron_field field="DE" code="[% patron.dateexpiry %]" />
67
      </login>
68
      </login>
68
  </accounts>
69
  </accounts>
69
70
(-)a/t/db_dependent/SIP/Patron.t (-2 / +45 lines)
Lines 4-10 Link Here
4
# This needs to be extended! Your help is appreciated..
4
# This needs to be extended! Your help is appreciated..
5
5
6
use Modern::Perl;
6
use Modern::Perl;
7
use Test::More tests => 5;
7
use Test::More tests => 6;
8
8
9
use Koha::Database;
9
use Koha::Database;
10
use Koha::Patrons;
10
use Koha::Patrons;
Lines 116-121 subtest "Test build_patron_attribute_string" => sub { Link Here
116
    is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
116
    is( $attribute_string, "XYTest Attribute|YZAnother Test Attribute|", 'Attribute field generated correctly with multiple params' );
117
};
117
};
118
118
119
subtest "Test build_custom_field_string" => sub {
120
121
    plan tests => 5;
122
123
    my $patron = $builder->build_object( { class => 'Koha::Patrons',value=>{surname => "Duck", firstname => "Darkwing"} } );
124
125
126
    my $ils_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
127
128
    my $server = {};
129
    $server->{account}->{custom_patron_field}->{field} = "DW";
130
    my $attribute_string = $ils_patron->build_custom_field_string( $server );
131
    is( $attribute_string, "", 'Custom field not generated if no value passed' );
132
133
    $server = {};
134
    $server->{account}->{custom_patron_field}->{template} = "[% patron.surname %]";
135
    $attribute_string = $ils_patron->build_custom_field_string( $server );
136
    is( $attribute_string, "", 'Custom field not generated if no field passed' );
137
138
139
    $server = {};
140
    $server->{account}->{custom_patron_field}->{field} = "DW";
141
    $server->{account}->{custom_patron_field}->{template} = "[% patron.firstname %] [% patron.surname %], let's get dangerous!";
142
    $attribute_string = $ils_patron->build_custom_field_string( $server );
143
    is( $attribute_string, "DWDarkwing Duck, let's get dangerous!|", 'Custom field processed correctly' );
144
145
    $server = {};
146
    $server->{account}->{custom_patron_field}->[0]->{field} = "DW";
147
    $server->{account}->{custom_patron_field}->[0]->{template} = "[% patron.firstname %] [% patron.surname %], let's get dangerous!";
148
    $server->{account}->{custom_patron_field}->[1]->{field} = "LM";
149
    $server->{account}->{custom_patron_field}->[1]->{template} = "Launchpad McQuack crashed on [% patron.dateexpiry %]";
150
    $attribute_string = $ils_patron->build_custom_field_string( $server );
151
    is( $attribute_string, "DWDarkwing Duck, let's get dangerous!|LMLaunchpad McQuack crashed on ".$patron->dateexpiry."|", 'Custom fields processed correctly when multiple exist' );
152
153
    $server = {};
154
    $server->{account}->{custom_patron_field}->[0]->{field} = "DW";
155
    $server->{account}->{custom_patron_field}->[0]->{template} = "[% IF (patron.firstname) %] patron.surname, let's get dangerous!";
156
    $server->{account}->{custom_patron_field}->[1]->{field} = "LM";
157
    $server->{account}->{custom_patron_field}->[1]->{template} = "Launchpad McQuack crashed on [% patron.dateexpiry %]";
158
    $attribute_string = $ils_patron->build_custom_field_string( $server );
159
    is( $attribute_string, "LMLaunchpad McQuack crashed on ".$patron->dateexpiry."|", 'Custom fields processed correctly, bad template generate no text' );
160
161
};
162
119
subtest "update_lastseen tests" => sub {
163
subtest "update_lastseen tests" => sub {
120
    plan tests => 2;
164
    plan tests => 2;
121
165
122
- 

Return to bug 20816