cvsuser     05/01/07 05:36:56

  Modified:    App-Repository/lib/App Repository.pm
  Log:
  get_hash_of_hashes_by_key(), get_hash_of_values_by_key()
  
  Revision  Changes    Path
  1.18      +105 -27   p5ee/App-Repository/lib/App/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository.pm,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Repository.pm     1 Dec 2004 20:19:49 -0000       1.17
  +++ Repository.pm     7 Jan 2005 13:36:56 -0000       1.18
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.17 2004/12/01 20:19:49 spadkins Exp $
  +## $Id: Repository.pm,v 1.18 2005/01/07 13:36:56 spadkins Exp $
   #############################################################################
   
   package App::Repository;
  @@ -853,9 +853,9 @@
       my ($self, $table, $params, $cols, $options) = @_;
       $cols = [] if (!$cols);
       my $row = $self->get_row($table, $params, $cols, $options);
  -    my $hash = {};
  -    my ($col, $value);
  +    my ($hash, $col, $value);
       if ($row && $#$row > -1) {
  +        $hash = {};
           for (my $idx = 0; $idx <= $#$cols; $idx++) {
               $col = $cols->[$idx];
               $value = $row->[$idx];
  @@ -957,33 +957,35 @@
       else {
           $object = $self->get_hash($table, $params, $cols, $options);
       }
  -    $object->{_repository} = $self;
  -    $object->{_table} = $table;
  -    bless $object, $class;
  -    if (!ref($params)) {
  -        $object->{_key} = $params;
  -    }
  -    else {
  -        my $primary_key = $tabledef->{primary_key};
  -        $primary_key = [$primary_key] if (ref($primary_key) eq "");
  -        my ($key);
  -        if ($primary_key) {
  -            $key = undef;
  -            foreach my $column (@$primary_key) {
  -                if (defined $object->{$column}) {
  -                    if (defined $key) {
  -                        $key .= "," . $object->{$column};
  +    if ($object) {
  +        $object->{_repository} = $self;
  +        $object->{_table} = $table;
  +        bless $object, $class;
  +        if (!ref($params)) {
  +            $object->{_key} = $params;
  +        }
  +        else {
  +            my $primary_key = $tabledef->{primary_key};
  +            $primary_key = [$primary_key] if (ref($primary_key) eq "");
  +            my ($key);
  +            if ($primary_key) {
  +                $key = undef;
  +                foreach my $column (@$primary_key) {
  +                    if (defined $object->{$column}) {
  +                        if (defined $key) {
  +                            $key .= "," . $object->{$column};
  +                        }
  +                        else {
  +                            $key = $object->{$column};
  +                        }
                       }
                       else {
  -                        $key = $object->{$column};
  +                        $key = undef;
  +                        last;
                       }
                   }
  -                else {
  -                    $key = undef;
  -                    last;
  -                }
  +                $object->{_key} = $key if (defined $key);
               }
  -            $object->{_key} = $key if (defined $key);
           }
       }
       &App::sub_exit($object) if ($App::trace);
  @@ -1056,6 +1058,82 @@
   }
   
   #############################################################################
  +# get_hash_of_values_by_key()
  +#############################################################################
  +
  +=head2 get_hash_of_values_by_key()
  +
  +    * Signature: $hashes = $rep->get_hash_of_values_by_key ($table, $params, 
$valuecol, $keycol, $options);
  +    * Param:     $table        string
  +    * Param:     $params       undef,HASH
  +    * Param:     $valuecol     string
  +    * Param:     $keycol       string
  +    * Param:     $options      undef,HASH
  +    * Return:    $hash         HASH
  +    * Throws:    App::Exception::Repository
  +    * Since:     0.50
  +
  +    Sample Usage:
  +
  +    $hash = $rep->get_hash_of_values_by_key ($table, \%params, $valuecol, 
$keycol, \%options);
  +
  +tbd.
  +
  +=cut
  +
  +sub get_hash_of_values_by_key {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $table, $params, $valuecol, $keycol, $options) = @_;
  +    my $rows = $self->get_rows($table, $params, [$keycol, $valuecol], 
$options);
  +    my $hash = {};
  +    if ($rows && $#$rows > -1) {
  +        foreach my $row (@$rows) {
  +            $hash->{$row->[0]} = $row->[1];
  +        }
  +    }
  +    &App::sub_exit($hash) if ($App::trace);
  +    return($hash);
  +}
  +
  +#############################################################################
  +# get_hash_of_hashes_by_key()
  +#############################################################################
  +
  +=head2 get_hash_of_hashes_by_key()
  +
  +    * Signature: $hashes = $rep->get_hash_of_hashes_by_key ($table, $params, 
$cols, $keycol, $options);
  +    * Param:     $table        string
  +    * Param:     $params       undef,HASH
  +    * Param:     $cols         ARRAY
  +    * Param:     $keycol       string
  +    * Param:     $options      undef,HASH
  +    * Return:    $hash         HASH
  +    * Throws:    App::Exception::Repository
  +    * Since:     0.50
  +
  +    Sample Usage:
  +
  +    $hash = $rep->get_hash_of_hashes_by_key ($table, \%params, $cols, 
$keycol, \%options);
  +
  +tbd.
  +
  +=cut
  +
  +sub get_hash_of_hashes_by_key {
  +    &App::sub_entry if ($App::trace);
  +    my ($self, $table, $params, $cols, $keycol, $options) = @_;
  +    my $hashes = $self->get_hashes($table, $params, $cols, $options);
  +    my $hash_of_hashes = {};
  +    if ($hashes && $#$hashes > -1) {
  +        foreach my $hash (@$hashes) {
  +            $hash_of_hashes->{$hash->{$keycol}} = $hash;
  +        }
  +    }
  +    &App::sub_exit($hash_of_hashes) if ($App::trace);
  +    return($hash_of_hashes);
  +}
  +
  +#############################################################################
   # set_hash()
   #############################################################################
   
  @@ -2342,7 +2420,7 @@
           $table_def->{name} = $table;
           if (! $table_def->{label}) {
               $label = $table;
  -            if ($self->{autolabel}) {
  +            if ($self->{auto_label}) {
                   $label = lc($label);
                   $label =~ s/^([a-z])/uc($1)/e;
                   $label =~ s/(_[a-z])/uc($1)/eg;
  @@ -2499,7 +2577,7 @@
           $column_def->{name} = $column;
           if (! $column_def->{label}) {
               $label = $column;
  -            if ($self->{autolabel}) {
  +            if ($self->{auto_label}) {
                   $label = lc($label);
                   $label =~ s/^([a-z])/uc($1)/e;
                   $label =~ s/(_[a-z])/uc($1)/eg;
  
  
  

Reply via email to