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

(-)a/Koha/Patron/Attribute.pm (-28 lines)
Lines 52-85 sub store { Link Here
52
    return $self->SUPER::store();
52
    return $self->SUPER::store();
53
}
53
}
54
54
55
=head3 opac_display
56
57
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
58
    if ( $attribute->opac_display ) { ... }
59
60
=cut
61
62
sub opac_display {
63
64
    my $self = shift;
65
66
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_display;
67
}
68
69
=head3 opac_editable
70
71
    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
72
    if ( $attribute->is_opac_editable ) { ... }
73
74
=cut
75
76
sub opac_editable {
77
78
    my $self = shift;
79
80
    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
81
}
82
83
=head3 type
55
=head3 type
84
56
85
    my $attribute_type = $attribute->type;
57
    my $attribute_type = $attribute->type;
(-)a/opac/opac-memberentry.pl (-4 / +4 lines)
Lines 518-524 sub DelEmptyFields { Link Here
518
sub FilterUnchangedAttributes {
518
sub FilterUnchangedAttributes {
519
    my ( $borrowernumber, $entered_attributes ) = @_;
519
    my ( $borrowernumber, $entered_attributes ) = @_;
520
520
521
    my @patron_attributes = grep {$_->opac_editable} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
521
    my @patron_attributes = grep {$_->type->opac_editable ? $_ : ()} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
522
522
523
    my $patron_attribute_types;
523
    my $patron_attribute_types;
524
    foreach my $attr (@patron_attributes) {
524
    foreach my $attr (@patron_attributes) {
Lines 581-587 sub GeneratePatronAttributesForm { Link Here
581
        return [];
581
        return [];
582
    }
582
    }
583
583
584
    my @displayable_attributes = grep { $_->opac_display }
584
    my @displayable_attributes = grep { $_->type->opac_display ? $_ : () }
585
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
585
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
586
586
587
    my %attr_values = ();
587
    my %attr_values = ();
Lines 594-607 sub GeneratePatronAttributesForm { Link Here
594
        }
594
        }
595
    }
595
    }
596
    elsif ( defined $borrowernumber ) {
596
    elsif ( defined $borrowernumber ) {
597
        my @editable_attributes = grep { $_->opac_editable } @displayable_attributes;
597
        my @editable_attributes = grep { $_->type->opac_editable ? $_ : () } @displayable_attributes;
598
        foreach my $attr (@editable_attributes) {
598
        foreach my $attr (@editable_attributes) {
599
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
599
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
600
        }
600
        }
601
    }
601
    }
602
602
603
    # Add the non-editable attributes (that don't come from the form)
603
    # Add the non-editable attributes (that don't come from the form)
604
    foreach my $attr ( grep { !$_->opac_editable } @displayable_attributes ) {
604
    foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
605
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
605
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
606
    }
606
    }
607
607
(-)a/t/db_dependent/Koha/Patron/Attributes.t (-79 lines)
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 20443