Changeset 327 for trunk


Ignore:
Timestamp:
05/02/12 18:19:57 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Rewrite fill_grouplist() sub to not do direct SQL calls. Steal
the algorithm from fill_grouptree and adapt to present an
indented, grouped-by-parent list of groups. See #1.

Tweak getChildren() to sort its results for more consistent behaviours;
may add a flag later to choose the sort field

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r326 r327  
    20032003  my $cur = shift || $curgroup;
    20042004
    2005   my @childgroups;
    2006   getChildren($dbh, $logingroup, \@childgroups, 'all');
    2007   my $childlist = join(',',@childgroups);
    2008 
    2009 ##fixme:  need to reorder list so that we can display a pseudotree in group dropdowns
    2010 
    2011   # weesa gonna discard parent_group_id for now
    2012   my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ".
    2013         "WHERE group_id IN ($logingroup".($childlist ? ",$childlist" : '').")".
    2014         "ORDER BY group_id");
    2015   $sth->execute;
     2005  # little recursive utility sub-sub
     2006  sub getgroupdrop {
     2007    my $root = shift;
     2008    my $cur = shift;    # to tag the selected group
     2009    my $grplist = shift;
     2010    my $indent = shift || '    ';
     2011
     2012    my @childlist;
     2013    getChildren($dbh,$root,\@childlist,'immediate');
     2014    return if $#childlist == -1;
     2015    foreach (@childlist) {
     2016      my %row;
     2017      $row{groupval} = $_;
     2018      $row{groupactive} = ($_ == $cur);
     2019      $row{groupname} = $indent.groupName($dbh, $_);
     2020      push @{$grplist}, \%row;
     2021      getgroupdrop($_, $cur, $grplist, $indent.'    ');
     2022    }
     2023  }
     2024
    20162025  my @grouplist;
    2017   while (my ($groupid,$pargroup,$groupname) = $sth->fetchrow_array()) {
    2018     my %row;
    2019     $row{groupname} = $groupname;
    2020     $row{groupval} = $groupid;
    2021 ##fixme: need magic
    2022 ## ... WTF?
    2023 #    $row{defgroup} = '';
    2024     $row{groupactive} = 1 if $groupid == $cur;
    2025     push @grouplist, \%row;
    2026   }
     2026  push @grouplist, { groupval => $logingroup, groupactive => $logingroup == $curgroup,
     2027        groupname => groupName($dbh, $logingroup) };
     2028  getgroupdrop($logingroup, $curgroup, \@grouplist);
    20272029
    20282030  $page->param("$template_var" => \@grouplist);
    2029 
    20302031} # end fill_grouplist()
    20312032
Note: See TracChangeset for help on using the changeset viewer.