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

raeburn raeburn@source.lon-capa.org
Fri, 19 Dec 2008 23:24:50 -0000


raeburn		Fri Dec 19 23:24:50 2008 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  - Check that navmap object could be created to avoid ISE when search of discussion postings is selected in Course Search.
  - Display link to roles page to re-select the course if no navmap object.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.302 loncom/interface/lonsearchcat.pm:1.303
--- loncom/interface/lonsearchcat.pm:1.302	Fri Dec 12 17:46:25 2008
+++ loncom/interface/lonsearchcat.pm	Fri Dec 19 23:24:49 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.302 2008/12/12 17:46:25 raeburn Exp $
+# $Id: lonsearchcat.pm,v 1.303 2008/12/19 23:24:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -519,72 +519,77 @@
         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/$LONCAPA::domain_re/$LONCAPA::username_re)/(\d+)/bulletinboard$#) {
-                $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
-                unless ($ressymb =~ m#bulletin___\d+___adm/wrapper#) {
-                    $ressymb=~s#(bulletin___\d+___)#$1adm/wrapper/#;
+        if (defined($navmap)) {
+            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/$LONCAPA::domain_re/$LONCAPA::username_re)/(\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;
+                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);
                             }
-                            $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##;
+                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;
                     }
-                    $disctype = &mt('bulletin board');
-                } else {
-                    $url = '/res/'.$url;
-                }
-                if ($url =~ /\?/) {
-                    $url .= '&symb=';
+                    if ($url =~ /\?/) {
+                        $url .= '&symb=';
+                    } else {
+                        $url .= '?symb=';
+                    }
+                    $url .= &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 {
-                    $url .= '?symb=';
+                    $r->print(' .');
                 }
-                $url .= &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>');
+            unless ($totaldiscussions) {
+                $r->print('<p>'.&mt('No matches found in postings').'.</p>');
+            }
+        } else {
+            $r->print('<div class="LC_error">'.&mt('An error occurred retrieving information about resources in the course.').'<br />'.&mt('It is recommended that you [_1]re-initialize the course[_2] and then try your search again.','<a href="/adm/roles">','</a>').'</div>');
         }
     }