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

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 19 Jul 2004 16:38:08 -0000


raeburn		Mon Jul 19 12:38:08 2004 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Discussion postings associated with resources and bulletin boards now
  searchable.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.230 loncom/interface/lonsearchcat.pm:1.231
--- loncom/interface/lonsearchcat.pm:1.230	Mon Jun 28 11:55:09 2004
+++ loncom/interface/lonsearchcat.pm	Mon Jul 19 12:38:07 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.230 2004/06/28 15:55:09 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.231 2004/07/19 16:38:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -76,6 +76,7 @@
 use LONCAPA::lonmetadata();
 use HTML::Entities();
 use Parse::RecDescent;
+use Apache::lonnavmaps;
 
 ######################################################################
 ######################################################################
@@ -463,10 +464,11 @@
         }
     }
     my $fulltext=$ENV{'form.crsfulltext'};
+    my $discuss=$ENV{'form.crsdiscuss'};
     my @allwords=($search_string,@New_Words);
     $totalfound=0;
     $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.
-	      $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr />');
+	      $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr /><b>'.&mt('Course content').':</b><br />');
     $r->rflush();
 # ======================================================= Go through the course
     undef %alreadyseen;
@@ -484,8 +486,83 @@
         untie(%hash);
     }
     unless ($totalfound) {
-	$r->print('<p>'.&mt('No resources found').'.</p>');
+	$r->print('<p>'.&mt('No matches found in resources').'.</p>');
     }
+
+# Check discussions if requested
+    if ($discuss) {
+        my $totaldiscussions = 0;
+        $r->print('<br /><br /><b>'.&mt('Discussion postings').':</b><br />'); 
+        my $navmap = Apache::lonnavmaps::navmap->new();
+        my @allres=$navmap->retrieveResources();
+        my %discussiontime = &Apache::lonnet::dump('discussiontimes',
+                               $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+                               $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+        foreach my $resource (@allres) {
+            my $result = '';
+            my $applies = 0;
+            my $symb = $resource->symb();
+            my $ressymb = $symb;
+            if ($symb =~ m#(___adm/\w+/\w+)/(\d+)/bulletinboard$#) {
+                $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
+                unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) {
+                    $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#;
+                }
+            }
+            if (defined($discussiontime{$ressymb})) { 
+                my %contrib = &Apache::lonnet::restore($ressymb,$ENV{'request.course.id'},
+                     $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+                     $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+                if ($contrib{'version'}) {
+                    for (my $id=1;$id<=$contrib{'version'};$id++) {
+                        unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) { 
+                            if ($contrib{$id.':subject'}) {
+                                $result .= $contrib{$id.':subject'};
+                            }
+                            if ($contrib{$id.':message'}) {
+                                $result .= $contrib{$id.':message'};
+                            }
+                            if ($contrib{$id,':attachmenturl'}) {
+                                if ($contrib{$id,':attachmenturl'} =~ m-/([^/]+)$-) {
+                                    $result .= $1;
+                                }
+                            }
+                            $applies = &checkwords($result,$applies,@allwords);
+                        }
+                    }
+                }
+            }
+# Does this discussion apply?
+            if ($applies) {
+                my ($map,$ind,$url)=&Apache::lonnet::decode_symb($ressymb);
+                my $disctype = &mt('resource');
+                if ($url =~ m#/bulletinboard$#) {
+                    if ($url =~m#^adm/wrapper/adm/.*/bulletinboard$#) {
+                        $url =~s#^adm/wrapper##;
+                    }
+                    $disctype = &mt('bulletin board');
+                } else {
+                    $url = '/res/'.$url;
+                }
+                if ($url =~ /\?/) {
+                    $url .= '&symb=';
+                } else {
+                    $url .= '?symb=';
+                }
+                $url .= &Apache::lonnet::escape($resource->symb());
+                my $title = $resource->compTitle();
+                $r->print('<br /><a href="'.$url.'" target="cat">'.
+                     ($title?$title:$url).'</a>&nbsp;&nbsp;-&nbsp;'.$disctype.'<br />');
+                $totaldiscussions++;
+            } else {
+                $r->print(' .');
+            }
+        }
+        unless ($totaldiscussions) {
+            $r->print('<p>'.&mt('No matches found in postings').'.</p>');
+        }
+    }
+ 
 # =================================================== Done going through course
     $r->print('</body></html>');
 }
@@ -504,14 +581,8 @@
 	$result.=&Apache::lonnet::ssi_body($url);
     }
     $result=~s/\s+/ /gs;
-    my $applies=0;
-    foreach (@allwords) {
-        if ($_=~/\w/) {
-	   if ($result=~/$_/si) {
-	      $applies++;
-           }
-       }
-    }
+    my $applies = 0;
+    $applies = &checkwords($result,$applies,@allwords);
 # Does this resource apply?
     if ($applies) {
        $r->print('<br />');
@@ -535,6 +606,18 @@
     }
 }
 
+sub checkwords {
+    my ($result,$applies,@allwords) = @_;
+    foreach (@allwords) {
+        if ($_=~/\w/) {
+            if ($result=~/$_/si) {
+                $applies++;
+            }
+        }
+    }
+    return $applies;
+}
+
 sub untiehash {
     if (tied(%hash)) {
         untie(%hash);
@@ -638,7 +721,8 @@
                                            'header' => 'Course Search',
 	 'note' => 'Enter terms or phrases, then press "Search" below',
 	 'use' => 'use related words',
-	 'full' =>'fulltext search (time consuming)'
+	 'full' =>'fulltext search (time consuming)',
+         'disc' => 'search discussion postings (resources and bulletin boards)',
 					   );
         $scrout.=(<<ENDCOURSESEARCH);
 <form name="loncapa_search" method="post" action="/adm/searchcat">
@@ -663,10 +747,14 @@
         my $relcheckbox = 
             &Apache::lonhtmlcommon::checkbox('crsrelated',
 				   $ENV{'form.crsrelated'});
+        my $discheckbox = 
+            &Apache::lonhtmlcommon::checkbox('crsdiscuss',
+                                   $ENV{'form.crsrelated'});
         $scrout.=(<<ENDENDCOURSE);
 </td></tr>
 <tr><td>$relcheckbox $lt{'use'}</td><td></td></tr>
 <tr><td>$crscheckbox $lt{'full'}</td><td></td></tr>
+<tr><td>$discheckbox $lt{'disc'}</td><td></td></tr>
 </table><p>
 &nbsp;<input type="submit" name="coursesubmit" value='$lt{'srch'}' />
 </p>