@@ -, +, @@
C4::Members::AttributeTypes::GetAttributeTypes to
Koha::Patron::Attribute::Types
---
C4/Auth_with_ldap.pm | 10 +-
C4/Members/AttributeTypes.pm | 44 ---------
C4/Members/Attributes.pm | 7 +-
Koha/Template/Plugin/Branches.pm | 23 ++++-
admin/patron-attr-types.pl | 94 ++----------------
.../en/modules/admin/patron-attr-types.tt | 96 +++++++------------
members/memberentry.pl | 8 +-
members/moremember.pl | 5 +-
reports/borrowers_stats.pl | 13 ++-
reports/issues_stats.pl | 7 +-
t/Members_AttributeTypes.t | 4 +-
t/db_dependent/Koha/Patron/Attribute/Types.t | 2 +
tools/import_borrowers.pl | 7 +-
tools/modborrowers.pl | 20 ++--
14 files changed, 109 insertions(+), 231 deletions(-)
--- a/C4/Auth_with_ldap.pm
+++ a/C4/Auth_with_ldap.pm
@@ -233,8 +233,9 @@ sub checkpw_ldap {
return 0; # B2, D2
}
if (C4::Context->preference('ExtendedPatronAttributes') && $borrowernumber && ($config{update} ||$config{replicate})) {
- foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) {
- my $code = $attribute_type->{code};
+ my $attribute_types = Koha::Patron::Attribute::Types->filter_by_branch_limitations;
+ while ( my $attribute_type = $attribute_types->next ) {
+ my $code = $attribute_type->code;
unless (exists($borrower{$code}) && $borrower{$code} !~ m/^\s*$/ ) {
next;
}
@@ -375,8 +376,9 @@ sub update_local {
# skip extended patron attributes in 'borrowers' attribute update
my @keys = keys %$borrower;
if (C4::Context->preference('ExtendedPatronAttributes')) {
- foreach my $attribute_type ( C4::Members::AttributeTypes::GetAttributeTypes() ) {
- my $code = $attribute_type->{code};
+ my $attribute_types = Koha::Patron::Attribute::Types->filter_by_branch_limitations;
+ while ( my $attribute_type = $attribute_types->next ) {
+ my $code = $attribute_type->code;
@keys = grep { $_ ne $code } @keys;
$debug and printf STDERR "ignoring extended patron attribute '%s' in update_local()\n", $code;
}
--- a/C4/Members/AttributeTypes.pm
+++ a/C4/Members/AttributeTypes.pm
@@ -28,8 +28,6 @@ C4::Members::AttributeTypes - mananage extended patron attribute types
=head1 SYNOPSIS
- my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes();
-
my $attr_type = C4::Members::AttributeTypes->new($code, $description);
$attr_type->code($code);
$attr_type->description($description);
@@ -47,48 +45,6 @@ C4::Members::AttributeTypes - mananage extended patron attribute types
=head1 FUNCTIONS
-=head2 GetAttributeTypes
-
- my @attribute_types = C4::Members::AttributeTypes::GetAttributeTypes($all_fields);
-
-Returns an array of hashrefs of each attribute type defined
-in the database. The array is sorted by code. Each hashref contains
-at least the following fields:
-
- - code
- - description
-
-If $all_fields is true, then each hashref also contains the other fields from borrower_attribute_types.
-
-=cut
-
-sub GetAttributeTypes {
- my $all = @_ ? shift : 0;
- my $no_branch_limit = @_ ? shift : 0;
- my $branch_limit = $no_branch_limit
- ? 0
- : C4::Context->userenv ? C4::Context->userenv->{"branch"} : 0;
- my $select = $all ? '*' : 'DISTINCT(code), description, class';
-
- my $dbh = C4::Context->dbh;
- my $query = "SELECT $select FROM borrower_attribute_types";
- $query .= qq{
- LEFT JOIN borrower_attribute_types_branches ON bat_code = code
- WHERE b_branchcode = ? OR b_branchcode IS NULL
- } if $branch_limit;
- $query .= " ORDER BY code";
- my $sth = $dbh->prepare($query);
- $sth->execute( $branch_limit ? $branch_limit : () );
- my $results = $sth->fetchall_arrayref({});
- $sth->finish;
- return @$results;
-}
-
-sub GetAttributeTypes_hashref {
- my %hash = map {$_->{code} => $_} GetAttributeTypes(@_);
- return \%hash;
-}
-
=head1 METHODS
my $attr_type = C4::Members::AttributeTypes->new($code, $description);
--- a/C4/Members/Attributes.pm
+++ a/C4/Members/Attributes.pm
@@ -22,7 +22,8 @@ use warnings;
use Text::CSV; # Don't be tempted to use Text::CSV::Unicode -- even in binary mode it fails.
use C4::Context;
-use C4::Members::AttributeTypes;
+
+use Koha::Patron::Attribute::Types;
use vars qw(@ISA @EXPORT_OK @EXPORT %EXPORT_TAGS);
our ($csv, $AttributeTypes);
@@ -110,7 +111,7 @@ The third option specifies whether repeatable codes are clobbered or collected.
Returns one reference to (merged) array of hashref.
-Caches results of C4::Members::AttributeTypes::GetAttributeTypes_hashref(1) for efficiency.
+Caches results of attribute types for efficiency. # FIXME That is very bad and can cause side-effects undef plack
=cut
@@ -118,7 +119,7 @@ sub extended_attributes_merge {
my $old = shift or return;
my $new = shift or return $old;
my $keep = @_ ? shift : 0;
- $AttributeTypes or $AttributeTypes = C4::Members::AttributeTypes::GetAttributeTypes_hashref(1);
+ $AttributeTypes or $AttributeTypes = Koha::Patron::Attribute::Types->search->unblessed;
my @merged = @$old;
foreach my $att (@$new) {
unless ($att->{code}) {
--- a/Koha/Template/Plugin/Branches.pm
+++ a/Koha/Template/Plugin/Branches.pm
@@ -58,6 +58,7 @@ sub GetURL {
sub all {
my ( $self, $params ) = @_;
my $selected = $params->{selected};
+ my $selecteds = $params->{selecteds};
my $unfiltered = $params->{unfiltered} || 0;
my $search_params = $params->{search_params} || {};
@@ -69,11 +70,23 @@ sub all {
? Koha::Libraries->search( $search_params, { order_by => ['branchname'] } )->unblessed
: Koha::Libraries->search_filtered( $search_params, { order_by => ['branchname'] } )->unblessed;
- for my $l ( @$libraries ) {
- if ( defined $selected and $l->{branchcode} eq $selected
- or not defined $selected and C4::Context->userenv and $l->{branchcode} eq ( C4::Context->userenv->{branch} // q{} )
- ) {
- $l->{selected} = 1;
+ if (defined $selecteds) {
+ # For a select multiple, must be a Koha::Libraries
+ my @selected_branchcodes = $selecteds ? $selecteds->get_column( ['branchcode'] ) : ();
+ $libraries = [ map {
+ my $l = $_;
+ $l->{selected} = 1
+ if grep { $_ eq $l->{branchcode} } @selected_branchcodes;
+ $l;
+ } @$libraries ];
+ }
+ else {
+ for my $l ( @$libraries ) {
+ if ( defined $selected and $l->{branchcode} eq $selected
+ or not defined $selected and C4::Context->userenv and $l->{branchcode} eq ( C4::Context->userenv->{branch} // q{} )
+ ) {
+ $l->{selected} = 1;
+ }
}
}
--- a/admin/patron-attr-types.pl
+++ a/admin/patron-attr-types.pl
@@ -29,6 +29,7 @@ use C4::Context;
use C4::Output;
use C4::Koha;
use C4::Members::AttributeTypes;
+use Koha::Patron::Attribute::Types;
use Koha::AuthorisedValues;
use Koha::Libraries;
@@ -86,23 +87,12 @@ exit 0;
sub add_attribute_type_form {
my $template = shift;
- my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
- my @branches_loop;
- foreach my $branch (@$branches) {
- push @branches_loop, {
- branchcode => $branch->{branchcode},
- branchname => $branch->{branchname},
- };
- }
-
my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
$template->param(
attribute_type_form => 1,
confirm_op => 'add_attribute_type_confirmed',
categories => $patron_categories,
- branches_loop => \@branches_loop,
);
- $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS'));
}
sub error_add_attribute_type_form {
@@ -110,25 +100,6 @@ sub error_add_attribute_type_form {
$template->param(description => scalar $input->param('description'));
- if ($input->param('repeatable')) {
- $template->param(repeatable_checked => 1);
- }
- if ($input->param('unique_id')) {
- $template->param(unique_id_checked => 1);
- }
- if ($input->param('opac_display')) {
- $template->param(opac_display_checked => 1);
- }
- if ($input->param('opac_editable')) {
- $template->param(opac_editable_checked => 1);
- }
- if ($input->param('staff_searchable')) {
- $template->param(staff_searchable_checked => 1);
- }
- if ($input->param('display_checkout')) {
- $template->param(display_checkout_checked => 'checked="checked"');
- }
-
$template->param( category_code => scalar $input->param('category_code') );
$template->param( class => scalar $input->param('class') );
@@ -154,6 +125,8 @@ sub add_update_attribute_type {
my $existing = C4::Members::AttributeTypes->fetch($code);
if (defined($existing)) {
$template->param(duplicate_code_error => $code);
+ # FIXME Regression here
+ # Form will not be refilled with entered values on error
error_add_attribute_type_form($template);
return 0;
}
@@ -231,53 +204,8 @@ sub edit_attribute_type_form {
my $template = shift;
my $code = shift;
- my $attr_type = C4::Members::AttributeTypes->fetch($code);
-
- $template->param(code => $code);
- $template->param(description => $attr_type->description());
- $template->param(class => $attr_type->class());
-
- if ($attr_type->repeatable()) {
- $template->param(repeatable_checked => 1);
- }
- $template->param(repeatable_disabled => 1);
- if ($attr_type->unique_id()) {
- $template->param(unique_id_checked => 1);
- }
- $template->param(unique_id_disabled => 1);
- if ($attr_type->opac_display()) {
- $template->param(opac_display_checked => 1);
- }
- if ($attr_type->opac_editable()) {
- $template->param(opac_editable_checked => 1);
- }
- if ($attr_type->staff_searchable()) {
- $template->param(staff_searchable_checked => 1);
- }
- if ($attr_type->display_checkout()) {
- $template->param(display_checkout_checked => 'checked="checked"');
- }
- $template->param( authorised_value_category => $attr_type->authorised_value_category() );
- $template->param(classes_val_loop => GetAuthorisedValues( 'PA_CLASS' ));
-
- my $branches = Koha::Libraries->search( {}, { order_by => ['branchname'] } )->unblessed;
- my @branches_loop;
- my $selected_branches = $attr_type->branches;
- foreach my $branch (@$branches) {
- my $selected = ( grep {$_->{branchcode} eq $branch->{branchcode}} @$selected_branches ) ? 1 : 0;
- push @branches_loop, {
- branchcode => $branch->{branchcode},
- branchname => $branch->{branchname},
- selected => $selected,
- };
- }
- $template->param( branches_loop => \@branches_loop );
-
- $template->param(
- category_code => $attr_type->category_code,
- category_class => $attr_type->class,
- category_description => $attr_type->category_description,
- );
+ my $attr_type = Koha::Patron::Attribute::Types->find($code);
+ $template->param(attribute_type => $attr_type);
my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']});
$template->param(
@@ -292,18 +220,17 @@ sub edit_attribute_type_form {
sub patron_attribute_type_list {
my $template = shift;
- my @attr_types = C4::Members::AttributeTypes::GetAttributeTypes( 1, 1 );
+ my @attr_types = Koha::Patron::Attribute::Types->search->as_list;
- my @classes = uniq( map { $_->{class} } @attr_types );
+ my @classes = uniq( map { $_->class } @attr_types );
@classes = sort @classes;
my @attributes_loop;
+ # FIXME This is not efficient and should be improved
for my $class (@classes) {
- my ( @items, $branches );
+ my @items;
for my $attr (@attr_types) {
- next if $attr->{class} ne $class;
- my $attr_type = C4::Members::AttributeTypes->fetch($attr->{code});
- $attr->{branches} = $attr_type->branches;
+ next if $attr->class ne $class;
push @items, $attr;
}
my $av = Koha::AuthorisedValues->search({ category => 'PA_CLASS', authorised_value => $class });
@@ -312,7 +239,6 @@ sub patron_attribute_type_list {
class => $class,
items => \@items,
lib => $lib,
- branches => $branches,
};
}
$template->param(available_attribute_types => \@attributes_loop);
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt
@@ -1,6 +1,8 @@
[% USE raw %]
[% USE Asset %]
[% USE AuthorisedValues %]
+[% USE Branches %]
+[% USE scalar %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
Koha › Administration › Patron attribute types
@@ -60,10 +62,10 @@