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

(-)a/C4/Auth_with_ldap.pm (-1 lines)
Lines 23-29 use Carp; Link Here
23
use C4::Debug;
23
use C4::Debug;
24
use C4::Context;
24
use C4::Context;
25
use C4::Members::Attributes;
25
use C4::Members::Attributes;
26
use C4::Members::AttributeTypes;
27
use C4::Members::Messaging;
26
use C4::Members::Messaging;
28
use C4::Auth qw(checkpw_internal);
27
use C4::Auth qw(checkpw_internal);
29
use Koha::Patrons;
28
use Koha::Patrons;
(-)a/C4/Members/AttributeTypes.pm (-475 lines)
Lines 1-475 Link Here
1
package C4::Members::AttributeTypes;
2
3
# Copyright (C) 2008 LibLime
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use C4::Context;
22
23
24
25
=head1 NAME
26
27
C4::Members::AttributeTypes - mananage extended patron attribute types
28
29
=head1 SYNOPSIS
30
31
  my $attr_type = C4::Members::AttributeTypes->new($code, $description);
32
  $attr_type->code($code);
33
  $attr_type->description($description);
34
  $attr_type->repeatable($repeatable);
35
  $attr_type->unique_id($unique_id);
36
  $attr_type->opac_display($opac_display);
37
  $attr_type->opac_editable($opac_editable);
38
  $attr_type->staff_searchable($staff_searchable);
39
  $attr_type->authorised_value_category($authorised_value_category);
40
  $attr_type->store();
41
  $attr_type->delete();
42
43
  my $attr_type = C4::Members::AttributeTypes->fetch($code);
44
  $attr_type = C4::Members::AttributeTypes->delete($code);
45
46
=head1 FUNCTIONS
47
48
=head1 METHODS 
49
50
  my $attr_type = C4::Members::AttributeTypes->new($code, $description);
51
52
Create a new attribute type.
53
54
=cut 
55
56
sub new {
57
    my $class = shift;
58
    my $self = {};
59
60
    $self->{'code'} = shift;
61
    $self->{'description'} = shift;
62
    $self->{'repeatable'} = 0;
63
    $self->{'unique_id'} = 0;
64
    $self->{'opac_display'} = 0;
65
    $self->{'opac_editable'} = 0;
66
    $self->{'staff_searchable'} = 0;
67
    $self->{'display_checkout'} = 0;
68
    $self->{'authorised_value_category'} = '';
69
    $self->{'category_code'} = '';
70
    $self->{'category_description'} = '';
71
    $self->{'class'} = '';
72
73
    bless $self, $class;
74
    return $self;
75
}
76
77
=head2 fetch
78
79
  my $attr_type = C4::Members::AttributeTypes->fetch($code);
