|
Lines 19-24
use Modern::Perl;
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Koha::Patron::Attribute::Type; |
20 |
use Koha::Patron::Attribute::Type; |
| 21 |
use C4::Koha qw( GetAuthorisedValues ); |
21 |
use C4::Koha qw( GetAuthorisedValues ); |
|
|
22 |
use List::Util qw ( all ); |
| 22 |
|
23 |
|
| 23 |
use base qw(Koha::Objects Koha::Objects::Limit::Library); |
24 |
use base qw(Koha::Objects Koha::Objects::Limit::Library); |
| 24 |
|
25 |
|
|
Lines 47-60
Params:
Link Here
|
| 47 |
=cut |
48 |
=cut |
| 48 |
|
49 |
|
| 49 |
sub patron_attributes_form { |
50 |
sub patron_attributes_form { |
| 50 |
my $template = shift; |
51 |
my $template = shift; |
| 51 |
my $attributes = shift; |
52 |
my $logged_in_user = shift; |
| 52 |
my $op = shift; |
53 |
my $attributes = shift; |
| 53 |
my $query = shift // {}; |
54 |
my $op = shift; |
|
|
55 |
my $query = shift // {}; |
| 54 |
|
56 |
|
| 55 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
57 |
my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
| 56 |
my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( $query, {}, $library_id ); |
58 |
my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( $query, {}, $library_id ); |
| 57 |
if ( $attribute_types->count == 0 ) { |
59 |
if ( $attribute_types->count == 0 |
|
|
60 |
|| ( !$logged_in_user->is_superlibrarian && all { $_->hidden } $attribute_types->as_list ) ) |
| 61 |
{ |
| 58 |
$template->param( no_patron_attribute_types => 1 ); |
62 |
$template->param( no_patron_attribute_types => 1 ); |
| 59 |
return; |
63 |
return; |
| 60 |
} |
64 |
} |
|
Lines 68-79
sub patron_attributes_form {
Link Here
|
| 68 |
my @attribute_loop = (); |
72 |
my @attribute_loop = (); |
| 69 |
my $i = 0; |
73 |
my $i = 0; |
| 70 |
my %items_by_class; |
74 |
my %items_by_class; |
|
|
75 |
my @hidden_attributes; |
| 76 |
my $is_superlibrarian = $logged_in_user->is_superlibrarian; |
| 77 |
|
| 71 |
while ( my ($attr_type) = $attribute_types->next ) { |
78 |
while ( my ($attr_type) = $attribute_types->next ) { |
| 72 |
my $entry = { |
79 |
my $entry = { |
| 73 |
class => $attr_type->class(), |
80 |
class => $attr_type->class(), |
| 74 |
code => $attr_type->code(), |
81 |
code => $attr_type->code(), |
| 75 |
description => $attr_type->description(), |
82 |
description => $attr_type->description(), |
| 76 |
repeatable => $attr_type->repeatable(), |
83 |
repeatable => $attr_type->repeatable(), |
|
|
84 |
hidden => !$is_superlibrarian && $attr_type->hidden(), |
| 85 |
readonly => !$is_superlibrarian && $attr_type->readonly(), |
| 86 |
secret => !$is_superlibrarian && $attr_type->secret(), |
| 77 |
category => $attr_type->authorised_value_category(), |
87 |
category => $attr_type->authorised_value_category(), |
| 78 |
category_code => $attr_type->category_code(), |
88 |
category_code => $attr_type->category_code(), |
| 79 |
mandatory => $attr_type->mandatory(), |
89 |
mandatory => $attr_type->mandatory(), |
|
Lines 84-106
sub patron_attributes_form {
Link Here
|
| 84 |
my $newentry = {%$entry}; |
94 |
my $newentry = {%$entry}; |
| 85 |
$newentry->{value} = $attr->{attribute}; |
95 |
$newentry->{value} = $attr->{attribute}; |
| 86 |
$newentry->{use_dropdown} = 0; |
96 |
$newentry->{use_dropdown} = 0; |
| 87 |
if ( $attr_type->authorised_value_category() ) { |
97 |
|
| 88 |
$newentry->{use_dropdown} = 1; |
98 |
if ( !$is_superlibrarian && ( $attr_type->hidden() || $attr_type->secret() ) ) { |
| 89 |
$newentry->{auth_val_loop} = |
99 |
push @hidden_attributes, $newentry; |
| 90 |
C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} ); |
100 |
} else { |
|
|
101 |
if ( $attr_type->authorised_value_category() ) { |
| 102 |
$newentry->{use_dropdown} = 1; |
| 103 |
$newentry->{auth_val_loop} = |
| 104 |
GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} ); |
| 105 |
} |
| 106 |
undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' ); |
| 107 |
$i++; |
| 108 |
$newentry->{form_id} = "patron_attr_$i"; |
| 109 |
push @{ $items_by_class{ $attr_type->class() } }, $newentry; |
| 91 |
} |
110 |
} |
| 92 |
$i++; |
|
|
| 93 |
undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' ); |
| 94 |
$newentry->{form_id} = "patron_attr_$i"; |
| 95 |
push @{ $items_by_class{ $attr_type->class() } }, $newentry; |
| 96 |
} |
111 |
} |
| 97 |
} else { |
112 |
} else { |
| 98 |
$i++; |
|
|
| 99 |
my $newentry = {%$entry}; |
113 |
my $newentry = {%$entry}; |
| 100 |
if ( $attr_type->authorised_value_category() ) { |
114 |
if ( $attr_type->authorised_value_category() ) { |
| 101 |
$newentry->{use_dropdown} = 1; |
115 |
$newentry->{use_dropdown} = 1; |
| 102 |
$newentry->{auth_val_loop} = C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category() ); |
116 |
$newentry->{auth_val_loop} = C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category() ); |
| 103 |
} |
117 |
} |
|
|
118 |
$i++; |
| 104 |
$newentry->{form_id} = "patron_attr_$i"; |
119 |
$newentry->{form_id} = "patron_attr_$i"; |
| 105 |
push @{ $items_by_class{ $attr_type->class() } }, $newentry; |
120 |
push @{ $items_by_class{ $attr_type->class() } }, $newentry; |
| 106 |
} |
121 |
} |
|
Lines 115-122
sub patron_attributes_form {
Link Here
|
| 115 |
}; |
130 |
}; |
| 116 |
} |
131 |
} |
| 117 |
|
132 |
|
| 118 |
$template->param( patron_attributes => \@attribute_loop ); |
133 |
$template->param( patron_attributes => \@attribute_loop, hidden_patron_attributes => \@hidden_attributes ); |
| 119 |
|
|
|
| 120 |
} |
134 |
} |
| 121 |
|
135 |
|
| 122 |
=head2 Internal methods |
136 |
=head2 Internal methods |