Changeset 12958


Ignore:
Timestamp:
2006-09-29T17:21:09+12:00 (18 years ago)
Author:
mdewsnip
Message:

Place references are now separate document objects, so they can be searched from the bibliography search page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cic-hcap/perllib/plugins/CICPlug.pm

    r12942 r12958  
    289289my %designer_name_to_id_mapping;
    290290my %designer_name_to_place_ids_mapping;
     291my $place_reference_id = 1;
    291292
    292293
     
    781782    my $place_references = $place_references_sql_handle->fetchrow();
    782783    if (defined($place_references)) {
    783         $self->add_place_references_metadata($place_doc_obj, $place_id, $place_references);
     784        $self->process_place_references($place_doc_obj, $place_id, $place_name, $place_institution, $place_references);
    784785    }
    785786
     
    869870
    870871
    871 sub process_designers
     872sub process_place_references
    872873{
    873874    my $self = shift(@_);
    874     my $dbh = shift(@_);
    875     my $fail_log_handle = $self->{'failhandle'};
    876 
    877     # Prepare SQL statement for getting the Place name
    878     my $place_name_sql_statement = "SELECT Current_name FROM tblPlace WHERE Entry_ID=?";
    879     my $place_name_sql_handle = $dbh->prepare($place_name_sql_statement);
    880 
    881     # Prepare SQL statement for getting the Place institution
    882     my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
    883     my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
    884 
    885     # Prepare SQL statement for getting the Place "date of construction"
    886     my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
    887     my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
    888 
    889     # Prepare SQL statement for getting the Place non-PDF images
    890     my $place_images_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND Location NOT LIKE '%.pdf' AND Entry_ID=? ORDER BY Image_Order";
    891     my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
    892     $place_images_sql_handle->{LongReadLen} = 65536;
    893 
    894     # Create a document object for each designer
    895     my %designer_id_to_name_mapping;
    896     foreach my $designer_name (keys %designer_name_to_id_mapping) {
    897     my $designer_id = $designer_name_to_id_mapping{$designer_name};
    898     # print STDERR "       Designer $designer_id\n";
    899     my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
    900     $designer_doc_obj->set_OID("d$designer_id");
    901     &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
    902 
    903     &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
    904 
    905     # Get designer places
    906     my $designer_places_list_html = "";
    907     my $last_designer_place_id = "";
    908         foreach my $designer_place_id (sort(@{$designer_name_to_place_ids_mapping{$designer_name}})) {
    909         # The designer may have worked on a place multiple times, so check for this
    910         next if ($designer_place_id eq $last_designer_place_id);
    911         $last_designer_place_id = $designer_place_id;
    912 
    913         # Get place name
    914         $place_name_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
    915         my $designer_place_name = $place_name_sql_handle->fetchrow();
    916 
    917         # Get place institution name
    918         $place_institution_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
    919         my $designer_place_institution_name = $place_institution_sql_handle->fetchrow();
    920 
    921         # Get place date of construction
    922         $place_construction_date_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
    923         my $designer_place_construction_date_value = $place_construction_date_sql_handle->fetchrow() || "";
    924 
    925         # Get the first non-PDF image for this place
    926         my $designer_place_image_small_file_href;
    927             $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
    928         my $designer_place_image_location = $place_images_sql_handle->fetchrow();
    929         if (defined($designer_place_image_location)) {
    930         $designer_place_image_small_file_href = $self->generate_place_image_variant($designer_doc_obj, $designer_place_image_location, "small");
    931         }
    932         else {
    933         # There is no non-PDF image for this place
    934         $designer_place_image_small_file_href = "_httpcollection_/images/no_image-small.jpg";
    935         }
    936 
    937         $designer_places_list_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><img src=\"$designer_place_image_small_file_href\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\">$designer_place_name</a>, $designer_place_institution_name<br /><b>Date of construction:</b> $designer_place_construction_date_value</td></tr>\n";
    938     }
    939 
    940     &new_metadata_entry($designer_doc_obj, "DesignerPlacesListHTML", "<table>" . $designer_places_list_html . "</table>");
    941 
    942     $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
    943     $self->{'processor'}->process($designer_doc_obj);
    944     $self->{'num_processed'}++;
    945 
    946     $designer_id_to_name_mapping{$designer_doc_obj->get_OID()} = $designer_name;
    947     }
    948 
    949     # Write the designers.dm macrofile
    950     &write_static_browser_macrofile("designers", \%designer_id_to_name_mapping);
    951 }
    952 
    953 
    954 sub new_metadata_entry
    955 {
    956     my ($doc_obj, $metadata_name, $metadata_value) = (@_);
    957 
    958     # Don't bother with empty metadata
    959     return if ($metadata_value eq "");
    960 
    961     # Spaces aren't allowed in metadata names
    962     $metadata_name =~ s/ /_/g;
    963 
    964     # Anything from the database is ISO 8859-1 encoded, so convert to UTF-8
    965     $metadata_value = &unicode::ascii2utf8(\$metadata_value);
    966 
    967     # Escape any '&' characters so the metadata is HTML 4 compliant when displayed
    968     $metadata_value =~ s/&([^\#])/&amp;$1/g;
    969 
    970     $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
    971 }
    972 
    973 
    974 sub add_place_references_metadata
    975 {
    976     my $self = shift(@_);
    977     my ($place_doc_obj, $place_id, $place_references_rtf_string) = (@_);
     875    my $place_doc_obj = shift(@_);
     876    my $place_id = shift(@_);
     877    my $place_name = shift(@_);
     878    my $place_institution_name = shift(@_);
     879    my $place_references_rtf_string = shift(@_);
    978880    my $fail_log_handle = $self->{'failhandle'};
    979881
     
    995897    $place_reference =~ s/(<br \/>\s*)*$//;
    996898    next if ($place_reference !~ /\w/);
    997     &new_metadata_entry($place_doc_obj, "Reference", $place_reference);
    998899    $place_references_html .= "<p class=\"cicreference\">" . $place_reference . "</p>\n";
     900
     901    my $place_reference_author = "";
     902    my $place_reference_title = "";
    999903
    1000904    # Case 0: A magic word in the first sentence
     
    1008912    # Case 1: Author (possibly empty), then title in italics or quotes
    1009913    elsif ($place_reference =~ /^(.*?)<i>(.*?)<\/i>/ || $place_reference =~ /^(.*)"(.*?)"/) {
    1010         &new_metadata_entry($place_doc_obj, "ReferenceAuthor", $1);
    1011         &new_metadata_entry($place_doc_obj, "ReferenceTitle", $2);
     914        $place_reference_author = $1;
     915        $place_reference_title = $2;
    1012916    }
    1013917    # Case 2: Zero or one fullstops, assume no author and title is complete text
    1014918    elsif ($place_reference =~ /^[^\.]*\.[^\.]*$/ || $place_reference !~ /\./) {
    1015         &new_metadata_entry($place_doc_obj, "ReferenceTitle", $place_reference);
     919        $place_reference_title = $place_reference;
    1016920    }
    1017921    else {
     
    1019923        # print STDERR "Warning: Place $place_id -- Could not parse reference: $place_reference\n";
    1020924        print $fail_log_handle "Warning: Place $place_id -- Could not parse reference: $place_reference\n";
    1021     }
     925        next;
     926    }
     927
     928    # Create a new Reference document for this place reference
     929    my $place_reference_doc_obj = new doc($self->{'file'} . "-", "indexed_doc");
     930    $place_reference_doc_obj->set_OID("pr$place_reference_id");
     931    &new_metadata_entry($place_reference_doc_obj, "DocumentType", "PlaceReference");
     932    &new_metadata_entry($place_reference_doc_obj, "PlaceID", $place_id);
     933    &new_metadata_entry($place_reference_doc_obj, "PlaceName", $place_name);
     934    &new_metadata_entry($place_reference_doc_obj, "PlaceInstitutionName", $place_institution_name);
     935    &new_metadata_entry($place_reference_doc_obj, "Reference", $place_reference);
     936    &new_metadata_entry($place_reference_doc_obj, "ReferenceAuthor", $place_reference_author);
     937    &new_metadata_entry($place_reference_doc_obj, "ReferenceTitle", $place_reference_title);
     938
     939    $place_reference_doc_obj->add_utf8_text($place_reference_doc_obj->get_top_section(), "Some dummy text.");
     940    $self->{'processor'}->process($place_reference_doc_obj);
     941    $self->{'num_processed'}++;
     942    $place_reference_id++;
    1022943    }
    1023944
    1024945    &new_metadata_entry($place_doc_obj, "PlaceReferencesHTML", $place_references_html);
     946}
     947
     948
     949sub process_designers
     950{
     951    my $self = shift(@_);
     952    my $dbh = shift(@_);
     953    my $fail_log_handle = $self->{'failhandle'};
     954
     955    # Prepare SQL statement for getting the Place name
     956    my $place_name_sql_statement = "SELECT Current_name FROM tblPlace WHERE Entry_ID=?";
     957    my $place_name_sql_handle = $dbh->prepare($place_name_sql_statement);
     958
     959    # Prepare SQL statement for getting the Place institution
     960    my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
     961    my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
     962
     963    # Prepare SQL statement for getting the Place "date of construction"
     964    my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
     965    my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
     966
     967    # Prepare SQL statement for getting the Place non-PDF images
     968    my $place_images_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND Location NOT LIKE '%.pdf' AND Entry_ID=? ORDER BY Image_Order";
     969    my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
     970    $place_images_sql_handle->{LongReadLen} = 65536;
     971
     972    # Create a document object for each designer
     973    my %designer_id_to_name_mapping;
     974    foreach my $designer_name (keys %designer_name_to_id_mapping) {
     975    my $designer_id = $designer_name_to_id_mapping{$designer_name};
     976    # print STDERR "       Designer $designer_id\n";
     977    my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
     978    $designer_doc_obj->set_OID("d$designer_id");
     979    &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
     980
     981    &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
     982
     983    # Get designer places
     984    my $designer_places_list_html = "";
     985    my $last_designer_place_id = "";
     986        foreach my $designer_place_id (sort(@{$designer_name_to_place_ids_mapping{$designer_name}})) {
     987        # The designer may have worked on a place multiple times, so check for this
     988        next if ($designer_place_id eq $last_designer_place_id);
     989        $last_designer_place_id = $designer_place_id;
     990
     991        # Get place name
     992        $place_name_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
     993        my $designer_place_name = $place_name_sql_handle->fetchrow();
     994
     995        # Get place institution name
     996        $place_institution_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
     997        my $designer_place_institution_name = $place_institution_sql_handle->fetchrow();
     998
     999        # Get place date of construction
     1000        $place_construction_date_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
     1001        my $designer_place_construction_date_value = $place_construction_date_sql_handle->fetchrow() || "";
     1002
     1003        # Get the first non-PDF image for this place
     1004        my $designer_place_image_small_file_href;
     1005            $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
     1006        my $designer_place_image_location = $place_images_sql_handle->fetchrow();
     1007        if (defined($designer_place_image_location)) {
     1008        $designer_place_image_small_file_href = $self->generate_place_image_variant($designer_doc_obj, $designer_place_image_location, "small");
     1009        }
     1010        else {
     1011        # There is no non-PDF image for this place
     1012        $designer_place_image_small_file_href = "_httpcollection_/images/no_image-small.jpg";
     1013        }
     1014
     1015        $designer_places_list_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><img src=\"$designer_place_image_small_file_href\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\">$designer_place_name</a>, $designer_place_institution_name<br /><b>Date of construction:</b> $designer_place_construction_date_value</td></tr>\n";
     1016    }
     1017
     1018    &new_metadata_entry($designer_doc_obj, "DesignerPlacesListHTML", "<table>" . $designer_places_list_html . "</table>");
     1019
     1020    $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
     1021    $self->{'processor'}->process($designer_doc_obj);
     1022    $self->{'num_processed'}++;
     1023
     1024    $designer_id_to_name_mapping{$designer_doc_obj->get_OID()} = $designer_name;
     1025    }
     1026
     1027    # Write the designers.dm macrofile
     1028    &write_static_browser_macrofile("designers", \%designer_id_to_name_mapping);
     1029}
     1030
     1031
     1032sub new_metadata_entry
     1033{
     1034    my ($doc_obj, $metadata_name, $metadata_value) = (@_);
     1035
     1036    # Don't bother with empty metadata
     1037    return if ($metadata_value eq "");
     1038
     1039    # Spaces aren't allowed in metadata names
     1040    $metadata_name =~ s/ /_/g;
     1041
     1042    # Anything from the database is ISO 8859-1 encoded, so convert to UTF-8
     1043    $metadata_value = &unicode::ascii2utf8(\$metadata_value);
     1044
     1045    # Escape any '&' characters so the metadata is HTML 4 compliant when displayed
     1046    $metadata_value =~ s/&([^\#])/&amp;$1/g;
     1047
     1048    $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
    10251049}
    10261050
Note: See TracChangeset for help on using the changeset viewer.