Bug 20443: Remove opac_display and opac_editable from Patron::Attribute
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 17 Jul 2018 14:13:09 +0000 (11:13 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 23 Mar 2020 13:39:10 +0000 (13:39 +0000)
Same as previously for methods that have been added by bug 17792.
It's better to be explicite and tell we are fetch the related attribute's type

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Patron/Attribute.pm
opac/opac-memberentry.pl
t/db_dependent/Koha/Patron/Attributes.t

index 03bfd91..0a44cbf 100644 (file)
@@ -52,34 +52,6 @@ sub store {
     return $self->SUPER::store();
 }
 
-=head3 opac_display
-
-    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
-    if ( $attribute->opac_display ) { ... }
-
-=cut
-
-sub opac_display {
-
-    my $self = shift;
-
-    return Koha::Patron::Attribute::Types->find( $self->code )->opac_display;
-}
-
-=head3 opac_editable
-
-    my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... });
-    if ( $attribute->is_opac_editable ) { ... }
-
-=cut
-
-sub opac_editable {
-
-    my $self = shift;
-
-    return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable;
-}
-
 =head3 type
 
     my $attribute_type = $attribute->type;
index 48054f3..8985c5e 100755 (executable)
@@ -519,7 +519,7 @@ sub DelEmptyFields {
 sub FilterUnchangedAttributes {
     my ( $borrowernumber, $entered_attributes ) = @_;
 
-    my @patron_attributes = grep {$_->opac_editable} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
+    my @patron_attributes = grep {$_->type->opac_editable ? $_ : ()} Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
 
     my $patron_attribute_types;
     foreach my $attr (@patron_attributes) {
@@ -582,7 +582,7 @@ sub GeneratePatronAttributesForm {
         return [];
     }
 
-    my @displayable_attributes = grep { $_->opac_display }
+    my @displayable_attributes = grep { $_->type->opac_display ? $_ : () }
         Koha::Patron::Attributes->search({ borrowernumber => $borrowernumber })->as_list;
 
     my %attr_values = ();
@@ -595,14 +595,14 @@ sub GeneratePatronAttributesForm {
         }
     }
     elsif ( defined $borrowernumber ) {
-        my @editable_attributes = grep { $_->opac_editable } @displayable_attributes;
+        my @editable_attributes = grep { $_->type->opac_editable ? $_ : () } @displayable_attributes;
         foreach my $attr (@editable_attributes) {
             push @{ $attr_values{ $attr->code } }, $attr->attribute;
         }
     }
 
     # Add the non-editable attributes (that don't come from the form)
-    foreach my $attr ( grep { !$_->opac_editable } @displayable_attributes ) {
+    foreach my $attr ( grep { !$_->type->opac_editable } @displayable_attributes ) {
         push @{ $attr_values{ $attr->code } }, $attr->attribute;
     }
 
index fbe1190..e403e0d 100644 (file)
@@ -157,84 +157,6 @@ subtest 'store() unique_id attributes tests' => sub {
     $schema->storage->txn_rollback;
 };
 
-subtest 'opac_display() tests' => sub {
-
-    plan tests => 2;
-
-    $schema->storage->txn_begin;
-
-    my $patron
-        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
-    my $attribute_type_1 = $builder->build(
-        {   source => 'BorrowerAttributeType',
-            value  => { opac_display => 1 }
-        }
-    );
-
-    my $attribute_1 = Koha::Patron::Attribute->new(
-        {   borrowernumber => $patron,
-            code           => $attribute_type_1->{code},
-            attribute      => $patron
-        }
-    );
-    is( $attribute_1->opac_display, 1, '->opac_display returns 1' );
-
-    my $attribute_type_2 = $builder->build(
-        {   source => 'BorrowerAttributeType',
-            value  => { opac_display => 0 }
-        }
-    );
-
-    my $attribute_2 = Koha::Patron::Attribute->new(
-        {   borrowernumber => $patron,
-            code           => $attribute_type_2->{code},
-            attribute      => $patron
-        }
-    );
-    is( $attribute_2->opac_display, 0, '->opac_display returns 0' );
-
-    $schema->storage->txn_rollback;
-};
-
-subtest 'opac_editable() tests' => sub {
-
-    plan tests => 2;
-
-    $schema->storage->txn_begin;
-
-    my $patron
-        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
-    my $attribute_type_1 = $builder->build(
-        {   source => 'BorrowerAttributeType',
-            value  => { opac_editable => 1 }
-        }
-    );
-
-    my $attribute_1 = Koha::Patron::Attribute->new(
-        {   borrowernumber => $patron,
-            code           => $attribute_type_1->{code},
-            attribute      => $patron
-        }
-    );
-    is( $attribute_1->opac_editable, 1, '->opac_editable returns 1' );
-
-    my $attribute_type_2 = $builder->build(
-        {   source => 'BorrowerAttributeType',
-            value  => { opac_editable => 0 }
-        }
-    );
-
-    my $attribute_2 = Koha::Patron::Attribute->new(
-        {   borrowernumber => $patron,
-            code           => $attribute_type_2->{code},
-            attribute      => $patron
-        }
-    );
-    is( $attribute_2->opac_editable, 0, '->opac_editable returns 0' );
-
-    $schema->storage->txn_rollback;
-};
-
 subtest 'type() tests' => sub {
 
     plan tests => 4;