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

(-)a/Koha/Patron.pm (-10 / +8 lines)
Lines 2180-2195 sub extended_attributes { Link Here
2180
                }
2180
                }
2181
2181
2182
                # Check globally mandatory types
2182
                # Check globally mandatory types
2183
                my @required_attribute_types =
2183
                my @required_attribute_types = Koha::Patron::Attribute::Types->search(
2184
                    Koha::Patron::Attribute::Types->search(
2184
                    {
2185
                        {
2185
                        mandatory                                          => 1,
2186
                            mandatory => 1,
2186
                        'borrower_attribute_types_categories.categorycode' => [ undef, $self->categorycode ],
2187
                            category_code => [ undef, $self->categorycode ],
2187
                        'borrower_attribute_types_branches.b_branchcode'   => undef,
2188
                            'borrower_attribute_types_branches.b_branchcode' =>
2188
                    },
2189
                              undef,
2189
                    { join => [ 'borrower_attribute_types_branches', 'borrower_attribute_types_categories' ] }
2190
                        },
2190
                )->get_column('code');
2191
                        { join => 'borrower_attribute_types_branches' }
2192
                    )->get_column('code');
2193
                for my $type ( @required_attribute_types ) {
2191
                for my $type ( @required_attribute_types ) {
2194
                    Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw(
2192
                    Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw(
2195
                        type => $type,
2193
                        type => $type,
(-)a/Koha/Patron/Attribute/Type.pm (+22 lines)
Lines 60-65 sub attributes { Link Here
60
    Koha::Patron::Attributes->_new_from_dbic($attributes_rs);
60
    Koha::Patron::Attributes->_new_from_dbic($attributes_rs);
61
}
61
}
62
62
63
=head3 categories
64
65
Get or set attribute type's categories
66
67
    my @categories = $attribute_type->categories->as_list;
68
    $attribute_type->categories(\@categories);
69
70
=cut
71
72
sub categories {
73
    my ($self, $categories) = @_;
74
75
    if ($categories) {
76
        my @categorycodes = map { $_->_result } @$categories;
77
        $self->_result->set_categorycodes(\@categorycodes);
78
        return $self;
79
    }
80
81
    my $rs = $self->_result->categorycodes;
82
    return Koha::Patron::Categories->_new_from_dbic($rs);
83
}
84
63
=head2 Internal Methods
85
=head2 Internal Methods
64
86
65
=cut
87
=cut
(-)a/admin/patron-attr-types.pl (-2 / +6 lines)
Lines 123-129 sub add_update_attribute_type { Link Here
123
    my $mandatory                 = $input->param('mandatory') ? 1 : 0;
123
    my $mandatory                 = $input->param('mandatory') ? 1 : 0;
124
    my $authorised_value_category = $input->param('authorised_value_category');
124
    my $authorised_value_category = $input->param('authorised_value_category');
125
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
125
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
126
    my $category_code             = $input->param('category_code') || undef;
127
    my $class                     = $input->param('class');
126
    my $class                     = $input->param('class');
128
127
129
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
128
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
Lines 160-166 sub add_update_attribute_type { Link Here
160
            mandatory                 => $mandatory,
159
            mandatory                 => $mandatory,
161
            authorised_value_category => $authorised_value_category,
160
            authorised_value_category => $authorised_value_category,
162
            display_checkout          => $display_checkout,
161
            display_checkout          => $display_checkout,
163
            category_code             => $category_code,
164
            class                     => $class,
162
            class                     => $class,
165
        }
163
        }
166
    )->store;
164
    )->store;
Lines 168-173 sub add_update_attribute_type { Link Here
168
    my @branches = grep { ! /^\s*$/ } $input->multi_param('branches');
166
    my @branches = grep { ! /^\s*$/ } $input->multi_param('branches');
169
    $attr_type->library_limits( \@branches );
167
    $attr_type->library_limits( \@branches );
170
168
169
    my @categories = grep { ! /^\s*$/ } $input->multi_param('category_code');
170
    $attr_type->categories([
171
        Koha::Patron::Categories->search({ categorycode => \@categories })->as_list
172
    ]);
173
171
    if ( $op eq 'edit' ) {
174
    if ( $op eq 'edit' ) {
172
        $template->param( edited_attribute_type => $attr_type->code() );
175
        $template->param( edited_attribute_type => $attr_type->code() );
173
    }
176
    }
Lines 240-245 sub edit_attribute_type_form { Link Here
240
        $can_be_set_to_unique = 0 if $@;
243
        $can_be_set_to_unique = 0 if $@;
241
        $attr_type->unique_id(0);
244
        $attr_type->unique_id(0);
242
    }
245
    }
246
243
    $template->param(
247
    $template->param(
244
        attribute_type => $attr_type,
248
        attribute_type => $attr_type,
245
        attribute_type_form => 1,
249
        attribute_type_form => 1,
(-)a/installer/data/mysql/atomicupdate/bug-26573.pl (+45 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => '26573',
5
    description => 'Add table borrower_attribute_types_categories',
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{
11
            CREATE TABLE IF NOT EXISTS `borrower_attribute_types_categories` (
12
                `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
13
                `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
14
                KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`),
15
                KEY `categorycode` (`categorycode`),
16
                CONSTRAINT `borrower_attribute_types_categories_borrower_attribute_type_code` FOREIGN KEY (`borrower_attribute_type_code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
17
                CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
18
                PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`)
19
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
20
        });
21
22
        say $out "Table 'borrower_attribute_types_categories' created";
23
24
        if (column_exists('borrower_attribute_types', 'category_code')) {
25
            $dbh->do(q{
26
                INSERT IGNORE INTO borrower_attribute_types_categories (borrower_attribute_type_code, categorycode)
27
                SELECT `code`, `category_code` FROM `borrower_attribute_types`
28
                WHERE `category_code` IS NOT NULL
29
            });
30
31
            say $out "Data migrated from 'borrower_attribute_types.category_code' to 'borrower_attribute_types_categories'";
32
33
            $dbh->do(q{
34
                ALTER TABLE `borrower_attribute_types`
35
                DROP FOREIGN KEY `borrower_attribute_types_ibfk_1`
36
            });
37
            $dbh->do(q{
38
                ALTER TABLE `borrower_attribute_types`
39
                DROP COLUMN `category_code`
40
            });
41
42
            say $out "Column 'borrower_attribute_types.category_code' deleted";
43
        }
44
    },
45
};
(-)a/installer/data/mysql/kohastructure.sql (-4 / +19 lines)
Lines 1248-1261 CREATE TABLE `borrower_attribute_types` ( Link Here
1248
  `searched_by_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is included in "Standard" patron searches in the staff interface (1 for yes, 0 for no)',
1248
  `searched_by_default` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is included in "Standard" patron searches in the staff interface (1 for yes, 0 for no)',
1249
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1249
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1250
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1250
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1251
  `category_code` varchar(10) DEFAULT NULL COMMENT 'defines a category for an attribute_type',
1252
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1251
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1253
  `keep_for_pseudonymization` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)',
1252
  `keep_for_pseudonymization` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field is copied to anonymized_borrower_attributes (1 for yes, 0 for no)',
1254
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
1253
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
1255
  PRIMARY KEY (`code`),
1254
  PRIMARY KEY (`code`),
1256
  KEY `auth_val_cat_idx` (`authorised_value_category`),
1255
  KEY `auth_val_cat_idx` (`authorised_value_category`)
1257
  KEY `category_code` (`category_code`),
1258
  CONSTRAINT `borrower_attribute_types_ibfk_1` FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`)
1259
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1256
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1260
/*!40101 SET character_set_client = @saved_cs_client */;
1257
/*!40101 SET character_set_client = @saved_cs_client */;
1261
1258
Lines 1276-1281 CREATE TABLE `borrower_attribute_types_branches` ( Link Here
1276
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1273
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1277
/*!40101 SET character_set_client = @saved_cs_client */;
1274
/*!40101 SET character_set_client = @saved_cs_client */;
1278
1275
1276
--
1277
-- Table structure for table `borrower_attribute_types_categories`
1278
--
1279
1280
DROP TABLE IF EXISTS `borrower_attribute_types_categories`;
1281
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1282
/*!40101 SET character_set_client = utf8 */;
1283
CREATE TABLE `borrower_attribute_types_categories` (
1284
  `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1285
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1286
  KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`),
1287
  KEY `categorycode` (`categorycode`),
1288
  CONSTRAINT `borrower_attribute_types_categories_borrower_attribute_type_code` FOREIGN KEY (`borrower_attribute_type_code`) REFERENCES `borrower_attribute_types` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
1289
  CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
1290
  PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`)
1291
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1292
/*!40101 SET character_set_client = @saved_cs_client */;
1293
1279
--
1294
--
1280
-- Table structure for table `borrower_attributes`
1295
-- Table structure for table `borrower_attributes`
1281
--
1296
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt (-5 / +20 lines)
Lines 240-252 Link Here
240
        </li>
240
        </li>
241
        <li>
241
        <li>
242
            <label for="category">Category: </label>
242
            <label for="category">Category: </label>
243
            <select name="category_code" id="category">
243
            <select name="category_code" id="category" multiple size="10">
244
                <option value=""></option>
244
                <option value="">All categories</option>
245
                [% FOREACH cat IN categories %]
245
                [% FOREACH category IN categories %]
246
                    [% IF ( cat.categorycode == attribute_type.category_code ) %]<option value="[% cat.categorycode | html %]" selected="selected">[% cat.description |html %]</option>[% ELSE %]<option value="[% cat.categorycode | html %]">[% cat.description |html %]</option>[% END %]
246
                    [% SET selected = 0 %]
247
                    [% IF attribute_type %]
248
                        [% FOREACH cat IN attribute_type.categories %]
249
                            [% IF cat.categorycode == category.categorycode %]
250
                                [% SET selected = 1 %]
251
                            [% END %]
252
                        [% END %]
253
                    [% END %]
254
                    [% IF selected %]
255
                        <option value="[% category.categorycode | html %]" selected>[% category.description |html %]</option>
256
                    [% ELSE %]
257
                        <option value="[% category.categorycode | html %]">[% category.description |html %]</option>
258
                    [% END %]
247
                [% END %]
259
                [% END %]
248
            </select>
260
            </select>
249
            <div class="hint">Choose one to limit this attribute to one patron type. Please leave blank if you want these attributes to be available for all types of patrons.</div>
261
            <div class="hint">Select "All categories" if this attribute type should always be displayed. Otherwise select categories you want to associate with this value.</div>
250
        </li>
262
        </li>
251
        <li>
263
        <li>
252
            <label for="class">Class: </label>
264
            <label for="class">Class: </label>
Lines 429-434 Link Here
429
            if ( $("#branches option:selected").length < 1 ) {
441
            if ( $("#branches option:selected").length < 1 ) {
430
                $("#branches option:first").attr("selected", "selected");
442
                $("#branches option:first").attr("selected", "selected");
431
            }
443
            }
444
            if ( $("#category option:selected").length < 1 ) {
445
                $("#category option:first").attr("selected", "selected");
446
            }
432
447
433
            $("#opac_display").change( function() {
448
            $("#opac_display").change( function() {
434
                if ( this.checked ) {
449
                if ( this.checked ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-1 / +1 lines)
Lines 1637-1643 legend.collapsed i.fa.fa-caret-down::before { Link Here
1637
                                                        <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1637
                                                        <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1638
                                                    [% END %]
1638
                                                    [% END %]
1639
                                                    [% FOREACH patron_attribute IN pa_loo.items %]
1639
                                                    [% FOREACH patron_attribute IN pa_loo.items %]
1640
                                                        <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1640
                                                        <li data-category_code="[% patron_attribute.categorycodes.join(' ') | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1641
                                                            [% IF patron_attribute.mandatory %]
1641
                                                            [% IF patron_attribute.mandatory %]
1642
                                                                <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1642
                                                                <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1643
                                                            [% ELSE %]
1643
                                                            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt (-1 / +1 lines)
Lines 249-255 Link Here
249
                    </tr>
249
                    </tr>
250
                [% END %]
250
                [% END %]
251
            [% FOREACH patron_attribute IN pa_loo.items %]
251
            [% FOREACH patron_attribute IN pa_loo.items %]
252
                <tr data-category_code="[% patron_attribute.category_code | html %]">
252
                <tr>
253
                    <td>
253
                    <td>
254
                        [% patron_attribute.code | html %]
254
                        [% patron_attribute.code | html %]
255
                        ([% patron_attribute.description | html %])
255
                        ([% patron_attribute.description | html %])
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt (-1 / +1 lines)
Lines 551-557 Link Here
551
            information_category_node.html("");
551
            information_category_node.html("");
552
552
553
            if ( category && category.length > 0 ) {
553
            if ( category && category.length > 0 ) {
554
                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
554
                information_category_node.html(_("This attribute will be only applied to the following patron categories: %s").format(category));
555
            }
555
            }
556
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
556
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
557
            if ( type == 'select' ) {
557
            if ( type == 'select' ) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (-1 / +1 lines)
Lines 73-79 function update_category_code(category_code) { Link Here
73
    }
73
    }
74
    var mytables = $(".attributes_table");
74
    var mytables = $(".attributes_table");
75
    $(mytables).find("li").hide();
75
    $(mytables).find("li").hide();
76
    $(mytables).find(" li[data-category_code='"+category_code+"']").show();
76
    $(mytables).find(" li[data-category_code~='"+category_code+"']").show();
77
    $(mytables).find(" li[data-category_code='']").show();
77
    $(mytables).find(" li[data-category_code='']").show();
78
78
79
    //Change password length hint
79
    //Change password length hint
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (-1 / +1 lines)
Lines 982-988 Link Here
982
                                                [% FOREACH pa_value IN pa.values %]
982
                                                [% FOREACH pa_value IN pa.values %]
983
                                                    [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
983
                                                    [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
984
                                                    [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
984
                                                    [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
985
                                                    <li data-category_code="[% pa.type.category_code | html %]">
985
                                                    <li>
986
                                                        [% IF pa.type.mandatory && pa.type.opac_editable %]
986
                                                        [% IF pa.type.mandatory && pa.type.opac_editable %]
987
                                                            <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
987
                                                            <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
988
                                                        [% ELSE %]
988
                                                        [% ELSE %]
(-)a/members/memberentry.pl (-1 / +1 lines)
Lines 885-891 sub patron_attributes_form { Link Here
885
            description       => $attr_type->description(),
885
            description       => $attr_type->description(),
886
            repeatable        => $attr_type->repeatable(),
886
            repeatable        => $attr_type->repeatable(),
887
            category          => $attr_type->authorised_value_category(),
887
            category          => $attr_type->authorised_value_category(),
888
            category_code     => $attr_type->category_code(),
888
            categorycodes     => [ map { $_->categorycode } $attr_type->categories->as_list ],
889
            mandatory         => $attr_type->mandatory(),
889
            mandatory         => $attr_type->mandatory(),
890
            is_date           => $attr_type->is_date(),
890
            is_date           => $attr_type->is_date(),
891
        };
891
        };
(-)a/reports/borrowers_stats.pl (-1 lines)
Lines 485-491 sub patron_attributes_form { Link Here
485
            description       => $attr_type->description(),
485
            description       => $attr_type->description(),
486
            repeatable        => $attr_type->repeatable(),
486
            repeatable        => $attr_type->repeatable(),
487
            category          => $attr_type->authorised_value_category(),
487
            category          => $attr_type->authorised_value_category(),
488
            category_code     => $attr_type->category_code(),
489
        };
488
        };
490
489
491
        my $newentry = { %$entry };
490
        my $newentry = { %$entry };
(-)a/t/db_dependent/Auth_with_ldap.t (-6 lines)
Lines 90-106 my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; Link Here
90
my $attr_type    = $builder->build(
90
my $attr_type    = $builder->build(
91
    {
91
    {
92
        source => 'BorrowerAttributeType',
92
        source => 'BorrowerAttributeType',
93
        value  => {
94
            category_code => $categorycode
95
        }
96
    }
93
    }
97
);
94
);
98
my $attr_type2    = $builder->build(
95
my $attr_type2    = $builder->build(
99
    {
96
    {
100
        source => 'BorrowerAttributeType',
97
        source => 'BorrowerAttributeType',
101
        value  => {
102
            category_code => $categorycode
103
        }
104
    }
98
    }
105
);
99
);
106
100
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-1 lines)
Lines 285-291 subtest 'store() tests' => sub { Link Here
285
                    repeatable    => 0,
285
                    repeatable    => 0,
286
                    unique_id     => 1,
286
                    unique_id     => 1,
287
                    is_date       => 0,
287
                    is_date       => 0,
288
                    category_code => undef
289
                }
288
                }
290
            }
289
            }
291
        );
290
        );
(-)a/t/db_dependent/Koha/Patron/Attribute/Type.t (+35 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More;
6
use Koha::Database;
7
use t::lib::TestBuilder;
8
9
plan tests => 2;
10
11
my $schema  = Koha::Database->new->schema;
12
my $builder = t::lib::TestBuilder->new;
13
14
use_ok('Koha::Patron::Attribute::Type');
15
16
subtest 'categories' => sub {
17
    plan tests => 1;
18
19
    $schema->storage->txn_begin;
20
21
    my $category1 = $builder->build_object( { class => 'Koha::Patron::Categories' } );
22
    my $category2 = $builder->build_object( { class => 'Koha::Patron::Categories' } );
23
    Koha::Patron::Attribute::Types->delete();
24
    my $attribute_type = Koha::Patron::Attribute::Type->new({
25
        code => 'TEST',
26
        description => 'Test attribute type',
27
    });
28
    $attribute_type->store();
29
    $attribute_type->categories([ $category1, $category2 ]);
30
    $attribute_type->store();
31
    my @categories = $attribute_type->categories->as_list;
32
    is (scalar @categories, 2);
33
34
    $schema->storage->txn_rollback;
35
};
(-)a/t/db_dependent/Koha/Patron/Attribute/Types.t (-5 / +1 lines)
Lines 52-64 subtest 'new() tests' => sub { Link Here
52
    is( Koha::Patron::Attribute::Types->search()->count,
52
    is( Koha::Patron::Attribute::Types->search()->count,
53
        1, 'Only one object created' );
53
        1, 'Only one object created' );
54
54
55
    my $cateogory_code
55
    my $attribute_type_2 = Koha::Patron::Attribute::Type->new(
56
        = $builder->build( { source => 'Category' } )->{categorycode};
57
58
    my $attribute_type_with_category = Koha::Patron::Attribute::Type->new(
59
        {   code          => 'code_2',
56
        {   code          => 'code_2',
60
            description   => 'description',
57
            description   => 'description',
61
            category_code => $cateogory_code,
62
            repeatable    => 0
58
            repeatable    => 0
63
        }
59
        }
64
    )->store();
60
    )->store();
(-)a/t/db_dependent/api/v1/patrons.t (-2 lines)
Lines 621-627 subtest 'add() tests' => sub { Link Here
621
                        mandatory     => 0,
621
                        mandatory     => 0,
622
                        repeatable    => 1,
622
                        repeatable    => 1,
623
                        unique_id     => 0,
623
                        unique_id     => 0,
624
                        category_code => 'ST'
625
                    }
624
                    }
626
                }
625
                }
627
            );
626
            );
Lines 632-638 subtest 'add() tests' => sub { Link Here
632
                        mandatory     => 0,
631
                        mandatory     => 0,
633
                        repeatable    => 1,
632
                        repeatable    => 1,
634
                        unique_id     => 0,
633
                        unique_id     => 0,
635
                        category_code => 'ST'
636
                    }
634
                    }
637
                }
635
                }
