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

(-)a/Koha/CirculationRules.pm (-1 / +1 lines)
Lines 76-82 our $RULE_KINDS = { Link Here
76
    article_requests => {
76
    article_requests => {
77
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
77
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
78
    },
78
    },
79
    max_daily_article_requests => {
79
    open_article_requests_limit => {
80
        scope => [ 'branchcode', 'categorycode' ],
80
        scope => [ 'branchcode', 'categorycode' ],
81
    },
81
    },
82
82
(-)a/Koha/Patron.pm (-1 / +1 lines)
Lines 979-985 sub can_request_article { Link Here
979
        {
979
        {
980
            branchcode   => $library_id,
980
            branchcode   => $library_id,
981
            categorycode => $self->categorycode,
981
            categorycode => $self->categorycode,
982
            rule_name    => 'max_daily_article_requests'
982
            rule_name    => 'open_article_requests_limit'
983
        }
983
        }
984
    );
984
    );
985
985
(-)a/admin/smart-rules.pl (-14 / +14 lines)
Lines 458-484 elsif ($op eq "add-branch-cat") { Link Here
458
        );
458
        );
459
    }
459
    }
460
}
460
}
461
elsif ( $op eq "add-max-daily-article-requests" ) {
461
elsif ( $op eq "add-open-article-requests-limit" ) {
462
    my $categorycode               = $input->param('categorycode');
462
    my $categorycode                = $input->param('categorycode');
463
    my $max_daily_article_requests = strip_non_numeric( scalar $input->param('max_daily_article_requests') );
463
    my $open_article_requests_limit = strip_non_numeric( scalar $input->param('open_article_requests_limit') );
464
464
465
    Koha::Exceptions::Exception->throw("No value passed for article request limit")
465
    Koha::Exceptions::Exception->throw("No value passed for article request limit")
466
      if not defined $max_daily_article_requests # There is a JS check for that
466
      if not defined $open_article_requests_limit # There is a JS check for that
467
      || $max_daily_article_requests eq '';
467
      || $open_article_requests_limit eq '';
468
468
469
    if ( $branch eq "*" ) {
469
    if ( $branch eq "*" ) {
470
        if ( $categorycode eq "*" ) {
470
        if ( $categorycode eq "*" ) {
471
            Koha::CirculationRules->set_rules(
471
            Koha::CirculationRules->set_rules(
472
                {   categorycode => undef,
472
                {   categorycode => undef,
473
                    branchcode   => undef,
473
                    branchcode   => undef,
474
                    rules        => { max_daily_article_requests => $max_daily_article_requests, }
474
                    rules        => { open_article_requests_limit => $open_article_requests_limit, }
475
                }
475
                }
476
            );
476
            );
477
        } else {
477
        } else {
478
            Koha::CirculationRules->set_rules(
478
            Koha::CirculationRules->set_rules(
479
                {   categorycode => $categorycode,
479
                {   categorycode => $categorycode,
480
                    branchcode   => undef,
480
                    branchcode   => undef,
481
                    rules        => { max_daily_article_requests => $max_daily_article_requests, }
481
                    rules        => { open_article_requests_limit => $open_article_requests_limit, }
482
                }
482
                }
483
            );
483
            );
484
        }
484
        }
Lines 486-517 elsif ( $op eq "add-max-daily-article-requests" ) { Link Here
486
        Koha::CirculationRules->set_rules(
486
        Koha::CirculationRules->set_rules(
487
            {   categorycode => undef,
487
            {   categorycode => undef,
488
                branchcode   => $branch,
488
                branchcode   => $branch,
489
                rules        => { max_daily_article_requests => $max_daily_article_requests, }
489
                rules        => { open_article_requests_limit => $open_article_requests_limit, }
490
            }
490
            }
491
        );
491
        );
492
    } else {
492
    } else {
493
        Koha::CirculationRules->set_rules(
493
        Koha::CirculationRules->set_rules(
494
            {   categorycode => $categorycode,
494
            {   categorycode => $categorycode,
495
                branchcode   => $branch,
495
                branchcode   => $branch,
496
                rules        => { max_daily_article_requests => $max_daily_article_requests, }
496
                rules        => { open_article_requests_limit => $open_article_requests_limit, }
497
            }
497
            }
498
        );
498
        );
499
    }
499
    }
500
} elsif ( $op eq 'del-max-daily-article-requests' ) {
500
} elsif ( $op eq 'del-open-article-requests-limit' ) {
501
    my $categorycode = $input->param('categorycode');
501
    my $categorycode = $input->param('categorycode');
502
    if ( $branch eq "*" ) {
502
    if ( $branch eq "*" ) {
503
        if ( $categorycode eq "*" ) {
503
        if ( $categorycode eq "*" ) {
504
            Koha::CirculationRules->set_rules(
504
            Koha::CirculationRules->set_rules(
505
                {   branchcode   => undef,
505
                {   branchcode   => undef,
506
                    categorycode => undef,
506
                    categorycode => undef,
507
                    rules        => { max_daily_article_requests => undef, }
507
                    rules        => { open_article_requests_limit => undef, }
508
                }
508
                }
509
            );
509
            );
510
        } else {
510
        } else {
511
            Koha::CirculationRules->set_rules(
511
            Koha::CirculationRules->set_rules(
512
                {   categorycode => $categorycode,
512
                {   categorycode => $categorycode,
513
                    branchcode   => undef,
513
                    branchcode   => undef,
514
                    rules        => { max_daily_article_requests => undef, }
514
                    rules        => { open_article_requests_limit => undef, }
515
                }
515
                }
516
            );
516
            );
517
        }
517
        }
Lines 519-532 elsif ( $op eq "add-max-daily-article-requests" ) { Link Here
519
        Koha::CirculationRules->set_rules(
519
        Koha::CirculationRules->set_rules(
520
            {   branchcode   => $branch,
520
            {   branchcode   => $branch,
521
                categorycode => undef,
521
                categorycode => undef,
522
                rules        => { max_daily_article_requests => undef, }
522
                rules        => { open_article_requests_limit => undef, }
523
            }
523
            }
524
        );
524
        );
525
    } else {
525
    } else {
526
        Koha::CirculationRules->set_rules(
526
        Koha::CirculationRules->set_rules(
527
            {   categorycode => $categorycode,
527
            {   categorycode => $categorycode,
528
                branchcode   => $branch,
528
                branchcode   => $branch,
529
                rules        => { max_daily_article_requests => undef, }
529
                rules        => { open_article_requests_limit => undef, }
530
            }
530
            }
531
        );
531
        );
532
    }
532
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-11 / +11 lines)
Lines 788-802 Link Here
788
    [% END %]
788
    [% END %]
789
789
790
    [% IF Koha.Preference('ArticleRequests') %]
790
    [% IF Koha.Preference('ArticleRequests') %]
791
    <div id="max-daily-article-requests-patron-category" class="container">
791
    <div id="open-article-requests-limit-patron-category" class="container">
792
    [% IF humanbranch %]
792
    [% IF humanbranch %]
793
        <h3>Article requests limits for [% Branches.GetName( humanbranch ) | html %]</h3>
793
        <h3>Daily open article requests limit for [% Branches.GetName( humanbranch ) | html %]</h3>
794
    [% ELSE %]
794
    [% ELSE %]
795
        <h3>Default article requests limits</h3>
795
        <h3>Default open article requests limit</h3>
796
    [% END %]
796
    [% END %]
797
        <p>Specify the maximum number simultaneous current article requests a patron of a given category can have.</p>
797
        <p>Specify the maximum number simultaneous current article requests a patron of a given category can have.</p>
798
        <form id="set-article-requests-daily-limit" method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
798
        <form id="set-article-requests-daily-limit" method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
799
            <input type="hidden" name="op" value="add-max-daily-article-requests" />
799
            <input type="hidden" name="op" value="add-open-article-requests-limit" />
800
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
800
            <input type="hidden" name="branch" value="[% current_branch | html %]"/>
801
            <table>
801
            <table>
802
                <tr>
802
                <tr>
Lines 806-828 Link Here
806
                </tr>
806
                </tr>
807
                [% FOREACH c IN categorycodes %]
807
                [% FOREACH c IN categorycodes %]
808
                    [% NEXT UNLESS c %]
808
                    [% NEXT UNLESS c %]
809
                    [% SET max_daily_article_requests = CirculationRules.Search( branchcode, c, undef, 'max_daily_article_requests' ) %]
809
                    [% SET open_article_requests_limit = CirculationRules.Search( branchcode, c, undef, 'open_article_requests_limit' ) %]
810
810
811
                    [% IF ( max_daily_article_requests.defined && max_daily_article_requests != '' ) %]
811
                    [% IF ( open_article_requests_limit.defined && open_article_requests_limit != '' ) %]
812
                    <tr>
812
                    <tr>
813
                        <td>
813
                        <td>
814
                            [% Categories.GetName(c) | html %]
814
                            [% Categories.GetName(c) | html %]
815
                        </td>
815
                        </td>
816
                        <td>
816
                        <td>
817
                            [% IF max_daily_article_requests.defined && max_daily_article_requests != '' %]
817
                            [% IF open_article_requests_limit.defined && open_article_requests_limit != '' %]
818
                                [% max_daily_article_requests | html %]
818
                                [% open_article_requests_limit | html %]
819
                            [% ELSE %]
819
                            [% ELSE %]
820
                                <span>Unlimited</span>
820
                                <span>Unlimited</span>
821
                            [% END %]
821
                            [% END %]
822
                        </td>
822
                        </td>
823
823
824
                        <td class="actions">
824
                        <td class="actions">
825
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=del-max-daily-article-requests&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
825
                            <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=del-open-article-requests-limit&amp;categorycode=[% c | html %]&amp;branch=[% current_branch | html %]"><i class="fa fa-trash"></i> Delete</a>
826
                        </td>
826
                        </td>
827
                    </tr>
827
                    </tr>
828
                    [% END %]
828
                    [% END %]
Lines 835-841 Link Here
835
                        [% END %]
835
                        [% END %]
836
                        </select>
836
                        </select>
837
                    </td>
837
                    </td>
838
                    <td><input name="max_daily_article_requests" size="3" type="text" /></td>
838
                    <td><input name="open_article_requests_limit" size="3" type="text" /></td>
839
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
839
                    <td class="actions"><button type="submit" class="btn btn-default btn-xs"><i class="fa fa-plus"></i> Add</td>
840
                </tr>
840
                </tr>
841
            </table>
841
            </table>
Lines 1231-1237 Link Here
1231
            });
1231
            });
