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

(-)a/tools/modborrowers.pl (-24 / +17 lines)
Lines 117-125 if ( $op eq 'show' ) { Link Here
117
    my $patron_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id);
117
    my $patron_attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id);
118
    my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
118
    my @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
119
    while ( my $attr_type = $patron_attribute_types->next ) {
119
    while ( my $attr_type = $patron_attribute_types->next ) {
120
        # TODO Repeatable attributes are not correctly managed and can cause data lost.
121
        # This should be implemented.
122
        next if $attr_type->repeatable;
123
        next if $attr_type->unique_id; # Don't display patron attributes that must be unqiue
120
        next if $attr_type->unique_id; # Don't display patron attributes that must be unqiue
124
        my $options = $attr_type->authorised_value_category
121
        my $options = $attr_type->authorised_value_category
125
            ? GetAuthorisedValues( $attr_type->authorised_value_category )
122
            ? GetAuthorisedValues( $attr_type->authorised_value_category )
Lines 333-341 if ( $op eq 'do' ) { Link Here
333
        $infos->{$field} = dt_from_string($infos->{$field}) if $infos->{$field};
330
        $infos->{$field} = dt_from_string($infos->{$field}) if $infos->{$field};
334
    }
331
    }
335
332
336
    my @attributes = $input->multi_param('patron_attributes');
337
    my @attr_values = $input->multi_param('patron_attributes_value');
338
339
    my @errors;
333
    my @errors;
340
    my @borrowernumbers = $input->multi_param('borrowernumber');
334
    my @borrowernumbers = $input->multi_param('borrowernumber');
341
    # For each borrower selected
335
    # For each borrower selected
Lines 373-405 if ( $op eq 'do' ) { Link Here
373
        }
367
        }
374
368
375
        my $patron = Koha::Patrons->find( $borrowernumber );
369
        my $patron = Koha::Patrons->find( $borrowernumber );
376
        my $i=0;
370
        my @attributes = $input->multi_param('patron_attributes');
377
        for ( @attributes ) {
371
        my @attr_values = $input->multi_param('patron_attributes_value');
378
            next unless $_;
372
        my $attributes;
379
            my $attribute;
373
        my $i = 0;
380
            $attribute->{code} = $_;
374
        for my $code ( @attributes ) {
381
            $attribute->{attribute} = $attr_values[$i];
375
            push @{ $attributes->{$code}->{values} }, shift @attr_values; # Handling repeatables
382
            my $attr_type = Koha::Patron::Attribute::Types->find($_);
376
            $attributes->{$code}->{disabled} = grep { $_ eq sprintf("attr%s_value", ++$i) } @disabled;
377
        }
378
379
        for my $code ( keys %$attributes ) {
380
            my $attr_type = Koha::Patron::Attribute::Types->find($code);
383
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
381
            # If this borrower is not in the category of this attribute, we don't want to modify this attribute
384
            ++$i and next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
382
            next if $attr_type->category_code and $attr_type->category_code ne $patron->categorycode;
385
            my $valuename = "attr" . $i . "_value";
383
386
            if ( grep { $_ eq $valuename } @disabled ) {
384
            if ( $attributes->{$code}->{disabled} ) {
387
                # The attribute is disabled, we remove it for this borrower !
385
                # The attribute is disabled, we remove it for this borrower !
388
                eval {
386
                eval {
389
                    $patron->get_extended_attribute($attribute->{code})->delete;
387
                    $patron->get_extended_attribute($code)->delete;
390
                };
388
                };
391
                push @errors, { error => $@ } if $@;
389
                push @errors, { error => $@ } if $@;
392
            } else {
390
            } else {
393
                eval {
391
                eval {
394
                    # Note:
392
                    $patron->extended_attributes->search({'me.code' => $code})->filter_by_branch_limitations->delete;
395
                    # We should not need to filter by branch, but stay on the safe side
393
                    $patron->add_extended_attribute({ code => $code, attribute => $_ }) for @{$attributes->{$code}->{values}};
396
                    # Repeatable are not supported so we can do that - TODO
397
                    $patron->extended_attributes->search({'me.code' => $attribute->{code}})->filter_by_branch_limitations->delete;
398
                    $patron->add_extended_attribute($attribute);
399
                };
394
                };
400
                push @errors, { error => $@ } if $@;
395
                push @errors, { error => $@ } if $@;
401
            }
396
            }
402
            $i++;
403
        }
397
        }
404
    }
398
    }
405
    $op = "show_results"; # We have process modifications, the user want to view its
399
    $op = "show_results"; # We have process modifications, the user want to view its
406
- 

Return to bug 21083