638
            );
636
            );
(-)a/t/db_dependent/api/v1/patrons_extended_attributes.t (-9 lines)
Lines 116-122 subtest 'add() tests' => sub { Link Here
116
                mandatory     => 1,
116
                mandatory     => 1,
117
                repeatable    => 0,
117
                repeatable    => 0,
118
                unique_id     => 0,
118
                unique_id     => 0,
119
                category_code => undef
120
            }
119
            }
121
        }
120
        }
122
    );
121
    );
Lines 127-133 subtest 'add() tests' => sub { Link Here
127
                mandatory     => 0,
126
                mandatory     => 0,
128
                repeatable    => 1,
127
                repeatable    => 1,
129
                unique_id     => 0,
128
                unique_id     => 0,
130
                category_code => undef
131
            }
129
            }
132
        }
130
        }
133
    );
131
    );
Lines 138-144 subtest 'add() tests' => sub { Link Here
138
                mandatory     => 0,
136
                mandatory     => 0,
139
                repeatable    => 0,
137
                repeatable    => 0,
140
                unique_id     => 1,
138
                unique_id     => 1,
141
                category_code => undef
142
            }
139
            }
143
        }
140
        }
144
    );
141
    );
Lines 245-251 subtest 'overwrite() tests' => sub { Link Here
245
                mandatory     => 1,
242
                mandatory     => 1,
246
                repeatable    => 0,
243
                repeatable    => 0,
247
                unique_id     => 0,
244
                unique_id     => 0,
248
                category_code => undef
249
            }
