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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 22 Mar 2005 21:15:43 -0000


This is a MIME encoded message

--matthew1111526143
Content-Type: text/plain

matthew		Tue Mar 22 16:15:43 2005 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Updates to sorting - added "ascending/descending" input, modified internal
  logic of sorting so it now uses lonmeta::fields for most field descriptions,
  modified compact and summary views to show the data we're sorting on.
  
  
--matthew1111526143
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20050322161543.txt"

Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.240 loncom/interface/lonsearchcat.pm:1.241
--- loncom/interface/lonsearchcat.pm:1.240	Mon Mar 21 16:01:15 2005
+++ loncom/interface/lonsearchcat.pm	Tue Mar 22 16:15:42 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.240 2005/03/21 21:01:15 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.241 2005/03/22 21:15:42 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1545,7 +1545,7 @@
     } elsif ($customquery) {
         $query = '';
     }
-    &Apache::lonnet::logthis('advanced query = '.$/.$query);
+    #&Apache::lonnet::logthis('advanced query = '.$/.$query);
     return ($query,$customquery,$customshow,$libraries_to_query,
             $pretty_search_string);
 }
@@ -1658,7 +1658,7 @@
     }
     $pretty_search_string .= "<br />\n";
     $pretty_search_string =~ s:^<br /> and ::;
-    &Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
+    #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query);
     return ($final_query,$pretty_search_string,
             $libraries_to_query);
 }
@@ -2685,71 +2685,65 @@
               );
     #
     # 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]',
+    my @fields = 
+        (
+         {key=>'default' },
+         {key=>'title' },
+         {key =>'author' },
+         {key =>'subject'},
+         {key =>'url',desc=>'URL'},
+         {key =>'keywords'},
+         {key =>'language'},
+         {key =>'creationdate'},
+         {key =>'lastrevisiondate'},
+         {key =>'owner'},
+         {key =>'copyright'},
+         {key =>'authorspace'},
+         {key =>'lowestgradelevel'},
+         {key =>'highestgradelevel'},
+         {key =>'standards',desc=>'Standards'},
+         {key =>'count',desc=>'Number of accesses'},
+         {key =>'stdno',desc=>'Students Attempting'},
+         {key =>'avetries',desc=>'Average Number of Tries'},
+         {key =>'difficulty',desc=>'Mean Degree of Difficulty'},
+         {key =>'disc',desc=>'Mean Degree of Discrimination'},
+         {key =>'clear',desc=>'Evaluation: Clear'},
+         {key =>'technical',desc=>'Evaluation: Technically Correct'},
+         {key =>'correct',desc=>'Evaluation: Material is Correct'},
+         {key =>'helpful',desc=>'Evaluation: Material is Helpful'},
+         {key =>'depth',desc=>'Evaluation: Material has Depth'},
+         );
+    my %fieldnames = &Apache::lonmeta::fieldnames();
+    my @field_order;
+    foreach my $field_data (@fields) {
+        push(@field_order,$field_data->{'key'});
+        if (! exists($field_data->{'desc'})) {
+            $field_data->{'desc'}=$fieldnames{$field_data->{'key'}};
+        } else {
+            if (! defined($field_data->{'desc'})) {
+                $field_data->{'desc'} = ucfirst($field_data->{'key'});
+            }
+            $field_data->{'desc'} = &mt($field_data->{'desc'});
+        }
+    }
+    my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields;
+    $sort_fields{'select_form_order'} = \@field_order;
+    $ENV{'form.sortorder'} = 'asc' if (! exists($ENV{'form.sortorder'}));
+    my $sortform = &mt('Sort by [_1] [_2]',
                        &Apache::loncommon::select_form($ENV{'form.sortfield'},
                                                       'sortfield',
-                                                      %sort_fields));
+                                                      %sort_fields),
+                       &Apache::loncommon::select_form($ENV{'form.sortorder'},
+                                                      'sortorder',
+                                                      (asc =>&mt('Ascending'),
+                                                       desc=>&mt('Descending')
+                                                       ))
+                       );
     ##
     ## Output links (if necessary) for 'prev' and 'next' pages.
     $r->print
         ('<table width="100%"><tr><td width="25%" align="right">'.
-         $sortform.
+         '<nobr>'.$sortform.'</nobr>'.
          '</td><td width="25%" align="right">'.
          &prev_next_buttons($min,$ENV{'form.show'},$total_results).
          '</td><td align="right">'.
@@ -2769,10 +2763,22 @@
     ##
     ## Get results from MySQL table
     my $sort_command  = 'id>='.$min.' AND id<='.$max;
+    my $order;
+    if (exists($ENV{'form.sortorder'})) {
+        if ($ENV{'form.sortorder'} eq 'asc') {
+            $order = 'ASC';
+        } elsif ($ENV{'form.sortorder'} eq 'desc') {
+            $order = 'DESC';
+        } else {
+            $order = '';
+        }
+    } else {
+        $order = '';
+    }
     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'}.
+            'ORDER BY '.$ENV{'form.sortfield'}.' '.$order.
             '  LIMIT '.($min-1).','.($max-$min);
     }
     my @Results = &Apache::lonmysql::get_rows($table,$sort_command);
@@ -3336,12 +3342,23 @@
 sub summary_view {
     my ($prefix,%values) = @_;
     my $icon=&Apache::loncommon::icon($values{'url'});
-    my $result=<<END;
-$prefix<img src="$icon" />&nbsp;
+    my $result=qq{$prefix<img src="$icon" />};
+    if (exists($ENV{'form.sortfield'}) && 
+        $ENV{'form.sortfield'} !~ /^(default|
+                                     author|
+                                     url|
+                                     title|
+                                     owner|
+                                     lastrevisiondate|
+                                     copyright)$/x) {
+        my $tmp = $values{$ENV{'form.sortfield'}};
+        if (! defined($tmp)) { $tmp = 'undefined'; }
+        $result .= '&nbsp;'.$tmp.'&nbsp;';
+    }
+    $result.=<<END;
 <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
-   target='search_preview'>$values{'author'}</a><br />
-$values{'title'}<br />
-$values{'owner'} -- $values{'lastrevisiondate'}<br />
+   target='search_preview'>$values{'title'}</a><br />
+$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}<br />
 $values{'copyrighttag'}<br />
 $values{'extrashow'}
 </p>
@@ -3364,8 +3381,14 @@
 sub compact_view {
     my ($prefix,%values) = @_;
     my $result = 
-        $prefix.'<img src="'.&Apache::loncommon::icon($values{'url'}).
-        '">&nbsp;<a href="'.$values{'url'}.'" target="search_preview">'.
+        $prefix.'<img src="'.&Apache::loncommon::icon($values{'url'}).'">';
+    if (exists($ENV{'form.sortfield'}) && 
+        $ENV{'form.sortfield'} !~ /^(default|author|url|title)$/) {
+        my $tmp = $values{$ENV{'form.sortfield'}};
+        if (! defined($tmp)) { $tmp = 'undefined'; }
+        $result .= '&nbsp;'.$tmp.'&nbsp;';
+    }
+    $result.='&nbsp;<a href="'.$values{'url'}.'" target="search_preview">'.
         $values{'title'}.'</a>'.('&nbsp;'x2).
         '<b>'.$values{'author'}.'</b><br />';
     return $result;

--matthew1111526143--