From b56b3f5f97fc9a721506e54c1c3eb900e6c6dfcc Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 12 Jan 2011 16:05:30 +0100 Subject: [PATCH] linked_records_sorted entfernt und durch Zusatzparameter in linked_records ersetzt --- SL/DB/Helper/LinkedRecords.pm | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/SL/DB/Helper/LinkedRecords.pm b/SL/DB/Helper/LinkedRecords.pm index 1f91718bc..30b08f417 100644 --- a/SL/DB/Helper/LinkedRecords.pm +++ b/SL/DB/Helper/LinkedRecords.pm @@ -4,7 +4,7 @@ use strict; require Exporter; our @ISA = qw(Exporter); -our @EXPORT = qw(linked_records link_to_record linked_records_sorted); +our @EXPORT = qw(linked_records link_to_record); use Carp; use Sort::Naturally; @@ -13,6 +13,18 @@ use SL::DB::Helpers::Mappings; use SL::DB::RecordLink; sub linked_records { + my ($self, %params) = @_; + + my %sort_spec = ( by => delete($params{sort_by}), + dir => delete($params{sort_dir}) ); + + my $records = _linked_records_implementation($self, %params); + $records = sort_linked_records($self, $sort_spec{by}, $sort_spec{dir}, @{ $records }) if $sort_spec{by}; + + return $records; +} + +sub _linked_records_implementation { my $self = shift; my %params = @_; @@ -23,8 +35,8 @@ sub linked_records { my %from_to = ( from => delete($params{from}) || $both, to => delete($params{to}) || $both); - my @records = (@{ $self->linked_records(%params, direction => 'from', from => $from_to{from}) }, - @{ $self->linked_records(%params, direction => 'to', to => $from_to{to} ) }); + my @records = (@{ _linked_records_implementation($self, %params, direction => 'from', from => $from_to{from}) }, + @{ _linked_records_implementation($self, %params, direction => 'to', to => $from_to{to} ) }); my %record_map = map { ( ref($_) . $_->id => $_ ) } @records; @@ -88,12 +100,6 @@ sub link_to_record { return wantarray ? @links : $links[0]; } -sub linked_records_sorted { - my ($self, $sort_by, $sort_dir, %params) = @_; - - return sort_linked_records($self, $sort_by, $sort_dir, $self->linked_records(%params)); -} - sub sort_linked_records { my ($self_or_class, $sort_by, $sort_dir, @records) = @_; @@ -208,6 +214,10 @@ created today: to => 'SL::DB::Invoice', query => [ transdate => DateTime->today_local ]); +The optional parameters C<$params{sort_by}> and C<$params{sort_dir}> +can be used in order to sort the result. If C<$params{sort_by}> is +trueish then the result is sorted by calling L. + Returns an array reference. =item C @@ -259,19 +269,12 @@ Can be called both as a class or as an instance function. This function is not exported. -=item C - -Returns the result of L sorted by -L. C<%params> is passed to -L. C<$sort_by> and C<$sort_dir> are passed to -L. - =back =head1 EXPORTS -This mixin exports the functions L, -L and L. +This mixin exports the functions L and +L. =head1 BUGS -- 2.20.1