Bugzilla – Attachment 35980 Details for
Bug 13019
Add base classes on which to build Koha objects
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Store list of objects as needed
Store-list-of-objects-as-needed.patch (text/plain), 2.55 KB, created by
Kyle M Hall (khall)
on 2015-02-17 16:08:57 UTC
(
hide
)
Description:
Store list of objects as needed
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-02-17 16:08:57 UTC
Size:
2.55 KB
patch
obsolete
>From a790b1507ac71eae844fd0a3f933e8ceacd883c8 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 17 Feb 2015 10:10:28 -0500 >Subject: [PATCH] Store list of objects as needed > >http://bugs.koha-community.org/show_bug.cgi?id=13019 >--- > Koha/Objects.pm | 40 +++++++++++++++++++++++----------------- > 1 files changed, 23 insertions(+), 17 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index a364d25..2805035 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -54,6 +54,8 @@ sub new { > my ($class) = @_; > my $self = {}; > >+ $self->{_iterator} = 0; >+ > bless( $self, $class ); > } > >@@ -67,6 +69,8 @@ sub _new_from_dbic { > my ( $class, $resultset ) = @_; > my $self = { _resultset => $resultset }; > >+ $self->{_iterator} = 0; >+ > bless( $self, $class ); > } > >@@ -138,12 +142,7 @@ Returns undef if there are no more objects to return. > sub next { > my ( $self ) = @_; > >- my $result = $self->_resultset()->next(); >- return unless $result; >- >- my $object = $self->object_class()->_new_from_dbic( $result ); >- >- return $object; >+ return $self->_objects()->[ $self->{_iterator}++ ]; > } > > =head3 Koha::Objects->first(); >@@ -157,12 +156,7 @@ Returns the first object that is part of this set. > sub first { > my ( $self ) = @_; > >- my $result = $self->_resultset()->first(); >- return unless $result; >- >- my $object = $self->object_class()->_new_from_dbic( $result ); >- >- return $object; >+ return $self->_objects()->[0]; > } > > =head3 Koha::Objects->reset(); >@@ -177,7 +171,7 @@ with the first object in a set. > sub reset { > my ( $self ) = @_; > >- $self->_resultset()->reset(); >+ $self->{_iterator} = 0; > > return $self; > } >@@ -193,11 +187,23 @@ Returns an arrayref of the objects in this set. > sub as_list { > my ( $self ) = @_; > >- my @dbic_rows = $self->_resultset()->all(); >+ my $objects = $self->_objects(); >+ >+ return wantarray ? @$objects : $objects; >+} >+ >+=head3 Koha::Objects->_objects >+ >+Returns an arrayref of all the objects that are part of this Objects set >+ >+=cut >+ >+sub _objects { >+ my ( $self ) = @_; > >- my @objects = $self->_wrap(@dbic_rows); >+ $self->{_objects} ||= $self->_wrap( $self->_resultset()->all() ); > >- return wantarray ? @objects : \@objects; >+ return $self->{_objects}; > } > > =head3 Koha::Objects->_wrap >@@ -211,7 +217,7 @@ sub _wrap { > > my @objects = map { $self->object_class()->_new_from_dbic( $_ ) } @dbic_rows; > >- return @objects; >+ return wantarray ? @objects : \@objects;; > } > > =head3 Koha::Objects->_resultset >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13019
:
31964
|
32004
|
32007
|
32008
|
32009
|
32042
|
32043
|
32045
|
32056
|
32059
|
32065
|
32068
|
33418
|
33419
|
33420
|
33797
|
33840
|
33841
|
33842
|
33843
|
33844
|
33845
|
33846
|
33847
|
33848
|
33849
|
33850
|
33852
|
35813
|
35814
|
35815
|
35980