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

(-)a/Koha/Object.pm (+45 lines)
Lines 581-586 sub to_api { Link Here
581
        }
581
        }
582
    }
582
    }
583
583
584
    my $av_expand = $params->{av_expand};
585
584
    # Make sure we duplicate the $params variable to avoid
586
    # Make sure we duplicate the $params variable to avoid
585
    # breaking calls in a loop (Koha::Objects->to_api)
587
    # breaking calls in a loop (Koha::Objects->to_api)
586
    $params    = {%$params};
588
    $params    = {%$params};
Lines 627-632 sub to_api { Link Here
627
        }
629
        }
628
    }
630
    }
629
631
632
    if ( $av_expand && $self->can('_fetch_authorised_values') ) {
633
634
        # _fetch_authorised_values should return a hash as the following
635
        # {
636
        #  column_name => <authorised_value>->unblessed
637
        #  ...
638
        # }
639
        my $avs = $self->_fetch_authorised_values($av_expand);
640
641
        # Language selection will be implemented when lang overlay for av is ready
642
        # Now we will just fetch plain authorised values from the Koha::AuthorisedValues
643
        $avs = $self->_do_api_mapping($avs);
644
645
        $json_object->{_authorised_values} = $avs || {};
646
    }
647
648
    return $json_object;
649
}
650
651
=head3 _do_api_mapping
652
653
=cut
654
655
sub _do_api_mapping {
656
    my ($self, $json_object) = @_;
657
    # Rename attributes if there's a mapping
658
    if ( $self->can('to_api_mapping') ) {
659
        foreach my $column ( keys %{ $self->to_api_mapping } ) {
660
            my $mapped_column = $self->to_api_mapping->{$column};
661
            if ( exists $json_object->{$column}
662
                && defined $mapped_column )
663
            {
664
                # key != undef
665
                $json_object->{$mapped_column} = delete $json_object->{$column};
666
            }
667
            elsif ( exists $json_object->{$column}
668
                && !defined $mapped_column )
669
            {
670
                # key == undef
671
                delete $json_object->{$column};
672
            }
673
        }
674
    }
630
    return $json_object;
675
    return $json_object;
631
}
676
}
632
677
(-)a/Koha/REST/Plugin/Objects.pm (-5 / +7 lines)
Lines 53-59 the requested object. It passes through any embeds if specified. Link Here
53
            my $attributes = {};
53
            my $attributes = {};
54
54
55
            # Look for embeds
55
            # Look for embeds
56
            my $embed = $c->stash('koha.embed');
56
            my $embed     = $c->stash('koha.embed');
57
            my $av_expand = $c->req->headers->header('x-koha-av-expand');
58
57
            # Generate prefetches for embedded stuff
59
            # Generate prefetches for embedded stuff
58
            $c->dbic_merge_prefetch(
60
            $c->dbic_merge_prefetch(
59
                {
61
                {
Lines 66-72 the requested object. It passes through any embeds if specified. Link Here
66
68
67
            return unless $object;
69
            return unless $object;
68
70
69
            return $object->to_api({ embed => $embed });
71
            return $object->to_api({ embed => $embed, av_expand => $av_expand });
70
        }
72
        }
71
    );
73
    );
72
74
Lines 97-103 shouldn't be called twice in it. Link Here
97
            # Privileged reques?
99
            # Privileged reques?
98
            my $is_public = $c->stash('is_public');
100
            my $is_public = $c->stash('is_public');
99
            # Look for embeds
101
            # Look for embeds
100
            my $embed = $c->stash('koha.embed');
102
            my $embed     = $c->stash('koha.embed');
103
            my $av_expand = $c->req->headers->header('x-koha-av-expand');
101
104
102
            # Merge sorting into query attributes
105
            # Merge sorting into query attributes
103
            $c->dbic_merge_sorting(
106
            $c->dbic_merge_sorting(
Lines 202-208 shouldn't be called twice in it. Link Here
202
                }
205
                }
203
            );
206
            );
204
207
205
            return $objects->to_api({ embed => $embed, public => $is_public });
208
            return $objects->to_api({ embed => $embed, public => $is_public, av_expand => $av_expand });
206
        }
209
        }
207
    );
210
    );
208
}
211
}
209
- 

Return to bug 26635