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

(-)a/Koha/Patron/Attribute.pm (-28 lines)
Lines 51-84 sub store { Link Here
51
    return $self->SUPER::store();
51
    return $self->SUPER::store();
52
}
52
}
53
53
54
=head3 opac_display
55
56
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
57
    if ( $attribute->opac_display ) { ... }
58
59
=cut
60
61
sub opac_display {
62
63
    my $self = shift;
64
65
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_display;
66
}
67
68
=head3 opac_editable
69
70
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
71
    if ( $attribute->is_opac_editable ) { ... }
72
73
=cut
74
75
sub opac_editable {
76
77
    my $self = shift;
78
79
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
80
}
81
82
=head3 type
54
=head3 type
83
55
84
    my $attribute_type = $attribute->type;
56
    my $attribute_type = $attribute->type;
(-)a/opac/opac-memberentry.pl (-6 / +12 lines)
Lines 473-479 sub DelEmptyFields { Link Here
473
sub FilterUnchangedAttributes {
473
sub FilterUnchangedAttributes {
474
    my ( $borrowernumber, $entered_attributes ) = @_;
474
    my ( $borrowernumber, $entered_attributes ) = @_;
475
475
476
    my @patron_attributes = grep {$_->opac_editable} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
476
    my @patron_attributes = grep {$_->type->opac_editable} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
477
477
478
    my $patron_attribute_types;
478
    my $patron_attribute_types;
479
    foreach my $attr (@patron_attributes) {
479
    foreach my $attr (@patron_attributes) {
Lines 530-542 sub GeneratePatronAttributesForm { Link Here
530
    my ( $borrowernumber, $entered_attributes ) = @_;
530
    my ( $borrowernumber, $entered_attributes ) = @_;
531
531
532
    # Get all attribute types and the values for this patron (if applicable)
532
    # Get all attribute types and the values for this patron (if applicable)
533
    my @types = grep { $_->opac_editable() or $_->opac_display }
533
    my @types = Koha::Patron::Attribute::Types->search(
534
        Koha::Patron::Attribute::Types->search()->as_list();
534
        {   -or => [
535
                opac_editable => 1,
536
                opac_display  => 1
537
                ]
538
539
        }
540
    );
535
    if ( scalar(@types) == 0 ) {
541
    if ( scalar(@types) == 0 ) {
536
        return [];
542
        return [];
537
    }
543
    }
538
544
539
    my @displayable_attributes = grep { $_->opac_display }
545
    my @displayable_attributes = grep { $_->type->opac_display }
540
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
546
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
541
547
542
    my %attr_values = ();
548
    my %attr_values = ();
Lines 549-562 sub GeneratePatronAttributesForm { Link Here
549
        }
555
        }
550
    }
556
    }
551
    elsif ( defined $borrowernumber ) {
557
    elsif ( defined $borrowernumber ) {
552
        my @editable_attributes = grep { $_->opac_editable } @displayable_attributes;
558
        my @editable_attributes = grep { $_->type->opac_editable } @displayable_attributes;
553
        foreach my $attr (@editable_attributes) {
559
        foreach my $attr (@editable_attributes) {
554
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
560
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
555
        }
561
        }
556
    }
562
    }
557
563
558
    # Add the non-editable attributes (that don't come from the form)
564
    # Add the non-editable attributes (that don't come from the form)
559
    foreach my $attr ( grep { !$_->opac_editable } @displayable_attributes ) {
565
    foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
560
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
566
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
561
    }
567
    }
562
568
(-)a/t/db_dependent/Koha/Patron/Attributes.t (-80 / +1 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 3;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
use Test::Exception;
Lines 157-240 subtest 'store() unique_id attributes tests' => sub { Link Here
157
    $schema->storage->txn_rollback;
157
    $schema->storage->txn_rollback;
158
};
158
};
159
159
160
subtest 'opac_display() tests' => sub {
161
162
    plan tests => 2;
163
164
    $schema->storage->txn_begin;
165
166
    my $patron
167
        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
168
    my $attribute_type_1 = $builder->build(
169
        {   source => 'BorrowerAttributeType',
170
            value  => { opac_display => 1 }
171
        }
172
    );
173
174
    my $attribute_1 = Koha::Patron::Attribute->new(
175
        {   borrowernumber => $patron,
176
            code           => $attribute_type_1->{code},
177
            attribute      => $patron
178
        }
179
    );
180
    is( $attribute_1->opac_display, 1, '->opac_display returns 1' );
181
182
    my $attribute_type_2 = $builder->build(
183
        {   source => 'BorrowerAttributeType',
184
            value  => { opac_display => 0 }
185
        }
186
    );
187
188
    my $attribute_2 = Koha::Patron::Attribute->new(
189
        {   borrowernumber => $patron,
190
            code           => $attribute_type_2->{code},
191
            attribute      => $patron
192
        }
193
    );
194
    is( $attribute_2->opac_display, 0, '->opac_display returns 0' );
195
196
    $schema->storage->txn_rollback;
197
};
198
199
subtest 'opac_editable() tests' => sub {
200
201
    plan tests => 2;
202
203
    $schema->storage->txn_begin;
204
205
    my $patron
206
        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
207
    my $attribute_type_1 = $builder->build(
208
        {   source => 'BorrowerAttributeType',
209
            value  => { opac_editable => 1 }
210
        }
211
    );
212
213
    my $attribute_1 = Koha::Patron::Attribute->new(
214
        {   borrowernumber => $patron,
215
            code           => $attribute_type_1->{code},
216
            attribute      => $patron
217
        }
218
    );
219
    is( $attribute_1->opac_editable, 1, '->opac_editable returns 1' );
220
221
    my $attribute_type_2 = $builder->build(
222
        {   source => 'BorrowerAttributeType',
223
            value  => { opac_editable => 0 }
224
        }
225
    );
226
227
    my $attribute_2 = Koha::Patron::Attribute->new(
228
        {   borrowernumber => $patron,
229
            code           => $attribute_type_2->{code},
230
            attribute      => $patron
231
        }
232
    );
233
    is( $attribute_2->opac_editable, 0, '->opac_editable returns 0' );
234
235
    $schema->storage->txn_rollback;
236
};
237
238
subtest 'type() tests' => sub {
160
subtest 'type() tests' => sub {
239
161
240
    plan tests => 4;
162
    plan tests => 4;
241
- 

Return to bug 18339