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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 20 Aug 2004 15:45:52 -0000


matthew		Fri Aug 20 11:45:52 2004 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Search results are now sortable.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.231 loncom/interface/lonsearchcat.pm:1.232
--- loncom/interface/lonsearchcat.pm:1.231	Mon Jul 19 12:38:07 2004
+++ loncom/interface/lonsearchcat.pm	Fri Aug 20 11:45:51 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.231 2004/07/19 16:38:07 raeburn Exp $
+# $Id: lonsearchcat.pm,v 1.232 2004/08/20 15:45:51 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2633,10 +2633,74 @@
               &hidden_field('persistent_db_id').
               &hidden_field('start')
               );
+    #
+    # Build sorting selector
+    my @field_order =  ('default',
+                        'title',
+                        'author',
+                        'subject',
+                        'url',
+                        'keywords',
+                        'version',
+                        'language',
+                        'creationdate'=>,
+                        'lastrevisiondate',
+                        'owner',
+                        'copyright',
+                        'authorspace',
+                        'lowestgradeleve',
+                        'highestgradelevel',
+                        'standards',
+                        'count',
+                        'stdno',
+                        'avetries',
+                        'difficulty',
+                        'disc',
+                        'clear',
+                        'technical',
+                        'correct',
+                        'helpful',
+                        'depth',
+                        );                                              
+    my %sort_fields = ('default'     => 'Default',
+                       'title'       => 'Title',
+                       'author'      => 'Author',
+                       'subject'     => 'Subject',
+                       'url'         => 'URL',
+                       'keywords'    => 'Keywords',
+                       'version'     => 'Version',
+                       'language'    => 'Language',
+                       'creationdate'=> 'Creation Date',
+                       'lastrevisiondate' => 'Last Revision Date',
+                       'owner'       => 'Owner',
+                       'copyright'   => 'Copyright',
+                       'authorspace' => 'Authorspace',
+                       'lowestgradeleve' => 'Lowest Grade Level',
+                       'highestgradelevel' => 'Highest Grade Level',
+                       'standards'   => 'Standards',
+                       'count'       => 'Number of Accesses',
+                       'stdno'       => 'Students Attempting',
+                       'avetries'    => 'Average Number of Tries',
+                       'difficulty'  => 'Mean Degree of Difficulty',
+                       'disc'        => 'Mean Degree of Discrimination',
+                       'clear'       => 'Evaluation: Clear',
+                       'technical'   => 'Evaluation: Technically Correct',
+                       'correct'     => 'Evaluation: Material is Correct',
+                       'helpful'     => 'Evaluation: Material is Helpful',
+                       'depth'       => 'Evaluation: Material has Depth',
+                       'select_form_order' => \@field_order,
+                       );
+
+    my $sortform = &mt('Sort by [_1]',
+                       &Apache::loncommon::select_form($ENV{'form.sortfield'},
+                                                      'sortfield',
+                                                      %sort_fields));
     ##
     ## Output links (if necessary) for 'prev' and 'next' pages.
     $r->print
-        ('<table width="100%"><tr><td width="50%" align="right">'.
+        ('<table width="100%"><tr><td width="25%" align="right">'.
+         $sortform.
+         '</td><td width="25%" align="right">'.
          &prev_next_buttons($min,$ENV{'form.show'},$total_results).
          '</td><td align="right">'.
          &viewoptions().'</td></tr></table>'
@@ -2647,13 +2711,21 @@
                   "</form></body></html>");
         return;
     } else {
-        $r->print
-            ("<center>Results $min to $max out of $total_results</center>\n");
+        $r->print('<center>'.
+                  mt('Results [_1] to [_2] out of [_3]',
+                     $min,$max,$total_results).
+                  "</center>\n");
     }
     ##
     ## Get results from MySQL table
-    my @Results = &Apache::lonmysql::get_rows($table,
-                                              'id>='.$min.' AND id<='.$max);
+    my $sort_command  = 'id>='.$min.' AND id<='.$max;
+    if ($ENV{'form.sortfield'} ne 'default' && 
+        exists($sort_fields{$ENV{'form.sortfield'}})) {
+        $sort_command = $ENV{'form.sortfield'}.' IS NOT NULL '.
+            'ORDER BY '.$ENV{'form.sortfield'}.
+            '  LIMIT '.($min-1).','.($max-$min);
+    }
+    my @Results = &Apache::lonmysql::get_rows($table,$sort_command);
     ##
     ## Loop through the results and output them.
     foreach my $row (@Results) {