Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b56b3f5f

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID b56b3f5f97fc9a721506e54c1c3eb900e6c6dfcc
  • Vorgänger 3bd03753
  • Nachfolger b3420789

linked_records_sorted entfernt und durch Zusatzparameter in linked_records ersetzt

Unterschiede anzeigen:

SL/DB/Helper/LinkedRecords.pm
4 4

  
5 5
require Exporter;
6 6
our @ISA    = qw(Exporter);
7
our @EXPORT = qw(linked_records link_to_record linked_records_sorted);
7
our @EXPORT = qw(linked_records link_to_record);
8 8

  
9 9
use Carp;
10 10
use Sort::Naturally;
......
13 13
use SL::DB::RecordLink;
14 14

  
15 15
sub linked_records {
16
  my ($self, %params) = @_;
17

  
18
  my %sort_spec       = ( by  => delete($params{sort_by}),
19
                          dir => delete($params{sort_dir}) );
20

  
21
  my $records         = _linked_records_implementation($self, %params);
22
  $records            = sort_linked_records($self, $sort_spec{by}, $sort_spec{dir}, @{ $records }) if $sort_spec{by};
23

  
24
  return $records;
25
}
26

  
27
sub _linked_records_implementation {
16 28
  my $self     = shift;
17 29
  my %params   = @_;
18 30

  
......
23 35
    my %from_to    = ( from => delete($params{from}) || $both,
24 36
                       to   => delete($params{to})   || $both);
25 37

  
26
    my @records    = (@{ $self->linked_records(%params, direction => 'from', from => $from_to{from}) },
27
                      @{ $self->linked_records(%params, direction => 'to',   to   => $from_to{to}  ) });
38
    my @records    = (@{ _linked_records_implementation($self, %params, direction => 'from', from => $from_to{from}) },
39
                      @{ _linked_records_implementation($self, %params, direction => 'to',   to   => $from_to{to}  ) });
28 40

  
29 41
    my %record_map = map { ( ref($_) . $_->id => $_ ) } @records;
30 42

  
......
88 100
  return wantarray ? @links : $links[0];
89 101
}
90 102

  
91
sub linked_records_sorted {
92
  my ($self, $sort_by, $sort_dir, %params) = @_;
93

  
94
  return sort_linked_records($self, $sort_by, $sort_dir, $self->linked_records(%params));
95
}
96

  
97 103
sub sort_linked_records {
98 104
  my ($self_or_class, $sort_by, $sort_dir, @records) = @_;
99 105

  
......
208 214
                                        to        => 'SL::DB::Invoice',
209 215
                                        query     => [ transdate => DateTime->today_local ]);
210 216

  
217
The optional parameters C<$params{sort_by}> and C<$params{sort_dir}>
218
can be used in order to sort the result. If C<$params{sort_by}> is
219
trueish then the result is sorted by calling L</sort_linked_records>.
220

  
211 221
Returns an array reference.
212 222

  
213 223
=item C<link_to_record $record, %params>
......
259 269

  
260 270
This function is not exported.
261 271

  
262
=item C<linked_records_sorted $sort_by, $sort_dir, %params>
263

  
264
Returns the result of L</linked_records> sorted by
265
L</sort_linked_records>. C<%params> is passed to
266
L</linked_records>. C<$sort_by> and C<$sort_dir> are passed to
267
L</sort_linked_records>.
268

  
269 272
=back
270 273

  
271 274
=head1 EXPORTS
272 275

  
273
This mixin exports the functions L</linked_records>,
274
L</link_to_record> and L</linked_records_sorted>.
276
This mixin exports the functions L</linked_records> and
277
L</link_to_record>.
275 278

  
276 279
=head1 BUGS
277 280

  

Auch abrufbar als: Unified diff