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

(-)a/Koha/Item.pm (+60 lines)
Lines 2602-2607 sub location_update_trigger { Link Here
2602
    return $messages;
2602
    return $messages;
2603
}
2603
}
2604
2604
2605
2606
=head3 z3950_status
2607
2608
    my $statuses = $item->z3950_statuses( $status_strings );
2609
2610
Returns an array of statuses for use in z3950 results. Takes a hashref listing the display strings for the
2611
various statuses. Availability is determined by item statuses and the system preference z3950Status.
2612
2613
Status strings are defined in authorised values in the Z3950_STATUS category.
2614
2615
=cut
2616
2617
sub z3950_status {
2618
    my ( $self, $status_strings ) = @_;
2619
2620
    my @statuses;
2621
2622
    if ( $self->onloan() ) {
2623
        push @statuses, $status_strings->{CHECKED_OUT} // "CHECKED_OUT";
2624
    }
2625
2626
    if ( $self->itemlost() ) {
2627
        push @statuses, $status_strings->{LOST} // "LOST";
2628
    }
2629
2630
    if ( $self->is_notforloan() ) {
2631
        push @statuses, $status_strings->{NOT_FOR_LOAN} // "NOT_FOR_LOAN";
2632
    }
2633
2634
    if ( $self->damaged() ) {
2635
        push @statuses, $status_strings->{DAMAGED} // "DAMAGED";
2636
    }
2637
2638
    if ( $self->withdrawn() ) {
2639
        push @statuses, $status_strings->{WITHDRAWN} // "WITHDRAWN";
2640
    }
2641
2642
    if ( my $transfer = $self->get_transfer ) {
2643
        push @statuses, $status_strings->{IN_TRANSIT} // "IN_TRANSIT" if $transfer->in_transit;
2644
    }
2645
2646
    if ( C4::Reserves::GetReserveStatus( $self->itemnumber ) ne '' ) {
2647
        push @statuses, $status_strings->{ON_HOLD} // "ON_HOLD";
2648
    }
2649
    my $rules = C4::Context->yaml_preference('Z3950Status');
2650
    if ($rules) {
2651
        foreach my $field ( keys %$rules ) {
2652
            foreach my $value ( @{ $rules->{$field} } ) {
2653
                if ( defined $self->$field && $self->$field eq $value ) {
2654
                    push @statuses, $status_strings->{"SYSPREF"} // "SYSPREF";
2655
                    last;
2656
                }
2657
            }
2658
        }
2659
    }
2660
2661
    return \@statuses;
2662
2663
}
2664
2605
=head3 _type
2665
=head3 _type
2606
2666
2607
=cut
2667
=cut
(-)a/Koha/Z3950Responder/Session.pm (-32 / +3 lines)
Lines 20-26 package Koha::Z3950Responder::Session; Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Reserves qw( GetReserveStatus );
24
use C4::Search qw( new_record_from_zebra );
23
use C4::Search qw( new_record_from_zebra );
25
24
26
use Koha::Items;
25
use Koha::Items;
Lines 263-302 sub add_item_status { Link Here
263
    my $item = Koha::Items->find( $itemnumber );
262
    my $item = Koha::Items->find( $itemnumber );
264
    return unless $item;
263
    return unless $item;
265
264
266
    my @statuses;
265
    my $statuses = $item->z3950_status($status_strings);
267
268
    if ( $item->onloan() ) {
269
        push @statuses, $status_strings->{CHECKED_OUT};
270
    }
271
272
    if ( $item->itemlost() ) {
273
        push @statuses, $status_strings->{LOST};
274
    }
275
276
    if ( $item->notforloan() ) {
277
        push @statuses, $status_strings->{NOT_FOR_LOAN};
278
    }
279
280
    if ( $item->damaged() ) {
281
        push @statuses, $status_strings->{DAMAGED};
282
    }
283
284
    if ( $item->withdrawn() ) {
285
        push @statuses, $status_strings->{WITHDRAWN};
286
    }
287
288
    if ( my $transfer = $item->get_transfer ) {
289
        push @statuses, $status_strings->{IN_TRANSIT} if $transfer->in_transit;
290
    }
291
292
    if ( GetReserveStatus( $itemnumber ) ne '' ) {
293
        push @statuses, $status_strings->{ON_HOLD};
294
    }
295
266
296
    if ( $server->{add_status_multi_subfield} ) {
267
    if ( $server->{add_status_multi_subfield} ) {
297
        $field->add_subfields( map { ( $add_subfield, $_ ) } ( @statuses ? @statuses : $status_strings->{AVAILABLE} ) );
268
        $field->add_subfields( map { ( $add_subfield, $_ ) } ( @$statuses ? @$statuses : $status_strings->{AVAILABLE} ) );
298
    } else {
269
    } else {
299
        $field->add_subfields( $add_subfield, @statuses ? join( ', ', @statuses ) : $status_strings->{AVAILABLE} );
270
        $field->add_subfields( $add_subfield, @$statuses ? join( ', ', @$statuses ) : $status_strings->{AVAILABLE} );
300
    }
271
    }
301
}
272
}
302
273
(-)a/installer/data/mysql/atomicupdate/add_z3950status_syspref.pl (+21 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "36996",
6
    description => "Add z3950Status system preference",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        # Do you stuffs here
12
        $dbh->do(
13
            q{
14
            INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
15
            ('z3950Status','','','This syspref allows to define custom YAML based rules for marking items unavailable in z3950 results.','Textarea')
16
        }
17
        );
18
19
        say $out "Added new system preference 'Z3950Status'";
20
    },
