[Bio] / Sprout / CustomAttributes.pm Repository:
ViewVC logotype

Diff of /Sprout/CustomAttributes.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21, Sun Feb 18 22:13:53 2007 UTC revision 1.25, Sun May 6 10:16:52 2007 UTC
# Line 344  Line 344 
344                                      -labels => \%labelMap,                                      -labels => \%labelMap,
345                                      -default => 'string');                                      -default => 'string');
346      # Allow the user to specify a new field name. This is required if the      # Allow the user to specify a new field name. This is required if the
347      # user has selected the "(new)" marker. We put a little scriptlet in here that      # user has selected the "(new)" marker.
     # selects the (new) marker when the user enters the field.  
     push @retVal, "<script language=\"javaScript\">";  
348      my $fieldField = "document.$name.fieldName";      my $fieldField = "document.$name.fieldName";
349      my $newName = "\"" . NewName() . "\"";      my $newName = "\"" . NewName() . "\"";
350      push @retVal, $cgi->Tr($cgi->th("New Field Name"),      push @retVal, $cgi->Tr($cgi->th("New Field Name"),
# Line 387  Line 385 
385  =head3 LoadAttributesFrom  =head3 LoadAttributesFrom
386    
387  C<< my $stats = $attrDB->LoadAttributesFrom($fileName, %options); >>  C<< my $stats = $attrDB->LoadAttributesFrom($fileName, %options); >>
388    s
389  Load attributes from the specified tab-delimited file. Each line of the file must  Load attributes from the specified tab-delimited file. Each line of the file must
390  contain an object ID in the first column, an attribute key name in the second  contain an object ID in the first column, an attribute key name in the second
391  column, and attribute values in the remaining columns. The attribute values will  column, and attribute values in the remaining columns. The attribute values will
# Line 488  Line 486 
486                  # An ID without a key is a serious error.                  # An ID without a key is a serious error.
487                  my $lines = $retVal->Ask('linesIn');                  my $lines = $retVal->Ask('linesIn');
488                  Confess("Line $lines in $fileName has no attribute key.");                  Confess("Line $lines in $fileName has no attribute key.");
489                } elsif (! @values) {
490                    # A line with no values is not allowed.
491                    my $lines = $retVal->Ask('linesIn');
492                    Trace("Line $lines for key $key has no attribute values.") if T(1);
493                    $retVal->Add(skipped => 1);
494              } else {              } else {
495                  # The key contains a real part and an optional sub-part. We need the real part.                  # The key contains a real part and an optional sub-part. We need the real part.
496                  my ($realKey, $subKey) = $self->SplitKey($key);                  my ($realKey, $subKey) = $self->SplitKey($key);
# Line 1722  Line 1725 
1725      return sort @groups;      return sort @groups;
1726  }  }
1727    
1728    =head3 QueryAttributes
1729    
1730    C<< my @attributeData = $ca->QueryAttributes($filter, $filterParms); >>
1731    
1732    Return the attribute data based on an SQL filter clause. In the filter clause,
1733    the name C<$object> should be used for the object ID, C<$key> should be used for
1734    the key name, C<$subkey> for the subkey value, and C<$value> for the value field.
1735    
1736    =over 4
1737    
1738    =item filter
1739    
1740    Filter clause in the standard ERDB format, except that the field names are C<$object> for
1741    the object ID field, C<$key> for the key name field, C<$subkey> for the subkey field,
1742    and C<$value> for the value field. This abstraction enables us to hide the details of
1743    the database construction from the user.
1744    
1745    =item filterParms
1746    
1747    Parameters for the filter clause.
1748    
1749    =item RETURN
1750    
1751    Returns a list of tuples. Each tuple consists of an object ID, a key (with optional subkey), and
1752    one or more attribute values.
1753    
1754    =back
1755    
1756    =cut
1757    
1758    # This hash is used to drive the substitution process.
1759    my %AttributeParms = (object => 'HasValueFor(to-link)',
1760                          key    => 'HasValueFor(from-link)',
1761                          subkey => 'HasValueFor(subkey)',
1762                          value  => 'HasValueFor(value)');
1763    
1764    sub QueryAttributes {
1765        # Get the parameters.
1766        my ($self, $filter, $filterParms) = @_;
1767        # Declare the return variable.
1768        my @retVal = ();
1769        # Make sue we have filter parameters.
1770        my $realParms = (defined($filterParms) ? $filterParms : []);
1771        # Create the query by converting the filter.
1772        my $realFilter = $filter;
1773        for my $name (keys %AttributeParms) {
1774            $realFilter =~ s/\$$name/$AttributeParms{$name}/g;
1775        }
1776        my $query = $self->Get(['HasValueFor'], $realFilter, $realParms);
1777        # Loop through the results, forming the output attribute tuples.
1778        while (my $result = $query->Fetch()) {
1779            # Get the four values from this query result row.
1780            my ($objectID, $key, $subkey, $value) = $result->Values([$AttributeParms{object},
1781                                                                    $AttributeParms{key},
1782                                                                    $AttributeParms{subkey},
1783                                                                    $AttributeParms{value}]);
1784            # Combine the key and the subkey.
1785            my $realKey = ($subkey ? $key . $self->{splitter} . $subkey : $key);
1786            # Split the value.
1787            my @values = split $self->{splitter}, $value;
1788            # Output the result.
1789            push @retVal, [$objectID, $realKey, @values];
1790        }
1791        # Return the result.
1792        return @retVal;
1793    }
1794    
1795  =head2 Key and ID Manipulation Methods  =head2 Key and ID Manipulation Methods
1796    
1797  =head3 ParseID  =head3 ParseID
# Line 1840  Line 1910 
1910    
1911  =item RETURN  =item RETURN
1912    
1913  Returns a B<DBObject> for the attribute value's target object.  Returns a B<ERDBObject> for the attribute value's target object.
1914    
1915  =back  =back
1916    

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.25

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3