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 (-3 / +3 lines)
Lines 541-547 sub GeneratePatronAttributesForm { Link Here
541
        return [];
541
        return [];
542
    }
542
    }
543
543
544
    my @displayable_attributes = grep { $_->opac_display }
544
    my @displayable_attributes = grep { $_->type->opac_display }
545
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
545
        Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
546
546
547
    my %attr_values = ();
547
    my %attr_values = ();
Lines 554-567 sub GeneratePatronAttributesForm { Link Here
554
        }
554
        }
555
    }
555
    }
556
    elsif ( defined $borrowernumber ) {
556
    elsif ( defined $borrowernumber ) {
557
        my @editable_attributes = grep { $_->opac_editable } @displayable_attributes;
557
        my @editable_attributes = grep { $_->type->opac_editable } @displayable_attributes;
558
        foreach my $attr (@editable_attributes) {
558
        foreach my $attr (@editable_attributes) {
559
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
559
            push @{ $attr_values{ $attr->code } }, $attr->attribute;
560
        }
560
        }
561
    }
561
    }
562
562
563
    # Add the non-editable attributes (that don't come from the form)
563
    # Add the non-editable attributes (that don't come from the form)
564
    foreach my $attr ( grep { !$_->opac_editable } @displayable_attributes ) {
564
    foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
565
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
565
        push @{ $attr_values{ $attr->code } }, $attr->attribute;
566
    }
566
    }
567
567
(-)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