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

(-)a/Koha/Patron.pm (-4 / +4 lines)
Lines 2398-2406 sub extended_attributes { Link Here
2398
                # Check globally mandatory types
2398
                # Check globally mandatory types
2399
                my $interface = C4::Context->interface;
2399
                my $interface = C4::Context->interface;
2400
                my $params    = {
2400
                my $params    = {
2401
                    mandatory                                        => 1,
2401
                    mandatory                                          => 1,
2402
                    category_code                                    => [ undef, $self->categorycode ],
2402
                    'borrower_attribute_types_categories.categorycode' => [ undef, $self->categorycode ],
2403
                    'borrower_attribute_types_branches.b_branchcode' => undef,
2403
                    'borrower_attribute_types_branches.b_branchcode'   => undef,
2404
                };
2404
                };
2405
2405
2406
                if ( $interface eq 'opac' ) {
2406
                if ( $interface eq 'opac' ) {
Lines 2409-2415 sub extended_attributes { Link Here
2409
2409
2410
                my @required_attribute_types = Koha::Patron::Attribute::Types->search(
2410
                my @required_attribute_types = Koha::Patron::Attribute::Types->search(
2411
                    $params,
2411
                    $params,
2412
                    { join => 'borrower_attribute_types_branches' }
2412
                    { join => [ 'borrower_attribute_types_branches', 'borrower_attribute_types_categories' ] }
2413
                )->get_column('code');
2413
                )->get_column('code');
2414
2414
2415
                for my $type (@required_attribute_types) {
2415
                for my $type (@required_attribute_types) {
(-)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 / +4 lines)
Lines 119-125 sub add_update_attribute_type { Link Here
119
    my $opac_mandatory            = $input->param('opac_mandatory')            ? 1 : 0;
119
    my $opac_mandatory            = $input->param('opac_mandatory')            ? 1 : 0;
120
    my $authorised_value_category = $input->param('authorised_value_category');
120
    my $authorised_value_category = $input->param('authorised_value_category');
121
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
121
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
122
    my $category_code             = $input->param('category_code') || undef;
123
    my $class                     = $input->param('class');
122
    my $class                     = $input->param('class');
124
123
125
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
124
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
Lines 156-162 sub add_update_attribute_type { Link Here
156
            opac_mandatory            => $opac_mandatory,
155
            opac_mandatory            => $opac_mandatory,
157
            authorised_value_category => $authorised_value_category,
156
            authorised_value_category => $authorised_value_category,
158
            display_checkout          => $display_checkout,
157
            display_checkout          => $display_checkout,
159
            category_code             => $category_code,
160
            class                     => $class,
158
            class                     => $class,
161
        }
159
        }
162
    )->store;
160
    )->store;
Lines 164-169 sub add_update_attribute_type { Link Here
164
    my @branches = grep { !/^\s*$/ } $input->multi_param('branches');
162
    my @branches = grep { !/^\s*$/ } $input->multi_param('branches');
165
    $attr_type->library_limits( \@branches );
163
    $attr_type->library_limits( \@branches );
166
164
165
    my @categories = grep { !/^\s*$/ } $input->multi_param('category_code');
166
    $attr_type->categories( [ Koha::Patron::Categories->search( { categorycode => \@categories } )->as_list ] );
167
167
    if ( $op eq 'edit' ) {
168
    if ( $op eq 'edit' ) {
168
        $template->param( edited_attribute_type => $attr_type->code() );
169
        $template->param( edited_attribute_type => $attr_type->code() );
169
    } else {
170
    } else {
Lines 237-242 sub edit_attribute_type_form { Link Here
237
        $can_be_set_to_unique = 0 if $@;
238
        $can_be_set_to_unique = 0 if $@;
238
        $attr_type->unique_id(0);
239
        $attr_type->unique_id(0);
239
    }
240
    }
241
240
    $template->param(
242
    $template->param(
241
        attribute_type              => $attr_type,
243
        attribute_type              => $attr_type,
242
        attribute_type_form         => 1,
244
        attribute_type_form         => 1,
(-)a/installer/data/mysql/atomicupdate/bug-26573.pl (+54 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(
11
            q{
12
            CREATE TABLE IF NOT EXISTS `borrower_attribute_types_categories` (
13
                `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
14
                `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
15
                KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`),
16
                KEY `categorycode` (`categorycode`),
17
                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,
18
                CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
19
                PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`)
20
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
21
        }
22
        );
23
24
        say $out "Table 'borrower_attribute_types_categories' created";
25
26
        if ( column_exists( 'borrower_attribute_types', 'category_code' ) ) {
27
            $dbh->do(
28
                q{
29
                INSERT IGNORE INTO borrower_attribute_types_categories (borrower_attribute_type_code, categorycode)
30
                SELECT `code`, `category_code` FROM `borrower_attribute_types`
31
                WHERE `category_code` IS NOT NULL
32
            }
33
            );
34
35
            say $out
36
                "Data migrated from 'borrower_attribute_types.category_code' to 'borrower_attribute_types_categories'";
37
38
            $dbh->do(
39
                q{
40
                ALTER TABLE `borrower_attribute_types`
41
                DROP FOREIGN KEY `borrower_attribute_types_ibfk_1`
42
            }
43
            );
44
            $dbh->do(
45
                q{
46
                ALTER TABLE `borrower_attribute_types`
47
                DROP COLUMN `category_code`
48
            }
49
            );
50
51
            say $out "Column 'borrower_attribute_types.category_code' deleted";
52
        }
53
    },
54
};
(-)a/installer/data/mysql/kohastructure.sql (-4 / +19 lines)
Lines 1256-1270 CREATE TABLE `borrower_attribute_types` ( Link Here
1256
  `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)',
1256
  `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)',
1257
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1257
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1258
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1258
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1259
  `category_code` varchar(10) DEFAULT NULL COMMENT 'defines a category for an attribute_type',
1260
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1259
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1261
  `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)',
1260
  `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)',
1262
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not in the staff interface',
1261
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not in the staff interface',
1263
  `opac_mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not in the OPAC',
1262
  `opac_mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not in the OPAC',
1264
  PRIMARY KEY (`code`),
1263
  PRIMARY KEY (`code`),
1265
  KEY `auth_val_cat_idx` (`authorised_value_category`),
1264
  KEY `auth_val_cat_idx` (`authorised_value_category`)
1266
  KEY `category_code` (`category_code`),
1267
  CONSTRAINT `borrower_attribute_types_ibfk_1` FOREIGN KEY (`category_code`) REFERENCES `categories` (`categorycode`)
1268
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1265
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1269
/*!40101 SET character_set_client = @saved_cs_client */;
1266
/*!40101 SET character_set_client = @saved_cs_client */;
1270
1267
Lines 1285-1290 CREATE TABLE `borrower_attribute_types_branches` ( Link Here
1285
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1282
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1286
/*!40101 SET character_set_client = @saved_cs_client */;
1283
/*!40101 SET character_set_client = @saved_cs_client */;
1287
1284
1285
--
1286
-- Table structure for table `borrower_attribute_types_categories`
1287
--
1288
1289
DROP TABLE IF EXISTS `borrower_attribute_types_categories`;
1290
/*!40101 SET @saved_cs_client     = @@character_set_client */;
1291
/*!40101 SET character_set_client = utf8 */;
1292
CREATE TABLE `borrower_attribute_types_categories` (
1293
  `borrower_attribute_type_code` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1294
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
1295
  KEY `borrower_attribute_type_code` (`borrower_attribute_type_code`),
1296
  KEY `categorycode` (`categorycode`),
1297
  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,
1298
  CONSTRAINT `borrower_attribute_types_categories_categorycode` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE,
1299
  PRIMARY KEY (`borrower_attribute_type_code`, `categorycode`)
1300
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
1301
/*!40101 SET character_set_client = @saved_cs_client */;
1302
1288
--
1303
--
1289
-- Table structure for table `borrower_attributes`
1304
-- Table structure for table `borrower_attributes`
1290
--
1305
--
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt (-9 / +18 lines)
Lines 244-260 Link Here
244
                    </li>
244
                    </li>
245
                    <li>
245
                    <li>
246
                        <label for="category">Category: </label>
246
                        <label for="category">Category: </label>
247
                        <select name="category_code" id="category">
247
                        <select name="category_code" id="category" multiple size="10">
248
                            <option value=""></option>
248
                            <option value="">All categories</option>
249
                            [% FOREACH cat IN categories %]
249
                            [% FOREACH category IN categories %]
250
                                [% IF ( cat.categorycode == attribute_type.category_code ) %]
250
                                [% SET selected = 0 %]
251
                                    <option value="[% cat.categorycode | html %]" selected="selected">[% cat.description |html %]</option>
251
                                [% IF attribute_type %]
252
                                    [% FOREACH cat IN attribute_type.categories %]
253
                                        [% IF cat.categorycode == category.categorycode %]
254
                                            [% SET selected = 1 %]
255
                                        [% END %]
256
                                    [% END %]
257
                                [% END %]
258
                                [% IF selected %]
259
                                    <option value="[% category.categorycode | html %]" selected>[% category.description |html %]</option>
252
                                [% ELSE %]
260
                                [% ELSE %]
253
                                    <option value="[% cat.categorycode | html %]">[% cat.description |html %]</option>
261
                                    <option value="[% category.categorycode | html %]">[% category.description |html %]</option>
254
                                [% END %]
262
                                [% END %]
255
                            [% END %]
263
                            [% END %]
256
                        </select>
264
                        </select>
257
                        <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>
265
                        <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>
258
                    </li>
266
                    </li>
259
                    <li>
267
                    <li>
260
                        <label for="class">Class: </label>
268
                        <label for="class">Class: </label>
Lines 295-302 Link Here
295
        <div id="toolbar" class="btn-toolbar">
303
        <div id="toolbar" class="btn-toolbar">
296
            <a class="btn btn-default" id="newrule" href="/cgi-bin/koha/admin/patron-attr-types.pl?op=add_attribute_type"><i class="fa fa-plus"></i> New patron attribute type</a>
304
            <a class="btn btn-default" id="newrule" href="/cgi-bin/koha/admin/patron-attr-types.pl?op=add_attribute_type"><i class="fa fa-plus"></i> New patron attribute type</a>
297
        </div>
305
        </div>
298
299
        <h1>Patron attribute types</h1>
300
        [% IF ( added_attribute_type ) %]
306
        [% IF ( added_attribute_type ) %]
301
            <div class="alert alert-info">Added patron attribute type &quot;[% added_attribute_type | html %]&quot;</div>
307
            <div class="alert alert-info">Added patron attribute type &quot;[% added_attribute_type | html %]&quot;</div>
302
        [% END %]
308
        [% END %]
Lines 425-430 Link Here
425
            if ($("#branches option:selected").length < 1) {
431
            if ($("#branches option:selected").length < 1) {
426
                $("#branches option:first").attr("selected", "selected");
432
                $("#branches option:first").attr("selected", "selected");
427
            }
433
            }
434
            if ($("#category option:selected").length < 1) {
435
                $("#category option:first").attr("selected", "selected");
436
            }
428
437
429
            $("#opac_display")
438
            $("#opac_display")
430
                .change(function () {
439
                .change(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-1 / +1 lines)
Lines 1520-1526 Link Here
1520
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1520
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1521
                                                        [% END %]
1521
                                                        [% END %]
1522
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1522
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1523
                                                            <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1523
                                                            <li data-category_code="[% patron_attribute.categorycodes.join(' ') | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1524
                                                                [% IF patron_attribute.mandatory %]
1524
                                                                [% IF patron_attribute.mandatory %]
1525
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1525
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1526
                                                                [% ELSE %]
1526
                                                                [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt (-1 / +1 lines)
Lines 264-270 Link Here
264
                                    </tr>
264
                                    </tr>
265
                                [% END %]
265
                                [% END %]
266
                                [% FOREACH patron_attribute IN pa_loo.items %]
266
                                [% FOREACH patron_attribute IN pa_loo.items %]
267
                                    <tr data-category_code="[% patron_attribute.category_code | html %]">
267
                                    <tr>
268
                                        <td> [% patron_attribute.code | html %] ([% patron_attribute.description | html %]) </td>
268
                                        <td> [% patron_attribute.code | html %] ([% patron_attribute.description | html %]) </td>
269
                                        <td>
269
                                        <td>
270
                                            <input type="radio" name="Line" value="patron_attr.[% patron_attribute.code | html %]" />
270
                                            <input type="radio" name="Line" value="patron_attr.[% patron_attribute.code | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt (-1 / +1 lines)
Lines 595-601 Link Here
595
            information_category_node.html("");
595
            information_category_node.html("");
596
596
597
            if ( category && category.length > 0 ) {
597
            if ( category && category.length > 0 ) {
598
                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
598
                information_category_node.html(_("This attribute will be only applied to the following patron categories: %s").format(category));
599
            }
599
            }
600
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
600
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
601
            if ( type == 'select' ) {
601
            if ( type == 'select' ) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (-1 / +1 lines)
Lines 77-83 function update_category_code(category_code) { Link Here
77
    var mytables = $(".attributes_table");
77
    var mytables = $(".attributes_table");
78
    $(mytables).find("li").hide();
78
    $(mytables).find("li").hide();
79
    $(mytables)
79
    $(mytables)
80
        .find(" li[data-category_code='" + category_code + "']")
80
        .find(" li[data-category_code~='" + category_code + "']")
81
        .show();
81
        .show();
82
    $(mytables).find(" li[data-category_code='']").show();
82
    $(mytables).find(" li[data-category_code='']").show();
83
83
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt (-1 / +1 lines)
Lines 1226-1232 Link Here
1226
                                                    [% FOREACH pa_value IN pa.values %]
1226
                                                    [% FOREACH pa_value IN pa.values %]
1227
                                                        [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
1227
                                                        [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
1228
                                                        [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
1228
                                                        [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
1229
                                                        <li data-category_code="[% pa.type.category_code | html %]">
1229
                                                        <li>
1230
                                                            [% IF pa.type.opac_mandatory && pa.type.opac_editable %]
1230
                                                            [% IF pa.type.opac_mandatory && pa.type.opac_editable %]
1231
                                                                <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
1231
                                                                <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
1232
                                                            [% ELSE %]
1232
                                                            [% ELSE %]
(-)a/members/memberentry.pl (-1 / +1 lines)
Lines 948-954 sub patron_attributes_form { Link Here
948
            description   => $attr_type->description(),
948
            description   => $attr_type->description(),
949
            repeatable    => $attr_type->repeatable(),
949
            repeatable    => $attr_type->repeatable(),
950
            category      => $attr_type->authorised_value_category(),
950
            category      => $attr_type->authorised_value_category(),
951
            category_code => $attr_type->category_code(),
951
            categorycodes => [ map { $_->categorycode } $attr_type->categories->as_list ],
952
            mandatory     => $attr_type->mandatory(),
952
            mandatory     => $attr_type->mandatory(),
953
            is_date       => $attr_type->is_date(),
953
            is_date       => $attr_type->is_date(),
954
        };
954
        };
(-)a/reports/borrowers_stats.pl (-6 / +5 lines)
Lines 506-517 sub patron_attributes_form { Link Here
506
506
507
        # TODO The following can be simplified easily
507
        # TODO The following can be simplified easily
508
        my $entry = {
508
        my $entry = {
509
            class         => $attr_type->class(),
509
            class       => $attr_type->class(),
510
            code          => $attr_type->code(),
510
            code        => $attr_type->code(),
511
            description   => $attr_type->description(),
511
            description => $attr_type->description(),
512
            repeatable    => $attr_type->repeatable(),
512
            repeatable  => $attr_type->repeatable(),
513
            category      => $attr_type->authorised_value_category(),
513
            category    => $attr_type->authorised_value_category(),
514
            category_code => $attr_type->category_code(),
515
        };
514
        };
516
515
517
        my $newentry = {%$entry};
516
        my $newentry = {%$entry};
(-)a/t/db_dependent/Auth_with_ldap.t (-3 lines)
Lines 95-107 my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; Link Here
95
my $attr_type    = $builder->build(
95
my $attr_type    = $builder->build(
96
    {
96
    {
97
        source => 'BorrowerAttributeType',
97
        source => 'BorrowerAttributeType',
98
        value  => { category_code => $categorycode }
99
    }
98
    }
100
);
99
);
101
my $attr_type2 = $builder->build(
100
my $attr_type2 = $builder->build(
102
    {
101
    {
103
        source => 'BorrowerAttributeType',
102
        source => 'BorrowerAttributeType',
104
        value  => { category_code => $categorycode }
105
    }
103
    }
106
);
104
);
107
105
Lines 709-712 sub is_admin_bind { Link Here
709
}
707
}
710
708
711
$schema->storage->txn_rollback();
709
$schema->storage->txn_rollback();
712
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-5 / +4 lines)
Lines 332-342 subtest 'store() tests' => sub { Link Here
332
            {
332
            {
333
                class => 'Koha::Patron::Attribute::Types',
333
                class => 'Koha::Patron::Attribute::Types',
334
                value => {
334
                value => {
335
                    mandatory     => 0,
335
                    mandatory  => 0,
336
                    repeatable    => 0,
336
                    repeatable => 0,
337
                    unique_id     => 1,
337
                    unique_id  => 1,
338
                    is_date       => 0,
338
                    is_date    => 0,
339
                    category_code => undef
340
                }
339
                }
341
            }
340
            }
342
        );
341
        );
(-)a/t/db_dependent/Koha/Patron/Attribute/Type.t (+37 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
        {
26
            code        => 'TEST',
27
            description => 'Test attribute type',
28
        }
29
    );
30
    $attribute_type->store();
31
    $attribute_type->categories( [ $category1, $category2 ] );
32
    $attribute_type->store();
33
    my @categories = $attribute_type->categories->as_list;
34
    is( scalar @categories, 2 );
35
36
    $schema->storage->txn_rollback;
37
};
(-)a/t/db_dependent/Koha/Patron/Attribute/Types.t (-8 / +4 lines)
Lines 56-69 subtest 'new() tests' => sub { Link Here
56
        1, 'Only one object created'
56
        1, 'Only one object created'
57
    );
57
    );
58
58
59
    my $cateogory_code = $builder->build( { source => 'Category' } )->{categorycode};
59
    my $attribute_type_2 = Koha::Patron::Attribute::Type->new(
60
61
    my $attribute_type_with_category = Koha::Patron::Attribute::Type->new(
62
        {
60
        {
63
            code          => 'code_2',
61
            code        => 'code_2',
64
            description   => 'description',
62
            description => 'description',
65
            category_code => $cateogory_code,
63
            repeatable  => 0
66
            repeatable    => 0
67
        }
64
        }
68
    )->store();
65
    )->store();
69
66
Lines 465-468 subtest 'search_with_library_limits() tests' => sub { Link Here
465
462
466
    $schema->storage->txn_rollback;
463
    $schema->storage->txn_rollback;
467
};
464
};
468
(-)a/t/db_dependent/api/v1/patrons.t (-8 / +6 lines)
Lines 627-636 subtest 'add() tests' => sub { Link Here
627
                {
627
                {
628
                    class => 'Koha::Patron::Attribute::Types',
628
                    class => 'Koha::Patron::Attribute::Types',
629
                    value => {
629
                    value => {
630
                        mandatory     => 0,
630
                        mandatory  => 0,
631
                        repeatable    => 1,
631
                        repeatable => 1,
632
                        unique_id     => 0,
632
                        unique_id  => 0,
633
                        category_code => 'ST'
634
                    }
633
                    }
635
                }
634
                }
636
            );
635
            );
Lines 638-647 subtest 'add() tests' => sub { Link Here
638
                {
637
                {
639
                    class => 'Koha::Patron::Attribute::Types',
638
                    class => 'Koha::Patron::Attribute::Types',
640
                    value => {
639
                    value => {
641
                        mandatory     => 0,
640
                        mandatory  => 0,
642
                        repeatable    => 1,
641
                        repeatable => 1,
643
                        unique_id     => 0,
642
                        unique_id  => 0,
644
                        category_code => 'ST'
645
                    }
643
                    }
646
                }
644
                }
647
            );
645
            );
(-)a/t/db_dependent/api/v1/patrons_extended_attributes.t (-36 / +27 lines)
Lines 116-125 subtest 'add() tests' => sub { Link Here
116
        {
116
        {
117
            class => 'Koha::Patron::Attribute::Types',
117
            class => 'Koha::Patron::Attribute::Types',
118
            value => {
118
            value => {
119
                mandatory     => 1,
119
                mandatory  => 1,
120
                repeatable    => 0,
120
                repeatable => 0,
121
                unique_id     => 0,
121
                unique_id  => 0,
122
                category_code => undef
123
            }
122
            }
124
        }
123
        }
125
    );
124
    );
Lines 127-136 subtest 'add() tests' => sub { Link Here
127
        {
126
        {
128
            class => 'Koha::Patron::Attribute::Types',
127
            class => 'Koha::Patron::Attribute::Types',
129
            value => {
128
            value => {
130
                mandatory     => 0,
129
                mandatory  => 0,
131
                repeatable    => 1,
130
                repeatable => 1,
132
                unique_id     => 0,
131
                unique_id  => 0,
133
                category_code => undef
134
            }
132
            }
135
        }
133
        }
136
    );
134
    );
Lines 138-147 subtest 'add() tests' => sub { Link Here
138
        {
136
        {
139
            class => 'Koha::Patron::Attribute::Types',
137
            class => 'Koha::Patron::Attribute::Types',
140
            value => {
138
            value => {
141
                mandatory     => 0,
139
                mandatory  => 0,
142
                repeatable    => 0,
140
                repeatable => 0,
143
                unique_id     => 1,
141
                unique_id  => 1,
144
                category_code => undef
145
            }
142
            }
146
        }
143
        }
147
    );
144
    );
Lines 239-248 subtest 'overwrite() tests' => sub { Link Here
239
        {
236
        {
240
            class => 'Koha::Patron::Attribute::Types',
237
            class => 'Koha::Patron::Attribute::Types',
241
            value => {
238
            value => {
242
                mandatory     => 1,
239
                mandatory  => 1,
243
                repeatable    => 0,
240
                repeatable => 0,
244
                unique_id     => 0,
241
                unique_id  => 0,
245
                category_code => undef
246
            }
242
            }
247
        }
243
        }
248
    );
244
    );
Lines 250-259 subtest 'overwrite() tests' => sub { Link Here
250
        {
246
        {
251
            class => 'Koha::Patron::Attribute::Types',
247
            class => 'Koha::Patron::Attribute::Types',
252
            value => {
248
            value => {
253
                mandatory     => 0,
249
                mandatory  => 0,
254
                repeatable    => 1,
250
                repeatable => 1,
255
                unique_id     => 0,
251
                unique_id  => 0,
256
                category_code => undef
257
            }
252
            }
258
        }
253
        }
259
    );
254
    );
Lines 261-270 subtest 'overwrite() tests' => sub { Link Here
261
        {
256
        {
262
            class => 'Koha::Patron::Attribute::Types',
257
            class => 'Koha::Patron::Attribute::Types',
263
            value => {
258
            value => {
264
                mandatory     => 0,
259
                mandatory  => 0,
265
                repeatable    => 0,
260
                repeatable => 0,
266
                unique_id     => 1,
261
                unique_id  => 1,
267
                category_code => undef
268
            }
262
            }
269
        }
263
        }
270
    );
264
    );
Lines 381-390 subtest 'delete() tests' => sub { Link Here
381
        {
375
        {
382
            class => 'Koha::Patron::Attribute::Types',
376
            class => 'Koha::Patron::Attribute::Types',
383
            value => {
377
            value => {
384
                mandatory     => 0,
378
                mandatory  => 0,
385
                repeatable    => 1,
379
                repeatable => 1,
386
                unique_id     => 0,
380
                unique_id  => 0,
387
                category_code => undef
388
            }
381
            }
389
        }
382
        }
390
    );
383
    );
Lines 427-436 subtest 'update() tests' => sub { Link Here
427
        {
420
        {
428
            class => 'Koha::Patron::Attribute::Types',
421
            class => 'Koha::Patron::Attribute::Types',
429
            value => {
422
            value => {
430
                mandatory     => 0,
423
                mandatory  => 0,
431
                repeatable    => 1,
424
                repeatable => 1,
432
                unique_id     => 0,
425
                unique_id  => 0,
433
                category_code => undef
434
            }
426
            }
435
        }
427
        }
436
    );
428
    );
