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

(-)a/Koha/CirculationRule.pm (+82 lines)
Line 0 Link Here
1
package Koha::CirculationRule;
2
3
# Copyright Vaara-kirjastot 2015
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Object);
23
24
use Koha::Libraries;
25
use Koha::Patron::Categories;
26
use Koha::ItemTypes;
27
28
=head1 NAME
29
30
Koha::Hold - Koha Hold object class
31
32
=head1 API
33
34
=head2 Class Methods
35
36
=cut
37
38
=head3 library
39
40
=cut
41
42
sub library {
43
    my ($self) = @_;
44
45
    $self->{_library} ||= Koha::Libraries->find( $self->branchcode );
46
47
    return $self->{_library};
48
}
49
50
=head3 patron_category
51
52
=cut
53
54
sub patron_category {
55
    my ($self) = @_;
56
57
    $self->{_patron_category} ||= Koha::Patron::Categories->find( $self->categorycode );
58
59
    return $self->{_patron_category};
60
}
61
62
=head3 item_type
63
64
=cut
65
66
sub item_type {
67
    my ($self) = @_;
68
69
    $self->{_item_type} ||= Koha::ItemTypes->find( $self->itemtype );
70
71
    return $self->{item_type};
72
}
73
74
=head3 _type
75
76
=cut
77
78
sub _type {
79
    return 'CirculationRule';
80
}
81
82
1;
(-)a/Koha/CirculationRules.pm (+171 lines)
Line 0 Link Here
1
package Koha::CirculationRules;
2
3
# Copyright Vaara-kirjastot 2015
4
# Copyright Koha Development Team 2016
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 3 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
use Modern::Perl;
22
23
use Carp qw(croak);
24
25
use Koha::CirculationRule;
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::IssuingRules - Koha IssuingRule Object set class
32
33
=head1 API
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 get_effective_rule
40
41
=cut
42
43
sub get_effective_rule {
44
    my ( $self, $params ) = @_;
45
46
    my $rule_name    = $params->{rule_name};
47
    my $categorycode = $params->{categorycode};
48
    my $itemtype     = $params->{itemtype};
49
    my $branchcode   = $params->{branchcode};
50
51
    croak q{No rule name passed in!} unless $rule_name;
52
53
    my $search_params;
54
    $search_params->{rule_name} = $rule_name;
55
56
    $search_params->{categorycode} = defined $categorycode ? { 'in' => [ $categorycode, '*' ] } : undef;
57
    $search_params->{itemtype}     = defined $itemtype     ? { 'in' => [ $itemtype,     '*' ] } : undef;
58
    $search_params->{branchcode}   = defined $branchcode   ? { 'in' => [ $branchcode,   '*' ] } : undef;
59
60
    my $rule = $self->search(
61
        $search_params,
62
        {
63
            order_by => {
64
                -desc => [ 'branchcode', 'categorycode', 'itemtype' ]
65
            },
66
            rows => 1,
67
        }
68
    )->single;
69
70
    return $rule;
71
}
72
73
=head3 set_rule
74
75
=cut
76
77
sub set_rule {
78
    my ( $self, $params ) = @_;
79
80
    croak q{set_rule requires the parameter 'branchcode'!}
81
      unless exists $params->{branchcode};
82
    croak q{set_rule requires the parameter 'categorycode'!}
83
      unless exists $params->{categorycode};
84
    croak q{set_rule requires the parameter 'itemtype'!}
85
      unless exists $params->{itemtype};
86
    croak q{set_rule requires the parameter 'rule_name'!}
87
      unless exists $params->{rule_name};
88
    croak q{set_rule requires the parameter 'rule_value'!}
89
      unless exists $params->{rule_value};
90
91
    my $branchcode   = $params->{branchcode};
92
    my $categorycode = $params->{categorycode};
93
    my $itemtype     = $params->{itemtype};
94
    my $rule_name    = $params->{rule_name};
95
    my $rule_value   = $params->{rule_value};
96
97
    my $rule = $self->search(
98
        {
99
            rule_name    => $rule_name,
100
            branchcode   => $branchcode,
101
            categorycode => $categorycode,
102
            itemtype     => $itemtype,
103
        }
104
    )->next();
105
106
    if ($rule) {
107
        if ( defined $rule_value ) {
108
            $rule->rule_value($rule_value);
109
            $rule->update();
110
        }
111
        else {
112
            $rule->delete();
113
        }
114
    }
115
    else {
116
        if ( defined $rule_value ) {
117
            $rule = Koha::CirculationRule->new(
118
                {
119
                    branchcode   => $branchcode,
120
                    categorycode => $categorycode,
121
                    itemtype     => $itemtype,
122
                    rule_name    => $rule_name,
123
                    rule_value   => $rule_value,
124
                }
125
            );
126
            $rule->store();
127
        }
128
    }
129
130
    return $rule;
131
}
132
133
=head3 set_rules
134
135
=cut
136
137
sub set_rules {
138
    my ( $self, $params ) = @_;
139
    warn Data::Dumper::Dumper( $params );
140
141
    my $branchcode   = $params->{branchcode};
142
    my $categorycode = $params->{categorycode};
143
    my $itemtype     = $params->{itemtype};
144
    my $rules        = $params->{rules};
145
146
    foreach my $rule (@$rules) {
147
        Koha::CirculationRules->set_rule(
148
            {
149
                branchcode   => $branchcode,
150
                categorycode => $categorycode,
151
                itemtype     => $itemtype,
152
                rule_name    => $rule->{rule_name},
153
                rule_value   => $rule->{rule_value},
154
            }
155
        );
156
    }
157
}
158
159
=head3 type
160
161
=cut
162
163
sub _type {
164
    return 'CirculationRule';
165
}
166
167
sub object_class {
168
    return 'Koha::CirculationRule';
169
}
170
171
1;
(-)a/Koha/Template/Plugin/CirculationRules.pm (-1 / +45 lines)
Line 0 Link Here
0
- 
1
package Koha::Template::Plugin::CirculationRules;
2
3
# Copyright ByWater Solutions 2017
4
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw( Template::Plugin );
23
24
use Koha::CirculationRules;
25
26
sub Get {
27
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
28
29
    $branchcode   = undef if $branchcode eq q{};
30
    $categorycode = undef if $categorycode eq q{};
31
    $itemtype     = undef if $itemtype eq q{};
32
33
    my $rule = Koha::CirculationRules->search(
34
        {
35
            branchcode   => $branchcode,
36
            categorycode => $categorycode,
37
            itemtype     => $itemtype,
38
            rule_name    => $rule_name,
39
        }
40
    )->next();
41
42
    return $rule->rule_value if $rule;
43
}
44
45
1;

Return to bug 18887