80
81
Fetches an attribute type from the database.  If no
82
type with the given C<$code> exists, returns undef.
83
84
=cut
85
86
sub fetch {
87
    my $class = shift;
88
    my $code = shift;
89
    my $self = {};
90
    my $dbh = C4::Context->dbh();
91
92
    my $sth = $dbh->prepare_cached("
93
        SELECT borrower_attribute_types.*, categories.description AS category_description
94
        FROM borrower_attribute_types
95
        LEFT JOIN categories ON borrower_attribute_types.category_code=categories.categorycode
96
        WHERE code =?");
97
    $sth->execute($code);
98
    my $row = $sth->fetchrow_hashref;
99
    $sth->finish();
100
    return unless defined $row;
101
102
    $self->{'code'}                      = $row->{'code'};
103
    $self->{'description'}               = $row->{'description'};
104
    $self->{'repeatable'}                = $row->{'repeatable'};
105
    $self->{'unique_id'}                 = $row->{'unique_id'};
106
    $self->{'opac_display'}              = $row->{'opac_display'};
107
    $self->{'opac_editable'}             = $row->{'opac_editable'};
108
    $self->{'staff_searchable'}          = $row->{'staff_searchable'};
109
    $self->{'display_checkout'}          = $row->{'display_checkout'};
110
    $self->{'authorised_value_category'} = $row->{'authorised_value_category'};
111
    $self->{'category_code'}             = $row->{'category_code'};
112
    $self->{'category_description'}      = $row->{'category_description'};
113
    $self->{'class'}                     = $row->{'class'};
114
115
    $sth = $dbh->prepare("SELECT branchcode, branchname FROM borrower_attribute_types_branches, branches WHERE b_branchcode = branchcode AND bat_code = ?;");
116
    $sth->execute( $code );
117
    while ( my $data = $sth->fetchrow_hashref ) {
118
        push @{ $self->{branches} }, $data;
119
    }
120
    $sth->finish();
121
122
    bless $self, $class;
123
    return $self;
124
}
125
126
=head2 store
127
128
  $attr_type->store();
129
130
Stores attribute type in the database.  If the type
131
previously retrieved from the database via the fetch()
132
method, the DB representation of the type is replaced.
133
134
=cut
135
136
sub store {
137
    my $self = shift;
138
139
    my $dbh = C4::Context->dbh;
140
    my $sth;
141
    my $existing = __PACKAGE__->fetch($self->{'code'});
142
    if (defined $existing) {
143
        $sth = $dbh->prepare_cached("UPDATE borrower_attribute_types
144
                                     SET description = ?,
145
                                         repeatable = ?,
146
                                         unique_id = ?,
147
                                         opac_display = ?,
148
                                         opac_editable = ?,
149
                                         staff_searchable = ?,
150
                                         authorised_value_category = ?,
151
                                         display_checkout = ?,
152
                                         category_code = ?,
153
                                         class = ?
154
                                     WHERE code = ?");
155
    } else {
156
        $sth = $dbh->prepare_cached("INSERT INTO borrower_attribute_types 
157
                                        ( description,
158
                                          repeatable,
159
                                          unique_id,
160
                                          opac_display,
161
                                          opac_editable,
162
                                          staff_searchable,
163
                                          authorised_value_category,
164
                                          display_checkout,
165
                                          category_code,
166
                                          class,
167
                                          code
168
                                        )
169
                                        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
170
    }
171
172
    $sth->execute(
173
        $self->{'description'},
174
        $self->{'repeatable'},
175
        $self->{'unique_id'},
176
        $self->{'opac_display'},
177
        $self->{'opac_editable'},
178
        $self->{'staff_searchable'} || 0,
179
        $self->{'authorised_value_category'},
180
        $self->{'display_checkout'},
181
        $self->{'category_code'} || undef,
182
        $self->{'class'},
183
        $self->{'code'}
184
    );
185
186
    if ( defined $$self{branches} ) {
187
        $sth = $dbh->prepare("DELETE FROM borrower_attribute_types_branches WHERE bat_code = ?");
188
        $sth->execute( $$self{code} );
189
        $sth = $dbh->prepare(
190
            "INSERT INTO borrower_attribute_types_branches
191
                        ( bat_code, b_branchcode )
192
                        VALUES ( ?, ? )"
193
        );
194
        for my $branchcode ( @{$$self{branches}} ) {
195
            next if not $branchcode;
196
            $sth->bind_param( 1, $$self{code} );
197
            $sth->bind_param( 2, $branchcode );
198
            $sth->execute;
199
        }
200
    }
201
    $sth->finish;
202
}
203
204
=head2 code
205
206
  my $code = $attr_type->code();
207
  $attr_type->code($code);
208
209
Accessor.  Note that the code is immutable once
210
a type is created or fetched from the database.
211
212
=cut
213
214
sub code {
215
    my $self = shift;
216
    return $self->{'code'};
217
}
218
219
=head2 description
220
221
  my $description = $attr_type->description();
222
  $attr_type->description($description);
223
224
Accessor.
225
226
=cut
227
228
sub description {
229
    my $self = shift;
230
    @_ ? $self->{'description'} = shift : $self->{'description'};
231
}
232
233
=head2 branches
234
235
my $branches = $attr_type->branches();
236
$attr_type->branches($branches);
237
238
Accessor.
239
240
=cut
241
242
sub branches {
243
    my $self = shift;
244
    @_ ? $self->{branches} = shift : $self->{branches};
245
}
246
247
=head2 repeatable
248
249
  my $repeatable = $attr_type->repeatable();
250
  $attr_type->repeatable($repeatable);
251
252
Accessor.  The C<$repeatable> argument
253
is interpreted as a Perl boolean.
254
255
=cut
256
257
sub repeatable {
258
    my $self = shift;
259
    @_ ? $self->{'repeatable'} = ((shift) ? 1 : 0) : $self->{'repeatable'};
260
}
261
262
=head2 unique_id
263
264
  my $unique_id = $attr_type->unique_id();
265
  $attr_type->unique_id($unique_id);
266
267
Accessor.  The C<$unique_id> argument
268
is interpreted as a Perl boolean.
269
270
=cut
271
272
sub unique_id {
273
    my $self = shift;
274
    @_ ? $self->{'unique_id'} = ((shift) ? 1 : 0) : $self->{'unique_id'};
275
}
276
277
=head2 opac_display
278
279
  my $opac_display = $attr_type->opac_display();
280
  $attr_type->opac_display($opac_display);
281
282
Accessor.  The C<$opac_display> argument
283
is interpreted as a Perl boolean.
284
285
=cut
286
287
sub opac_display {
288
    my $self = shift;
289
    @_ ? $self->{'opac_display'} = ((shift) ? 1 : 0) : $self->{'opac_display'};
290
}
291
292
=head2 opac_editable
293
294
  my $opac_editable = $attr_type->opac_editable();
295
  $attr_type->opac_editable($opac_editable);
296
297
Accessor.  The C<$opac_editable> argument
298
is interpreted as a Perl boolean.
299
300
=cut
301
302
sub opac_editable {
303
    my $self = shift;
304
    @_ ? $self->{'opac_editable'} = ((shift) ? 1 : 0) : $self->{'opac_editable'};
305
}
306
307
=head2 staff_searchable
308
309
  my $staff_searchable = $attr_type->staff_searchable();
310
  $attr_type->staff_searchable($staff_searchable);
311
312
Accessor.  The C<$staff_searchable> argument
313
is interpreted as a Perl boolean.
314
315
=cut
316
317
sub staff_searchable {
318
    my $self = shift;
319
    @_ ? $self->{'staff_searchable'} = ((shift) ? 1 : 0) : $self->{'staff_searchable'};
320
}
321
322
=head2 display_checkout
323
324
my $display_checkout = $attr_type->display_checkout();
325
$attr_type->display_checkout($display_checkout);
326
327
Accessor.  The C<$display_checkout> argument
328
is interpreted as a Perl boolean.
329
330
=cut
331
332
sub display_checkout {
333
    my $self = shift;
334
    @_ ? $self->{'display_checkout'} = ((shift) ? 1 : 0) : $self->{'display_checkout'};
335
}
336
337
=head2 authorised_value_category
338
339
  my $authorised_value_category = $attr_type->authorised_value_category();
340
  $attr_type->authorised_value_category($authorised_value_category);
341
342
Accessor.
343
344
=cut
345
346
sub authorised_value_category {
347
    my $self = shift;
348
    @_ ? $self->{'authorised_value_category'} = shift : $self->{'authorised_value_category'};
349
}
350
351
=head2 category_code
352
353
my $category_code = $attr_type->category_code();
354
$attr_type->category_code($category_code);
355
356
Accessor.
357
358
=cut
359
360
sub category_code {
361
    my $self = shift;
362
    @_ ? $self->{'category_code'} = shift : $self->{'category_code'};
363
}
364
365
=head2 category_description
366
367
my $category_description = $attr_type->category_description();
368
$attr_type->category_description($category_description);
369
370
Accessor.
371
372
=cut
373
374
sub category_description {
375
    my $self = shift;
376
    @_ ? $self->{'category_description'} = shift : $self->{'category_description'};
377
}
378
379
=head2 class
380
381
my $class = $attr_type->class();
382
$attr_type->class($class);
383
384
Accessor.
385
386
=cut
387
388
sub class {
389
    my $self = shift;
390
    @_ ? $self->{'class'} = shift : $self->{'class'};
391
}
392
393
394
=head2 delete
395
396
  $attr_type->delete();
397
  C4::Members::AttributeTypes->delete($code);
398
399
Delete an attribute type from the database.  The attribute
400
type may be specified either by an object or by a code.
401
402
=cut
403
404
sub delete {
405
    my $arg = shift;
406
    my $code;
407
    if (ref($arg) eq __PACKAGE__) {
408
        $code = $arg->{'code'};
409
    } else {
410
        $code = shift;
411
    }
412
413
    my $dbh = C4::Context->dbh;
414
    my $sth = $dbh->prepare_cached("DELETE FROM borrower_attribute_types WHERE code = ?");
415
    $sth->execute($code);
416
    $sth->finish;
417
}
418
419
=head2 num_patrons
420
421
  my $count = $attr_type->num_patrons();
422
423
Returns the number of patron records that use
424
this attribute type.
425
426
=cut
427
428
sub num_patrons {
429
    my $self = shift;
430
431
    my $dbh = C4::Context->dbh;
432
    my $sth = $dbh->prepare_cached("SELECT COUNT(DISTINCT borrowernumber)
433
                                    FROM borrower_attributes
434
                                    WHERE code = ?");
435
    $sth->execute($self->{code});
436
    my ($count) = $sth->fetchrow_array;
437
    $sth->finish;
438
    return $count;
439
}
440
441
=head2 get_patrons
442
443
  my @borrowernumbers = $attr_type->get_patrons($attribute);
444
445
Returns the borrowernumber of the patron records that
446
have an attribute with the specifie value.
447
448
=cut
449
450
sub get_patrons {
451
    my $self = shift;
452
    my $value = shift;
453
454
    my $dbh = C4::Context->dbh;
455
    my $sth = $dbh->prepare_cached("SELECT DISTINCT borrowernumber
456
                                    FROM borrower_attributes
457
                                    WHERE code = ?
458
                                    AND   attribute = ?");
459
    $sth->execute($self->{code}, $value);
460
    my @results;
461
    while (my ($borrowernumber) = $sth->fetchrow_array) {
462
        push @results, $borrowernumber;
463
    } 
464
    return @results;
465
}
466
467
=head1 AUTHOR
468
469
Koha Development Team <http://koha-community.org/>
470
471
Galen Charlton <galen.charlton@liblime.com>
472
473
=cut
474
475
1;
(-)a/Koha/Patrons/Import.pm (-4 / +3 lines)
Lines 25-31 use Encode qw( decode_utf8 ); Link Here
25
25
26
use C4::Members;
26
use C4::Members;
27
use C4::Members::Attributes qw(:all);
27
use C4::Members::Attributes qw(:all);
28
use C4::Members::AttributeTypes;
29
28
30
use Koha::Libraries;
29
use Koha::Libraries;
31
use Koha::Patrons;
30
use Koha::Patrons;
Lines 431-442 Returns an attribute type based on matchpoint parameter. Link Here
431
sub set_attribute_types {
430
sub set_attribute_types {
432
    my ($self, $params) = @_;
431
    my ($self, $params) = @_;
433
432
434
    my $attribute_types;
433
    my $attribute_type;
435
    if( $params->{extended} ) {
434
    if( $params->{extended} ) {
436
        $attribute_types = C4::Members::AttributeTypes->fetch($params->{matchpoint});
435
        $attribute_type = Koha::Patron::Attribute::Types->find($params->{matchpoint});
437
    }
436
    }
438
437
439
    return $attribute_types;
438
    return $attribute_type;
440
}
439
}
441
440
442
=head2 set_column_keys
441
=head2 set_column_keys
(-)a/members/memberentry.pl (-3 / +2 lines)
Lines 31-37 use C4::Context; Link Here
31
use C4::Output;
31
use C4::Output;
32
use C4::Members;
32
use C4::Members;
33
use C4::Members::Attributes;
33
use C4::Members::Attributes;
34
use C4::Members::AttributeTypes;
35
use C4::Koha;
34
use C4::Koha;
36
use C4::Log;
35
use C4::Log;
37
use C4::Letters;
36
use C4::Letters;
Lines 407-417 if ($op eq 'save' || $op eq 'insert'){ Link Here
407
          eval {$attribute->check_unique_id};
406
          eval {$attribute->check_unique_id};
408
          if ( $@ ) {
407
          if ( $@ ) {
409
              push @errors, "ERROR_extended_unique_id_failed";
408
              push @errors, "ERROR_extended_unique_id_failed";
410
              my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code});
409
              my $attr_type = Koha::Patron::Attribute::Types->find($attr->code);
411
              $template->param(
410
              $template->param(
412
                  ERROR_extended_unique_id_failed_code => $attr->{code},
411
                  ERROR_extended_unique_id_failed_code => $attr->{code},
413
                  ERROR_extended_unique_id_failed_value => $attr->{attribute},
412
                  ERROR_extended_unique_id_failed_value => $attr->{attribute},
414
                  ERROR_extended_unique_id_failed_description => $attr_info->description()
413
                  ERROR_extended_unique_id_failed_description => $attr_type->description()
415
              );
414
              );
416
          }
415
          }
417
      }
416
      }
(-)a/members/moremember.pl (-1 lines)
Lines 32-38 use CGI qw ( -utf8 ); Link Here
32
use C4::Context;
32
use C4::Context;
33
use C4::Auth;
33
use C4::Auth;
34
use C4::Output;
34
use C4::Output;
35
use C4::Members::AttributeTypes;
36
use C4::Form::MessagingPreferences;
35
use C4::Form::MessagingPreferences;
37
use List::MoreUtils qw/uniq/;
36
use List::MoreUtils qw/uniq/;
38
use Koha::Patron::Attribute::Types;
37
use Koha::Patron::Attribute::Types;
(-)a/opac/opac-memberentry.pl (-2 / +2 lines)
Lines 101-111 foreach my $attr (@$attributes) { Link Here
101
    my $attribute = Koha::Patron::Attribute->new($attr);
101
    my $attribute = Koha::Patron::Attribute->new($attr);
102
    eval {$attribute->check_unique_id};
102
    eval {$attribute->check_unique_id};
103
    if ( $@ ) {
103
    if ( $@ ) {
104
        my $attr_info = C4::Members::AttributeTypes->fetch($attr->{code});
104
        my $attr_type = Koha::Patron::Attribute::Types->find($attr->{code});
105
        $template->param(
105
        $template->param(
106
            extended_unique_id_failed_code => $attr->{code},
106
            extended_unique_id_failed_code => $attr->{code},
107
            extended_unique_id_failed_value => $attr->{attribute},
107
            extended_unique_id_failed_value => $attr->{attribute},
108
            extended_unique_id_failed_description => $attr_info->description()
108
            extended_unique_id_failed_description => $attr_type->description,
109
        );
109
        );
110
        $conflicting_attribute = 1;
110
        $conflicting_attribute = 1;
111
    }
111
    }
(-)a/opac/opac-user.pl (-1 lines)
Lines 27-33 use C4::Circulation; Link Here
27
use C4::External::BakerTaylor qw( image_url link_url );
27
use C4::External::BakerTaylor qw( image_url link_url );
28
use C4::Reserves;
28
use C4::Reserves;
29
use C4::Members;
29
use C4::Members;
30
use C4::Members::AttributeTypes;
31
use C4::Output;
30
use C4::Output;
32
use C4::Biblio;
31
use C4::Biblio;
33
use C4::Items;
32
use C4::Items;
(-)a/t/Members_AttributeTypes.t (-77 lines)
Lines 1-77 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::MockModule;
21
use Test::More;
22
23
use Module::Load::Conditional qw/check_install/;
24
25
use Koha::Patron::Attribute::Types;
26
27
BEGIN {
28
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
29
        plan tests => 8;
30
    } else {
31
        plan skip_all => "Need Test::DBIx::Class"
32
    }
33
}
34
35
use_ok('C4::Members::AttributeTypes');
36
37
use Test::DBIx::Class;
38
39
fixtures_ok [
40
    Category => [
41
        ['categorycode'],
42
        ['orange'], ['yellow'],
43
    ],
44
    BorrowerAttributeType => [
45
    [
46
        'code',             'description',
47
        'repeatable',       'unique_id',
48
        'opac_display',
49
        'staff_searchable', 'authorised_value_category',
50
        'display_checkout', 'category_code',
51
        'class'
52
    ],
53
    [ 'one', 'ISBN', '1', '1', '1', '1', 'red',  '1', 'orange', 'green' ],
54
    [ 'two', 'ISSN', '0', '0', '0', '0', 'blue', '0', 'yellow', 'silver' ]
55
56
    ],
57
], 'add fixtures';
58
59
my $db = Test::MockModule->new('Koha::Database');
60
$db->mock( _new_schema => sub { return Schema(); } );
61
62
my @members_attributetypes = @{Koha::Patron::Attribute::Types->search->unblessed};
63
64
is( $members_attributetypes[0]->{'code'}, 'one', 'First code value is one' );
65
66
is( $members_attributetypes[1]->{'code'}, 'two', 'Second code value is two' );
67
68
is( $members_attributetypes[0]->{'class'},
69
    'green', 'First class value is green' );
70
71
is( $members_attributetypes[1]->{'class'},
72
    'silver', 'Second class value is silver' );
73
74
ok( C4::Members::AttributeTypes->fetch('one'), "testing fetch feature" );
75
76
ok( !C4::Members::AttributeTypes->fetch('FAKE'),
77
    "testing fetch feature doesn't work if value not in database" );
(-)a/t/db_dependent/Koha/Patrons.t (-16 / +24 lines)
Lines 38-43 use Koha::Holds; Link Here
38
use Koha::Old::Holds;
38
use Koha::Old::Holds;
39
use Koha::Patrons;
39
use Koha::Patrons;
40
use Koha::Old::Patrons;
40
use Koha::Old::Patrons;
41
use Koha::Patron::Attribute::Types;
41
use Koha::Patron::Categories;
42
use Koha::Patron::Categories;
42
use Koha::Patron::Relationship;
43
use Koha::Patron::Relationship;
43
use Koha::Database;
44
use Koha::Database;
Lines 2029-2070 subtest 'extended_attributes' => sub { Link Here
2029
2030
2030
    set_logged_in_user($patron_1);
2031
    set_logged_in_user($patron_1);
2031
2032
2032
    my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
2033
    my $attribute_type1 = Koha::Patron::Attribute::Type->new(
2033
    $attribute_type1->unique_id(1);
2034
        {
2034
    $attribute_type1->store();
2035
            code        => 'my code1',
2035
2036
            description => 'my description1',
2036
    my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
2037
            unique_id   => 1
2037
    $attribute_type2->opac_display(1);
2038
        }
2038
    $attribute_type2->staff_searchable(1);
2039
    )->store;
2039
    $attribute_type2->store();
2040
    my $attribute_type2 = Koha::Patron::Attribute::Type->new(
2041
        {
2042
            code             => 'my code2',
2043
            description      => 'my description2',
2044
            opac_display     => 1,
2045
            staff_searchable => 1
2046
        }
2047
    )->store;
2040
2048
2041
    my $new_library = $builder->build( { source => 'Branch' } );
2049
    my $new_library = $builder->build( { source => 'Branch' } );
2042
    my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3');
2050
    my $attribute_type_limited = Koha::Patron::Attribute::Type->new(
2043
    $attribute_type_limited->branches([ $new_library->{branchcode} ]);
2051
        { code => 'my code3', description => 'my description3' } )->store;
2044
    $attribute_type_limited->store;
2052
    $attribute_type_limited->library_limits( [ $new_library->{branchcode} ] );
2045
2053
2046
    my $attributes_for_1 = [
2054
    my $attributes_for_1 = [
2047
        {
2055
        {
2048
            value => 'my attribute1',
2056
            attribute => 'my attribute1',
2049
            code => $attribute_type1->code(),
2057
            code => $attribute_type1->code(),
2050
        },
2058
        },
2051
        {
2059
        {
2052
            value => 'my attribute2',
2060
            attribute => 'my attribute2',
2053
            code => $attribute_type2->code(),
2061
            code => $attribute_type2->code(),
2054
        },
2062
        },
2055
        {
2063
        {
2056
            value => 'my attribute limited',
2064
            attribute => 'my attribute limited',
2057
            code => $attribute_type_limited->code(),
2065
            code => $attribute_type_limited->code(),
2058
        }
2066
        }
2059
    ];
2067
    ];
2060
2068
2061
    my $attributes_for_2 = [
2069
    my $attributes_for_2 = [
2062
        {
2070
        {
2063
            value => 'my attribute12',
2071
            attribute => 'my attribute12',
2064
            code => $attribute_type1->code(),
2072
            code => $attribute_type1->code(),
2065
        },
2073
        },
2066
        {
2074
        {
2067
            value => 'my attribute limited 2',
2075
            attribute => 'my attribute limited 2',
2068
            code => $attribute_type_limited->code(),
2076
            code => $attribute_type_limited->code(),
2069
        }
2077
        }
2070
    ];
2078
    ];
(-)a/t/db_dependent/Koha/Patrons/Import.t (-2 / +2 lines)
Lines 503-510 subtest 'test_set_column_keys' => sub { Link Here
503
    my $attr_type_3 = $patrons_import->set_attribute_types($params_3);
503
    my $attr_type_3 = $patrons_import->set_attribute_types($params_3);
504
504
505
    # Then ...
505
    # Then ...
506
    isa_ok($attr_type_3, 'C4::Members::AttributeTypes');
506
    isa_ok($attr_type_3, 'Koha::Patron::Attribute::Type');
507
    is($attr_type_3->{code}, $code_3, 'Got the expected code attribute type from set attribute types');
507
    is($attr_type_3->code, $code_3, 'Got the expected code attribute type from set attribute types');
508
};
508
};
509
509
510
subtest 'test_set_column_keys' => sub {
510
subtest 'test_set_column_keys' => sub {
(-)a/t/db_dependent/Members/Attributes.t (-12 / +18 lines)
Lines 21-27 use Modern::Perl; Link Here
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Members;
23
use C4::Members;
24
use C4::Members::AttributeTypes;
25
use Koha::Database;
24
use Koha::Database;
26
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
27
use t::lib::Mocks;
26
use t::lib::Mocks;
Lines 57-75 my $patron = $builder->build( Link Here
57
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
56
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
58
my $borrowernumber = $patron->{borrowernumber};
57
my $borrowernumber = $patron->{borrowernumber};
59
58
60
my $attribute_type1 = C4::Members::AttributeTypes->new('my code1', 'my description1');
59
my $attribute_type1 = Koha::Patron::Attribute::Type->new(
61
$attribute_type1->unique_id(1);
60
    {
62
$attribute_type1->store();
61
        code        => 'my code1',
63
62
        description => 'my description1',
64
my $attribute_type2 = C4::Members::AttributeTypes->new('my code2', 'my description2');
63
        unique_id   => 1
65
$attribute_type2->opac_display(1);
64
    }
66
$attribute_type2->staff_searchable(1);
65
)->store;
67
$attribute_type2->store();
66
my $attribute_type2 = Koha::Patron::Attribute::Type->new(
67
    {
68
        code             => 'my code2',
69
        description      => 'my description2',
70
        opac_display     => 1,
71
        staff_searchable => 1
72
    }
73
)->store;
68
74
69
my $new_library = $builder->build( { source => 'Branch' } );
75
my $new_library = $builder->build( { source => 'Branch' } );
70
my $attribute_type_limited = C4::Members::AttributeTypes->new('my code3', 'my description3');
76
my $attribute_type_limited = Koha::Patron::Attribute::Type->new(
71
$attribute_type_limited->branches([ $new_library->{branchcode} ]);
77
    { code => 'my code3', description => 'my description3' } )->store;
72
$attribute_type_limited->store;
78
$attribute_type_limited->library_limits( [ $new_library->{branchcode} ] );
73
79
74
$patron = Koha::Patrons->find($borrowernumber);
80
$patron = Koha::Patrons->find($borrowernumber);
75
my $borrower_attributes = $patron->extended_attributes;
81
my $borrower_attributes = $patron->extended_attributes;
(-)a/t/db_dependent/Utils/Datatables_Members.t (-7 / +10 lines)
Lines 23-29 use C4::Context; Link Here
23
use C4::Members;
23
use C4::Members;
24
24
25
use C4::Members::Attributes;
25
use C4::Members::Attributes;
26
use C4::Members::AttributeTypes;
27
26
28
use Koha::Library;
27
use Koha::Library;
29
use Koha::Patrons;
28
use Koha::Patrons;
Lines 276-289 $search_results = C4::Utils::DataTables::Members::search({ Link Here
276
is( $search_results->{ iTotalDisplayRecords }, 0,
275
is( $search_results->{ iTotalDisplayRecords }, 0,
277
    "No members are found by userid, surname search");
276
    "No members are found by userid, surname search");
278
277
279
my $attribute_type = C4::Members::AttributeTypes->new( 'ATM_1', 'my attribute type' );
278
my $attribute_type = Koha::Patron::Attribute::Type->new(
280
$attribute_type->{staff_searchable} = 1;
279
    {
281
$attribute_type->store;
280
        code             => 'ATM_1',
281
        description      => 'my attribute type',
282
        staff_searchable => 1
283
    }
284
)->store;
282
285
283
Koha::Patrons->find( $john_doe->{borrowernumber} )->extended_attributes(
286
Koha::Patrons->find( $john_doe->{borrowernumber} )->extended_attributes(
284
    [
287
    [
285
        {
288
        {
286
            code      => $attribute_type->{code},
289
            code      => $attribute_type->code,
287
            attribute => 'the default value for a common user'
290
            attribute => 'the default value for a common user'
288
        }
291
        }
289
    ]
292
    ]
Lines 291-297 Koha::Patrons->find( $john_doe->{borrowernumber} )->extended_attributes( Link Here
291
Koha::Patrons->find( $jane_doe->{borrowernumber} )->extended_attributes(
294
Koha::Patrons->find( $jane_doe->{borrowernumber} )->extended_attributes(
292
    [
295
    [
293
        {
296
        {
294
            code      => $attribute_type->{code},
297
            code      => $attribute_type->code,
295
            attribute => 'the default value for another common user'
298
            attribute => 'the default value for another common user'
296
        }
299
        }
297
    ]
300
    ]
Lines 299-305 Koha::Patrons->find( $jane_doe->{borrowernumber} )->extended_attributes( Link Here
299
Koha::Patrons->find( $john_smith->{borrowernumber} )->extended_attributes(
302
Koha::Patrons->find( $john_smith->{borrowernumber} )->extended_attributes(
300
    [
303
    [
301
        {
304
        {
302
            code      => $attribute_type->{code},
305
            code      => $attribute_type->code,
303
            attribute => 'Attribute which not appears even if contains "Dupont"'
306
            attribute => 'Attribute which not appears even if contains "Dupont"'
304
        }
307
        }
305
    ]
308
    ]
(-)a/tools/modborrowers.pl (-3 / +2 lines)
Lines 379-387 if ( $op eq 'do' ) { Link Here
379
            my $attribute;
379
            my $attribute;
380
            $attribute->{code} = $_;
380
            $attribute->{code} = $_;
381
            $attribute->{attribute} = $attr_values[$i];
381
            $attribute->{attribute} = $attr_values[$i];
382
            my $attr_type = C4::Members::AttributeTypes->fetch( $_ );
382
            my $attr_type = Koha::Patron::Attribute::Types->find($_);
383
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
383
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
384
            ++$i and next if $attr_type->{category_code} and $attr_type->{category_code} ne $patron->category_code;
384
            ++$i and next if $attr_type->category_code and $attr_type->category_code ne $patron->category_code;
385
            my $valuename = "attr" . $i . "_value";
385
            my $valuename = "attr" . $i . "_value";
386
            if ( grep { $_ eq $valuename } @disabled ) {
386
            if ( grep { $_ eq $valuename } @disabled ) {
387
                # The attribute is disabled, we remove it for this borrower !
387
                # The attribute is disabled, we remove it for this borrower !
388
- 

Return to bug 20443