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

(-)a/C4/Serials.pm (-20 / +21 lines)
Lines 616-647 sub SearchSubscriptions { Link Here
616
    my $dbh = C4::Context->dbh;
616
    my $dbh = C4::Context->dbh;
617
    my $sth = $dbh->prepare($query);
617
    my $sth = $dbh->prepare($query);
618
    $sth->execute(@where_args);
618
    $sth->execute(@where_args);
619
    my $results =  $sth->fetchall_arrayref( {} );
619
    my $results = $sth->fetchall_arrayref( {} );
620
620
621
    my %additional_fields_by_id = map { $_->id => $_->name } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list;
621
    my %additional_fields_by_id = map { $_->id => $_->name } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list;
622
622
    if (%additional_fields_by_id) {
623
    for my $subscription ( @$results ) {
623
        my %subscriptions_by_id = map { $_->{subscriptionid } => $_ } @{$results};
624
        $subscription->{cannotedit} = not can_edit_subscription( $subscription );
624
        my $field_values_rs = Koha::AdditionalFieldValues->search(
625
        $subscription->{cannotdisplay} = not can_show_subscription( $subscription );
625
            {
626
626
                field_id => { -in => [ keys %additional_fields_by_id ] },
627
        if (%additional_fields_by_id) {
627
                record_id => { -in => [ keys %subscriptions_by_id ] }
628
            my @additional_field_values = Koha::AdditionalFieldValues->search(
628
            }
629
                {
629
        );
630
                    field_id => { -in => [ keys %additional_fields_by_id ] },
630
        while (my $field_value = $field_values_rs->next) {
631
                    record_id => $subscription->{subscriptionid}
631
            my $field_name = $additional_fields_by_id{$field_value->field_id};
632
                }
632
            $subscriptions_by_id{$field_value->record_id}->{additional_fields}->{$field_name} = $field_value->value;
633
            )->as_list;
634
635
            $subscription->{additional_fields} = {
636
                map { $additional_fields_by_id{$_->field_id} => $_->value } @additional_field_values
637
            };
638
        }
633
        }
639
        else {
634
    }
635
    else {
636
        for my $subscription ( @{$results} ) {
640
            $subscription->{additional_fields} = {};
637
            $subscription->{additional_fields} = {};
641
        }
638
        }
642
    }
639
    }
643
640
644
    return @$results;
641
    for my $subscription ( @{$results} ) {
642
        $subscription->{cannotedit} = not can_edit_subscription( $subscription );
643
        $subscription->{cannotdisplay} = not can_show_subscription( $subscription );
644
    }
645
646
    return @{$results};
645
}
647
}
646
648
647
649
648
- 

Return to bug 31856