[LON-CAPA-cvs] cvs: loncom /interface lonmeta.pm lonsearchcat.pm /metadata_database/LONCAPA lonmetadata.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 19 Jan 2007 14:23:46 -0000


This is a MIME encoded message

--raeburn1169216626
Content-Type: text/plain

raeburn		Fri Jan 19 09:23:46 2007 EDT

  Modified files:              
    /loncom/interface	lonmeta.pm lonsearchcat.pm 
    /loncom/metadata_database/LONCAPA	lonmetadata.pm 
  Log:
  Prefer a null value as the option value in a select box when the user chooses "Not specified" - searching in MySQL for IS NULL seems better.
  
  In cases where there are multiple ways to enter metadata for a single field, eliminate storage of comma(s) when the user has not specified anything
  for the field.
  
  Advanced search for portfolio files can now include the name(s) of added (course-specified) field(s) with/without the value(s).
  
  addedfieldnames and addedfieldvalues eliminated from the portfolio_metadata table in MySQL - searches do a join on the portfolio_addedfields table instead.
  
  
--raeburn1169216626
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070119092346.txt"

Index: loncom/interface/lonmeta.pm
diff -u loncom/interface/lonmeta.pm:1.200 loncom/interface/lonmeta.pm:1.201
--- loncom/interface/lonmeta.pm:1.200	Tue Jan 16 02:36:10 2007
+++ loncom/interface/lonmeta.pm	Fri Jan 19 09:23:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Metadata display handler
 #
-# $Id: lonmeta.pm,v 1.200 2007/01/16 07:36:10 raeburn Exp $
+# $Id: lonmeta.pm,v 1.201 2007/01/19 14:23:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -631,14 +631,14 @@
                 if ($meta_options{$item}) {
                     push(@cur_values_inst,$item);
                 } else {
-                    if ($item ne 'Not Specified') {
+                    if ($item ne '') {
                         $cur_values_stu .= $item.',';
                     }
                 }
             }
             my @key_order = sort(keys(%meta_options));
