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

(-)a/C4/Category.pm (-181 lines)
Lines 1-181 Link Here
1
package C4::Category;
2
3
# Copyright 2009 Liblime
4
# Parts Copyright 2011 Tamil
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use strict;
22
use warnings;
23
use C4::Context;
24
25
our $AUTOLOAD;
26
27
28
29
30
=head1 NAME
31
32
C4::Category - objects from the categories table
33
34
=head1 SYNOPSIS
35
36
    use C4::Category;
37
    my @categories = C4::Category->all;
38
    print join("\n", map { $_->description } @categories), "\n";
39
40
=head1 DESCRIPTION
41
42
Objects of this class represent a row in the C<categories> table.
43
44
Currently, the bare minimum for using this as a read-only data source has
45
been implemented.  The API was designed to make it easy to transition to
46
an ORM later on.
47
48
=head1 API
49
50
=head2 Class Methods
51
52
=cut
53
54
=head3 C4::Category->new(\%opts)
55
56
Given a hashref, a new (in-memory) C4::Category object will be instantiated.
57
The database is not touched.
58
59
=cut
60
61
sub new {
62
    my ($class, $opts) = @_;
63
    bless $opts => $class;
64
}
65
66
67
68
69
=head3 C4::Category->all
70
71
This returns all the categories as objects.  By default they're ordered by
72
C<description>.
73
74
=cut
75
76
sub all {
77
    my ( $class ) = @_;
78
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
79
    my $dbh = C4::Context->dbh;
80
    # The categories table is small enough for
81
    # `SELECT *` to be harmless.
82
    my $query = "SELECT categories.* FROM categories";
83
    $query .= qq{
84
        LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode
85
        WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL
86
    } if $branch_limit;
87
    $query .= " ORDER BY description";
88
    return map { $class->new($_) } @{
89
        $dbh->selectall_arrayref(
90
            $query,
91
            { Slice => {} },
92
            $branch_limit ? $branch_limit : ()
93
        )
94
    };
95
}
96
97
98
99
100
=head2 Object Methods
101
102
These are read-only accessors for attributes of a C4::Category object.
103
104
=head3 $category->categorycode
105
106
=cut
107
108
=head3 $category->description
109
110
=cut
111
112
=head3 $category->enrolmentperiod
113
114
=cut
115
116
=head3 $category->upperagelimit
117
118
=cut
119
120
=head3 $category->dateofbirthrequired
121
122
=cut
123
124
=head3 $category->finetype
125
126
=cut
127
128
=head3 $category->bulk
129
130
=cut
131
132
=head3 $category->enrolmentfee
133
134
=cut
135
136
=head3 $category->overduenoticerequired
137
138
=cut
139
140
=head3 $category->issuelimit
141
142
=cut
143
144
=head3 $category->reservefee
145
146
=cut
147
148
=head3 $category->category_type
149
150
=cut
151
152
sub AUTOLOAD {
153
    my $self = shift;
154
    my $attr = $AUTOLOAD;
155
    $attr =~ s/.*://;
156
    if (exists $self->{$attr}) {
157
        return $self->{$attr};
158
    } else {
159
        return undef;
160
    }
161
}
162
163
sub DESTROY { }
164
165
166
167
168
=head1 SEE ALSO
169
170
The following modules make reference to the C<categories> table.
171
172
L<C4::Members>, L<C4::Overdues>, L<C4::Reserves>
173
174
175
=head1 AUTHOR
176
177
John Beppu <john.beppu@liblime.com>
178
179
=cut
180
181
1;
(-)a/C4/ItemCirculationAlertPreference.pm (-2 / +3 lines)
Lines 20-29 package C4::ItemCirculationAlertPreference; Link Here
20
use strict;
20
use strict;
21
use warnings;
21
use warnings;
22
use C4::Context;
22
use C4::Context;
23
use C4::Category;
24
use C4::ItemType;
23
use C4::ItemType;
25
use Carp qw(carp croak);
24
use Carp qw(carp croak);
26
25
26
use Koha::Patron::Categories;
27
27
our $AUTOLOAD;
28
our $AUTOLOAD;
28
29
29
# helper function for validating \%opts
30
# helper function for validating \%opts
Lines 330-336 sub grid { Link Here
330
    my ($class, $where) = @_;
331
    my ($class, $where) = @_;
331
    my @branch_prefs = $class->find($where);
332
    my @branch_prefs = $class->find($where);
332
    my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} });
