Принадлежность к рубрикам (разделам) сайта1
% my @sections = $document->sections(); % my $document_sections = @sections ? $keeper->get_sections ( id => \@sections, return_mode => 'hash_ref' ) : {}; % my $sections_ = {}; % $sections_->{$section_tree->{root}->id} = 1 if exists $section_tree->{root}; % for my $secti (@sections) { % $sections_->{ $secti } = 1; % my $sect = exists $document_sections->{$secti} ? $document_sections->{$secti} : undef; % next unless ref $sect; % while ( $sect->pid != 1 && (exists $section_tree->{$sect->pid} && (exists $section_tree->{root} && $section_tree->{$sect->pid} != $section_tree->{root}) || ( !exists $section_tree->{root} && $section_tree->{$sect->pid} != $section_tree->{0} ) ) ) { % $sections_->{ $sect->pid } = 1; % $sect = $section_tree->{$sect->pid}; % } % } % my @fullsections = keys(%{ $sections_ });
    % tree( $section_tree->{root}, $section_tree, \@fullsections, \@sections, 0 );
Примечания
1) Символом checkbox показаны привязки к рубрикам (может быть несколько рубрик);
1) Символом radio buttom показана главная (не обязательно корневая) рубрика.
<%ARGS> $document => undef <%INIT> return undef if (! ref($document)); return undef unless ($document->{attributes}->{sections}); my $root_section = $keeper->get_section_by_id( $Contenido::Section::ROOT || 1, light => 1 ); my $section_tree = exists $request->{section_tree} ? $request->{section_tree} : $keeper->get_section_tree(); $request->{section_tree} ||= $section_tree; sub tree { my ($sect, $section_tree, $fullsections, $sections, $depth) = @_; my $count_checked = 0; my @childs; if (ref $sect && $sect->id) { @childs = ref $section_tree && exists $section_tree->{$sect->id} ? @{ $section_tree->{$sect->id}{children} } : (); my $checked = (grep {$_ == $sect->id } @{ $sections }) ? ' checked' : ''; my $main = ($sect->id == $sections->[0]) ? ' checked' : ''; $count_checked++ if( grep {$_ == $sect->{id} } @{ $fullsections } ); if( @childs && $sect->id != 1) { $m->out("{id}');\">{id}\" src=\"/contenido/i/open11x11.gif\" width=\"11\" height=\"11\" border=\"0\">"); } else { $m->out( '' ); } $m->out("{id}\" value=\"1\" $checked>{id}\"$main>"); $m->out("$sect->{name}
\n"); } if (@childs) { my $check_childs = undef; if( $depth > 0 ) { $m->out( ''."\n" ); } if( $check_childs > 0 && $sect->id != 1) { $m->out( "\n" ); } } return $count_checked; }