Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b3420789

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID b3420789a7e752f170fb7f433f468a34140028ee
  • Vorgänger b56b3f5f
  • Nachfolger eb0d6c3a

linked_records: Parameter 'filter' für Filtern nach "darf von aktueller Benutzerin gesehen werden"

Unterschiede anzeigen:

SL/DB/Helper/LinkedRecords.pm
17 17

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

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

  
24 26
  return $records;
25 27
}
26 28

  
27
sub _linked_records_implementation {
29
sub linked_records_implementation {
28 30
  my $self     = shift;
29 31
  my %params   = @_;
30 32

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

  
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}  ) });
40
    my @records    = (@{ linked_records_implementation($self, %params, direction => 'from', from => $from_to{from}) },
41
                      @{ linked_records_implementation($self, %params, direction => 'to',   to   => $from_to{to}  ) });
40 42

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

  
......
171 173
  return [ sort($comparator @records) ];
172 174
}
173 175

  
176
sub filter_linked_records {
177
  my ($self_or_class, $filter, @records) = @_;
178

  
179
  if ($filter eq 'accessible') {
180
    my $employee = SL::DB::Manager::Employee->current;
181
    @records     = grep { !$_->can('may_be_accessed') || $_->may_be_accessed($employee) } @records;
182
  } else {
183
    croak "Unsupported filter parameter '${filter}'";
184
  }
185

  
186
  return \@records;
187
}
188

  
174 189
1;
175 190

  
176 191
__END__
......
218 233
can be used in order to sort the result. If C<$params{sort_by}> is
219 234
trueish then the result is sorted by calling L</sort_linked_records>.
220 235

  
236
The optional parameter C<$params{filter}> controls whether or not the
237
result is filtered. Supported values are:
238

  
239
=over 2
240

  
241
=item C<accessible>
242

  
243
Removes all objects for which the function C<may_be_accessed> from the
244
mixin L<SL::DB::Helper::MayBeAccessed> exists and returns falsish for
245
the current employee.
246

  
247
=back
248

  
221 249
Returns an array reference.
222 250

  
223 251
=item C<link_to_record $record, %params>

Auch abrufbar als: Unified diff