@@ -, +, @@ C4::Category->all - Same prerequisite as before - On the 'Item circulation alerts' admin page (admin/item_circulation_alerts.pl), modify the settings for check-in and checkout (NOTE: Should not we display all patron categories on this page? If yes, it must be done in another bug report to ease backporting it). - Search for patrons in the admin (budget) and acquisition (order) module. - On the patron home page (search form in the header) --- C4/Category.pm | 181 --------------------- C4/ItemCirculationAlertPreference.pm | 4 +- Koha/Patron/Categories.pm | 15 ++ Koha/Template/Plugin/Categories.pm | 20 +-- acqui/add_user_search.pl | 6 +- admin/add_user_search.pl | 6 +- admin/item_circulation_alerts.pl | 6 +- debian/templates/plack.psgi | 1 - .../prog/en/includes/patron-search.inc | 10 +- .../prog/en/modules/members/member.tt | 4 +- members/guarantor_search.pl | 6 +- members/member.pl | 1 - members/members-home.pl | 5 +- members/members-update-do.pl | 1 - members/members-update.pl | 1 - members/nl-search.pl | 7 +- misc/plack/koha.psgi | 2 +- patroncards/add_user_search.pl | 6 +- reports/reserves_stats.pl | 1 - serials/add_user_search.pl | 6 +- t/db_dependent/Category.t | 62 ------- t/db_dependent/Circulation/CheckIfIssuedToPatron.t | 1 - t/db_dependent/Circulation/GetIssues.t | 6 +- t/db_dependent/Koha/Patron/Categories.t | 21 ++- t/db_dependent/Members/GetAllIssues.t | 1 - t/db_dependent/Members/GetOverdues.t | 1 - t/db_dependent/Members/GetPendingIssues.t | 1 - t/db_dependent/Members/IssueSlip.t | 1 - t/db_dependent/Ratings.t | 4 +- t/db_dependent/Utils/Datatables_Members.t | 3 +- t/db_dependent/Utils/Datatables_Virtualshelves.t | 3 +- 31 files changed, 81 insertions(+), 312 deletions(-) delete mode 100644 C4/Category.pm delete mode 100755 t/db_dependent/Category.t --- a/C4/Category.pm +++ a/C4/Category.pm @@ -1,181 +0,0 @@ -package C4::Category; - -# Copyright 2009 Liblime -# Parts Copyright 2011 Tamil -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use strict; -use warnings; -use C4::Context; - -our $AUTOLOAD; - - - - -=head1 NAME - -C4::Category - objects from the categories table - -=head1 SYNOPSIS - - use C4::Category; - my @categories = C4::Category->all; - print join("\n", map { $_->description } @categories), "\n"; - -=head1 DESCRIPTION - -Objects of this class represent a row in the C table. - -Currently, the bare minimum for using this as a read-only data source has -been implemented. The API was designed to make it easy to transition to -an ORM later on. - -=head1 API - -=head2 Class Methods - -=cut - -=head3 C4::Category->new(\%opts) - -Given a hashref, a new (in-memory) C4::Category object will be instantiated. -The database is not touched. - -=cut - -sub new { - my ($class, $opts) = @_; - bless $opts => $class; -} - - - - -=head3 C4::Category->all - -This returns all the categories as objects. By default they're ordered by -C. - -=cut - -sub all { - my ( $class ) = @_; - my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; - my $dbh = C4::Context->dbh; - # The categories table is small enough for - # `SELECT *` to be harmless. - my $query = "SELECT categories.* FROM categories"; - $query .= qq{ - LEFT JOIN categories_branches ON categories_branches.categorycode = categories.categorycode - WHERE categories_branches.branchcode = ? OR categories_branches.branchcode IS NULL - } if $branch_limit; - $query .= " ORDER BY description"; - return map { $class->new($_) } @{ - $dbh->selectall_arrayref( - $query, - { Slice => {} }, - $branch_limit ? $branch_limit : () - ) - }; -} - - - - -=head2 Object Methods - -These are read-only accessors for attributes of a C4::Category object. - -=head3 $category->categorycode - -=cut - -=head3 $category->description - -=cut - -=head3 $category->enrolmentperiod - -=cut - -=head3 $category->upperagelimit - -=cut - -=head3 $category->dateofbirthrequired - -=cut - -=head3 $category->finetype - -=cut - -=head3 $category->bulk - -=cut - -=head3 $category->enrolmentfee - -=cut - -=head3 $category->overduenoticerequired - -=cut - -=head3 $category->issuelimit - -=cut - -=head3 $category->reservefee - -=cut - -=head3 $category->category_type - -=cut - -sub AUTOLOAD { - my $self = shift; - my $attr = $AUTOLOAD; - $attr =~ s/.*://; - if (exists $self->{$attr}) { - return $self->{$attr}; - } else { - return undef; - } -} - -sub DESTROY { } - - - - -=head1 SEE ALSO - -The following modules make reference to the C table. - -L, L, L - - -=head1 AUTHOR - -John Beppu - -=cut - -1; --- a/C4/ItemCirculationAlertPreference.pm +++ a/C4/ItemCirculationAlertPreference.pm @@ -20,10 +20,10 @@ package C4::ItemCirculationAlertPreference; use strict; use warnings; use C4::Context; -use C4::Category; use Carp qw(carp croak); use Koha::ItemTypes; +use Koha::Patron::Categories; our $AUTOLOAD; @@ -331,7 +331,7 @@ sub grid { my ($class, $where) = @_; my @branch_prefs = $class->find($where); my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} }); - my @cc = C4::Category->all; + my @cc = Koha::Patron::Categories->search_limited; my @it = Koha::ItemTypes->search; my $notification = $where->{notification}; my %disabled = map { --- a/Koha/Patron/Categories.pm +++ a/Koha/Patron/Categories.pm @@ -19,6 +19,8 @@ use Modern::Perl; use Carp; +use C4::Context; # Sigh... + use Koha::Database; use Koha::Patron::Category; @@ -35,6 +37,19 @@ Koha::Patron::Categories - Koha Patron Category Object set class =cut +sub search_limited { + my ( $self ) = @_; + my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; + return $self->search({}, {order_by => ['description']}) unless $branch_limit; + return $self->search({ + 'categories_branches.branchcode' => [$branch_limit, undef]}, + { + join => 'categories_branches', + order_by => ['description'], + } + ); +} + =head3 type =cut --- a/Koha/Template/Plugin/Categories.pm +++ a/Koha/Template/Plugin/Categories.pm @@ -20,28 +20,10 @@ use Modern::Perl; use Template::Plugin; use base qw( Template::Plugin ); -use C4::Category; use Koha::Patron::Categories; -sub GetName { - my ( $self, $categorycode ) = @_; - - return Koha::Patron::Categories->find( $categorycode )->description; -} - sub all { - my ( $self, $params ) = @_; - my $selected = $params->{selected}; - - my @categories = C4::Category->all; - if ( $selected ) { - for my $category ( @categories ) { - if ( $category->{categorycode} eq $selected ) { - $category->{selected} = 1; - } - } - } - return @categories; + return Koha::Patron::Categories->search_limited; } 1; --- a/acqui/add_user_search.pl +++ a/acqui/add_user_search.pl @@ -22,10 +22,11 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; use C4::Branch qw( GetBranches ); -use C4::Category; use C4::Output; use C4::Members; +use Koha::Patron::Categories; + my $input = new CGI; my $dbh = C4::Context->dbh; @@ -54,6 +55,7 @@ my $search_patrons_with_acq_perm_only = my $onlymine = C4::Branch::onlymine; my $branches = C4::Branch::GetBranches( $onlymine ); +my $patron_categories = Koha::Patron::Categories->search_limited; $template->param( patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", @@ -61,7 +63,7 @@ $template->param( json_template => 'acqui/tables/members_results.tt', selection_type => 'add', alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), - categories => [ C4::Category->all ], + categories => $patron_categories, branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ], aaSorting => 1, ); --- a/admin/add_user_search.pl +++ a/admin/add_user_search.pl @@ -22,10 +22,11 @@ use Modern::Perl; use CGI qw ( -utf8 ); use C4::Auth; use C4::Branch qw( GetBranches ); -use C4::Category; use C4::Output; use C4::Members; +use Koha::Patron::Categories; + my $input = new CGI; my $dbh = C4::Context->dbh; @@ -55,6 +56,7 @@ my $search_patrons_with_acq_perm_only = my $onlymine = C4::Branch::onlymine; my $branches = C4::Branch::GetBranches( $onlymine ); +my $patron_categories = Koha::Patron::Categories->search_limited; $template->param( patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only, view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results", @@ -62,7 +64,7 @@ $template->param( json_template => 'acqui/tables/members_results.tt', selection_type => $selection_type, alphabet => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ), - categories => [ C4::Category->all ], + categories => $patron_categories, branches => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ], aaSorting => 1, ); --- a/admin/item_circulation_alerts.pl +++ a/admin/item_circulation_alerts.pl @@ -27,11 +27,11 @@ use JSON; use C4::Auth; use C4::Context; use C4::Branch; -use C4::Category; use C4::ItemCirculationAlertPreference; use C4::Output; use Koha::ItemTypes; +use Koha::Patron::Categories; # shortcut for long package name our $preferences = 'C4::ItemCirculationAlertPreference'; @@ -65,9 +65,7 @@ sub show { } my $branch_name = exists($br->{$branch}) && $br->{$branch}->{branchname}; - my @categories = ( - C4::Category->all - ); + my @categories = Koha::Patron::Categories->search_limited; my @item_types = Koha::ItemTypes->search; my $grid_checkout = $preferences->grid({ branchcode => $branch, notification => 'CHECKOUT' }); my $grid_checkin = $preferences->grid({ branchcode => $branch, notification => 'CHECKIN' }); --- a/debian/templates/plack.psgi +++ a/debian/templates/plack.psgi @@ -28,7 +28,6 @@ use Plack::App::URLMap; # Pre-load libraries use C4::Boolean; use C4::Branch; -use C4::Category; use C4::Koha; use C4::Languages; use C4::Letters; --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -97,14 +97,14 @@

- [% SET categories = Categories.all( selected => categorycode_filter ) %] + [% SET categories = Categories.all() %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt @@ -478,11 +478,11 @@ function filterByFirstLetterSurname(letter) {

  • - [% SET categories = Categories.all( selected => categorycode_filter ) %] + [% SET categories = Categories.all() %]