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

(-)a/C4/Utils/DataTables/Members.pm (+2 lines)
Lines 5-10 use C4::Context; Link Here
5
use C4::Utils::DataTables;
5
use C4::Utils::DataTables;
6
use Koha::DateUtils;
6
use Koha::DateUtils;
7
use C4::Members::Attributes qw(SearchIdMatchingAttribute );
7
use C4::Members::Attributes qw(SearchIdMatchingAttribute );
8
use Koha::Patron::Attributes;
8
9
9
sub search {
10
sub search {
10
    my ( $params ) = @_;
11
    my ( $params ) = @_;
Lines 183-188 sub search { Link Here
183
        my $balance = $patron_object->account->balance;
184
        my $balance = $patron_object->account->balance;
184
        # FIXME Should be formatted from the template
185
        # FIXME Should be formatted from the template
185
        $patron->{fines} = sprintf("%.2f", $balance);
186
        $patron->{fines} = sprintf("%.2f", $balance);
187
        $patron->{attributes} = Koha::Patron::Attributes->search({ borrowernumber => $patron_object->borrowernumber });
186
188
187
        if( $patron->{dateexpiry} ) {
189
        if( $patron->{dateexpiry} ) {
188
            # FIXME We should not format the date here, do it in template-side instead
190
            # FIXME We should not format the date here, do it in template-side instead
(-)a/Koha/Patron/Attribute.pm (-1 / +32 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Exceptions::Patron::Attribute;
21
use Koha::Exceptions::Patron::Attribute;
22
use Koha::Patron::Attribute::Types;
22
use Koha::Patron::Attribute::Types;
23
use Koha::AuthorisedValues;
23
24
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 91-97 sub type { Link Here
91
92
92
    my $self = shift;
93
    my $self = shift;
93
94
94
    return Koha::Patron::Attribute::Types->find( $self->code );
95
    return scalar Koha::Patron::Attribute::Types->find( $self->code );
96
}
97
98
=head3 display_value
99
100
    my $display_value = $attribute->display_value;
101
102
Returns the authorised value description corresponding to the attribute if its
103
type is associated to an authorised value category.
104
105
Returns the raw attribute's value otherwise.
106
107
=cut
108
109
sub display_value {
110
    my $self = shift;
111
112
    my $value = $self->attribute;
113
114
    my $type = $self->type;
115
    if ($type->authorised_value_category) {
116
        my $authorised_values = Koha::AuthorisedValues->search({
117
            category => $type->authorised_value_category,
118
            authorised_value => $value,
119
        });
120
        if ($authorised_values->count) {
121
            $value = $authorised_values->next->lib;
122
        }
123
    }
124
125
    return $value;
95
}
126
}
96
127
97
=head2 Internal methods
128
=head2 Internal methods
(-)a/admin/columns_settings.yml (+3 lines)
Lines 221-226 modules: Link Here
221
          columnname: od_checkouts
221
          columnname: od_checkouts
222
        -
222
        -
223
          columnname: fines
223
          columnname: fines
224
        -
225
          columnname: extended_attributes
226
          is_hidden: 1
224
        -
227
        -
225
          columnname: circ_notes
228
          columnname: circ_notes
226
        -
229
        -
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/member.tt (+2 lines)
Lines 107-112 Link Here
107
                  <th>Expires on</th>
107
                  <th>Expires on</th>
108
                  <th>OD/Checkouts</th>
108
                  <th>OD/Checkouts</th>
109
                  <th>Fines</th>
109
                  <th>Fines</th>
110
                  <th>Extended attributes</th>
110
                  <th>Circ note</th>
111
                  <th>Circ note</th>
111
                  <th>&nbsp;</th>
112
                  <th>&nbsp;</th>
112
                </tr>
113
                </tr>
Lines 479-484 Link Here
479
                    { 'mDataProp': 'dt_dateexpiry' },
480
                    { 'mDataProp': 'dt_dateexpiry' },
480
                    { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
481
                    { 'mDataProp': 'dt_od_checkouts', 'bSortable': false },
481
                    { 'mDataProp': 'dt_fines', 'bSortable': false },
482
                    { 'mDataProp': 'dt_fines', 'bSortable': false },
483
                    { 'mDataProp': 'dt_extended_attributes', 'bSortable': false },
482
                    { 'mDataProp': 'dt_borrowernotes' },
484
                    { 'mDataProp': 'dt_borrowernotes' },
483
                    { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
485
                    { 'mDataProp': 'dt_action', 'bSortable': false, 'sClass': 'actions' }
484
                ],
486
                ],
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/tables/members_results.tt (+1 lines)
Lines 29-34 Link Here
29
                    "[% IF data.overdues %]<span class='overdue'><strong>[% data.overdues %]</strong></span>[% ELSE %][% data.overdues %][% END %] / [% data.issues %]",
29
                    "[% IF data.overdues %]<span class='overdue'><strong>[% data.overdues %]</strong></span>[% ELSE %][% data.overdues %][% END %] / [% data.issues %]",
30
                "dt_fines":
30
                "dt_fines":
31
                    "<span style='text-align: right; display: block;'>[% IF data.fines < 0 %]<span class='credit'>[% data.fines | $Price %]</span> [% ELSIF data.fines > 0 %] <span class='debit'><strong>[% data.fines | $Price %]</strong></span> [% ELSE %] [% data.fines | $Price %] [% END %]</span>",
31
                    "<span style='text-align: right; display: block;'>[% IF data.fines < 0 %]<span class='credit'>[% data.fines | $Price %]</span> [% ELSIF data.fines > 0 %] <span class='debit'><strong>[% data.fines | $Price %]</strong></span> [% ELSE %] [% data.fines | $Price %] [% END %]</span>",
32
                "dt_extended_attributes": "<ul>[% FOREACH attribute IN data.attributes %]<li>[% attribute.type.description %]: [% attribute.display_value | html | html_line_break | collapse %]</li>[% END %]</ul>",
32
                "dt_borrowernotes":
33
                "dt_borrowernotes":
33
                    "[% data.borrowernotes.replace('\\\\' , '\\\\') |html |html_line_break |collapse %]",
34
                    "[% data.borrowernotes.replace('\\\\' , '\\\\') |html |html_line_break |collapse %]",
34
                "dt_action":
35
                "dt_action":
(-)a/t/db_dependent/Koha/Patron/Attributes.t (-2 / +40 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 => 6;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
use Test::Exception;
Lines 275-277 subtest 'type() tests' => sub { Link Here
275
    $schema->storage->txn_rollback;
275
    $schema->storage->txn_rollback;
276
};
276
};
277
277
278
- 
278
subtest 'display_value() tests' => sub {
279
280
    plan tests => 2;
281
282
    $schema->storage->txn_begin;
283
284
    my $borrower = $builder->build({ source => 'Borrower' });
285
286
    {
287
        my $category = $builder->build({ source => 'AuthorisedValueCategory' });
288
        my $attr_type = $builder->build({
289
            source => 'BorrowerAttributeType',
290
            value => { authorised_value_category => $category->{category_name} },
291
        });
292
        my $authorisedvalue = $builder->build({
293
            source => 'AuthorisedValue',
294
            value => { category => $category->{category_name} },
295
        });
296
        my $attribute = Koha::Patron::Attribute->new(
297
            {   borrowernumber => $borrower->{borrowernumber},
298
                code           => $attr_type->{code},
299
                attribute      => $authorisedvalue->{authorised_value},
300
            }
301
        )->store;
302
303
        is($attribute->display_value, $authorisedvalue->{lib}, 'display_value() returns the authorised value description');
304
    }
305
306
    {
307
        my $attr_type = $builder->build({ source => 'BorrowerAttributeType' });
308
        my $attr = $builder->build({ source => 'BorrowerAttribute' });
309
        my $attribute = Koha::Patron::Attributes->find($attr->{id});
310
311
        is($attribute->display_value, $attr->{attribute}, "display_value() returns the raw attribute's value");
312
    }
313
314
    $schema->storage->txn_rollback;
315
};
316

Return to bug 19909