1 |
8 |
ahitrov@rambler.ru |
%# vim:syn=mason |
2 |
|
|
<%args> |
3 |
|
|
$object |
4 |
|
|
$name => undef |
5 |
|
|
$SETS => undef |
6 |
|
|
</%args> |
7 |
|
|
<%init> |
8 |
|
|
return undef unless ref $SETS; |
9 |
|
|
return undef unless $name; |
10 |
|
|
|
11 |
|
|
# Если оно хранится в поле типа integer[] то нам вернется массив, если в data, то ссылка на массив. |
12 |
|
|
# Просекаем фишку |
13 |
|
|
|
14 |
|
|
my %ids; |
15 |
|
|
while (my ($k, $v) = each(%$SETS)) { |
16 |
|
|
next unless $v; |
17 |
|
|
if ( $k =~ /^${name}_(\d+)_(delete|id)/ ) { |
18 |
|
|
my $id = $1; |
19 |
|
|
my $key = $2; |
20 |
|
|
if ( ref $v eq 'ARRAY' ) { |
21 |
|
|
map { $ids{$_}{$key} => $_ } @$v; |
22 |
|
|
} else { |
23 |
|
|
$ids{$id}{$key} = $id; |
24 |
|
|
} |
25 |
|
|
} elsif ( $k =~ /^${name}_(addanotheritem)/ ) { |
26 |
|
|
if ( ref $v eq 'ARRAY' ) { |
27 |
|
|
map { $ids{$_}{id} => $_ } @$v; |
28 |
|
|
} else { |
29 |
|
|
$ids{$v}{id} = $v; |
30 |
|
|
} |
31 |
|
|
} |
32 |
|
|
} |
33 |
225 |
ahitrov |
warn "\n\nPickup form ($name)".Dumper(\%ids)."\n" if $DEBUG; |
34 |
8 |
ahitrov@rambler.ru |
my @ids = map { $_->{id} } grep { !exists $_->{delete} } values %ids; |
35 |
225 |
ahitrov |
warn "What to leave ($name)".Dumper(\@ids)."\n\n" if $DEBUG; |
36 |
8 |
ahitrov@rambler.ru |
|
37 |
|
|
return \@ids; |
38 |
|
|
|
39 |
|
|
</%init> |