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

Diff of /Sprout/ERDB.pm

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

revision 1.81, Wed Dec 20 20:03:25 2006 UTC revision 1.84, Wed Jan 24 10:22:22 2007 UTC
# Line 548  Line 548 
548          if (my $notes = $entityData->{Notes}) {          if (my $notes = $entityData->{Notes}) {
549              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";              $retVal .= "<p>" . HTMLNote($notes->{content}) . "</p>\n";
550          }          }
551          # Now we want a list of the entity's relationships. First, we set up the relationship subsection.          # See if we need a list of the entity's relationships.
552            my $relCount = keys %{$relationshipList};
553            if ($relCount > 0) {
554                # First, we set up the relationship subsection.
555          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";          $retVal .= "<h4>Relationships for <b>$key</b></h4>\n<ul>\n";
556          # Loop through the relationships.          # Loop through the relationships.
557          for my $relationship (sort keys %{$relationshipList}) {          for my $relationship (sort keys %{$relationshipList}) {
# Line 564  Line 567 
567          }          }
568          # Close off the relationship list.          # Close off the relationship list.
569          $retVal .= "</ul>\n";          $retVal .= "</ul>\n";
570            }
571          # Get the entity's relations.          # Get the entity's relations.
572          my $relationList = $entityData->{Relations};          my $relationList = $entityData->{Relations};
573          # Create a header for the relation subsection.          # Create a header for the relation subsection.
# Line 1841  Line 1845 
1845          for my $dir ('from', 'to') {          for my $dir ('from', 'to') {
1846              if ($structure->{$dir} eq $originEntityName) {              if ($structure->{$dir} eq $originEntityName) {
1847                  # Delete all relationship instances on this side of the entity instance.                  # Delete all relationship instances on this side of the entity instance.
1848                    Trace("Disconnecting in $dir direction with ID \"$originEntityID\".");
1849                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);                  $dbh->SQL("DELETE FROM $relationshipName WHERE ${dir}_link = ?", 0, $originEntityID);
1850                  $found = 1;                  $found = 1;
1851              }              }
# Line 2587  Line 2592 
2592              # primary relations are allowed that privilege.              # primary relations are allowed that privilege.
2593              Trace("Checking for full-text index on $relationName.") if T(2);              Trace("Checking for full-text index on $relationName.") if T(2);
2594              if ($self->_IsPrimary($relationName)) {              if ($self->_IsPrimary($relationName)) {
2595                  # Get the relation's entity/relationship structure.                  $self->CreateSearchIndex($relationName);
                 my $structure = $self->_GetStructure($relationName);  
                 Trace("Checking for search fields in $relationName.") if T(3);  
                 # Check for a searchable fields list.  
                 if (exists $structure->{searchFields}) {  
                     # Here we know that we need to create a full-text search index.  
                     # Get an SQL-formatted field name list.  
                     my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));  
                     # Create the index.  
                     $dbh->create_index(tbl => $relationName, idx => "search_idx",  
                                        flds => $fields, kind => 'fulltext');  
                     Trace("Index created for $fields in $relationName.") if T(2);  
                 }  
2596              }              }
2597          }          }
2598      }      }
# Line 2611  Line 2604 
2604      return $retVal;      return $retVal;
2605  }  }
2606    
2607    =head3 CreateSearchIndex
2608    
2609    C<< $erdb->CreateSearchIndex($objectName); >>
2610    
2611    Check for a full-text search index on the specified entity or relationship object, and
2612    if one is required, rebuild it.
2613    
2614    =over 4
2615    
2616    =item objectName
2617    
2618    Name of the entity or relationship to be indexed.
2619    
2620    =back
2621    
2622    =cut
2623    
2624    sub CreateSearchIndex {
2625        # Get the parameters.
2626        my ($self, $objectName) = @_;
2627        # Get the relation's entity/relationship structure.
2628        my $structure = $self->_GetStructure($objectName);
2629        # Get the database handle.
2630        my $dbh = $self->{_dbh};
2631        Trace("Checking for search fields in $objectName.") if T(3);
2632        # Check for a searchable fields list.
2633        if (exists $structure->{searchFields}) {
2634            # Here we know that we need to create a full-text search index.
2635            # Get an SQL-formatted field name list.
2636            my $fields = join(", ", _FixNames(@{$structure->{searchFields}}));
2637            # Create the index. If it already exists, it will be dropped.
2638            $dbh->create_index(tbl => $objectName, idx => "search_idx",
2639                               flds => $fields, kind => 'fulltext');
2640            Trace("Index created for $fields in $objectName.") if T(2);
2641        }
2642    }
2643    
2644  =head3 DropRelation  =head3 DropRelation
2645    
2646  C<< $erdb->DropRelation($relationName); >>  C<< $erdb->DropRelation($relationName); >>
# Line 3297  Line 3327 
3327      # Substitute the bulletin board codes.      # Substitute the bulletin board codes.
3328      $retVal =~ s!\[(/?[bi])\]!<$1>!g;      $retVal =~ s!\[(/?[bi])\]!<$1>!g;
3329      $retVal =~ s!\[p\]!</p><p>!g;      $retVal =~ s!\[p\]!</p><p>!g;
3330        $retVal =~ s!\[link\s+([^\]]+)\]!<a href="$1">!g;
3331        $retVal =~ s!\[/link\]!</a>!g;
3332      # Return the result.      # Return the result.
3333      return $retVal;      return $retVal;
3334  }  }
# Line 4241  Line 4273 
4273          _FixupFields($relationshipStructure, $relationshipName, 2, 3);          _FixupFields($relationshipStructure, $relationshipName, 2, 3);
4274          # Format a description for the FROM field.          # Format a description for the FROM field.
4275          my $fromEntity = $relationshipStructure->{from};          my $fromEntity = $relationshipStructure->{from};
4276          my $fromComment = "<b>id</b> of the source <b><a href=\"#$fromEntity\">$fromEntity</a></b>.";          my $fromComment = "[b]id[/b] of the source [b][link #$fromEntity]$fromEntity\[/link][/b].";
4277          # Get the FROM entity's key type.          # Get the FROM entity's key type.
4278          my $fromType = $entityList->{$fromEntity}->{keyType};          my $fromType = $entityList->{$fromEntity}->{keyType};
4279          # Add the FROM field.          # Add the FROM field.
# Line 4251  Line 4283 
4283                                                      PrettySort => 1});                                                      PrettySort => 1});
4284          # Format a description for the TO field.          # Format a description for the TO field.
4285          my $toEntity = $relationshipStructure->{to};          my $toEntity = $relationshipStructure->{to};
4286          my $toComment = "<b>id</b> of the target <b><a href=\"#$toEntity\">$toEntity</a></b>.";          my $toComment = "[b]id[/b] of the target [b][link #$toEntity]$toEntity\[/link][/b].";
4287          # Get the TO entity's key type.          # Get the TO entity's key type.
4288          my $toType = $entityList->{$toEntity}->{keyType};          my $toType = $entityList->{$toEntity}->{keyType};
4289          # Add the TO field.          # Add the TO field.
# Line 4954  Line 4986 
4986      # Compute the number of columns.      # Compute the number of columns.
4987      my $colCount = @colNames;      my $colCount = @colNames;
4988      # Generate the title row.      # Generate the title row.
4989      my $htmlString = "<p><table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";      my $htmlString = "<table border=\"2\"><tr><td colspan=\"$colCount\" align=\"center\">$tablename</td></tr>\n";
4990      # Loop through the columns, adding the column header rows.      # Loop through the columns, adding the column header rows.
4991      $htmlString .= "<tr>";      $htmlString .= "<tr>";
4992      for my $colName (@colNames) {      for my $colName (@colNames) {
# Line 4973  Line 5005 
5005  =cut  =cut
5006    
5007  sub _CloseTable {  sub _CloseTable {
5008      return "</table></p>\n";      return "</table>\n";
5009  }  }
5010    
5011  =head3 _ShowField  =head3 _ShowField

Legend:
Removed from v.1.81  
changed lines
  Added in v.1.84

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3