245
            }
250
        }
246
        }
251
    );
247
    );
Lines 256-262 subtest 'overwrite() tests' => sub { Link Here
256
                mandatory     => 0,
252
                mandatory     => 0,
257
                repeatable    => 1,
253
                repeatable    => 1,
258
                unique_id     => 0,
254
                unique_id     => 0,
259
                category_code => undef
260
            }
255
            }
261
        }
256
        }
262
    );
257
    );
Lines 267-273 subtest 'overwrite() tests' => sub { Link Here
267
                mandatory     => 0,
262
                mandatory     => 0,
268
                repeatable    => 0,
263
                repeatable    => 0,
269
                unique_id     => 1,
264
                unique_id     => 1,
270
                category_code => undef
271
            }
265
            }
272
        }
266
        }
273
    );
267
    );
Lines 393-399 subtest 'delete() tests' => sub { Link Here
393
                mandatory     => 0,
387
                mandatory     => 0,
394
                repeatable    => 1,
388
                repeatable    => 1,
395
                unique_id     => 0,
389
                unique_id     => 0,
396
                category_code => undef
397
            }
390
            }
398
        }
391
        }
399
    );
392
    );
Lines 442-448 subtest 'update() tests' => sub { Link Here
442
                mandatory     => 0,
435
                mandatory     => 0,
443
                repeatable    => 1,
436
                repeatable    => 1,
444
                unique_id     => 0,
437
                unique_id     => 0,
445
                category_code => undef
446
            }