Lines 438-447 subtest 'update() tests' => sub { Link Here
438
        {
430
        {
439
            class => 'Koha::Patron::Attribute::Types',
431
            class => 'Koha::Patron::Attribute::Types',
440
            value => {
432
            value => {
441
                mandatory     => 0,
433
                mandatory  => 0,
442
                repeatable    => 0,
434
                repeatable => 0,
443
                unique_id     => 1,
435
                unique_id  => 1,
444
                category_code => undef
445
            }
436
            }
446
        }
437
        }
447
    );
438
    );
(-)a/tools/modborrowers.pl (-8 / +8 lines)
Lines 38-44 use Koha::Libraries; Link Here
38
use Koha::Patron::Categories;
38
use Koha::Patron::Categories;
39
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
39
use Koha::Patron::Debarments qw( AddDebarment DelDebarment );
40
use Koha::Patrons;
40
use Koha::Patrons;
41
use List::MoreUtils qw(uniq);
41
use List::MoreUtils qw(uniq none);
42
use Koha::Patron::Messages;
42
use Koha::Patron::Messages;
43
use Try::Tiny;
43
use Try::Tiny;
44
44
Lines 165-174 if ( $op eq 'cud-show' || $op eq 'show' ) { Link Here
165
            options        => $options,
165
            options        => $options,
166
            };
