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

(-)a/Koha/Item.pm (+60 lines)
Lines 2605-2610 sub location_update_trigger { Link Here
2605
    return $messages;
2605
    return $messages;
2606
}
2606
}
2607
2607
2608
2609
=head3 z3950_status
2610
2611
    my $statuses = $item->z3950_statuses( $status_strings );
2612
2613
Returns an array of statuses for use in z3950 results. Takes a hashref listing the display strings for the
2614
various statuses. Availability is determined by item statuses and the system preference z3950Status.
2615
2616
Status strings are defined in authorised values in the Z3950_STATUS category.
2617
2618
=cut
2619
2620
sub z3950_status {
2621
    my ( $self, $status_strings ) = @_;
2622
2623
    my @statuses;
2624
2625
    if ( $self->onloan() ) {
2626
        push @statuses, $status_strings->{CHECKED_OUT} // "CHECKED_OUT";
2627
    }
2628
2629
    if ( $self->itemlost() ) {
2630
        push @statuses, $status_strings->{LOST} // "LOST";
2631
    }
2632
2633
    if ( $self->is_notforloan() ) {
2634
        push @statuses, $status_strings->{NOT_FOR_LOAN} // "NOT_FOR_LOAN";
2635
    }
2636
2637
    if ( $self->damaged() ) {
2638
        push @statuses, $status_strings->{DAMAGED} // "DAMAGED";
2639
    }
2640
2641
    if ( $self->withdrawn() ) {
2642
        push @statuses, $status_strings->{WITHDRAWN} // "WITHDRAWN";
2643
    }
2644
2645
    if ( my $transfer = $self->get_transfer ) {
2646
        push @statuses, $status_strings->{IN_TRANSIT} // "IN_TRANSIT" if $transfer->in_transit;
2647
    }
2648
2649
    if ( C4::Reserves::GetReserveStatus( $self->itemnumber ) ne '' ) {
2650
        push @statuses, $status_strings->{ON_HOLD} // "ON_HOLD";
2651
    }
2652
    my $rules = C4::Context->yaml_preference('Z3950Status');
2653
    if ($rules) {
2654
        foreach my $field ( keys %$rules ) {
2655
            foreach my $value ( @{ $rules->{$field} } ) {
2656
                if ( defined $self->$field && $self->$field eq $value ) {
2657
                    push @statuses, $status_strings->{"SYSPREF"} // "SYSPREF";
2658
                    last;
2659
                }
2660
            }
2661
        }
2662
    }
2663
2664
    return \@statuses;
2665
2666
}
2667
2608
=head3 _type
2668
=head3 _type
2609
2669
2610
=cut
2670
=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 857-861 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
857
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
857
('XSLTListsDisplay','default','','Enable XSLT stylesheet control over lists pages display on intranet','Free'),
858
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
858
('XSLTResultsDisplay','default','','Enable XSL stylesheet control over results page display on intranet','Free'),
859
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
859
('z3950AuthorAuthFields','701,702,700',NULL,'Define the MARC biblio fields for Personal Name Authorities to fill biblio.author','free'),
860
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo')
860
('z3950NormalizeAuthor','0','','If ON, Personal Name Authorities will replace authors in biblio.author','YesNo'),
861
('z3950Status','','','This syspref allows to define custom YAML based rules for marking items unavailable in z3950 results.','Textarea')
861
;
862
;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref (+10 lines)
Lines 106-111 Searching: Link Here
106
            - "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':"
106
            - "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':"
107
            - pref: ESPreventAutoTruncate
107
            - pref: ESPreventAutoTruncate
108
              class: long
108
              class: long
109
        -
110
            - pref: z3950Status
111
              type: textarea
112
              syntax: text/x-yaml
113
              class: code
114
            - "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/>"
115
            - "Examples:<br/><br/>"
116
            - "<pre>ccode: [REF,ARC]</pre><br/>  - would mark all REF and ARC collections (Reference and Archives) items as unavailable in Z3950 results.<br/><br/>"
117
            - "You can define multiple keys and values, items meeting ANY of the criteria will be marked unavailable:<br/><br/>"
118
            - "<pre>itype: [REF]<br/>holdingbranch: [REPAIR]</pre><br/>  - would mark all reference items AND items at the REPAIR branch as unavailable."
109
    Search form:
119
    Search form:
110
        -
120
        -
111
            - pref: LoadSearchHistoryToTheFirstLoggedUser
121
            - pref: LoadSearchHistoryToTheFirstLoggedUser
(-)a/t/db_dependent/Koha/Item.t (-1 / +84 lines)
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