21
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +2 lines)
Lines 854-858 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
854
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
854
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
855
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
855
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
856
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
856
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
857
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
857
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
858
('z3950Status','','','This syspref allows to define custom YAML based rules for marking items unavailable in z3950 results.','Textarea')
858
;
859
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+10 lines)
Lines 99-104 Searching: Link Here
99
            - "List of search fields (separated by | or ,) that should not be autotruncated by Elasticsearch even if <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=QueryAutoTruncate'>QueryAutoTruncate</a> is set to 'Yes':"
99
            - "List of search fields (separated by | or ,) that should not be autotruncated by Elasticsearch even if <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=QueryAutoTruncate'>QueryAutoTruncate</a> is set to 'Yes':"
100
            - pref: ESPreventAutoTruncate
100
            - pref: ESPreventAutoTruncate
101
              class: long
101
              class: long
102
        -
103
            - pref: z3950Status
104
              type: textarea
105
              syntax: text/x-yaml
106
              class: code
107
            - "Define custom rules to show specific items as not available in Z3950. Rules are defined with item database fields as keys and an array of values.<br/>"
108
            - "Examples:<br/><br/>"
109
            - "<pre>ccode: [REF,ARC]</pre><br/>  - would mark all REF and ARC collections (Reference and Archives) items as unavailable in Z3950 results.<br/><br/>"
110
            - "You can define multiple keys and values, items meeting ANY of the criteria will be marked unavailable:<br/><br/>"
111
            - "<pre>itype: [REF]<br/>holdingbranch: [REPAIR]</pre><br/>  - would mark all reference items AND items at the REPAIR branch as unavailable."
102
    Search form:
112
    Search form:
103
        -
113
        -
104
            - pref: LoadSearchHistoryToTheFirstLoggedUser
114
            - pref: LoadSearchHistoryToTheFirstLoggedUser
