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 839-845 if ( C4::Context->preference('uppercasesurnames') ) { Link Here
839
}
838
}
840
839
841
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
840
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
842
    patron_attributes_form( $template, $extended_patron_attributes, $op );
841
    Koha::Patron::Attribute::Types::patron_attributes_form( $template, $extended_patron_attributes, $op );
843
}
842
}
844
843
845
if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
844
if ( C4::Context->preference('EnhancedMessagingPreferences') ) {
Lines 929-1006 sub parse_extended_patron_attributes { Link Here
929
    return \@attr;
928
    return \@attr;
930
}
929
}
931
930
932
sub patron_attributes_form {
933
    my $template   = shift;
934
    my $attributes = shift;
935
    my $op         = shift;
936
937
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
938
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
939
    if ( $attribute_types->count == 0 ) {
940
        $template->param( no_patron_attribute_types => 1 );
941
        return;
942
    }
943
944
    # map patron's attributes into a more convenient structure
945
    my %attr_hash = ();
946
    foreach my $attr (@$attributes) {
947
        push @{ $attr_hash{ $attr->{code} } }, $attr;
948
    }
949
950
    my @attribute_loop = ();
951
    my $i              = 0;
952
    my %items_by_class;
953
    while ( my ($attr_type) = $attribute_types->next ) {
954
        my $entry = {
955
            class         => $attr_type->class(),
956
            code          => $attr_type->code(),
957
            description   => $attr_type->description(),
958
            repeatable    => $attr_type->repeatable(),
959
            category      => $attr_type->authorised_value_category(),
960
            category_code => $attr_type->category_code(),
961
            mandatory     => $attr_type->mandatory(),
962
            is_date       => $attr_type->is_date(),
963
        };
964
        if ( exists $attr_hash{ $attr_type->code() } ) {
965
            foreach my $attr ( @{ $attr_hash{ $attr_type->code() } } ) {
966
                my $newentry = {%$entry};
967
                $newentry->{value}        = $attr->{attribute};
968
                $newentry->{use_dropdown} = 0;
969
                if ( $attr_type->authorised_value_category() ) {
970
                    $newentry->{use_dropdown} = 1;
971
                    $newentry->{auth_val_loop} =
972
                        GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
973
                }
974
                $i++;
975
                undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
976
                $newentry->{form_id} = "patron_attr_$i";
977
                push @{ $items_by_class{ $attr_type->class() } }, $newentry;
978
            }
979
        } else {
980
            $i++;
981
            my $newentry = {%$entry};
982
            if ( $attr_type->authorised_value_category() ) {
983
                $newentry->{use_dropdown}  = 1;
984
                $newentry->{auth_val_loop} = GetAuthorisedValues( $attr_type->authorised_value_category() );
985
            }
986
            $newentry->{form_id} = "patron_attr_$i";
987
            push @{ $items_by_class{ $attr_type->class() } }, $newentry;
988
        }
989
    }
990
    for my $class ( sort keys %items_by_class ) {
991
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
992
        my $lib = $av->count ? $av->next->lib : $class;
993
        push @attribute_loop, {
994
            class => $class,
995
            items => $items_by_class{$class},
996
            lib   => $lib,
997
        };
998
    }
999
1000
    $template->param( patron_attributes => \@attribute_loop );
1001
1002
}
1003
1004
sub add_guarantors {
931
sub add_guarantors {
1005
    my ( $patron, $input ) = @_;
932
    my ( $patron, $input ) = @_;
1006
933
1007
- 

Return to bug 39971