Changeset 1791


Ignore:
Timestamp:
06/24/16 12:20:47 (8 years ago)
Author:
nanardon
Message:

Allow recursive masse data fetching

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Root.pm

    r1692 r1791  
    9090 
    9191    $c->stash->{template} = 'login/index.tt'; 
     92    return 0; 
    9293} 
    9394 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Stat.pm

    r1790 r1791  
    9494 
    9595    my $op = $self->_get_attributes('aggregateFunction'); 
    96     if (my $attr = $self->base->attribute($otype, $attribute)) { 
    97         if (my $obj = $attr->reference) { 
    98             if (my @reffilter = $self->_get_attributes('refFilter')) { 
    99                 $reffiltered = {}; 
    100                 foreach ($self->base->search_objects($obj, @reffilter)) { 
    101                     $reffiltered->{$_} = 1; 
    102                 } 
    103             } 
    104         } 
    105         if ($self->_get_attributes('refall') && $attr->has_values_list && !$op) { 
    106             foreach ($attr->can_values) { 
     96 
     97    my ($refOtype, $refAttr) = ($otype, undef); 
     98 
     99    foreach (split(/\./, $attribute)) { 
     100        if (my $attr = $self->base->attribute($refOtype, $_)) { 
     101            if (my $obj = $attr->reference) { 
     102                ($refOtype, $refAttr) = ($obj, $attr); 
     103            } else { 
     104                ($refOtype, $refAttr) = (undef, undef); 
     105            } 
     106        } 
     107    } 
     108 
     109    if ($refAttr && $refOtype) { 
     110        if (my @reffilter = $self->_get_attributes('refFilter')) { 
     111            $reffiltered = {}; 
     112            foreach ($self->base->search_objects($refOtype, @reffilter)) { 
     113                $reffiltered->{$_} = 1; 
     114            } 
     115        } 
     116        if ($self->_get_attributes('refall') && $refAttr->has_values_list && !$op) { 
     117            foreach ($refAttr->can_values) { 
    107118                if ($reffiltered && !$reffiltered->{$_}) { 
    108119                    next; 
     
    136147                next; 
    137148            } 
    138             $_ ||= '(none)'; 
     149            defined($_) && $_ ne '' or $_ = '(none)'; 
    139150            if ($op) { 
    140151                push(@{$aggdata{$id}}, $_); 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1788 r1791  
    639639 
    640640sub attributes_summary { 
    641     my ($class, $base, $attribute) = @_; 
     641    my ($class, $base, $dotAttribute) = @_; 
     642 
     643    my ($attribute, $recursiveAttr) = $dotAttribute =~ /(\w+)(?:\.(.*))?/; 
     644     
    642645    my $attr = $base->attribute($class->type, $attribute) or do { 
    643646        $base->log(LA_ERR, "Cannot instantiate %s attribute", $attribute); 
     
    676679 
    677680    my %values; 
    678     while (my $res = $sth->fetchrow_hashref) { 
    679         $values{$res->{value}} = 1 if ($res->{value}); 
     681    if ($recursiveAttr) { 
     682        my $otype = $attr->reference or do { 
     683            $base->log(LA_ERR, "Cannot do recursive search, no ref for attribute %s", $attribute); 
     684            return; 
     685        }; 
     686        my %parentRes = $base->attributes_summary_by_object($otype, $recursiveAttr) or return; 
     687 
     688        while (my $res = $sth->fetchrow_hashref) { 
     689            defined($res->{value}) or next; 
     690            $values{ $parentRes{ $res->{value} } } = 1; 
     691        } 
     692    } else { 
     693        while (my $res = $sth->fetchrow_hashref) { 
     694            $values{$res->{value}} = 1 if ($res->{value}); 
     695        } 
    680696    } 
    681697    sort keys %values 
     
    689705 
    690706sub attributes_summary_by_object { 
    691     my ($class, $base, $attribute) = @_; 
     707    my ($class, $base, $dotAttribute) = @_; 
     708 
     709    my ($attribute, $recursiveAttr) = $dotAttribute =~ /(\w+)(?:\.(.*))?/; 
     710 
    692711    my $attr = $base->attribute($class->type, $attribute) or do { 
    693712        $base->log(LA_ERR, "Cannot instantiate %s attribute", $attribute); 
     
    702721        return; 
    703722    } 
     723 
    704724    if ($attr->{managed}) { 
    705725        return $class->SUPER::attributes_summary_by_object($base, $attribute); 
     
    726746 
    727747    my %values; 
    728     while (my $res = $sth->fetchrow_hashref) { 
    729         defined($res->{value}) or next; 
    730         push(@{ $values{ $res->{name} } }, $res->{value}); 
     748    if ($recursiveAttr) { 
     749        my $otype = $attr->reference or do { 
     750            $base->log(LA_ERR, "Cannot do recursive search, no ref for attribute %s", $attribute); 
     751            return; 
     752        }; 
     753        my %parentRes = $base->attributes_summary_by_object($otype, $recursiveAttr) or return; 
     754 
     755        while (my $res = $sth->fetchrow_hashref) { 
     756            defined($res->{value}) or next; 
     757            push(@{ $values{ $res->{name} } }, @{ $parentRes{ $res->{value} } || []}); 
     758        } 
     759    } else { 
     760        while (my $res = $sth->fetchrow_hashref) { 
     761            defined($res->{value}) or next; 
     762            push(@{ $values{ $res->{name} } }, $res->{value}); 
     763        } 
    731764    } 
    732765    %values 
Note: See TracChangeset for help on using the changeset viewer.