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

(-)a/Koha/Patron.pm (-4 / +4 lines)
Lines 2272-2280 sub extended_attributes { Link Here
2272
                # Check globally mandatory types
2272
                # Check globally mandatory types
2273
                my $interface = C4::Context->interface;
2273
                my $interface = C4::Context->interface;
2274
                my $params    = {
2274
                my $params    = {
2275
                    mandatory                                        => 1,
2275
                    mandatory                                          => 1,
2276
                    category_code                                    => [ undef, $self->categorycode ],
2276
                    'borrower_attribute_types_categories.categorycode' => [ undef, $self->categorycode ],
2277
                    'borrower_attribute_types_branches.b_branchcode' => undef,
2277
                    'borrower_attribute_types_branches.b_branchcode'   => undef,
2278
                };
2278
                };
2279
2279
2280
                if ( $interface eq 'opac' ) {
2280
                if ( $interface eq 'opac' ) {
Lines 2283-2289 sub extended_attributes { Link Here
2283
2283
2284
                my @required_attribute_types = Koha::Patron::Attribute::Types->search(
2284
                my @required_attribute_types = Koha::Patron::Attribute::Types->search(
2285
                    $params,
2285
                    $params,
2286
                    { join => 'borrower_attribute_types_branches' }
2286
                    { join => [ 'borrower_attribute_types_branches', 'borrower_attribute_types_categories' ] }
2287
                )->get_column('code');
2287
                )->get_column('code');
2288
                for my $type (@required_attribute_types) {
2288
                for my $type (@required_attribute_types) {
2289
                    Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw(
2289
                    Koha::Exceptions::Patron::MissingMandatoryExtendedAttribute->throw(
(-)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 118-124 sub add_update_attribute_type { Link Here
118
    my $mandatory                 = $input->param('mandatory')                 ? 1 : 0;
118
    my $mandatory                 = $input->param('mandatory')                 ? 1 : 0;
119
    my $authorised_value_category = $input->param('authorised_value_category');
119
    my $authorised_value_category = $input->param('authorised_value_category');
120
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
120
    my $display_checkout          = $input->param('display_checkout') ? 1 : 0;
121
    my $category_code             = $input->param('category_code') || undef;
122
    my $class                     = $input->param('class');
121
    my $class                     = $input->param('class');
123
122
124
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
123
    my $attr_type = Koha::Patron::Attribute::Types->find($code);
Lines 154-160 sub add_update_attribute_type { Link Here
154
            mandatory                 => $mandatory,
153
            mandatory                 => $mandatory,
155
            authorised_value_category => $authorised_value_category,
154
            authorised_value_category => $authorised_value_category,
156
            display_checkout          => $display_checkout,
155
            display_checkout          => $display_checkout,
157
            category_code             => $category_code,
158
            class                     => $class,
156
            class                     => $class,
159
        }
157
        }
160
    )->store;
158
    )->store;
Lines 162-167 sub add_update_attribute_type { Link Here
162
    my @branches = grep { !/^\s*$/ } $input->multi_param('branches');
160
    my @branches = grep { !/^\s*$/ } $input->multi_param('branches');
163
    $attr_type->library_limits( \@branches );
161
    $attr_type->library_limits( \@branches );
164
162
163
    my @categories = grep { !/^\s*$/ } $input->multi_param('category_code');
164
    $attr_type->categories( [ Koha::Patron::Categories->search( { categorycode => \@categories } )->as_list ] );
165
165
    if ( $op eq 'edit' ) {
166
    if ( $op eq 'edit' ) {
166
        $template->param( edited_attribute_type => $attr_type->code() );
167
        $template->param( edited_attribute_type => $attr_type->code() );
167
    } else {
168
    } else {
Lines 235-240 sub edit_attribute_type_form { Link Here
235
        $can_be_set_to_unique = 0 if $@;
236
        $can_be_set_to_unique = 0 if $@;
236
        $attr_type->unique_id(0);
237
        $attr_type->unique_id(0);
237
    }
238
    }
239
238
    $template->param(
240
    $template->param(
239
        attribute_type              => $attr_type,
241
        attribute_type              => $attr_type,
240
        attribute_type_form         => 1,
242
        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 (-5 / +20 lines)
Lines 1257-1270 CREATE TABLE `borrower_attribute_types` ( Link Here
1257
  `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
  `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)',
1258
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1258
  `authorised_value_category` varchar(32) DEFAULT NULL COMMENT 'foreign key from authorised_values that links this custom field to an authorized value category',
1259
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1259
  `display_checkout` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if this field displays in checkout screens',
1260
  `category_code` varchar(10) DEFAULT NULL COMMENT 'defines a category for an attribute_type',
1261
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1260
  `class` varchar(255) NOT NULL DEFAULT '' COMMENT 'defines a class for an attribute_type',
1262
  `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)',
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)',
1263
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
1262
  `mandatory` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'defines if the attribute is mandatory or not',
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
--
Lines 6755-6758 CREATE TABLE `zebraqueue` ( Link Here
6755
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
6770
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
6756
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
6771
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
6757
6772
6758
-- Dump completed on 2024-11-25 12:13:27
6773
-- Dump completed on 2024-11-25 12:13:27
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt (-11 / +22 lines)
Lines 1-3 Link Here
1
2
?
1
[% USE raw %]
3
[% USE raw %]
2
[% USE Asset %]
4
[% USE Asset %]
3
[% USE Koha %]
5
[% USE Koha %]
Lines 235-251 Link Here
235
                    </li>
237
                    </li>
236
                    <li>
238
                    <li>
237
                        <label for="category">Category: </label>
239
                        <label for="category">Category: </label>
238
                        <select name="category_code" id="category">
240
                        <select name="category_code" id="category" multiple size="10">
239
                            <option value=""></option>
241
                           <option value="">All categories</option>
240
                            [% FOREACH cat IN categories %]
242
                           [% FOREACH category IN categories %]
241
                                [% IF ( cat.categorycode == attribute_type.category_code ) %]
243
                               [% SET selected = 0 %]
242
                                    <option value="[% cat.categorycode | html %]" selected="selected">[% cat.description |html %]</option>
244
                               [% IF attribute_type %]
243
                                [% ELSE %]
245
                                   [% FOREACH cat IN attribute_type.categories %]
244
                                    <option value="[% cat.categorycode | html %]">[% cat.description |html %]</option>
246
                                       [% IF cat.categorycode == category.categorycode %]
245
                                [% END %]
247
                                           [% SET selected = 1 %]
248
                                       [% END %]
249
                                   [% END %]
250
                               [% END %]
251
                               [% IF selected %]
252
                                   <option value="[% category.categorycode | html %]" selected>[% category.description |html %]</option>
253
                               [% ELSE %]
254
                                   <option value="[% category.categorycode | html %]">[% category.description |html %]</option>
255
                               [% END %]
246
                            [% END %]
256
                            [% END %]
247
                        </select>
257
                        </select>
248
                        <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>
258
                        <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>
249
                    </li>
259
                    </li>
250
                    <li>
260
                    <li>
251
                        <label for="class">Class: </label>
261
                        <label for="class">Class: </label>
Lines 286-293 Link Here
286
        <div id="toolbar" class="btn-toolbar">
296
        <div id="toolbar" class="btn-toolbar">
287
            <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
            <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>
288
        </div>
298
        </div>
289
290
        <h1>Patron attribute types</h1>
291
        [% IF ( added_attribute_type ) %]
299
        [% IF ( added_attribute_type ) %]
292
            <div class="alert alert-info">Added patron attribute type &quot;[% added_attribute_type | html %]&quot;</div>
300
            <div class="alert alert-info">Added patron attribute type &quot;[% added_attribute_type | html %]&quot;</div>
293
        [% END %]
301
        [% END %]
Lines 408-413 Link Here
408
            if ($("#branches option:selected").length < 1) {
416
            if ($("#branches option:selected").length < 1) {
409
                $("#branches option:first").attr("selected", "selected");
417
                $("#branches option:first").attr("selected", "selected");
410
            }
418
            }
419
            if ( $("#category option:selected").length < 1 ) {
420
                $("#category option:first").attr("selected", "selected");
421
            }
411
422
412
            $("#opac_display")
423
            $("#opac_display")
413
                .change(function () {
424
                .change(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-1 / +1 lines)
Lines 1541-1547 Link Here
1541
                                                        <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1541
                                                        <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1542
                                                    [% END %]
1542
                                                    [% END %]
1543
                                                    [% FOREACH patron_attribute IN pa_loo.items %]
1543
                                                    [% FOREACH patron_attribute IN pa_loo.items %]
1544
                                                        <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1544
                                                        <li data-category_code="[% patron_attribute.categorycodes.join(' ') | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1545
                                                            [% IF patron_attribute.mandatory %]
1545
                                                            [% IF patron_attribute.mandatory %]
1546
                                                                <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1546
                                                                <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1547
                                                            [% ELSE %]
1547
                                                            [% ELSE %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/borrowers_stats.tt (-1 / +1 lines)
Lines 261-267 Link Here
261
                                    </tr>
261
                                    </tr>
262
                                [% END %]
262
                                [% END %]
263
                                [% FOREACH patron_attribute IN pa_loo.items %]
263
                                [% FOREACH patron_attribute IN pa_loo.items %]
264
                                    <tr data-category_code="[% patron_attribute.category_code | html %]">
264
                                    <tr>
265
                                        <td> [% patron_attribute.code | html %] ([% patron_attribute.description | html %]) </td>
265
                                        <td> [% patron_attribute.code | html %] ([% patron_attribute.description | html %]) </td>
266
                                        <td>
266
                                        <td>
267
                                            <input type="radio" name="Line" value="patron_attr.[% patron_attribute.code | html %]" />
267
                                            <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 593-599 Link Here
593
            information_category_node.html("");
593
            information_category_node.html("");
594
594
595
            if ( category && category.length > 0 ) {
595
            if ( category && category.length > 0 ) {
596
                information_category_node.html(_("This attribute will be only applied to the patron's category %s").format(category));
596
                information_category_node.html(_("This attribute will be only applied to the following patron categories: %s").format(category));
597
            }
597
            }
598
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
598
            var disable_input_node = $(li_node).find("input:checkbox[name='disable_input']");
599
            if ( type == 'select' ) {
599
            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 1059-1065 Link Here
1059
                                                    [% FOREACH pa_value IN pa.values %]
1059
                                                    [% FOREACH pa_value IN pa.values %]
1060
                                                        [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
1060
                                                        [% IF loop.first %]<a id="patron-attr-start-[% pa.type.code | html %]"></a>[% END %]
1061
                                                        [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
1061
                                                        [% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
1062
                                                        <li data-category_code="[% pa.type.category_code | html %]">
1062
                                                        <li>
1063
                                                            [% IF pa.type.mandatory && pa.type.opac_editable %]
1063
                                                            [% IF pa.type.mandatory && pa.type.opac_editable %]
1064
                                                                <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
1064
                                                                <label for="[% form_id | html %]" class="required">[% pa.type.description | html %]: </label>
1065
                                                            [% ELSE %]
1065
                                                            [% ELSE %]
(-)a/members/memberentry.pl (-3 / +2 lines)
Lines 297-304 foreach my $guarantor (@guarantors) { Link Here
297
    if (   ( $op eq 'cud-save' || $op eq 'cud-insert' )
297
    if (   ( $op eq 'cud-save' || $op eq 'cud-insert' )
298
        && ( $guarantor->is_child || $guarantor->is_guarantee || ( $patron && $patron->is_guarantor ) ) )
298
        && ( $guarantor->is_child || $guarantor->is_guarantee || ( $patron && $patron->is_guarantor ) ) )
299
    {
299
    {
300
        push @errors, 'ERROR_child_is_guarantor'     if ( $guarantor->is_child );
300
        push @errors, 'ERROR_guarantor_is_guarantee';
301
        push @errors, 'ERROR_guarantor_is_guarantee' if ( !$guarantor->is_child );
302
    }
301
    }
303
}
302
}
304
303
Lines 986-992 sub patron_attributes_form { Link Here
986
            description   => $attr_type->description(),
985
            description   => $attr_type->description(),
987
            repeatable    => $attr_type->repeatable(),
986
            repeatable    => $attr_type->repeatable(),
988
            category      => $attr_type->authorised_value_category(),
987
            category      => $attr_type->authorised_value_category(),
989
            category_code => $attr_type->category_code(),
988
            categorycodes => [ map { $_->categorycode } $attr_type->categories->as_list ],
990
            mandatory     => $attr_type->mandatory(),
989
            mandatory     => $attr_type->mandatory(),
991
            is_date       => $attr_type->is_date(),
990
            is_date       => $attr_type->is_date(),
992
        };
991
        };
(-)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 94-106 my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; Link Here
94
my $attr_type    = $builder->build(
94
my $attr_type    = $builder->build(
95
    {
95
    {
96
        source => 'BorrowerAttributeType',
96
        source => 'BorrowerAttributeType',
97
        value  => { category_code => $categorycode }
98
    }
97
    }
99
);
98
);
100
my $attr_type2 = $builder->build(
99
my $attr_type2 = $builder->build(
101
    {
100
    {
102
        source => 'BorrowerAttributeType',
101
        source => 'BorrowerAttributeType',
103
        value  => { category_code => $categorycode }
104
    }
102
    }
105
);
103
);
106
104
Lines 708-711 sub is_admin_bind { Link Here
708
}
706
}
709
707
710
$schema->storage->txn_rollback();
708
$schema->storage->txn_rollback();
711
(-)a/t/db_dependent/Koha/Patron/Attribute.t (-5 / +4 lines)
Lines 328-338 subtest 'store() tests' => sub { Link Here
328
            {
328
            {
329
                class => 'Koha::Patron::Attribute::Types',
329
                class => 'Koha::Patron::Attribute::Types',
330
                value => {
330
                value => {
331
                    mandatory     => 0,
331
                    mandatory  => 0,
332
                    repeatable    => 0,
332
                    repeatable => 0,
333
                    unique_id     => 1,
333
                    unique_id  => 1,
334
                    is_date       => 0,
334
                    is_date    => 0,
335
                    category_code => undef
336
                }
335
                }
337
            }
336
            }
338
        );
337
        );
(-)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 55-68 subtest 'new() tests' => sub { Link Here
55
        1, 'Only one object created'
55
        1, 'Only one object created'
56
    );
56
    );
57
57
58
    my $cateogory_code = $builder->build( { source => 'Category' } )->{categorycode};
58
    my $attribute_type_2 = Koha::Patron::Attribute::Type->new(
59
60
    my $attribute_type_with_category = Koha::Patron::Attribute::Type->new(
61
        {
59
        {
62
            code          => 'code_2',
60
            code        => 'code_2',
63
            description   => 'description',
61
            description => 'description',
64
            category_code => $cateogory_code,
62
            repeatable  => 0
65
            repeatable    => 0
66
        }
63
        }
67
    )->store();
64
    )->store();
68
65
Lines 464-467 subtest 'search_with_library_limits() tests' => sub { Link Here
464
461
465
    $schema->storage->txn_rollback;
462
    $schema->storage->txn_rollback;
466
};
463
};
467
(-)a/t/db_dependent/api/v1/patrons.t (-8 / +6 lines)
Lines 626-635 subtest 'add() tests' => sub { Link Here
626
                {
626
                {
627
                    class => 'Koha::Patron::Attribute::Types',
627
                    class => 'Koha::Patron::Attribute::Types',
628
                    value => {
628
                    value => {
629
                        mandatory     => 0,
629
                        mandatory  => 0,
630
                        repeatable    => 1,
630
                        repeatable => 1,
631
                        unique_id     => 0,
631
                        unique_id  => 0,
632
                        category_code => 'ST'
633
                    }
632
                    }
634
                }
633
                }
635
            );
634
            );
Lines 637-646 subtest 'add() tests' => sub { Link Here
637
                {
636
                {
638
                    class => 'Koha::Patron::Attribute::Types',
637
                    class => 'Koha::Patron::Attribute::Types',
639
                    value => {
638
                    value => {
640
                        mandatory     => 0,
639
                        mandatory  => 0,
641
                        repeatable    => 1,
640
                        repeatable => 1,
642
                        unique_id     => 0,
641
                        unique_id  => 0,
643
                        category_code => 'ST'
644
                    }
642
                    }
645
                }
643
                }
646
            );
644
            );
(-)a/t/db_dependent/api/v1/patrons_extended_attributes.t (-36 / +27 lines)
Lines 115-124 subtest 'add() tests' => sub { Link Here
115
        {
115
        {
116
            class => 'Koha::Patron::Attribute::Types',
116
            class => 'Koha::Patron::Attribute::Types',
117
            value => {
117
            value => {
118
                mandatory     => 1,
118
                mandatory  => 1,
119
                repeatable    => 0,
119
                repeatable => 0,
120
                unique_id     => 0,
120
                unique_id  => 0,
121
                category_code => undef
122
            }
121
            }
123
        }
122
        }
124
    );
123
    );
Lines 126-135 subtest 'add() tests' => sub { Link Here
126
        {
125
        {
127
            class => 'Koha::Patron::Attribute::Types',
126
            class => 'Koha::Patron::Attribute::Types',
128
            value => {
127
            value => {
129
                mandatory     => 0,
128
                mandatory  => 0,
130
                repeatable    => 1,
129
                repeatable => 1,
131
                unique_id     => 0,
130
                unique_id  => 0,
132
                category_code => undef
133
            }
131
            }
134
        }
132
        }
135
    );
133
    );
Lines 137-146 subtest 'add() tests' => sub { Link Here
137
        {
135
        {
138
            class => 'Koha::Patron::Attribute::Types',
136
            class => 'Koha::Patron::Attribute::Types',
139
            value => {
137
            value => {
140
                mandatory     => 0,
138
                mandatory  => 0,
141
                repeatable    => 0,
139
                repeatable => 0,
142
                unique_id     => 1,
140
                unique_id  => 1,
143
                category_code => undef
144
            }
141
            }
145
        }
142
        }
146
    );
143
    );
Lines 238-247 subtest 'overwrite() tests' => sub { Link Here
238
        {
235
        {
239
            class => 'Koha::Patron::Attribute::Types',
236
            class => 'Koha::Patron::Attribute::Types',
240
            value => {
237
            value => {
241
                mandatory     => 1,
238
                mandatory  => 1,
242
                repeatable    => 0,
239
                repeatable => 0,
243
                unique_id     => 0,
240
                unique_id  => 0,
244
                category_code => undef
245
            }
241
            }
246
        }
242
        }
247
    );
243
    );
Lines 249-258 subtest 'overwrite() tests' => sub { Link Here
249
        {
245
        {
250
            class => 'Koha::Patron::Attribute::Types',
246
            class => 'Koha::Patron::Attribute::Types',
251
            value => {
247
            value => {
252
                mandatory     => 0,
248
                mandatory  => 0,
253
                repeatable    => 1,
249
                repeatable => 1,
254
                unique_id     => 0,
250
                unique_id  => 0,
255
                category_code => undef
256
            }
251
            }
257
        }
252
        }
258
    );
253
    );
Lines 260-269 subtest 'overwrite() tests' => sub { Link Here
260
        {
255
        {
261
            class => 'Koha::Patron::Attribute::Types',
256
            class => 'Koha::Patron::Attribute::Types',
262
            value => {
257
            value => {
263
                mandatory     => 0,
258
                mandatory  => 0,
264
                repeatable    => 0,
259
                repeatable => 0,
265
                unique_id     => 1,
260
                unique_id  => 1,
266
                category_code => undef
267
            }
261
            }
268
        }
262
        }
269
    );
263
    );
Lines 380-389 subtest 'delete() tests' => sub { Link Here
380
        {
374
        {
381
            class => 'Koha::Patron::Attribute::Types',
375
            class => 'Koha::Patron::Attribute::Types',
382
            value => {
376
            value => {
383
                mandatory     => 0,
377
                mandatory  => 0,
384
                repeatable    => 1,
378
                repeatable => 1,
385
                unique_id     => 0,
379
                unique_id  => 0,
386
                category_code => undef
387
            }
380
            }
388
        }
381
        }
389
    );
382
    );
Lines 426-435 subtest 'update() tests' => sub { Link Here
426
        {
419
        {
427
            class => 'Koha::Patron::Attribute::Types',
420
            class => 'Koha::Patron::Attribute::Types',
428
            value => {
421
            value => {
429
                mandatory     => 0,
422
                mandatory  => 0,
430
                repeatable    => 1,
423
                repeatable => 1,
431
                unique_id     => 0,
424
                unique_id  => 0,
432
                category_code => undef
433
            }
425
            }
434
        }
426
        }
435
    );
427
    );
Lines 437-446 subtest 'update() tests' => sub { Link Here
437
        {
429
        {
438
            class => 'Koha::Patron::Attribute::Types',
430
            class => 'Koha::Patron::Attribute::Types',
439
            value => {
431
            value => {
440
                mandatory     => 0,
432
                mandatory  => 0,
441
                repeatable    => 0,
433
                repeatable => 0,
442
                unique_id     => 1,
434
                unique_id  => 1,
443
                category_code => undef
444
            }
435
            }
445
        }
436
        }
446
    );
437
    );
(-)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
43
44
my $input = CGI->new;
44
my $input = CGI->new;
Lines 164-173 if ( $op eq 'cud-show' || $op eq 'show' ) { Link Here
164
            options        => $options,
164
            options        => $options,
165
            };
165
            };
166
166
167
        my $category_code = $attr_type->category_code;
167
        my @categories = $attr_type->categories->as_list;
168
        my ($category_lib) =
168
        my ($category_lib) = join( ', ', map { $_->description } @categories );
169
            map { ( defined $category_code and $attr_type->category_code eq $_->categorycode ) ? $_->description : () }
170
            @patron_categories;
171
        push @patron_attributes_codes,
169
        push @patron_attributes_codes,
172
            {
170
            {
173
            attribute_code => $attr_type->code,
171
            attribute_code => $attr_type->code,
Lines 433-440 if ( $op eq 'cud-do' ) { Link Here
433
431
434
            next unless $attr_type;
432
            next unless $attr_type;
435
433
436
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
434
            # If this borrower is not in one of the categories of this attribute, we don't want to modify this attribute
437
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
435
            my @attr_type_categories = $attr_type->categories->as_list;
436
            if (@attr_type_categories) {
437
                next if none { $patron->categorycode eq $_->categorycode } @attr_type_categories;
438
            }
438
439
439
            if ( $attributes->{$code}->{disabled} ) {
440
            if ( $attributes->{$code}->{disabled} ) {
440
441
441
- 

Return to bug 26573