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

(-)a/Koha/Patron/Attribute/Types.pm (+85 lines)
Lines 18-23 package Koha::Patron::Attribute::Types; Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Koha::Patron::Attribute::Type;
20
use Koha::Patron::Attribute::Type;
21
use C4::Koha qw( GetAuthorisedValues );
21
22
22
use base qw(Koha::Objects Koha::Objects::Limit::Library);
23
use base qw(Koha::Objects Koha::Objects::Limit::Library);
23
24
Lines 27-32 Koha::Patron::Attribute::Types Object set class Link Here
27
28
28
=head1 API
29
=head1 API
29
30
31
=head2 Class Methods
32
33
=cut
34
35
=head3 patron_attributes_form
36
37
    my $patron_attributes_form = Koha::Patron::Attribute::Types::patron_attributes_form
38
39
    Static method that returns patron attribute types to be rendered in a form
40
41
=cut
42
43
sub patron_attributes_form {
44
    my $template   = shift;
45
    my $attributes = shift;
46
    my $op         = shift;
47
48
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
49
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
50
    if ( $attribute_types->count == 0 ) {
51
        $template->param( no_patron_attribute_types => 1 );
52
        return;
53
    }
54
55
    # map patron's attributes into a more convenient structure
56
    my %attr_hash = ();
57
    foreach my $attr (@$attributes) {
58
        push @{ $attr_hash{ $attr->{code} } }, $attr;
59
    }
60
61
    my @attribute_loop = ();
62
    my $i              = 0;
63
    my %items_by_class;
64
    while ( my ($attr_type) = $attribute_types->next ) {
65
        my $entry = {
66
            class         => $attr_type->class(),
67
            code          => $attr_type->code(),
68
            description   => $attr_type->description(),
69
            repeatable    => $attr_type->repeatable(),
70
            category      => $attr_type->authorised_value_category(),
71
            category_code => $attr_type->category_code(),
72
            mandatory     => $attr_type->mandatory(),
73
            is_date       => $attr_type->is_date(),
74
        };
75
        if ( exists $attr_hash{ $attr_type->code() } ) {
76
            foreach my $attr ( @{ $attr_hash{ $attr_type->code() } } ) {
77
                my $newentry = {%$entry};
78
                $newentry->{value}        = $attr->{attribute};
79
                $newentry->{use_dropdown} = 0;
80
                if ( $attr_type->authorised_value_category() ) {
81
                    $newentry->{use_dropdown} = 1;
82
                    $newentry->{auth_val_loop} =
83
                        C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
84
                }
85
                $i++;
86
                undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
87
                $newentry->{form_id} = "patron_attr_$i";
88
                push @{ $items_by_class{ $attr_type->class() } }, $newentry;
89
            }
90
        } else {
91
            $i++;
92
            my $newentry = {%$entry};
93
            if ( $attr_type->authorised_value_category() ) {
94
                $newentry->{use_dropdown}  = 1;
95
                $newentry->{auth_val_loop} = C4::Koha::GetAuthorisedValues( $attr_type->authorised_value_category() );
96
            }
97
            $newentry->{form_id} = "patron_attr_$i";
98
            push @{ $items_by_class{ $attr_type->class() } }, $newentry;
99
        }
100
    }
101
    for my $class ( sort keys %items_by_class ) {
102
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
103
        my $lib = $av->count ? $av->next->lib : $class;
104
        push @attribute_loop, {
105
            class => $class,
106
            items => $items_by_class{$class},
107
            lib   => $lib,
108
        };
109
    }
110
111
    $template->param( patron_attributes => \@attribute_loop );
112
113
}
114
30
=head2 Internal methods
115
=head2 Internal methods
31
116
32
=cut
117
=cut
(-)a/members/memberentry.pl (-75 / +1 lines)
Lines 29-35 use CGI qw ( -utf8 ); Link Here
29
use C4::Auth qw( get_template_and_user haspermission );
29
use C4::Auth qw( get_template_and_user haspermission );
30
use C4::Context;
30
use C4::Context;
31
use C4::Output  qw( output_and_exit output_and_exit_if_error output_html_with_http_headers );
31
use C4::Output  qw( output_and_exit output_and_exit_if_error output_html_with_http_headers );
32
use C4::Koha    qw( GetAuthorisedValues );
33
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
32
use C4::Letters qw( GetPreparedLetter EnqueueLetter SendQueuedMessages );
34
use C4::Form::MessagingPreferences;
33
use C4::Form::MessagingPreferences;
35
use Koha::AuthUtils;
34
use Koha::AuthUtils;
Lines 834-840 if ( C4::Context->preference('uppercasesurnames') ) { Link Here
834
}
833
}
835
834
836
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
835
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
837
    patron_attributes_form( $template, $extended_patron_attributes, $op );
