From 94fb62a0f351de802e3163522ff4655c8a00fa30 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 17 Mar 2015 10:45:27 +0100 Subject: [PATCH] Bug 13799: Use Koha::Objects This add 'unblessed' subroutines to both Koha::Objects and Koha::Object to be able to pass it to Mojolicious --- Koha/Object.pm | 12 ++++++++++++ Koha/Objects.pm | 12 ++++++++++++ Koha/REST/V1/Borrowers.pm | 10 +++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Koha/Object.pm b/Koha/Object.pm index a77eb5c..6e53461 100644 --- a/Koha/Object.pm +++ b/Koha/Object.pm @@ -207,6 +207,18 @@ sub id { return $id; } +=head3 $object->unblessed(); + +Returns an unblessed representation of object. + +=cut + +sub unblessed { + my ($self) = @_; + + return { $self->_result->get_columns }; +} + =head3 $object->_result(); Returns the internal DBIC Row object diff --git a/Koha/Objects.pm b/Koha/Objects.pm index 8ef6390..1ff91cb 100644 --- a/Koha/Objects.pm +++ b/Koha/Objects.pm @@ -181,6 +181,18 @@ sub as_list { return wantarray ? @objects : \@objects; } +=head3 Koha::Objects->unblessed + +Returns an unblessed representation of objects. + +=cut + +sub unblessed { + my ($self) = @_; + + return [ map { $_->unblessed } $self->as_list ]; +} + =head3 Koha::Objects->_wrap wraps the DBIC object in a corresponding Koha object diff --git a/Koha/REST/V1/Borrowers.pm b/Koha/REST/V1/Borrowers.pm index 332cdeb..b58ad2a 100644 --- a/Koha/REST/V1/Borrowers.pm +++ b/Koha/REST/V1/Borrowers.pm @@ -4,23 +4,23 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; -use C4::Members; +use Koha::Borrowers; sub list_borrowers { my ($c, $args, $cb) = @_; - my $borrowers = C4::Members::Search; + my $borrowers = Koha::Borrowers->search; - $c->$cb($borrowers, 200); + $c->$cb($borrowers->unblessed, 200); } sub get_borrower { my ($c, $args, $cb) = @_; - my $borrower = C4::Members::GetMemberDetails($args->{borrowernumber}); + my $borrower = Koha::Borrowers->find($args->{borrowernumber}); if ($borrower) { - return $c->$cb($borrower, 200); + return $c->$cb($borrower->unblessed, 200); } $c->$cb({error => "Borrower not found"}, 404); -- 1.7.9.5