@@ -, +, @@ --- C4/Utils/DataTables/Members.pm | 2 ++ Koha/Patron/Attribute.pm | 33 +++++++++++++++++- admin/columns_settings.yml | 3 ++ .../prog/en/modules/members/member.tt | 2 ++ .../en/modules/members/tables/members_results.tt | 1 + t/db_dependent/Koha/Patron/Attributes.t | 40 +++++++++++++++++++++- 6 files changed, 79 insertions(+), 2 deletions(-) --- a/C4/Utils/DataTables/Members.pm +++ a/C4/Utils/DataTables/Members.pm @@ -5,6 +5,7 @@ use C4::Context; use C4::Utils::DataTables; use Koha::DateUtils; use C4::Members::Attributes qw(SearchIdMatchingAttribute ); +use Koha::Patron::Attributes; sub search { my ( $params ) = @_; @@ -183,6 +184,7 @@ sub search { my $balance = $patron_object->account->balance; # FIXME Should be formatted from the template $patron->{fines} = sprintf("%.2f", $balance); + $patron->{attributes} = Koha::Patron::Attributes->search({ borrowernumber => $patron_object->borrowernumber }); if( $patron->{dateexpiry} ) { # FIXME We should not format the date here, do it in template-side instead --- a/Koha/Patron/Attribute.pm +++ a/Koha/Patron/Attribute.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Koha::Database; use Koha::Exceptions::Patron::Attribute; use Koha::Patron::Attribute::Types; +use Koha::AuthorisedValues; use base qw(Koha::Object); @@ -91,7 +92,37 @@ sub type { my $self = shift; - return Koha::Patron::Attribute::Types->find( $self->code ); + return scalar Koha::Patron::Attribute::Types->find( $self->code ); +} + +=head3 display_value + + my $display_value = $attribute->display_value; + +Returns the authorised value description corresponding to the attribute if its +type is associated to an authorised value category. + +Returns the raw attribute's value otherwise. + +=cut + +sub display_value { + my $self = shift; + + my $value = $self->attribute; + + my $type = $self->type; + if ($type->authorised_value_category) { + my $authorised_values = Koha::AuthorisedValues->search({ + category => $type->authorised_value_category, + authorised_value => $value, + }); + if ($authorised_values->count) { + $value = $authorised_values->next->lib; + } + } + + return $value; } =head2 Internal methods --- a/admin/columns_settings.yml +++ a/admin/columns_settings.yml @@ -222,6 +222,9 @@ modules: - columnname: fines - + columnname: extended_attributes + is_hidden: 1 + - columnname: circ_notes - columnname: actions --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt @@ -108,6 +108,7 @@ Expires on OD/Checkouts Fines + Extended attributes Circ note   @@ -481,6 +482,7 @@ { 'mDataProp': 'dt_dateexpiry' }, { 'mDataProp': 'dt_od_checkouts', 'bSortable': false }, { 'mDataProp': 'dt_fines', 'bSortable': false }, + { 'mDataProp': 'dt_extended_attributes', 'bSortable': false }, { 'mDataProp': 'dt_borrowernotes' }, { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' } ], --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt @@ -30,6 +30,7 @@ "[% IF data.overdues %][% data.overdues | html %][% ELSE %][% data.overdues | html %][% END %] / [% data.issues | html %]", "dt_fines": "[% IF data.fines < 0 %][% data.fines | $Price | html %] [% ELSIF data.fines > 0 %] [% data.fines | $Price | html %] [% ELSE %] [% data.fines | $Price | html %] [% END %]", + "dt_extended_attributes": "", "dt_borrowernotes": "[% data.borrowernotes.replace('\\\\' , '\\\\') |html_line_break |collapse %]", "dt_action": --- a/t/db_dependent/Koha/Patron/Attributes.t +++ a/t/db_dependent/Koha/Patron/Attributes.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use t::lib::TestBuilder; use Test::Exception; @@ -275,3 +275,41 @@ subtest 'type() tests' => sub { $schema->storage->txn_rollback; }; +subtest 'display_value() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $borrower = $builder->build({ source => 'Borrower' }); + + { + my $category = $builder->build({ source => 'AuthorisedValueCategory' }); + my $attr_type = $builder->build({ + source => 'BorrowerAttributeType', + value => { authorised_value_category => $category->{category_name} }, + }); + my $authorisedvalue = $builder->build({ + source => 'AuthorisedValue', + value => { category => $category->{category_name} }, + }); + my $attribute = Koha::Patron::Attribute->new( + { borrowernumber => $borrower->{borrowernumber}, + code => $attr_type->{code}, + attribute => $authorisedvalue->{authorised_value}, + } + )->store; + + is($attribute->display_value, $authorisedvalue->{lib}, 'display_value() returns the authorised value description'); + } + + { + my $attr_type = $builder->build({ source => 'BorrowerAttributeType' }); + my $attr = $builder->build({ source => 'BorrowerAttribute' }); + my $attribute = Koha::Patron::Attributes->find($attr->{id}); + + is($attribute->display_value, $attr->{attribute}, "display_value() returns the raw attribute's value"); + } + + $schema->storage->txn_rollback; +}; --