(-)a/t/db_dependent/Koha/Item.t (-2 / +85 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
22
23
use Test::More tests => 34;
23
use Test::More tests => 35;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
26
26
Lines 44-49 use t::lib::Dates; Link Here
44
my $schema  = Koha::Database->new->schema;
44
my $schema  = Koha::Database->new->schema;
45
my $builder = t::lib::TestBuilder->new;
45
my $builder = t::lib::TestBuilder->new;
46
46
47
subtest 'z3950_status' => sub {
48
    plan tests => 9;
49
50
    $schema->storage->txn_begin;
51
    t::lib::Mocks::mock_preference( 'z3950Status', '' );
52
53
    my $itemtype = $builder->build_object( { class => "Koha::ItemTypes" } );
54
    my $item     = $builder->build_sample_item(
55
        {
56
            itype => $itemtype->itemtype,
57
        }
58
    );
59
60
    my $statuses = $item->z3950_status();
61
    is( scalar @{$statuses}, 0, "No statuses set when pref blank and item has no status" );
62
63
    $item->onloan('2001-01-01')->store();
64
    $statuses = $item->z3950_status();
65
    is_deeply( $statuses, ['CHECKED_OUT'], "Item status is checked out when onloan is set" );
66
67
    $item->damaged(1)->withdrawn(1)->itemlost(1)->store();
68
    $statuses = $item->z3950_status();
69
    is_deeply(
70
        $statuses, [ 'CHECKED_OUT', 'LOST', 'DAMAGED', 'WITHDRAWN' ],
71
        "Multiple item statuses set from other fields"
72
    );
73
74
    $itemtype->notforloan(1)->store();
75
    $statuses = $item->z3950_status();
76
    is_deeply(
77
        $statuses, [ 'CHECKED_OUT', 'LOST', 'NOT_FOR_LOAN', 'DAMAGED', 'WITHDRAWN' ],
78
        "Not for loan status correctly added from itemtype"
79
    );
80
81
    $statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded' } );
82
    is_deeply(
83
        $statuses, [ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded' ],
84
        "Lost items correctly substituted when values passed"
85
    );
86
87
    $builder->build_object(
88
        { class => 'Koha::Item::Transfers', value => { itemnumber => $item->itemnumber, datesent => '1999-12-31' } } );
89
    $builder->build_object( { class => 'Koha::Holds', value => { itemnumber => $item->itemnumber, found => 'W' } } );
90
91
    $statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits' } );
92
    is_deeply(
93
        $statuses, [ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded', 'IN_TRANSIT', 'Patron awaits' ],
94
        "Hold and transit statuses applied correctly"
95
    );
96
97
    t::lib::Mocks::mock_preference( 'z3950Status', "homebranch: [" . $item->homebranch . "]" );
98
    $statuses = $item->z3950_status( { LOST => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits' } );
99
    is_deeply(
100
        $statuses,
101
        [ 'CHECKED_OUT', 'Gone', 'NOT_FOR_LOAN', 'DAMAGED', 'Weeded', 'IN_TRANSIT', 'Patron awaits', 'SYSPREF' ],
102
        "System preference statuses applied correctly"
103
    );
104
105
    my $item_2 = $builder->build_sample_item(
106
        {
107
            homebranch => $item->homebranch,
108
        }
109
    );
110
111
    $statuses = $item_2->z3950_status(
112
        {
113
            LOST      => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits',
114
            'SYSPREF' => 'Library policy forbids'
115
        }
116
    );
117
    is_deeply( $statuses, ['Library policy forbids'], "system preference statuses substituted correctly" );
118
119
    t::lib::Mocks::mock_preference( 'z3950Status', "ccode: [FAKE]\r\n\nhomebranch: [" . $item->homebranch . "]" );
120
    $statuses = $item_2->z3950_status(
121
        {
122
            LOST      => 'Gone', 'WITHDRAWN' => 'Weeded', 'ON_HOLD' => 'Patron awaits',
123
            'SYSPREF' => 'Library policy forbids'
124
        }
125
    );
126
    is_deeply( $statuses, ['Library policy forbids'], "Status applied when any field matches" );
127
128
    $schema->storage->txn_rollback;
129
};
130
47
subtest 'return_claims relationship' => sub {
131
subtest 'return_claims relationship' => sub {
48
    plan tests => 3;
132
    plan tests => 3;
49
133
50
- 

Return to bug 36996