Lines 434-439
sub from_api_mapping {
Link Here
|
434 |
return $self->{_from_api_mapping}; |
434 |
return $self->{_from_api_mapping}; |
435 |
} |
435 |
} |
436 |
|
436 |
|
|
|
437 |
=head3 new_from_api |
438 |
|
439 |
my $object = Koha::Object->new_from_api; |
440 |
my $object = Koha::Object->new_from_api( $attrs ); |
441 |
|
442 |
Creates a new object, mapping the API attribute names to the ones on the DB schema. |
443 |
|
444 |
=cut |
445 |
|
446 |
sub new_from_api { |
447 |
my ( $class, $params ) = @_; |
448 |
|
449 |
my $self = $class->new; |
450 |
return $self->set_from_api( $params ); |
451 |
} |
452 |
|
453 |
=head3 set_from_api |
454 |
|
455 |
my $object = Koha::Object->new(...); |
456 |
$object->set_from_api( $attrs ) |
457 |
|
458 |
Sets the object's attributes mapping API attribute names to the ones on the DB schema. |
459 |
|
460 |
=cut |
461 |
|
462 |
sub set_from_api { |
463 |
my ( $self, $from_api_params ) = @_; |
464 |
|
465 |
return $self->set( $self->attributes_from_api( $from_api_params ) ); |
466 |
} |
467 |
|
437 |
=head3 $object->unblessed_all_relateds |
468 |
=head3 $object->unblessed_all_relateds |
438 |
|
469 |
|
439 |
my $everything_into_one_hashref = $object->unblessed_all_relateds |
470 |
my $everything_into_one_hashref = $object->unblessed_all_relateds |
Lines 555-581
Returns the passed params, converted from API naming into the model.
Link Here
|
555 |
=cut |
586 |
=cut |
556 |
|
587 |
|
557 |
sub attributes_from_api { |
588 |
sub attributes_from_api { |
558 |
my ( $self, $attributes ) = @_; |
589 |
my ( $self, $from_api_params ) = @_; |
559 |
|
590 |
|
560 |
my $mapping = $self->from_api_mapping; |
591 |
my $from_api_mapping = $self->from_api_mapping; |
561 |
|
592 |
|
562 |
foreach my $attribute ( keys %{$mapping} ) { |
593 |
my $params; |
563 |
my $mapped_attribute = $mapping->{$attribute}; |
594 |
|
564 |
if ( exists $attributes->{$attribute} |
595 |
while (my ($key, $value) = each %{ $from_api_params } ) { |
565 |
&& defined $mapped_attribute ) |
596 |
if ( exists $from_api_mapping->{$key} ) { |
566 |
{ |
597 |
$params->{$from_api_mapping->{$key}} = $value; |
567 |
# key => !undef |
|
|
568 |
$attributes->{$mapped_attribute} = delete $attributes->{$attribute}; |
569 |
} |
598 |
} |
570 |
elsif ( exists $attributes->{$attribute} |
599 |
else { |
571 |
&& !defined $mapped_attribute ) |
600 |
$params->{$key} = $value; |
572 |
{ |
|
|
573 |
# key => undef / to be deleted |
574 |
delete $attributes->{$attribute}; |
575 |
} |
601 |
} |
576 |
} |
602 |
} |
577 |
|
603 |
|
578 |
return $attributes; |
604 |
return $params; |
579 |
} |
605 |
} |
580 |
|
606 |
|
581 |
=head3 _type |
607 |
=head3 _type |
582 |
- |
|
|