-            unshift (@key_order,'Not Specified');
-            $meta_options{'Not Specified'} = 'Not Specified';
+            unshift (@key_order,'');
+            $meta_options{''} = 'Not specified';
             $meta_options{'select_form_order'} = \@key_order;
         } else {
             $cur_values_stu = $value;
@@ -1340,8 +1340,15 @@
         my $row_alt = 1;
         foreach my $field_name (@fields) {
             if (defined($env{'form.new_'.$field_name})) {
-                $Apache::lonpublisher::metadatafields{$field_name}=
-                    join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
+                my @values = &Apache::loncommon::get_env_multiple('form.new_'.$field_name);
+                my $newvalue = '';
+                foreach my $item (@values) {
+                    if ($item ne '') {
+                        $newvalue .= $item.',';
+                    }
+                }
+                $newvalue =~ s/,$//; 
+                $Apache::lonpublisher::metadatafields{$field_name}=$newvalue;
             }
             if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
 		&& exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.278 loncom/interface/lonsearchcat.pm:1.279
--- loncom/interface/lonsearchcat.pm:1.278	Wed Dec  6 17:22:37 2006
+++ loncom/interface/lonsearchcat.pm	Fri Jan 19 09:23:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.278 2006/12/06 22:22:37 albertel Exp $
+# $Id: lonsearchcat.pm,v 1.279 2007/01/19 14:23:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -832,10 +832,21 @@
 $closebutton
 END
     my $srchtype = 'Catalog';
+    my $jscript;
     if ($env{'form.area'} eq 'portfolio') {
         $srchtype = 'Portfolio';
+        $jscript = '<script type="text/javascript">
+function additional_metadata() {
+    if (document.advsearch.newfield.checked) {
+        document.advsearch.phase.value = "disp_adv";
+        document.advsearch.numaddedfields.value = parseInt(document.advsearch.numaddedfields.value) +1;
+        document.advsearch.submit();
     }
-    my $scrout= &Apache::loncommon::start_page("Advanced $srchtype Search");
+}
+</script>';
+    }
+    my $scrout= &Apache::loncommon::start_page("Advanced $srchtype Search",
+                                               $jscript);
     $scrout .= <<"ENDHEADER";
 $bread_crumb
 <form method="post" action="/adm/searchcat" name="advsearch">
@@ -935,33 +946,33 @@
     
     if ($env{'form.area'} eq 'portfolio') {
         # Added fields
+        my $curnumadd = $env{'form.numaddedfields'};
+        if ($curnumadd eq '') {
+            $curnumadd = 1;
+        }
         $scrout .= '<h3>'.&mt('Custom Metadata fields').'</h3>';
         $scrout .= "<table>\n";
         $scrout .= '<tr><td>&nbsp;</td><td align="center">'.
                    &mt('Field Name').'</td>'.'<td align="center">'.
-                   &mt('Field Value(s)').'</td></tr>'.
-                   '<tr><td>'.&mt('1: ').
-                   '</td><td align="center">'.
-                   '<input type="text" name="addedfield_0" size="10" /></td>'.
-                   '<td align="center"><input type="text" '.
-                   'name="addedvalues_0" size="15" /></td></tr>';
-        for (my $j=1; $j<=$env{'form.numaddedfields'}; $j++) {
+                   &mt('Field Value(s)').'</td></tr>';
+
+        for (my $j=0; $j<$curnumadd; $j++) {
             my $num = $j+1;
             $scrout .= '<tr><td>'.&mt('Custom metadata [_1]: ',$num).
                        '</td><td align="center">'.
                        '<input type="text" name="addedfield_'.$j.
-                       '" size="10" /></td>'.
+                       '" size="10" value="'.$env{'form.addedfield_'.$j}.
+                       '" /></td>'.
                        '<td align="center"><input type="text" '.
-                       'name="addedvalues_'.$j.'" size="15" /></td></tr>';
+                       'name="addedvalues_'.$j.'" size="15" value="'.
+                       $env{'form.addedvalues_'.$j}.'" /></td></tr>';
         }
-        my $numadded = 1 + $env{'form.numaddedfields'};
-        $scrout .= '<tr><td colspan="3">&nbsp;</td></tr>'.
-                   '<tr><td align="left" colspan="3">'.
-                   '<input type="button" name="newfield" '.
-                   'value="Additional custom field/value" '.
-                   'onclick="javascript:additional_metadata()" />'.
-                   '<input type="hidden" name="numaddedfelds" value="'.
-                   $numadded.'" /></td></tr></table>';
+        $scrout .= '<tr><td align="left" colspan="3"><label>'.
+                   '<input type="checkbox" name="newfield" '.
+                   'value="1" onclick="javascript:additional_metadata()" />'.
+                   &mt('Another custom field/value pair?').'</label>'.
+                   '<input type="hidden" name="numaddedfields" value="'.
+                   $curnumadd.'" /></td></tr></table>';
     } else {
         #
         # Dynamic metadata
@@ -1413,6 +1424,17 @@
             $fillflag++;
         }
     }
+    if ($env{'form.area'} eq 'portfolio') {
+        # Added metadata fields
+        for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
+            my $field = $env{'form.addedfield_'.$i};
+            $field =~ s/^\s*(\S*)\s*$/$1/;
+            $field =~ s/\W/_/g;
+            if ($field ne '') {
+                $fillflag++;
+            }
+        }
+    }
     if (! $fillflag) {
 	&output_blank_field_error($r,$closebutton,
                                   'phase=disp_adv',$hidden_fields);
@@ -1503,9 +1525,25 @@
         #
         # Added metadata fields
         for (my $i=0; $i<$env{'form.numaddedfields'} ; $i++) {
-            if (($env{'form.addedfield_'.$i} ne '') && 
-                ($env{'form.addedvalue_'.$i} ne '')) {
-                my $stuff = 1; #FIXME 
+            my $field = $env{'form.addedfield_'.$i};
+            $field =~ s/^\s*(\S*)\s*$/$1/;
+            $field =~ s/\W/_/g;
+            $field =~ tr/A-Z/a-z/; 
+            if ($field ne '') {
+                my $value = $env{'form.addedvalues_'.$i};
+                if ($value ne '') {
+                    $value =~ s/'/''/g;
+                    my ($error,$query) = 
+                        &process_phrase_input($value,0,'pf.value');
+                    if (!defined($error)) {
+                        push(@queries,"pf.field = '$field' AND $query");
+                        $pretty_search_string .=
+                            $font.$field.'</font>: '.
+                            $env{'form.addedvalues_'.$i}.'<br />';
+                    }
+                } else {
+                    push(@queries,"pf.field = '$field' AND pf.value IS NULL");
+                }
             }
         }
     } else {
@@ -1598,7 +1636,7 @@
     #
     if (@queries) {
         if ($env{'form.area'} eq 'portfolio') {
-            $query ="SELECT pm.*,pa.keynum,pa.scope FROM portfolio_metadata pm, portfolio_access pa  WHERE (pm.url = pa.url AND (pa.start < NOW() AND (pa.end IS NULL OR pa.end > NOW())) AND (".join(') AND (',@queries).'))';
+            $query ="SELECT pm.*,pa.keynum,pa.scope FROM portfolio_metadata pm, portfolio_access pa, portfolio_addedfields pf WHERE (pm.url = pa.url AND pf.url = pm.url AND (pa.start < NOW() AND (pa.end IS NULL OR pa.end > NOW())) AND (".join(') AND (',@queries).'))';
         } else {
 	    $query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')';
         }
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.18 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.19
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.18	Fri Jan 19 01:09:08 2007
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm	Fri Jan 19 09:23:46 2007
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonmetadata.pm,v 1.18 2007/01/19 06:09:08 albertel Exp $
+# $Id: lonmetadata.pm,v 1.19 2007/01/19 14:23:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -184,8 +184,6 @@
      { name => 'domain',    type=>'TEXT'},
      { name => 'groupname',     type=>'TEXT'},
      { name => 'courserestricted', type=>'TEXT'},
-     { name => 'addedfieldnames',  type=>'TEXT'},
-     { name => 'addedfieldvalues', type=>'TEXT'},
       #--------------------------------------------------
      { name => 'dependencies',   type=>'TEXT'},
      { name => 'modifyinguser',  type=>'TEXT'},
@@ -994,20 +992,6 @@
             }
         } # End of ($token->[0] eq 'S')
     }
-    if (keys(%addedfields) > 0) {
-        foreach my $key (sort keys(%addedfields)) {
-            $metacache{'addedfieldnames'} .= $key.',';
-            $metacache{'addedfieldvalues'} .= $addedfields{$key}.'&&&';
-        }
-        $metacache{'addedfieldnames'} =~ s/,$//;
-        $metacache{'addedfieldvalues'} =~ s/\&\&\&$//;
-        if ($metacache{'keys'}) {
-            $metacache{'keys'}.=',addedfieldnames';
-        } else {
-            $metacache{'keys'}='addedfieldnames';
-        }
-        $metacache{'keys'}.=',addedfieldvalues';
-    }
     return (\%metacache,$metacache{'courserestricted'},\%addedfields);
 }
 

--raeburn1169216626--