[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.6, Fri Nov 10 21:59:34 2006 UTC revision 1.7, Wed Nov 15 12:04:05 2006 UTC
# Line 506  Line 506 
506                                                      -default => 1)                                                      -default => 1)
507                                     ),                                     ),
508                            );                            );
509      # Now the two buttons: UPDATE and DELETE.      # Now the three buttons: UPDATE, SHOW, and DELETE.
510      push @retVal, $cgi->Tr($cgi->th(" "),      push @retVal, $cgi->Tr($cgi->th(" "),
511                             $cgi->td({align => 'center'},                             $cgi->td({align => 'center'},
512                                      $cgi->submit(-name => 'Delete', -value => 'DELETE') . " " .                                      $cgi->submit(-name => 'Delete', -value => 'DELETE') . " " .
513                                      $cgi->submit(-name => 'Store',  -value => 'STORE')                                      $cgi->submit(-name => 'Store',  -value => 'STORE') . " " .
514                                        $cgi->submit(-name => 'Show',   -value => 'SHOW')
515                                     )                                     )
516                            );                            );
517      # Close the table and the form.      # Close the table and the form.
# Line 854  Line 855 
855                  # Get the key, value, and URL. We ignore the first element because that's the                  # Get the key, value, and URL. We ignore the first element because that's the
856                  # object ID, and we already know the object ID.                  # object ID, and we already know the object ID.
857                  my (undef, $key, $value, $url) = @{$dataTuple};                  my (undef, $key, $value, $url) = @{$dataTuple};
858                    # Remove the buggy "1" for $url.
859                    if ($url eq "1") {
860                        $url = undef;
861                    }
862                  # Only proceed if this is not an old key.                  # Only proceed if this is not an old key.
863                  if (! $myOldKeys->{$key}) {                  if (! $myOldKeys->{$key}) {
864                      # See if we've run into this key before.                      # See if we've run into this key before.
# Line 1110  Line 1115 
1115          # MatchSqlPattern method          # MatchSqlPattern method
1116          my %secondaries = $self->GetSecondaryFields($entityType);          my %secondaries = $self->GetSecondaryFields($entityType);
1117          my @fieldList = grep { MatchSqlPattern($_, $key) } keys %secondaries;          my @fieldList = grep { MatchSqlPattern($_, $key) } keys %secondaries;
1118          # Now we figure out whether or not we need to filter by object.          # Now we figure out whether or not we need to filter by object. We will always
1119            # filter by key to a limited extent, so if we're filtering by object we need an
1120            # AND to join the object ID filter with the key filter.
1121          my $filter = "";          my $filter = "";
1122          my @params = ();          my @params = ();
1123          if (defined($actualObjectID)) {          if (defined($actualObjectID)) {
1124              # Here the caller wants to filter on object ID.              # Here the caller wants to filter on object ID.
1125              $filter = "$entityType(id) = ?";              $filter = "$entityType(id) = ? AND ";
1126              push @params, $actualObjectID;              push @params, $actualObjectID;
1127          }          }
1128          # It's time to begin making queries. We process one attribute key at a time, because          # It's time to begin making queries. We process one attribute key at a time, because
# Line 1124  Line 1131 
1131          # the DBD. That's a good thing, because an invalid key name will cause an SQL error.          # the DBD. That's a good thing, because an invalid key name will cause an SQL error.
1132          for my $key (@fieldList) {          for my $key (@fieldList) {
1133              # Get all of the attribute values for this key.              # Get all of the attribute values for this key.
1134              my @dataRows = $self->GetAll([$entityType], $filter, \@params,              my @dataRows = $self->GetAll([$entityType], "$filter$entityType($key) IS NOT NULL",
1135                                           ["$entityType(id)", "$entityType($key)"]);                                           \@params, ["$entityType(id)", "$entityType($key)"]);
1136              # Process each value separately. We need to verify the values and reformat the              # Process each value separately. We need to verify the values and reformat the
1137              # tuples. Note that GetAll will give us one row per matching object ID,              # tuples. Note that GetAll will give us one row per matching object ID,
1138              # with the ID first followed by a list of the data values. This is very              # with the ID first followed by a list of the data values. This is very
# Line 1321  Line 1328 
1328      return 1;      return 1;
1329  }  }
1330    
1331    =head3 EraseAttribute
1332    
1333    C<< $attrDB->EraseAttribute($entityName, $key); >>
1334    
1335    Erase all values for the specified attribute key. This does not remove the
1336    key from the database; it merely removes all the values.
1337    
1338    =over 4
1339    
1340    =item entityName
1341    
1342    Name of the entity to which the key belongs. If undefined, all entities will be
1343    examined for the desired key.
1344    
1345    =item key
1346    
1347    Key to erase.
1348    
1349    =back
1350    
1351    =cut
1352    
1353    sub EraseAttribute {
1354        # Get the parameters.
1355        my ($self, $entityName, $key) = @_;
1356        # Determine the relevant entity types.
1357        my @objects = ();
1358        if (! $entityName) {
1359            push @objects, $self->GetEntityTypes();
1360        } else {
1361            push @objects, $entityName;
1362        }
1363        # Loop through the entity types.
1364        for my $entityType (@objects) {
1365            # Now check for this key in this entity.
1366            my %secondaries = $self->GetSecondaryFields($entityType);
1367            if (exists $secondaries{$key}) {
1368                # We found it, so delete all the values of the key.
1369                $self->DeleteValue($entityName, undef, $key);
1370            }
1371        }
1372        # Return a 1, for backward compatability.
1373        return 1;
1374    }
1375    
1376  1;  1;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3