Bugzilla – Attachment 78213 Details for
Bug 19909
Show attributes in patron search results
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19909: Show attributes in patron search results
Bug-19909-Show-attributes-in-patron-search-results.patch (text/plain), 8.14 KB, created by
Katrin Fischer
on 2018-08-28 06:26:37 UTC
(
hide
)
Description:
Bug 19909: Show attributes in patron search results
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2018-08-28 06:26:37 UTC
Size:
8.14 KB
patch
obsolete
>From c37e1329c011869433a8a11ae7db3ab7ad912aa3 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 3 Jan 2018 11:53:59 +0100 >Subject: [PATCH] Bug 19909: Show attributes in patron search results > >Add a new column (hidden by default) in the results table which >displays all attributes associated to the corresponding patron. > >New subroutine Koha::Patron::Attribute::display_value that >returns the authorised value description and defaults to the raw value >if the attribute's type is not associated to an authorised value >category > >Test plan: >1. Create some patron attribute types, with and without an associated >authorised value category >2. Choose an existing patron and set a value for each attribute >3. Go to patron search and do a search that will return your patron (and >some others to avoid the redirection) >4. Show column 'Extended attributes' by clicking on 'Column visibility' >button >5. Note that all attributes are displayed correctly >6. prove t/db_dependent/Koha/Patron/Attributes.t > >Signed-off-by: Cab Vinton <bibliwho@gmail.com> >--- > 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(-) > >diff --git a/C4/Utils/DataTables/Members.pm b/C4/Utils/DataTables/Members.pm >index 1e3f642..030c78c 100644 >--- a/C4/Utils/DataTables/Members.pm >+++ b/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 >diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm >index 906fc6d..577110f 100644 >--- a/Koha/Patron/Attribute.pm >+++ b/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 >diff --git a/admin/columns_settings.yml b/admin/columns_settings.yml >index 3e2a672..3195dce 100644 >--- a/admin/columns_settings.yml >+++ b/admin/columns_settings.yml >@@ -222,6 +222,9 @@ modules: > - > columnname: fines > - >+ columnname: extended_attributes >+ is_hidden: 1 >+ - > columnname: circ_notes > - > columnname: actions >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt >index 1a765a6..432f4ce 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt >@@ -108,6 +108,7 @@ > <th>Expires on</th> > <th>OD/Checkouts</th> > <th>Fines</th> >+ <th>Extended attributes</th> > <th>Circ note</th> > <th> </th> > </tr> >@@ -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' } > ], >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt >index 6799c31..d4a0ea7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt >@@ -30,6 +30,7 @@ > "[% IF data.overdues %]<span class='overdue'><strong>[% data.overdues | html %]</strong></span>[% ELSE %][% data.overdues | html %][% END %] / [% data.issues | html %]", > "dt_fines": > "<span style='text-align: right; display: block;'>[% IF data.fines < 0 %]<span class='credit'>[% data.fines | $Price | html %]</span> [% ELSIF data.fines > 0 %] <span class='debit'><strong>[% data.fines | $Price | html %]</strong></span> [% ELSE %] [% data.fines | $Price | html %] [% END %]</span>", >+ "dt_extended_attributes": "<ul>[% FOREACH attribute IN data.attributes %]<li>[% attribute.type.description | html %]: [% attribute.display_value | html | html_line_break | collapse %]</li>[% END %]</ul>", > "dt_borrowernotes": > "[% data.borrowernotes.replace('\\\\' , '\\\\') |html_line_break |collapse %]", > "dt_action": >diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t >index 044f317..fb406c3 100644 >--- a/t/db_dependent/Koha/Patron/Attributes.t >+++ b/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; >+}; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19909
:
70243
|
77161
|
77467
|
78213
|
105267
|
105281
|
106528