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

(-)a/Koha/IssuingRules.pm (+3 lines)
Lines 150-155 sub article_requestable_rules { Link Here
150
    'article requested'. Constructed by an intelligent guess in the
150
    'article requested'. Constructed by an intelligent guess in the
151
    issuing rules (see article_requestable_rules).
151
    issuing rules (see article_requestable_rules).
152
152
153
    Note: pref ArticleRequestsLinkControl overrides the algorithm.
154
153
    Optional parameters: categorycode.
155
    Optional parameters: categorycode.
154
156
155
    Note: the routine is used in opac-search to obtain a reasonable
157
    Note: the routine is used in opac-search to obtain a reasonable
Lines 164-169 sub guess_article_requestable_itemtypes { Link Here
164
    my ( $class, $params ) = @_;
166
    my ( $class, $params ) = @_;
165
    my $category = $params->{categorycode};
167
    my $category = $params->{categorycode};
166
    return {} if !C4::Context->preference('ArticleRequests');
168
    return {} if !C4::Context->preference('ArticleRequests');
169
    return { '*' => 1 } if C4::Context->preference('ArticleRequestsLinkControl') eq 'always';
167
170
168
    my $cache = Koha::Caches->get_instance;
171
    my $cache = Koha::Caches->get_instance;
169
    my $last_article_requestable_guesses = $cache->get_from_cache(GUESSED_ITEMTYPES_KEY);
172
    my $last_article_requestable_guesses = $cache->get_from_cache(GUESSED_ITEMTYPES_KEY);
(-)a/installer/data/mysql/atomicupdate/bug_17530.perl (+8 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q|
4
INSERT IGNORE INTO  systempreferences (variable, value, options, explanation, type) VALUES ('ArticleRequestsLinkControl', 'always', 'always\|calc', 'Control display of article request link on search results', 'Choice')
5
    |);
6
    SetVersion( $DBversion );
7
    print "Upgrade to $DBversion done (Bug 17530 - Add pref ArticleRequestsLinkControl)\n";
8
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 47-52 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
47
('AnonSuggestions','0',NULL,'Set to enable Anonymous suggestions to AnonymousPatron borrowernumber','YesNo'),
47
('AnonSuggestions','0',NULL,'Set to enable Anonymous suggestions to AnonymousPatron borrowernumber','YesNo'),
48
('AnonymousPatron','0',NULL,'Set the identifier (borrowernumber) of the anonymous patron. Used for Suggestion and reading history privacy',''),
48
('AnonymousPatron','0',NULL,'Set the identifier (borrowernumber) of the anonymous patron. Used for Suggestion and reading history privacy',''),
49
('ArticleRequests', '0', NULL, 'Enables the article request feature', 'YesNo'),
49
('ArticleRequests', '0', NULL, 'Enables the article request feature', 'YesNo'),
50
('ArticleRequestsLinkControl', 'calc', 'always|calc', 'Control display of article request link on search results', 'Choice'),
50
('ArticleRequestsMandatoryFields', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''yes''', 'multiple'),
51
('ArticleRequestsMandatoryFields', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''yes''', 'multiple'),
51
('ArticleRequestsMandatoryFieldsItemsOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''item_only''', 'multiple'),
52
('ArticleRequestsMandatoryFieldsItemsOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''item_only''', 'multiple'),
52
('ArticleRequestsMandatoryFieldsRecordOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''bib_only''', 'multiple'),
53
('ArticleRequestsMandatoryFieldsRecordOnly', '', NULL, 'Comma delimited list of required fields for bibs where article requests rule = ''bib_only''', 'multiple'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+6 lines)
Lines 944-949 Circulation: Link Here
944
                  no: "Don't enable"
944
                  no: "Don't enable"
945
            - patrons to place article requests.
945
            - patrons to place article requests.
946
        -
946
        -
947
            - pref: ArticleRequestsLinkControl
948
              choices:
949
                  always: Always show
950
                  calc: Use algorithm to show or hide
951
            - article request link on search results.
952
        -
947
            - For records that are record level or item level requestable, make the following fields mandatory
953
            - For records that are record level or item level requestable, make the following fields mandatory
948
            - pref: ArticleRequestsMandatoryFields
954
            - pref: ArticleRequestsMandatoryFields
949
              multiple:
955
              multiple:
(-)a/t/db_dependent/ArticleRequests.t (-1 / +4 lines)
Lines 221-230 subtest 'search_limited' => sub { Link Here
221
};
221
};
222
222
223
subtest 'may_article_request' => sub {
223
subtest 'may_article_request' => sub {
224
    plan tests => 3;
224
    plan tests => 4;
225
225
226
    # mocking
226
    # mocking
227
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
227
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
228
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
228
    $cache->set_in_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY, {
229
    $cache->set_in_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY, {
229
        '*'  => { 'CR' => 1 },
230
        '*'  => { 'CR' => 1 },
230
        'S'  => { '*'  => 1 },
231
        'S'  => { '*'  => 1 },
Lines 235-240 subtest 'may_article_request' => sub { Link Here
235
    is( $itemtype->may_article_request, 1, 'SER/* should be true' );
236
    is( $itemtype->may_article_request, 1, 'SER/* should be true' );
236
    is( $itemtype->may_article_request({ categorycode => 'S' }), 1, 'SER/S should be true' );
237
    is( $itemtype->may_article_request({ categorycode => 'S' }), 1, 'SER/S should be true' );
237
    is( $itemtype->may_article_request({ categorycode => 'PT' }), '', 'SER/PT should be false' );
238
    is( $itemtype->may_article_request({ categorycode => 'PT' }), '', 'SER/PT should be false' );
239
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always');
240
    is( $itemtype->may_article_request({ categorycode => 'PT' }), '1', 'Result should be true when LinkControl is set to always' );
238
241
239
    # Cleanup
242
    # Cleanup
240
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
243
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
(-)a/t/db_dependent/Koha/IssuingRules/guess_article_requestable_itemtypes.t (-2 / +7 lines)
Lines 15-23 our $builder = t::lib::TestBuilder->new; Link Here
15
our $cache = Koha::Caches->get_instance;
15
our $cache = Koha::Caches->get_instance;
16
16
17
subtest 'guess_article_requestable_itemtypes' => sub {
17
subtest 'guess_article_requestable_itemtypes' => sub {
18
    plan tests => 12;
18
    plan tests => 13;
19
19
20
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
20
    t::lib::Mocks::mock_preference('ArticleRequests', 1);
21
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'calc');
21
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
22
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
22
    Koha::IssuingRules->delete;
23
    Koha::IssuingRules->delete;
23
    my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
24
    my $itype1 = $builder->build_object({ class => 'Koha::ItemTypes' });
Lines 64-69 subtest 'guess_article_requestable_itemtypes' => sub { Link Here
64
    is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
65
    is( $res->{$itype1->itemtype}, 1, 'Item type 1 seems permitted' );
65
    is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
66
    is( $res->{$itype2->itemtype}, undef, 'Item type 2 seems not permitted' );
66
67
68
    # Finally test the overriding pref
69
    t::lib::Mocks::mock_preference('ArticleRequestsLinkControl', 'always');
70
    $res = Koha::IssuingRules->guess_article_requestable_itemtypes({});
71
    is( $res->{'*'}, 1, 'Override algorithm with pref setting' );
72
67
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
73
    $cache->clear_from_cache( Koha::IssuingRules::GUESSED_ITEMTYPES_KEY );
68
};
74
};
69
75
70
- 

Return to bug 17530