Lines 631-637
sub SearchSubscriptions {
Link Here
|
631 |
my $dbh = C4::Context->dbh; |
631 |
my $dbh = C4::Context->dbh; |
632 |
my $sth = $dbh->prepare($query); |
632 |
my $sth = $dbh->prepare($query); |
633 |
$sth->execute(@where_args); |
633 |
$sth->execute(@where_args); |
634 |
my $results = $sth->fetchall_arrayref( {} ); |
634 |
my $results = $sth->fetchall_arrayref( {} ); |
635 |
|
635 |
|
636 |
my $total_results = @{$results}; |
636 |
my $total_results = @{$results}; |
637 |
|
637 |
|
Lines 639-666
sub SearchSubscriptions {
Link Here
|
639 |
$results = [ splice( @{$results}, 0, $params->{results_limit} ) ]; |
639 |
$results = [ splice( @{$results}, 0, $params->{results_limit} ) ]; |
640 |
} |
640 |
} |
641 |
my %additional_fields_by_id = map { $_->id => $_->name } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list; |
641 |
my %additional_fields_by_id = map { $_->id => $_->name } Koha::AdditionalFields->search( { tablename => 'subscription' } )->as_list; |
642 |
|
642 |
if (%additional_fields_by_id) { |
643 |
for my $subscription ( @$results ) { |
643 |
my %subscriptions_by_id = map { $_->{subscriptionid } => $_ } @{$results}; |
644 |
$subscription->{cannotedit} = not can_edit_subscription( $subscription ); |
644 |
my $field_values_rs = Koha::AdditionalFieldValues->search( |
645 |
$subscription->{cannotdisplay} = not can_show_subscription( $subscription ); |
645 |
{ |
646 |
|
646 |
field_id => { -in => [ keys %additional_fields_by_id ] }, |
647 |
if (%additional_fields_by_id) { |
647 |
record_id => { -in => [ keys %subscriptions_by_id ] } |
648 |
my @additional_field_values = Koha::AdditionalFieldValues->search( |
648 |
} |
649 |
{ |
649 |
); |
650 |
field_id => { -in => [ keys %additional_fields_by_id ] }, |
650 |
while (my $field_value = $field_values_rs->next) { |
651 |
record_id => $subscription->{subscriptionid} |
651 |
my $field_name = $additional_fields_by_id{$field_value->field_id}; |
652 |
} |
652 |
$subscriptions_by_id{$field_value->record_id}->{additional_fields}->{$field_name} = $field_value->value; |
653 |
)->as_list; |
|
|
654 |
|
655 |
$subscription->{additional_fields} = { |
656 |
map { $additional_fields_by_id{$_->field_id} => $_->value } @additional_field_values |
657 |
}; |
658 |
} |
653 |
} |
659 |
else { |
654 |
} |
|
|
655 |
else { |
656 |
for my $subscription ( @{$results} ) { |
660 |
$subscription->{additional_fields} = {}; |
657 |
$subscription->{additional_fields} = {}; |
661 |
} |
658 |
} |
662 |
} |
659 |
} |
663 |
|
660 |
|
|
|
661 |
for my $subscription ( @{$results} ) { |
662 |
$subscription->{cannotedit} = not can_edit_subscription( $subscription ); |
663 |
$subscription->{cannotdisplay} = not can_show_subscription( $subscription ); |
664 |
} |
665 |
|
664 |
return wantarray ? @{$results} : { results => $results, total => $total_results }; |
666 |
return wantarray ? @{$results} : { results => $results, total => $total_results }; |
665 |
} |
667 |
} |
666 |
|
668 |
|
667 |
- |
|
|