1232
1232
1233
            $("#set-article-requests-daily-limit").on("submit", function(){
1233
            $("#set-article-requests-daily-limit").on("submit", function(){
1234
                if (! $("input[name='max_daily_article_requests'").val().length){
1234
                if (! $("input[name='open_article_requests_limit'").val().length){
1235
                    alert("Please set a daily limit for this patron's category");
1235
                    alert("Please set a daily limit for this patron's category");
1236
                    return false;
1236
                    return false;
1237
                }
1237
                }
(-)a/t/db_dependent/Koha/Patron.t (-3 / +2 lines)
Lines 738-744 subtest 'can_request_article() tests' => sub { Link Here
738
        {
738
        {
739
            categorycode => undef,
739
            categorycode => undef,
740
            branchcode   => $library_1->id,
740
            branchcode   => $library_1->id,
741
            rule_name    => 'max_daily_article_requests',
741
            rule_name    => 'open_article_requests_limit',
742
            rule_value   => 4,
742
            rule_value   => 4,
743
        }
743
        }
744
    );
744
    );
Lines 802-808 subtest 'can_request_article() tests' => sub { Link Here
802
        {
802
        {
803
            categorycode => undef,
803
            categorycode => undef,
804
            branchcode   => $library_2->id,
804
            branchcode   => $library_2->id,
805
            rule_name    => 'max_daily_article_requests',
805
            rule_name    => 'open_article_requests_limit',
806
            rule_value   => 3,
806
            rule_value   => 3,
807
        }
807
        }
808
    );
808
    );
809
- 

Return to bug 27945