438
            }
447
        }
439
        }
448
    );
440
    );
Lines 453-459 subtest 'update() tests' => sub { Link Here
453
                mandatory     => 0,
445
                mandatory     => 0,
454
                repeatable    => 0,
446
                repeatable    => 0,
455
                unique_id     => 1,
447
                unique_id     => 1,
456
                category_code => undef
457
            }
448
            }
458
        }
449
        }
459
    );
450
    );
(-)a/tools/modborrowers.pl (-8 / +8 lines)
Lines 37-43 use Koha::Libraries; Link Here
37
use Koha::Patron::Categories;
37
use Koha::Patron::Categories;
38
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
38
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
39
use Koha::Patrons;
39
use Koha::Patrons;
40
use List::MoreUtils qw(uniq);
40
use List::MoreUtils qw(uniq none);
41
41
42
my $input = CGI->new;
42
my $input = CGI->new;
43
my $op = $input->param('op') || 'show_form';
43
my $op = $input->param('op') || 'show_form';
Lines 146-155 if ( $op eq 'cud-show' || $op eq 'show' ) { Link Here
146
                options        => $options,
146
                options        => $options,
147
            };
147
            };
148
148
149
        my $category_code = $attr_type->category_code;
149
        my @categories = $attr_type->categories->as_list;
150
        my ($category_lib) =
150
        my ( $category_lib ) = join(', ',  map { $_->description } @categories);
151
            map { ( defined $category_code and $attr_type->category_code eq $_->categorycode ) ? $_->description : () }
152
            @patron_categories;
153
        push @patron_attributes_codes,
151
        push @patron_attributes_codes,
154
            {
152
            {
155
                attribute_code => $attr_type->code,
153
                attribute_code => $attr_type->code,
Lines 416-423 if ( $op eq 'cud-do' ) { Link Here
416
414
417
            next unless $attr_type;
415
            next unless $attr_type;
418
416
419
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
417
            # If this borrower is not in one of the categories of this attribute, we don't want to modify this attribute
420
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
418
            my @attr_type_categories = $attr_type->categories->as_list;
419
            if (@attr_type_categories) {
420
                next if none { $patron->categorycode eq $_->categorycode } @attr_type_categories;
421
            }
421
422
422
            if ( $attributes->{$code}->{disabled} ) {
423
            if ( $attributes->{$code}->{disabled} ) {
423
                # The attribute is disabled, we remove it for this borrower !
424
                # The attribute is disabled, we remove it for this borrower !
424
- 

Return to bug 26573