166
            };
167
167
168
        my $category_code = $attr_type->category_code;
168
        my @categories = $attr_type->categories->as_list;
169
        my ($category_lib) =
169
        my ($category_lib) = join( ', ', map { $_->description } @categories );
170
            map { ( defined $category_code and $attr_type->category_code eq $_->categorycode ) ? $_->description : () }
171
            @patron_categories;
172
        push @patron_attributes_codes,
170
        push @patron_attributes_codes,
173
            {
171
            {
174
            attribute_code => $attr_type->code,
172
            attribute_code => $attr_type->code,
Lines 437-444 if ( $op eq 'cud-do' ) { Link Here
437
435
438
            next unless $attr_type;
436
            next unless $attr_type;
439
437
440
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
438
            # If this borrower is not in one of the categories of this attribute, we don't want to modify this attribute
441
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
439
            my @attr_type_categories = $attr_type->categories->as_list;
440
            if (@attr_type_categories) {
441
                next if none { $patron->categorycode eq $_->categorycode } @attr_type_categories;
442
            }
442
443
443
            # Remove any current values of same type
444
            # Remove any current values of same type
444
            @extended_attributes = grep { $_->{code} ne $code } @extended_attributes;
445
            @extended_attributes = grep { $_->{code} ne $code } @extended_attributes;
445
- 

Return to bug 26573