836
    Koha::Patron::Attribute::Types::patron_attributes_form( $template, $extended_patron_attributes, $op );
838
}
837
}
839
838
840
if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
839
if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
Lines 920-997 sub parse_extended_patron_attributes { Link Here
920
    return \@attr;
919
    return \@attr;
921
}
920
}
922
921
923
sub patron_attributes_form {
924
    my $template   = shift;
925
    my $attributes = shift;
926
    my $op         = shift;
927
928
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
929
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
930
    if ( $attribute_types->count == 0 ) {
931
        $template->param( no_patron_attribute_types => 1 );
932
        return;
933
    }
934
935
    # map patron's attributes into a more convenient structure
936
    my %attr_hash = ();
937
    foreach my $attr (@$attributes) {
938
        push @{ $attr_hash{ $attr->{code} } }, $attr;
939
    }
940
941
    my @attribute_loop = ();
942
    my $i              = 0;
943
    my %items_by_class;
944
    while ( my ($attr_type) = $attribute_types->next ) {
945
        my $entry = {
946
            class         => $attr_type->class(),
947
            code          => $attr_type->code(),
948
            description   => $attr_type->description(),
949
            repeatable    => $attr_type->repeatable(),
950
            category      => $attr_type->authorised_value_category(),
951
            category_code => $attr_type->category_code(),
952
            mandatory     => $attr_type->mandatory(),
953
            is_date       => $attr_type->is_date(),
954
        };
955
        if ( exists $attr_hash{ $attr_type->code() } ) {
956
            foreach my $attr ( @{ $attr_hash{ $attr_type->code() } } ) {
957
                my $newentry = {%$entry};
958
                $newentry->{value}        = $attr->{attribute};
959
                $newentry->{use_dropdown} = 0;
960
                if ( $attr_type->authorised_value_category() ) {
961
                    $newentry->{use_dropdown} = 1;
962
                    $newentry->{auth_val_loop} =
963
                        GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
964
                }
965
                $i++;
966
                undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
967
                $newentry->{form_id} = "patron_attr_$i";
968
                push @{ $items_by_class{ $attr_type->class() } }, $newentry;
969
            }
970
        } else {
971
            $i++;
972
            my $newentry = {%$entry};
973
            if ( $attr_type->authorised_value_category() ) {
974
                $newentry->{use_dropdown}  = 1;
975
                $newentry->{auth_val_loop} = GetAuthorisedValues( $attr_type->authorised_value_category() );
976
            }
977
            $newentry->{form_id} = "patron_attr_$i";
978
            push @{ $items_by_class{ $attr_type->class() } }, $newentry;
979
        }
980
    }
981
    for my $class ( sort keys %items_by_class ) {
982
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
983
        my $lib = $av->count ? $av->next->lib : $class;
984
        push @attribute_loop, {
985
            class => $class,
986
            items => $items_by_class{$class},
987
            lib   => $lib,
988
        };
989
    }
990
991
    $template->param( patron_attributes => \@attribute_loop );
992
993
}
994
995
sub add_guarantors {
922
sub add_guarantors {
996
    my ( $patron, $input ) = @_;
923
    my ( $patron, $input ) = @_;
997
924
998
- 

Return to bug 39971