--- loncom/interface/lonsearchcat.pm 2005/01/19 20:22:36 1.230.2.1 +++ loncom/interface/lonsearchcat.pm 2004/12/17 21:44:19 1.235 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.230.2.1 2005/01/19 20:22:36 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.235 2004/12/17 21:44:19 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -76,6 +76,7 @@ use Apache::lonlocal; use LONCAPA::lonmetadata(); use HTML::Entities(); use Parse::RecDescent; +use Apache::lonnavmaps; ###################################################################### ###################################################################### @@ -471,10 +472,11 @@ sub course_search { } } my $fulltext=$ENV{'form.crsfulltext'}; + my $discuss=$ENV{'form.crsdiscuss'}; my @allwords=($search_string,@New_Words); $totalfound=0; $r->print('LON-CAPA Course Search'. - $bodytag.'
'.$pretty_search_string.'

'); + $bodytag.'
'.$pretty_search_string.'

'.&mt('Course content').':
'); $r->rflush(); # ======================================================= Go through the course my $c=$r->connection; @@ -494,8 +496,83 @@ sub course_search { untie(%hash); } unless ($totalfound) { - $r->print('

'.&mt('No resources found').'.

'); + $r->print('

'.&mt('No matches found in resources').'.

'); } + +# Check discussions if requested + if ($discuss) { + my $totaldiscussions = 0; + $r->print('

'.&mt('Discussion postings').':
'); + 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('
'. + ($title?$title:$url).'  - '.$disctype.'
'); + $totaldiscussions++; + } else { + $r->print(' .'); + } + } + unless ($totaldiscussions) { + $r->print('

'.&mt('No matches found in postings').'.

'); + } + } + # =================================================== Done going through course $r->print(''); } @@ -519,14 +596,8 @@ sub checkonthis { $result.=&Apache::lonnet::ssi_body($url.'?symb='.&Apache::lonnet::escape($symb)); } $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('
'); @@ -557,6 +628,18 @@ sub checkonthis { } } +sub checkwords { + my ($result,$applies,@allwords) = @_; + foreach (@allwords) { + if ($_=~/\w/) { + if ($result=~/$_/si) { + $applies++; + } + } + } + return $applies; +} + sub untiehash { if (tied(%hash)) { untie(%hash); @@ -598,18 +681,18 @@ sub print_basic_search_form { my $scrout = &search_html_header().$bodytag; if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { # Define interface components - my $userelatedwords= + my $userelatedwords= ''; + my $onlysearchdomain=''; my $adv_search_link = ' 'use related words', - 'full' =>'fulltext search (time consuming)' + 'full' =>'fulltext search (time consuming)', + 'disc' => 'search discussion postings (resources and bulletin boards)', ); $scrout.=(< @@ -685,10 +769,14 @@ ENDCOURSESEARCH my $relcheckbox = &Apache::lonhtmlcommon::checkbox('crsrelated', $ENV{'form.crsrelated'}); + my $discheckbox = + &Apache::lonhtmlcommon::checkbox('crsdiscuss', + $ENV{'form.crsrelated'}); $scrout.=(< -$relcheckbox $lt{'use'} -$crscheckbox $lt{'full'} + + +

 

@@ -2567,10 +2655,74 @@ sub display_results { &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 - ('
'. + ('
'. + $sortform. + ''. &prev_next_buttons($min,$ENV{'form.show'},$total_results). ''. &viewoptions().'
' @@ -2581,13 +2733,21 @@ sub display_results { ""); return; } else { - $r->print - ("
Results $min to $max out of $total_results
\n"); + $r->print('
'. + mt('Results [_1] to [_2] out of [_3]', + $min,$max,$total_results). + "
\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) {