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

(-)a/Koha/Item.pm (-16 / +1 lines)
Lines 2089-2105 sub api_strings_mapping { Link Here
2089
2089
2090
    foreach my $col ( keys %{$columns_info} ) {
2090
    foreach my $col ( keys %{$columns_info} ) {
2091
2091
2092
        # Skip columns not in public read list
2093
        next
2094
          unless !$params->{public}
2095
          || any { $col eq $_ } $public_read_list;
2096
2097
        # Skip columns that are not exposed on the API by to_api_mapping
2098
        # i.e. mapping exists but points to undef
2099
        next
2100
          if $col eq 'more_subfields_xml'    # not dealt with as a regular field
2101
          || ( exists $to_api_mapping->{$col} && !defined $to_api_mapping->{$col} );
2102
2103
        # By now, we are done with known columns, now check the framework for mappings
2092
        # By now, we are done with known columns, now check the framework for mappings
2104
        my $field = $self->_result->result_source->name . '.' . $col;
2093
        my $field = $self->_result->result_source->name . '.' . $col;
2105
2094
Lines 2113-2123 sub api_strings_mapping { Link Here
2113
2102
2114
            my $str  = C4::Biblio::GetAuthorisedValueDesc( $itemtagfield, $subfield->{tagsubfield}, $self->$col, '', $tagslib, undef, $params->{public} );
2103
            my $str  = C4::Biblio::GetAuthorisedValueDesc( $itemtagfield, $subfield->{tagsubfield}, $self->$col, '', $tagslib, undef, $params->{public} );
2115
            my $type = exists $code_to_type->{$code} ? $code_to_type->{$code} : 'av';
2104
            my $type = exists $code_to_type->{$code} ? $code_to_type->{$code} : 'av';
2116
2105
            $strings->{$col} = {
2117
            # The _strings entry should match the API attribute name
2118
            my $mapped_attr = exists $to_api_mapping->{$col} ? $to_api_mapping->{$col} : $col;
2119
2120
            $strings->{$mapped_attr} = {
2121
                str  => $str,
2106
                str  => $str,
2122
                type => $type,
2107
                type => $type,
2123
                ( $type eq 'av' ? ( category => $code ) : () ),
2108
                ( $type eq 'av' ? ( category => $code ) : () ),
(-)a/Koha/Object.pm (-10 / +35 lines)
Lines 570-582 sub to_api { Link Here
570
    # Remove forbidden attributes if required (including their coded values)
570
    # Remove forbidden attributes if required (including their coded values)
571
    if ( $params->{public} ) {
571
    if ( $params->{public} ) {
572
        for my $field ( keys %{$json_object} ) {
572
        for my $field ( keys %{$json_object} ) {
573
            delete $json_object->{$field} unless any { $_ eq $field } @{ $self->public_read_list };
573
            delete $json_object->{$field}
574
              unless any { $_ eq $field } @{ $self->public_read_list };
574
        }
575
        }
575
576
576
        if ( $strings ) {
577
        if ($strings) {
577
            foreach my $field (keys %{$avs}) {
578
            foreach my $field ( keys %{$avs} ) {
578
                delete $avs->{$field}
579
                delete $avs->{$field}
579
                    unless any { $_ eq $field } @{ $self->public_read_list };
580
                  unless any { $_ eq $field } @{ $self->public_read_list };
580
            }
581
            }
581
        }
582
        }
582
    }
583
    }
Lines 588-602 sub to_api { Link Here
588
        foreach my $column ( keys %{ $self->to_api_mapping } ) {
589
        foreach my $column ( keys %{ $self->to_api_mapping } ) {
589
            my $mapped_column = $self->to_api_mapping->{$column};
590
            my $mapped_column = $self->to_api_mapping->{$column};
590
            if ( exists $json_object->{$column}
591
            if ( exists $json_object->{$column}
591
                && defined $mapped_column ) {
592
                && defined $mapped_column )
593
            {
592
594
593
                # key != undef
595
                # key != undef
594
                $json_object->{$mapped_column} = delete $json_object->{$column};
596
                $json_object->{$mapped_column} = delete $json_object->{$column};
595
                $avs->{$mapped_column}         = delete $avs->{$column}
597
                $avs->{$mapped_column}         = delete $avs->{$column}
596
                  if exists $avs->{$column};
598
                  if exists $avs->{$column};
597
599
598
            } elsif ( exists $json_object->{$column}
600
            }
599
                && !defined $mapped_column ) {
601
            elsif ( exists $json_object->{$column}
602
                && !defined $mapped_column )
603
            {
600
604
601
                # key == undef
605
                # key == undef
602
                delete $json_object->{$column};
606
                delete $json_object->{$column};
Lines 610-617 sub to_api { Link Here
610
614
611
    if ($embeds) {
615
    if ($embeds) {
612
        foreach my $embed ( keys %{$embeds} ) {
616
        foreach my $embed ( keys %{$embeds} ) {
613
            if ( $embed =~ m/^(?<relation>.*)_count$/
617
            if (    $embed =~ m/^(?<relation>.*)_count$/
614
                and $embeds->{$embed}->{is_count} ) {
618
                and $embeds->{$embed}->{is_count} )
619
            {
615
620
616
                my $relation = $+{relation};
621
                my $relation = $+{relation};
617
                $json_object->{$embed} = $self->$relation->count;
622
                $json_object->{$embed} = $self->$relation->count;
Lines 671-676 sub to_api_mapping { Link Here
671
    return {};
676
    return {};
672
}
677
}
673
678
679
=head3 api_strings_mapping
680
681
    my $params = { is_public => 1 };
682
    my $string_map = $object->api_strings_mapping($params);
683
684
Generic method that returns the string map for coded attributes.
685
686
Return should be a hashref keyed on database field name with the values
687
being hashrefs containing 'str', 'type' and optionally 'category'. 
688
689
This is then use in to_api to render the _strings embed when requested.
690
691
Note: this only returns an empty I<hashref>. Each class should have its
692
own mapping returned.
693
694
=cut
695
696
sub api_strings_mapping {
697
    return {};
698
}
699
674
=head3 public_read_list
700
=head3 public_read_list
675
701
676
702
677
- 

Return to bug 33161