333
    my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} });
333
    my @cc = C4::Category->all;
334
    my @cc = Koha::Patron::Categories->search_limited;
334
    my @it = C4::ItemType->all;
335
    my @it = C4::ItemType->all;
335
    my $notification = $where->{notification};
336
    my $notification = $where->{notification};
336
    my %disabled = map {
337
    my %disabled = map {
(-)a/Koha/Patron/Categories.pm (+15 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use Carp;
20
use Carp;
21
21
22
use C4::Context; # Sigh...
23
22
use Koha::Database;
24
use Koha::Database;
23
25
24
use Koha::Patron::Category;
26
use Koha::Patron::Category;
Lines 35-40 Koha::Patron::Categories - Koha Patron Category Object set class Link Here
35
37
36
=cut
38
=cut
37
39
40
sub search_limited {
41
    my ( $self ) = @_;
42
    my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
43
    return $self->search({}, {order_by => ['description']}) unless $branch_limit;
44
    return $self->search({
45
        'categories_branches.branchcode' => [$branch_limit, undef]},
46
        {
47
            join => 'categories_branches',
48
            order_by => ['description'],
49
        }
50
    );
51
}
52
38
=head3 type
53
=head3 type
39
54
40
=cut
55
=cut
(-)a/Koha/Template/Plugin/Categories.pm (-13 / +2 lines)
Lines 20-40 use Modern::Perl; Link Here
20
use Template::Plugin;
20
use Template::Plugin;
21
use base qw( Template::Plugin );
21
use base qw( Template::Plugin );
22
22
23
use C4::Category;
23
use Koha::Patron::Categories;
24
24
25
sub all {
25
sub all {
26
    my ( $self, $params ) = @_;
26
    return Koha::Patron::Categories->search_limited;
27
    my $selected = $params->{selected};
28
29
    my @categories = C4::Category->all;
30
    if ( $selected ) {
31
        for my $category ( @categories ) {
32
            if ( $category->{categorycode} eq $selected ) {
33
                $category->{selected} = 1;
34
            }
35
        }
36
    }
37
    return @categories;
38
}
27
}
39
28
40
1;
29
1;
(-)a/acqui/add_user_search.pl (-2 / +4 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Branch qw( GetBranches );
24
use C4::Branch qw( GetBranches );
25
use C4::Category;
26
use C4::Output;
25
use C4::Output;
27
use C4::Members;
26
use C4::Members;
28
27
28
use Koha::Patron::Categories;
29
29
my $input = new CGI;
30
my $input = new CGI;
30
31
31
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
Lines 54-59 my $search_patrons_with_acq_perm_only = Link Here
54
my $onlymine = C4::Branch::onlymine;
55
my $onlymine = C4::Branch::onlymine;
55
my $branches = C4::Branch::GetBranches( $onlymine );
56
my $branches = C4::Branch::GetBranches( $onlymine );
56
57
58
my $patron_categories = Koha::Patron::Categories->search_limited;
57
$template->param(
59
$template->param(
58
    patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
60
    patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
59
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
61
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
Lines 61-67 $template->param( Link Here
61
    json_template => 'acqui/tables/members_results.tt',
63
    json_template => 'acqui/tables/members_results.tt',
62
    selection_type => 'add',
64
    selection_type => 'add',
63
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
65
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
64
    categories      => [ C4::Category->all ],
66
    categories      => $patron_categories,
65
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
67
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
66
    aaSorting       => 1,
68
    aaSorting       => 1,
67
);
69
);
(-)a/admin/add_user_search.pl (-2 / +4 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Branch qw( GetBranches );
24
use C4::Branch qw( GetBranches );
25
use C4::Category;
26
use C4::Output;
25
use C4::Output;
27
use C4::Members;
26
use C4::Members;
28
27
28
use Koha::Patron::Categories;
29
29
my $input = new CGI;
30
my $input = new CGI;
30
31
31
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
Lines 55-60 my $search_patrons_with_acq_perm_only = Link Here
55
my $onlymine = C4::Branch::onlymine;
56
my $onlymine = C4::Branch::onlymine;
56
my $branches = C4::Branch::GetBranches( $onlymine );
57
my $branches = C4::Branch::GetBranches( $onlymine );
57
58
59
my $patron_categories = Koha::Patron::Categories->search_limited;
58
$template->param(
60
$template->param(
59
    patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
61
    patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
60
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
62
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
Lines 62-68 $template->param( Link Here
62
    json_template => 'acqui/tables/members_results.tt',
64
    json_template => 'acqui/tables/members_results.tt',
63
    selection_type => $selection_type,
65
    selection_type => $selection_type,
64
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
66
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
65
    categories      => [ C4::Category->all ],
67
    categories      => $patron_categories,
66
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
68
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
67
    aaSorting       => 1,
69
    aaSorting       => 1,
68
);
70
);
(-)a/admin/item_circulation_alerts.pl (-4 / +3 lines)
Lines 27-37 use JSON; Link Here
27
use C4::Auth;
27
use C4::Auth;
28
use C4::Context;
28
use C4::Context;
29
use C4::Branch;
29
use C4::Branch;
30
use C4::Category;
31
use C4::ItemType;
30
use C4::ItemType;
32
use C4::ItemCirculationAlertPreference;
31
use C4::ItemCirculationAlertPreference;
33
use C4::Output;
32
use C4::Output;
34
33
34
use Koha::Patron::Categories;
35
35
# shortcut for long package name
36
# shortcut for long package name
36
our $preferences = 'C4::ItemCirculationAlertPreference';
37
our $preferences = 'C4::ItemCirculationAlertPreference';
37
38
Lines 75-83 sub show { Link Here
75
    }
76
    }
76
    my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
77
    my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname};
77
78
78
    my @categories = (
79
    my @categories = Koha::Patron::Categories->search_limited;
79
        C4::Category->all
80
    );
81
    my @item_types = map { br($_, 'description') }  (
80
    my @item_types = map { br($_, 'description') }  (
82
        C4::ItemType->all
81
        C4::ItemType->all
83
    );
82
    );
(-)a/debian/templates/plack.psgi (-1 lines)
Lines 28-34 use Plack::App::URLMap; Link Here
28
# Pre-load libraries
28
# Pre-load libraries
29
use C4::Boolean;
29
use C4::Boolean;
30
use C4::Branch;
30
use C4::Branch;
31
use C4::Category;
32
use C4::Koha;
31
use C4::Koha;
33
use C4::Languages;
32
use C4::Languages;
34
use C4::Letters;
33
use C4::Letters;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-5 / +5 lines)
Lines 97-110 Link Here
97
97
98
        <p>
98
        <p>
99
            <label for="categorycode">Category: </label>
99
            <label for="categorycode">Category: </label>
100
            [% SET categories = Categories.all( selected => categorycode_filter ) %]
100
            [% SET categories = Categories.all() %]
101
            <select name="categorycode_filter" id="categorycode">
101
            <select name="categorycode_filter" id="categorycode">
102
                <option value="">Any</option>
102
                <option value="">Any</option>
103
                [% FOREACH categorie IN categories %]
103
                [% FOREACH category IN categories %]
104
                    [% IF ( categorie.selected ) %]
104
                    [% IF category.categorycode == categorycode_filter %]
105
                        <option value="[% categorie.categorycode %]" selected="selected">[% categorie.description %]</option>
105
                        <option value="[% category.categorycode %]" selected="selected">[% category.description %]</option>
106
                    [% ELSE %]
106
                    [% ELSE %]
107
                        <option value="[% categorie.categorycode %]">[% categorie.description %]</option>
107
                        <option value="[% category.categorycode %]">[% category.description %]</option>
108
                    [% END %]
108
                    [% END %]
109
                [% END %]
109
                [% END %]
110
            </select>
110
            </select>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (-2 / +2 lines)
Lines 474-484 function filterByFirstLetterSurname(letter) { Link Here
474
            </li>
474
            </li>
475
            <li>
475
            <li>
476
              <label for="categorycode_filter">Category:</label>
476
              <label for="categorycode_filter">Category:</label>
477
              [% SET categories = Categories.all( selected => categorycode_filter ) %]
477
              [% SET categories = Categories.all() %]
478
              <select id="categorycode_filter">
478
              <select id="categorycode_filter">
479
                <option value="">Any</option>
479
                <option value="">Any</option>
480
                [% FOREACH cat IN categories %]
480
                [% FOREACH cat IN categories %]
481
                  [% IF cat.selected %]
481
                  [% IF cat.categorycode == categorycode_filter %]
482
                    <option selected="selected" value="[% cat.categorycode %]">[% cat.description %]</option>
482
                    <option selected="selected" value="[% cat.categorycode %]">[% cat.description %]</option>
483
                  [% ELSE %]
483
                  [% ELSE %]
484
                    <option value="[% cat.categorycode %]">[% cat.description %]</option>
484
                    <option value="[% cat.categorycode %]">[% cat.description %]</option>
(-)a/members/guarantor_search.pl (-2 / +4 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Branch qw( GetBranches );
24
use C4::Branch qw( GetBranches );
25
use C4::Category;
26
use C4::Output;
25
use C4::Output;
27
use C4::Members;
26
use C4::Members;
28
27
28
use Koha::Patron::Categories;
29
29
my $input = new CGI;
30
my $input = new CGI;
30
31
31
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
Lines 47-59 my $referer = $input->referer(); Link Here
47
my $onlymine = C4::Branch::onlymine;
48
my $onlymine = C4::Branch::onlymine;
48
my $branches = C4::Branch::GetBranches( $onlymine );
49
my $branches = C4::Branch::GetBranches( $onlymine );
49
50
51
my $patron_categories = Koha::Patron::Categories->search_limited;
50
$template->param(
52
$template->param(
51
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
53
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
52
    columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ],
54
    columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ],
53
    json_template => 'members/tables/guarantor_search.tt',
55
    json_template => 'members/tables/guarantor_search.tt',
54
    selection_type => 'select',
56
    selection_type => 'select',
55
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
57
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
56
    categories      => [ C4::Category->all ],
58
    categories      => $patron_categories,
57
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
59
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
58
    aaSorting       => 1,
60
    aaSorting       => 1,
59
);
61
);
(-)a/members/member.pl (-1 lines)
Lines 28-34 use C4::Auth; Link Here
28
use C4::Output;
28
use C4::Output;
29
use CGI qw( -utf8 );
29
use CGI qw( -utf8 );
30
use C4::Branch;
30
use C4::Branch;
31
use C4::Category;
32
use C4::Members qw( GetMember );
31
use C4::Members qw( GetMember );
33
use Koha::DateUtils;
32
use Koha::DateUtils;
34
use Koha::List::Patron;
33
use Koha::List::Patron;
(-)a/members/members-home.pl (-3 / +2 lines)
Lines 25-33 use C4::Output; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Members;
26
use C4::Members;
27
use C4::Branch;
27
use C4::Branch;
28
use C4::Category;
29
use Koha::Borrower::Modifications;
28
use Koha::Borrower::Modifications;
30
use Koha::List::Patron;
29
use Koha::List::Patron;
30
use Koha::Patron::Categories;
31
31
32
my $query = new CGI;
32
my $query = new CGI;
33
my $branch = $query->param('branchcode');
33
my $branch = $query->param('branchcode');
Lines 67-73 if ( C4::Branch::onlymine ) { Link Here
67
    }
67
    }
68
}
68
}
69
69
70
my @categories;
71
my $no_add = 0;
70
my $no_add = 0;
72
if(scalar(@branchloop) < 1){
71
if(scalar(@branchloop) < 1){
73
    $no_add = 1;
72
    $no_add = 1;
Lines 77-83 else { Link Here
77
    $template->param(branchloop=>\@branchloop);
76
    $template->param(branchloop=>\@branchloop);
78
}
77
}
79
78
80
@categories=C4::Category->all;
79
my @categories = Koha::Patron::Categories->search_limited;
81
if(scalar(@categories) < 1){
80
if(scalar(@categories) < 1){
82
    $no_add = 1;
81
    $no_add = 1;
83
    $template->param(no_categories => 1);
82
    $template->param(no_categories => 1);
(-)a/members/members-update-do.pl (-1 lines)
Lines 25-31 use C4::Output; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Members;
26
use C4::Members;
27
use C4::Branch;
27
use C4::Branch;
28
use C4::Category;
29
use Koha::Borrower::Modifications;
28
use Koha::Borrower::Modifications;
30
29
31
my $query = new CGI;
30
my $query = new CGI;
(-)a/members/members-update.pl (-1 lines)
Lines 25-31 use C4::Output; Link Here
25
use C4::Context;
25
use C4::Context;
26
use C4::Members;
26
use C4::Members;
27
use C4::Branch;
27
use C4::Branch;
28
use C4::Category;
29
use Koha::Borrower::Modifications;
28
use Koha::Borrower::Modifications;
30
29
31
my $query = new CGI;
30
my $query = new CGI;
(-)a/members/nl-search.pl (-4 / +3 lines)
Lines 37-43 See http://www.lanekortet.no/ for more information (in Norwegian). Link Here
37
use Modern::Perl;
37
use Modern::Perl;
38
use CGI;
38
use CGI;
39
use C4::Auth;
39
use C4::Auth;
40
use C4::Category;
41
use C4::Context;
40
use C4::Context;
42
use C4::Output;
41
use C4::Output;
43
use C4::Members;
42
use C4::Members;
Lines 46-51 use C4::Utils::DataTables::Members; Link Here
46
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLSearch NLDecodePin NLGetFirstname NLGetSurname NLSync );
45
use Koha::NorwegianPatronDB qw( NLCheckSysprefs NLSearch NLDecodePin NLGetFirstname NLGetSurname NLSync );
47
use Koha::Database;
46
use Koha::Database;
48
use Koha::DateUtils;
47
use Koha::DateUtils;
48
use Koha::Patron::Categories;
49
49
50
my $cgi = CGI->new;
50
my $cgi = CGI->new;
51
my $dbh = C4::Context->dbh;
51
my $dbh = C4::Context->dbh;
Lines 92-102 if ( $op && $op eq 'search' ) { Link Here
92
            my $result = NLSearch( $identifier );
92
            my $result = NLSearch( $identifier );
93
            unless ($result->fault) {
93
            unless ($result->fault) {
94
                my $r = $result->result();
94
                my $r = $result->result();
95
                # Send the data to the template
95
                my $categories = Koha::Patron::Categories->search_limited;
96
                my @categories = C4::Category->all;
97
                $template->param(
96
                $template->param(
98
                    'result'     => $r,
97
                    'result'     => $r,
99
                    'categories' => \@categories,
98
                    'categories' => $categories,
100
                );
99
                );
101
            } else {
100
            } else {
102
                $template->param( 'error' => join ', ', $result->faultcode, $result->faultstring, $result->faultdetail );
101
                $template->param( 'error' => join ', ', $result->faultcode, $result->faultstring, $result->faultdetail );
(-)a/misc/plack/koha.psgi (-1 / +1 lines)
Lines 43-50 use C4::Letters; Link Here
43
use C4::Koha;
43
use C4::Koha;
44
use C4::XSLT;
44
use C4::XSLT;
45
use C4::Branch;
45
use C4::Branch;
46
use C4::Category;
47
use Koha::DateUtils;
46
use Koha::DateUtils;
47
use Koha::Patron::Categories;
48
=for preload
48
=for preload
49
use C4::Tags; # FIXME
49
use C4::Tags; # FIXME
50
=cut
50
=cut
(-)a/patroncards/add_user_search.pl (-2 / +4 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Branch qw( GetBranches );
24
use C4::Branch qw( GetBranches );
25
use C4::Category;
26
use C4::Output;
25
use C4::Output;
27
use C4::Members;
26
use C4::Members;
28
27
28
use Koha::Patron::Categories;
29
29
my $input = new CGI;
30
my $input = new CGI;
30
31
31
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
Lines 47-59 my $referer = $input->referer(); Link Here
47
my $onlymine = C4::Branch::onlymine;
48
my $onlymine = C4::Branch::onlymine;
48
my $branches = C4::Branch::GetBranches( $onlymine );
49
my $branches = C4::Branch::GetBranches( $onlymine );
49
50
51
my $patron_categories = Koha::Patron::Categories->search_limited;
50
$template->param(
52
$template->param(
51
    view            => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
53
    view            => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
52
    columns         => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'],
54
    columns         => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'],
53
    json_template   => 'patroncards/tables/members_results.tt',
55
    json_template   => 'patroncards/tables/members_results.tt',
54
    selection_type  => 'add',
56
    selection_type  => 'add',
55
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
57
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
56
    categories      => [ C4::Category->all ],
58
    categories      => $patron_categories,
57
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
59
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
58
    aaSorting       => 1,
60
    aaSorting       => 1,
59
);
61
);
(-)a/reports/reserves_stats.pl (-1 lines)
Lines 31-37 use C4::Koha; Link Here
31
use C4::Output;
31
use C4::Output;
32
use C4::Reports;
32
use C4::Reports;
33
use C4::Members;
33
use C4::Members;
34
use C4::Category;
35
use Koha::DateUtils;
34
use Koha::DateUtils;
36
use List::MoreUtils qw/any/;
35
use List::MoreUtils qw/any/;
37
use YAML;
36
use YAML;
(-)a/serials/add_user_search.pl (-2 / +4 lines)
Lines 22-31 use Modern::Perl; Link Here
22
use CGI qw ( -utf8 );
22
use CGI qw ( -utf8 );
23
use C4::Auth;
23
use C4::Auth;
24
use C4::Branch qw( GetBranches );
24
use C4::Branch qw( GetBranches );
25
use C4::Category;
26
use C4::Output;
25
use C4::Output;
27
use C4::Members;
26
use C4::Members;
28
27
28
use Koha::Patron::Categories;
29
29
my $input = new CGI;
30
my $input = new CGI;
30
31
31
my $dbh = C4::Context->dbh;
32
my $dbh = C4::Context->dbh;
Lines 46-51 my $referer = $input->referer(); Link Here
46
47
47
my $onlymine = C4::Branch::onlymine;
48
my $onlymine = C4::Branch::onlymine;
48
my $branches = C4::Branch::GetBranches( $onlymine );
49
my $branches = C4::Branch::GetBranches( $onlymine );
50
my $patron_categories = Koha::Patron::Categories->search_limited;
49
51
50
$template->param(
52
$template->param(
51
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
53
    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
Lines 53-59 $template->param( Link Here
53
    json_template => 'serials/tables/members_results.tt',
55
    json_template => 'serials/tables/members_results.tt',
54
    selection_type => 'add',
56
    selection_type => 'add',
55
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
57
    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
56
    categories      => [ C4::Category->all ],
58
    categories      => $patron_categories,
57
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
59
    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
58
    aaSorting       => 1,
60
    aaSorting       => 1,
59
);
61
);
(-)a/t/db_dependent/Category.t (-62 lines)
Lines 1-62 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2014 - Koha Team
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 t::lib::TestBuilder;
23
use Test::More tests => 3;
24
25
use Koha::Database;
26
27
BEGIN {
28
    use_ok('C4::Category');
29
}
30
31
my $schema  = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new();
35
36
my $nonexistent_categorycode = 'NONEXISTEN';
37
$builder->build({
38
    source => 'Category',
39
    value  => {
40
        categorycode          => $nonexistent_categorycode,
41
        description           => 'Desc',
42
        enrolmentperiod       => 12,
43
        enrolementperioddate  => '2014-01-02',
44
        upperagelimit         => 99,
45
        dateofbirthrequired   => 1,
46
        enrolmentfee          => 1.5,
47
        reservefee            => 2.5,
48
        hidelostitems         => 0,
49
        overduenoticerequired => 0,
50
        category_type         => 'A',
51
    },
52
});
53
54
my @categories = C4::Category->all;
55
ok( @categories, 'all returns categories' );
56
57
my $match = grep {$_->{categorycode} eq $nonexistent_categorycode } @categories;
58
is( $match, 1, 'all returns the inserted category');
59
60
$schema->storage->txn_rollback;
61
62
1;
(-)a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t (-1 lines)
Lines 24-30 use C4::Biblio; Link Here
24
use C4::Items;
24
use C4::Items;
25
use C4::Members;
25
use C4::Members;
26
use C4::Branch;
26
use C4::Branch;
27
use C4::Category;
28
use MARC::Record;
27
use MARC::Record;
29
28
30
BEGIN {
29
BEGIN {
(-)a/t/db_dependent/Circulation/GetIssues.t (-3 / +3 lines)
Lines 8-15 use C4::Biblio; Link Here
8
use C4::Items;
8
use C4::Items;
9
use C4::Members;
9
use C4::Members;
10
use C4::Branch;
10
use C4::Branch;
11
use C4::Category;
12
use C4::Circulation;
11
use C4::Circulation;
12
use Koha::Patron::Categories;
13
use MARC::Record;
13
use MARC::Record;
14
14
15
my $dbh = C4::Context->dbh;
15
my $dbh = C4::Context->dbh;
Lines 43-51 my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumb Link Here
43
43
44
my $categorycode;
44
my $categorycode;
45
my $category_created;
45
my $category_created;
46
my @categories = C4::Category->all;
46
my @categories = Koha::Patron::Categories->search_limited;
47
if (@categories) {
47
if (@categories) {
48
    $categorycode = $categories[0]->{categorycode}
48
    $categorycode = $categories[0]->categorycode
49
} else {
49
} else {
50
    $categorycode = 'C';
50
    $categorycode = 'C';
51
    C4::Context->dbh->do(
51
    C4::Context->dbh->do(
(-)a/t/db_dependent/Koha/Patron/Categories.t (-2 / +19 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 9;
23
23
24
use C4::Context;
24
use Koha::Database;
25
use Koha::Database;
25
use Koha::Patron::Category;
26
use Koha::Patron::Category;
26
use Koha::Patron::Categories;
27
use Koha::Patron::Categories;
Lines 49-56 is( $retrieved_category_1->categorycode, $new_category_1->categorycode, 'Find a Link Here
49
is_deeply( $retrieved_category_1->branch_limitations, [ $branch->{branchcode} ], 'The branch limitation should have been stored and retrieved' );
50
is_deeply( $retrieved_category_1->branch_limitations, [ $branch->{branchcode} ], 'The branch limitation should have been stored and retrieved' );
50
is_deeply( $retrieved_category_1->default_messaging, [], 'By default there is not messaging option' );
51
is_deeply( $retrieved_category_1->default_messaging, [], 'By default there is not messaging option' );
51
52
53
my $another_branch = $builder->build( { source => 'Branch', } );
54
C4::Context->_new_userenv('my_new_userenv');
55
C4::Context->set_userenv( 0, 0, 'usercnum', 'firstname', 'surname', $another_branch->{branchcode}, 'My wonderful library', '', '', '' );
56
my $new_category_3 = Koha::Patron::Category->new(
57
    {   categorycode => 'mycatcodeZ',
58
        description  => 'mycatdescZ',
59
    }
60
)->store;
61
$new_category_3->add_branch_limitation( $another_branch->{branchcode} );
62
is( Koha::Patron::Categories->search->count, $nb_of_categories + 3, 'The 3rd patron category should have been added' );
63
my @limited_categories = Koha::Patron::Categories->search_limited;
64
my @limited_category_codes = map { $_->categorycode } @limited_categories;
65
is( scalar( grep { $_ eq $new_category_1->categorycode } @limited_category_codes ), 0, 'The first category is limited to another branch' );
66
is( scalar( grep { $_ eq $new_category_2->categorycode } @limited_category_codes ), 1, 'The second category is not limited' );
67
is( scalar( grep { $_ eq $new_category_3->categorycode } @limited_category_codes ), 1, 'The third category is limited to my branch ' );
68
52
$retrieved_category_1->delete;
69
$retrieved_category_1->delete;
53
is( Koha::Patron::Categories->search->count, $nb_of_categories + 1, 'Delete should have deleted the patron category' );
70
is( Koha::Patron::Categories->search->count, $nb_of_categories + 2, 'Delete should have deleted the patron category' );
54
71
55
$schema->storage->txn_rollback;
72
$schema->storage->txn_rollback;
56
73
(-)a/t/db_dependent/Members/GetAllIssues.t (-1 lines)
Lines 9-15 use C4::Biblio; Link Here
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
14
use MARC::Record;
13
use MARC::Record;
15
14
(-)a/t/db_dependent/Members/GetOverdues.t (-1 lines)
Lines 9-15 use C4::Biblio; Link Here
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
14
use MARC::Record;
13
use MARC::Record;
15
14
(-)a/t/db_dependent/Members/GetPendingIssues.t (-1 lines)
Lines 9-15 use C4::Biblio; Link Here
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
14
use MARC::Record;
13
use MARC::Record;
15
14
(-)a/t/db_dependent/Members/IssueSlip.t (-1 lines)
Lines 9-15 use C4::Biblio; Link Here
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
11
use C4::Branch;
12
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
14
13
15
use Koha::DateUtils qw( dt_from_string output_pref );
14
use Koha::DateUtils qw( dt_from_string output_pref );
(-)a/t/db_dependent/Ratings.t (-2 / +2 lines)
Lines 22-29 use Test::More tests => 14; Link Here
22
use C4::Biblio qw/AddBiblio/;
22
use C4::Biblio qw/AddBiblio/;
23
use C4::Members;
23
use C4::Members;
24
use C4::Context;
24
use C4::Context;
25
use C4::Category;
26
use Koha::Database;
25
use Koha::Database;
26
use Koha::Patron::Categories;
27
27
28
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
29
29
Lines 41-47 my $library = $builder->build({ Link Here
41
41
42
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
42
my ($biblionumber) = AddBiblio( MARC::Record->new, '' );
43
43
44
my @categories   = C4::Category->all;
44
my @categories   = Koha::Patron::Categories->search_limited;
45
my $categorycode = $categories[0]->categorycode;
45
my $categorycode = $categories[0]->categorycode;
46
my $branchcode   = $library->{branchcode};
46
my $branchcode   = $library->{branchcode};
47
47
(-)a/t/db_dependent/Utils/Datatables_Members.t (-1 / +3 lines)
Lines 26-31 use C4::Members; Link Here
26
use C4::Members::Attributes;
26
use C4::Members::Attributes;
27
use C4::Members::AttributeTypes;
27
use C4::Members::AttributeTypes;
28
28
29
use Koha::Patron::Categories;
30
29
use t::lib::Mocks;
31
use t::lib::Mocks;
30
32
31
use_ok( "C4::Utils::DataTables::Members" );
33
use_ok( "C4::Utils::DataTables::Members" );
Lines 37-43 $dbh->{AutoCommit} = 0; Link Here
37
$dbh->{RaiseError} = 1;
39
$dbh->{RaiseError} = 1;
38
40
39
# Pick a categorycode from the DB
41
# Pick a categorycode from the DB
40
my @categories   = C4::Category->all;
42
my @categories   = Koha::Patron::Categories->search_limited;
41
my $categorycode = $categories[0]->categorycode;
43
my $categorycode = $categories[0]->categorycode;
42
# Add a new branch so we control what borrowers it has
44
# Add a new branch so we control what borrowers it has
43
my $branchcode   = "UNC";
45
my $branchcode   = "UNC";
(-)a/t/db_dependent/Utils/Datatables_Virtualshelves.t (-2 / +2 lines)
Lines 24-29 use C4::Context; Link Here
24
use C4::Branch;
24
use C4::Branch;
25
use C4::Members;
25
use C4::Members;
26
26
27
use Koha::Patron::Categories;
27
use Koha::Virtualshelf;
28
use Koha::Virtualshelf;
28
use Koha::Virtualshelves;
29
use Koha::Virtualshelves;
29
30
Lines 38-44 $dbh->{RaiseError} = 1; Link Here
38
$dbh->do(q|DELETE FROM virtualshelves|);
39
$dbh->do(q|DELETE FROM virtualshelves|);
39
40
40
# Pick a categorycode from the DB
41
# Pick a categorycode from the DB
41
my @categories   = C4::Category->all;
42
my @categories   = Koha::Patron::Categories->search_limited;
42
my $categorycode = $categories[0]->categorycode;
43
my $categorycode = $categories[0]->categorycode;
43
my $branchcode   = "ABC";
44
my $branchcode   = "ABC";
44
my $branch_data = {
45
my $branch_data = {
45
- 

Return to bug 15407