[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 05 May 2004 14:14:10 -0000


This is a MIME encoded message

--matthew1083766450
Content-Type: text/plain

matthew		Wed May  5 10:14:10 2004 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Made access count searchable.  Expanded output for xml and fielded search
  result views.
  
  
--matthew1083766450
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040505101410.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.221 loncom/interface/lonsearchcat.pm:1.222
--- loncom/interface/lonsearchcat.pm:1.221	Tue May  4 11:20:17 2004
+++ loncom/interface/lonsearchcat.pm	Wed May  5 10:14:10 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.221 2004/05/04 15:20:17 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.222 2004/05/05 14:14:10 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -790,10 +790,13 @@
     $scrout .= '<tr><td>&nbsp;</td><td align="center">'.&mt('Minimum').'</td>'.
         '<td align="center">'.&mt('Maximum').'</td></tr>'."\n";
     foreach my $statistic 
-        ({ name=>'stdno',
-           description=>'Number of Students',},
+        ({ name=>'count',
+           description=>'Network-wide number of accesses (hits)',},
+         { name=>'stdno',
+           description=>
+               'Total number of students who have worked on this problem',},
          { name => 'avetries',
-           description=>'Average tries to answer correctly',},
+           description=>'Average number of tries till solved',},
          { name => 'difficulty',
            description=>'Degree of difficulty',},
          { name => 'disc',
@@ -1184,8 +1187,8 @@
                        'notes','abstract','extension','owner',
 #                       'custommetadata','customshow',
                        'modifyinguser','standards','mime');
-    my @StatsFields = ('stdno','avetries','difficulty','disc');
-    my @EvalFields = ('clear','depth','helpful','correct','technical');
+    my @StatsFields = &statfields();
+    my @EvalFields = &evalfields();
     my $fillflag=0;
     my $pretty_search_string = "<br />\n";
     # Clean up fields for safety
@@ -1210,11 +1213,20 @@
                                       ref($ENV{'form.category'}));
     #
     # Check to see if enough information was filled in
-    for my $field (@BasicFields) {
+    foreach my $field (@BasicFields) {
 	if (&filled($ENV{'form.'.$field})) {
 	    $fillflag++;
 	}
     }
+    foreach my $field (@StatsFields,@EvalFields) {
+        if (&filled($ENV{'form.'.$field.'_max'})) {
+            $fillflag++;
+        }
+        if (&filled($ENV{'form.'.$field.'_min'})) {
+            $fillflag++;
+        }
+    }
+
     for my $field ('lowestgradelevel','highestgradelevel') {
         if ( $ENV{'form.'.$field} =~ /^\d+$/ &&
              $ENV{'form.'.$field} > 0) {
@@ -2874,6 +2886,41 @@
 ######################################################################
 ######################################################################
 
+sub has_stat_data {
+    my ($values) = @_;
+    if ( (defined($values->{'count'})      && $values->{'count'}      ne '') ||
+         (defined($values->{'stdno'})      && $values->{'stdno'}      ne '') ||
+         (defined($values->{'disc'})       && $values->{'disc'}       ne '') ||
+         (defined($values->{'avetries'})   && $values->{'avetries'}   ne '') ||
+         (defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) {
+        return 1;
+    }
+    return 0;
+}
+
+sub statfields {
+    return ('count','stdno','disc','avetries','difficulty');
+}
+
+sub has_eval_data {
+    my ($values) = @_;
+    if ( (defined($values->{'clear'})     && $values->{'clear'}     ne '') ||
+         (defined($values->{'technical'}) && $values->{'technical'} ne '') ||
+         (defined($values->{'correct'})   && $values->{'correct'}   ne '') ||
+         (defined($values->{'helpful'})   && $values->{'helpful'}   ne '') ||
+         (defined($values->{'depth'})     && $values->{'depth'}     ne '')) {
+        return 1;
+    }
+    return 0;
+}
+
+sub evalfields { 
+    return ('clear','technical','correct','helpful','depth');
+}
+
+######################################################################
+######################################################################
+
 =pod 
 
 =item &summary_view() 
@@ -2934,28 +2981,35 @@
 sub fielded_format_view {
     my ($prefix,%values) = @_;
     my $icon=&Apache::loncommon::icon($values{'url'});
+    my %Translated = &Apache::lonmeta::fieldnames();
     my $result=<<END;
 $prefix <img src="$icon" />
-<b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
-              target='search_preview'>$values{'url'}</a>
-<br />
-<b>Title:</b> $values{'title'}<br />
-<b>Author(s):</b> $values{'author'}<br />
-<b>Subject:</b> $values{'subject'}<br />
-<b>Keyword(s):</b> $values{'keywords'}<br />
-<b>Notes:</b> $values{'notes'}<br />
-<b>MIME Type:</b> $values{'mimetag'}<br />
-<b>Language:</b> $values{'language'}<br />
-<b>Creation Date:</b> $values{'creationdate'}<br />
-<b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
-<b>Publisher/Owner:</b> $values{'owner'}<br />
-<b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
-<b>Repository Location:</b> $values{'hostname'}<br />
-<b>Abstract:</b> $values{'shortabstract'}<br />
-$values{'extrashow'}
-</p>
-<hr align='left' width='200' noshade />
+<dl>
+<dt>URL:</dt>
+    <dd><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
+         target='search_preview'>$values{'url'}</a></dd>
 END
+    foreach my $field ('title','author','subject','keywords','notes',
+                       'mimetag','language','creationdate','lastrevisiondate',
+                       'owner','copyrighttag','hostname','abstract') {
+        $result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n".
+            (' 'x8).'<dd>'.$values{$field}.'</dd>'."\n";
+    }
+    if (&has_stat_data(\%values)) {
+        foreach my $field (&statfields()) {
+            $result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n".
+                (' 'x8).'<dd>'.$values{$field}.'</dd>'."\n";
+        }
+    }
+    if (&has_eval_data(\%values)) {
+        foreach my $field (&evalfields()) {
+            $result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n".
+                (' 'x8).'<dd>'.$values{$field}.'</dd>'."\n";
+        }
+    }
+    $result .= "</dl>\n";
+    $result .= $values{'extrashow'};
+    $result .= '<hr align="left" width="200" noshade />'."\n";
     return $result;
 }
 
@@ -2974,33 +3028,54 @@
 ######################################################################
 sub xml_sgml_view {
     my ($prefix,%values) = @_;
-    my $xml = <<END;
-<LonCapaResource>
-<url>$values{'url'}</url>
-<title>$values{'title'}</title>
-<author>$values{'author'}</author>
-<subject>$values{'subject'}</subject>
-<keywords>$values{'keywords'}</keywords>
-<notes>$values{'notes'}</notes>
-<mimeInfo>
-<mime>$values{'mime'}</mime>
-<mimetag>$values{'mimetag'}</mimetag>
-</mimeInfo>
-<languageInfo>
-<language>$values{'language'}</language>
-<languagetag>$values{'languagetag'}</languagetag>
-</languageInfo>
-<creationdate>$values{'creationdate'}</creationdate>
-<lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
-<owner>$values{'owner'}</owner>
-<copyrightInfo>
-<copyright>$values{'copyright'}</copyright>
-<copyrighttag>$values{'copyrighttag'}</copyrighttag>
-</copyrightInfo>
-<repositoryLocation>$values{'hostname'}</repositoryLocation>
-<shortabstract>$values{'shortabstract'}</shortabstract>
-</LonCapaResource>
-END
+    my $xml = '<LonCapaResource>'."\n";
+    # The usual suspects
+    foreach my $field ('url','title','author','subject','keywords','notes') {
+        $xml .= qq{<$field>$values{$field}</$field>}."\n";
+    }
+    #
+    $xml .= "<mimeInfo>\n";
+    foreach my $field ('mime','mimetag') {
+        $xml .= qq{<$field>$values{$field}</$field>}."\n";
+    }
+    $xml .= "</mimeInfo>\n";
+    #
+    $xml .= "<languageInfo>\n";
+    foreach my $field ('language','languagetag') {
+        $xml .= qq{<$field>$values{$field}</$field>}."\n";
+    }
+    $xml .= "</languageInfo>\n";
+    #
+    foreach my $field ('creationdate','lastrevisiondate','owner') {
+        $xml .= qq{<$field>$values{$field}</$field>}."\n";
+    }
+    #
+    $xml .= "<copyrightInfo>\n";
+    foreach my $field ('copyright','copyrighttag') {
+        $xml .= qq{<$field>$values{$field}</$field>}."\n";
+    }
+    $xml .= "</copyrightInfo>\n";
+    $xml .= qq{<repositoryLocation>$values{'hostname'}</repositoryLocation>}.
+        "\n";
+    $xml .= qq{<shortabstract>$values{'shortabstract'}</shortabstract>}."\n";
+    #
+    if (&has_stat_data(\%values)){
+        $xml .= "<problemstatistics>\n";
+        foreach my $field (&statfields()) {
+            $xml .= qq{<$field>$values{$field}</$field>}."\n";            
+        }
+        $xml .= "</problemstatistics>\n";
+    }
+    #
+    if (&has_eval_data(\%values)) {
+        $xml .= "<evaluation>\n";
+        foreach my $field (&evalfields) {
+            $xml .= qq{<$field>$values{$field}</$field>}."\n";            
+        }
+        $xml .= "</evaluation>\n";
+    }    
+    #
+    $xml .= "</LonCapaResource>\n";
     $xml = &HTML::Entities::encode($xml,'<>&');
     my $result=<<END;
 $prefix

--matthew1083766450--