Annotation of loncom/interface/lonnavmaps.pm, revision 1.276
1.2 www 1: # The LearningOnline Network with CAPA
2: # Navigate Maps Handler
1.1 www 3: #
1.276 ! albertel 4: # $Id: lonnavmaps.pm,v 1.275 2004/08/13 20:12:11 albertel Exp $
1.20 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.245 www 28: ###
1.2 www 29:
1.1 www 30: package Apache::lonnavmaps;
31:
32: use strict;
1.2 www 33: use Apache::Constants qw(:common :http);
1.18 albertel 34: use Apache::loncommon();
1.150 www 35: use Apache::lonmenu();
1.229 www 36: use Apache::lonlocal;
1.73 bowersj2 37: use POSIX qw (floor strftime);
1.192 bowersj2 38: use Data::Dumper; # for debugging, not always used
1.2 www 39:
1.133 bowersj2 40: # symbolic constants
41: sub SYMB { return 1; }
42: sub URL { return 2; }
43: sub NOTHING { return 3; }
44:
45: # Some data
46:
1.140 bowersj2 47: my $resObj = "Apache::lonnavmaps::resource";
48:
1.135 bowersj2 49: # Keep these mappings in sync with lonquickgrades, which uses the colors
50: # instead of the icons.
51: my %statusIconMap =
1.224 bowersj2 52: (
53: $resObj->CLOSED => '',
54: $resObj->OPEN => 'navmap.open.gif',
55: $resObj->CORRECT => 'navmap.correct.gif',
56: $resObj->INCORRECT => 'navmap.wrong.gif',
57: $resObj->ATTEMPTED => 'navmap.ellipsis.gif',
58: $resObj->ERROR => ''
59: );
1.135 bowersj2 60:
61: my %iconAltTags =
62: ( 'navmap.correct.gif' => 'Correct',
63: 'navmap.wrong.gif' => 'Incorrect',
64: 'navmap.open.gif' => 'Open' );
1.133 bowersj2 65:
1.136 bowersj2 66: # Defines a status->color mapping, null string means don't color
67: my %colormap =
1.140 bowersj2 68: ( $resObj->NETWORK_FAILURE => '',
69: $resObj->CORRECT => '',
70: $resObj->EXCUSED => '#3333FF',
71: $resObj->PAST_DUE_ANSWER_LATER => '',
72: $resObj->PAST_DUE_NO_ANSWER => '',
73: $resObj->ANSWER_OPEN => '#006600',
74: $resObj->OPEN_LATER => '',
75: $resObj->TRIES_LEFT => '',
76: $resObj->INCORRECT => '',
77: $resObj->OPEN => '',
1.207 bowersj2 78: $resObj->NOTHING_SET => '',
79: $resObj->ATTEMPTED => '',
80: $resObj->ANSWER_SUBMITTED => ''
81: );
1.136 bowersj2 82: # And a special case in the nav map; what to do when the assignment
83: # is not yet done and due in less then 24 hours
84: my $hurryUpColor = "#FF0000";
1.130 www 85:
1.268 albertel 86: sub launch_win {
87: my ($mode,$script)=@_;
88: my $result;
89: if ($script ne 'no') {
90: $result.='<script type="text/javascript">';
91: }
92: $result.='function launch_navmapwin() {
93: newWindow=open(\'/adm/navmaps?launchExternal\',\'loncapanav\',\'width=400,height=600,scrollbars=1\');
94: }';
95: if ($mode eq 'now') {
96: $result.="\nlaunch_navmapwin();\n";
97: }
98: if ($script ne 'no') {
99: $result.='</script>';
100: }
101: if ($mode eq 'link') {
102: $result.='<a href="javascript:launch_navmapwin();void(0);">'
1.276 ! albertel 103: .&mt("Launch navigation window")."</a> ";
1.268 albertel 104: }
105: return $result;
106: }
107:
1.269 albertel 108: sub close {
109: if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
110: return(<<ENDCLOSE);
111: <script type="text/javascript">
112: window.status='Accessing Nav Control';
113: menu=window.open("/adm/rat/empty.html","loncapanav",
114: "height=600,width=400,scrollbars=1");
115: window.status='Closing Nav Control';
116: menu.close();
117: window.status='Done.';
118: </script>
119: ENDCLOSE
120: }
1.268 albertel 121:
1.270 albertel 122: sub update {
123: if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
124: if (!$ENV{'request.course.id'}) { return ''; }
125: if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; }
126: return(<<ENDUPDATE);
127: <form name="navform"></form>
128: <script type="text/javascript">
129: this.document.navform.action='/adm/navmaps#curloc';
130: this.document.navform.target='loncapanav';
131: this.document.navform.submit();
132: </script>
133: ENDUPDATE
134: }
1.268 albertel 135:
1.1 www 136: sub handler {
1.99 bowersj2 137: my $r = shift;
1.118 bowersj2 138: real_handler($r);
139: }
140:
141: sub real_handler {
142: my $r = shift;
1.2 www 143:
1.51 bowersj2 144: # Handle header-only request
145: if ($r->header_only) {
146: if ($ENV{'browser.mathml'}) {
1.232 www 147: &Apache::loncommon::content_type($r,'text/xml');
1.51 bowersj2 148: } else {
1.232 www 149: &Apache::loncommon::content_type($r,'text/html');
1.51 bowersj2 150: }
151: $r->send_http_header;
152: return OK;
153: }
154:
155: # Send header, don't cache this page
156: if ($ENV{'browser.mathml'}) {
1.232 www 157: &Apache::loncommon::content_type($r,'text/xml');
1.51 bowersj2 158: } else {
1.232 www 159: &Apache::loncommon::content_type($r,'text/html');
1.51 bowersj2 160: }
161: &Apache::loncommon::no_cache($r);
162: $r->send_http_header;
163:
1.268 albertel 164: if ($ENV{QUERY_STRING} eq 'collapseExternal') {
165: &Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
166: &Apache::lonnet::appenv('environment.remotenavmap' => 'off');
1.275 albertel 167: my $menu=&Apache::lonmenu::reopenmenu();
168: my $navstatus=&Apache::lonmenu::get_nav_status();
169: if ($menu) {
170: $menu=(<<MENU)
171: swmenu=$menu
172: swmenu.clearTimeout(swmenu.menucltim);
173: $navstatus
174: MENU
175: }
1.268 albertel 176: $r->print(<<"ENDSUBM");
177: <html>
178: <head>
179: <script type="text/javascript">
180: function submitthis() {
1.275 albertel 181: $menu
1.268 albertel 182: self.close();
183: }
1.275 albertel 184:
1.268 albertel 185: </script>
186: </head>
187: <body bgcolor="#FFFFFF" onLoad="submitthis()"></body>
188: </html>
189: ENDSUBM
190: return;
191: }
192: if ($ENV{QUERY_STRING} eq 'launchExternal') {
193: &Apache::lonnet::put('environment',{'remotenavmap' => 'on'});
194: &Apache::lonnet::appenv('environment.remotenavmap' => 'on');
195: }
196:
1.106 bowersj2 197: # Create the nav map
1.221 bowersj2 198: my $navmap = Apache::lonnavmaps::navmap->new();
1.51 bowersj2 199:
1.55 bowersj2 200: if (!defined($navmap)) {
201: my $requrl = $r->uri;
202: $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
203: return HTTP_NOT_ACCEPTABLE;
204: }
1.64 bowersj2 205:
1.111 bowersj2 206: $r->print("<html><head>\n");
1.229 www 207: $r->print("<title>".&mt('Navigate Course Contents')."</title>");
1.150 www 208: # ------------------------------------------------------------ Get query string
1.276 ! albertel 209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort','showOnlyHomework']);
1.158 bowersj2 210:
1.150 www 211: # ----------------------------------------------------- Force menu registration
212: my $addentries='';
1.268 albertel 213: my $more_unload;
214: if ($ENV{'environment.remotenavmap'} eq 'on') {
215: $r->print('<script type="text/javascript">
216: function collapse() {
217: this.document.location="/adm/navmaps?collapseExternal";
218: }
219: </script>');
220: # FIXME need to be smarter to only catch window close events
221: # $more_unload="collapse()"
222: }
1.150 www 223: if ($ENV{'form.register'}) {
1.268 albertel 224: $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
225: '" onUnload="'.&Apache::lonmenu::unloadevents().';'.
226: $more_unload.'"';
227: $r->print(&Apache::lonmenu::registerurl(1));
228: } else {
229: $addentries=' onUnload="'.$more_unload.'"';
1.150 www 230: }
1.111 bowersj2 231:
1.64 bowersj2 232: # Header
1.150 www 233: $r->print('</head>'.
234: &Apache::loncommon::bodytag('Navigate Course Contents','',
1.151 www 235: $addentries,'','',$ENV{'form.register'}));
1.262 www 236: $r->print('<script>window.focus();</script>'.
1.265 albertel 237: &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT'));
238:
1.124 bowersj2 239: $r->rflush();
240:
1.55 bowersj2 241: # Check that it's defined
242: if (!($navmap->courseMapDefined())) {
243: $r->print('<font size="+2" color="red">Coursemap undefined.</font>' .
244: '</body></html>');
245: return OK;
246: }
247:
1.178 bowersj2 248: # See if there's only one map in the top-level, if we don't
249: # already have a filter... if so, automatically display it
1.222 bowersj2 250: # (older code; should use retrieveResources)
1.179 bowersj2 251: if ($ENV{QUERY_STRING} !~ /filter/) {
1.178 bowersj2 252: my $iterator = $navmap->getIterator(undef, undef, undef, 0);
1.222 bowersj2 253: my $curRes;
1.178 bowersj2 254: my $sequenceCount = 0;
255: my $sequenceId;
1.222 bowersj2 256: while ($curRes = $iterator->next()) {
1.178 bowersj2 257: if (ref($curRes) && $curRes->is_sequence()) {
258: $sequenceCount++;
259: $sequenceId = $curRes->map_pc();
1.179 bowersj2 260: }
1.178 bowersj2 261: }
262:
263: if ($sequenceCount == 1) {
264: # The automatic iterator creation in the render call
265: # will pick this up. We know the condition because
266: # the defined($ENV{'form.filter'}) also ensures this
267: # is a fresh call.
268: $ENV{'form.filter'} = "$sequenceId";
1.155 bowersj2 269: }
270: }
271:
1.268 albertel 272: if ($ENV{QUERY_STRING} eq 'launchExternal') {
273: $r->print('
274: <form name="returnwin" action="/adm/flip?postdata=return%3a"
275: method="post" target="loncapaclient">
276: </form>');
277: $r->print('
278: <script type="text/javascript">
279: this.document.returnwin.submit();
280: </script>');
281: }
282:
283: if ($ENV{'environment.remotenavmap'} ne 'on') {
284: $r->print(&launch_win('link','yes'));
285: }
286: if ($ENV{'environment.remotenavmap'} eq 'on') {
287: # $r->print("<a href='navmaps?collapseExternal'>" .
288: $r->print("<a href='javascript:collapse();void(0);'>" .
1.276 ! albertel 289: &mt("Close navigation window").
1.268 albertel 290: "</a> ");
291: }
292:
1.191 bowersj2 293: my $jumpToFirstHomework = 0;
1.184 bowersj2 294: # Check to see if the student is jumping to next open, do-able problem
295: if ($ENV{QUERY_STRING} eq 'jumpToFirstHomework') {
1.191 bowersj2 296: $jumpToFirstHomework = 1;
1.184 bowersj2 297: # Find the next homework problem that they can do.
298: my $iterator = $navmap->getIterator(undef, undef, undef, 1);
1.222 bowersj2 299: my $curRes;
1.184 bowersj2 300: my $foundDoableProblem = 0;
301: my $problemRes;
302:
1.222 bowersj2 303: while (($curRes = $iterator->next()) && !$foundDoableProblem) {
1.184 bowersj2 304: if (ref($curRes) && $curRes->is_problem()) {
305: my $status = $curRes->status();
1.191 bowersj2 306: if ($curRes->completable()) {
1.184 bowersj2 307: $problemRes = $curRes;
308: $foundDoableProblem = 1;
309:
310: # Pop open all previous maps
311: my $stack = $iterator->getStack();
312: pop @$stack; # last resource in the stack is the problem
313: # itself, which we don't need in the map stack
314: my @mapPcs = map {$_->map_pc()} @$stack;
315: $ENV{'form.filter'} = join(',', @mapPcs);
316:
317: # Mark as both "here" and "jump"
318: $ENV{'form.postsymb'} = $curRes->symb();
319: }
320: }
321: }
322:
323: # If we found no problems, print a note to that effect.
324: if (!$foundDoableProblem) {
325: $r->print("<font size='+2'>All homework assignments have been completed.</font><br /><br />");
326: }
327: } else {
328: $r->print("<a href='navmaps?jumpToFirstHomework'>" .
1.229 www 329: &mt("Go To My First Homework Problem")."</a> ");
1.184 bowersj2 330: }
331:
1.191 bowersj2 332: my $suppressEmptySequences = 0;
333: my $filterFunc = undef;
1.201 bowersj2 334: my $resource_no_folder_link = 0;
335:
1.191 bowersj2 336: # Display only due homework.
337: my $showOnlyHomework = 0;
1.276 ! albertel 338: if ($ENV{'form.showOnlyHomework'} eq "1") {
1.191 bowersj2 339: $showOnlyHomework = 1;
340: $suppressEmptySequences = 1;
341: $filterFunc = sub { my $res = shift;
1.201 bowersj2 342: return $res->completable() || $res->is_map();
1.191 bowersj2 343: };
1.276 ! albertel 344: $r->print("<a href='navmaps?sort=$ENV{'form.sort'}'>" .
! 345: &mt("Show Everything")."</a> ");
1.229 www 346: $r->print("<p><font size='+2'>".&mt("Uncompleted Homework")."</font></p>");
1.191 bowersj2 347: $ENV{'form.filter'} = '';
348: $ENV{'form.condition'} = 1;
1.201 bowersj2 349: $resource_no_folder_link = 1;
1.191 bowersj2 350: } else {
1.276 ! albertel 351: $r->print("<a href='navmaps?sort=$ENV{'form.sort'}&showOnlyHomework=1'>" .
1.229 www 352: &mt("Show Only Uncompleted Homework")."</a> ");
1.191 bowersj2 353: }
354:
1.276 ! albertel 355: my %selected=($ENV{'form.sort'} => 'selected=on');
! 356: my $sort_html=("<form>
1.270 albertel 357: <nobr>
1.276 ! albertel 358: <input type=\"hidden\" name=\"showOnlyHomework\" value=\"".$ENV{'form.showOnlyHomework'}."\" />
! 359: <input type=\"submit\" value=\"".&mt('Sort by:')."\" />
1.270 albertel 360: <select name=\"sort\">
1.276 ! albertel 361: <option value=\"default\" $selected{'default'}>".&mt('Default')."</option>
! 362: <option value=\"title\" $selected{'title'} >".&mt('Title')."</option>
! 363: <option value=\"duedate\" $selected{'duedate'}>".&mt('Duedate')."</option>
1.270 albertel 364: </select>
365: </nobr>
366: </form>");
1.133 bowersj2 367: # renderer call
1.270 albertel 368: my $renderArgs = { 'cols' => [0,2,3],
369: 'sort' => $ENV{'form.sort'},
1.191 bowersj2 370: 'url' => '/adm/navmaps',
371: 'navmap' => $navmap,
372: 'suppressNavmap' => 1,
373: 'suppressEmptySequences' => $suppressEmptySequences,
374: 'filterFunc' => $filterFunc,
1.201 bowersj2 375: 'resource_no_folder_link' => $resource_no_folder_link,
1.276 ! albertel 376: 'sort_html'=> $sort_html,
1.191 bowersj2 377: 'r' => $r};
378: my $render = render($renderArgs);
379: $navmap->untieHashes();
1.133 bowersj2 380:
1.191 bowersj2 381: # If no resources were printed, print a reassuring message so the
382: # user knows there was no error.
383: if ($renderArgs->{'counter'} == 0) {
384: if ($showOnlyHomework) {
1.229 www 385: $r->print("<p><font size='+1'>".&mt("All homework is currently completed").".</font></p>");
1.191 bowersj2 386: } else { # both jumpToFirstHomework and normal use the same: course must be empty
387: $r->print("<p><font size='+1'>This course is empty.</font></p>");
388: }
389: }
1.51 bowersj2 390:
1.128 bowersj2 391: $r->print("</body></html>");
1.134 bowersj2 392: $r->rflush();
1.59 bowersj2 393:
1.51 bowersj2 394: return OK;
395: }
396:
397: # Convenience functions: Returns a string that adds or subtracts
398: # the second argument from the first hash, appropriate for the
399: # query string that determines which folders to recurse on
400: sub addToFilter {
401: my $hashIn = shift;
402: my $addition = shift;
403: my %hash = %$hashIn;
404: $hash{$addition} = 1;
405:
406: return join (",", keys(%hash));
407: }
408:
409: sub removeFromFilter {
410: my $hashIn = shift;
411: my $subtraction = shift;
412: my %hash = %$hashIn;
413:
414: delete $hash{$subtraction};
415: return join(",", keys(%hash));
416: }
417:
418: # Convenience function: Given a stack returned from getStack on the iterator,
419: # return the correct src() value.
420: # Later, this should add an anchor when we start putting anchors in pages.
421: sub getLinkForResource {
422: my $stack = shift;
423: my $res;
424:
425: # Check to see if there are any pages in the stack
426: foreach $res (@$stack) {
1.248 www 427: if (defined($res)) {
428: if ($res->is_page()) {
429: return $res->src();
430: }
431: # in case folder was skipped over as "only sequence"
432: my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
433: if ($map=~/\.page$/) {
1.249 www 434: return &Apache::lonnet::clutter($map).'#'.
435: &Apache::lonnet::escape(&Apache::lonnet::declutter($src));
1.248 www 436: }
1.51 bowersj2 437: }
438: }
439:
440: # Failing that, return the src of the last resource that is defined
441: # (when we first recurse on a map, it puts an undefined resource
442: # on the bottom because $self->{HERE} isn't defined yet, and we
443: # want the src for the map anyhow)
444: foreach (@$stack) {
445: if (defined($_)) { $res = $_; }
446: }
447:
448: return $res->src();
449: }
450:
1.251 www 451: # Convenience function: This separates the logic of how to create
1.53 bowersj2 452: # the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
1.251 www 453: # etc.) into a separate function. It takes a resource object as the
1.53 bowersj2 454: # first parameter, and the part number of the resource as the second.
455: # It's basically a big switch statement on the status of the resource.
456:
457: sub getDescription {
458: my $res = shift;
459: my $part = shift;
1.69 bowersj2 460: my $status = $res->status($part);
1.53 bowersj2 461:
1.182 bowersj2 462: if ($status == $res->NETWORK_FAILURE) {
1.229 www 463: return &mt("Having technical difficulties; please check status later");
1.182 bowersj2 464: }
1.53 bowersj2 465: if ($status == $res->NOTHING_SET) {
1.229 www 466: return &mt("Not currently assigned.");
1.53 bowersj2 467: }
468: if ($status == $res->OPEN_LATER) {
1.73 bowersj2 469: return "Open " . timeToHumanString($res->opendate($part));
1.53 bowersj2 470: }
471: if ($status == $res->OPEN) {
1.79 bowersj2 472: if ($res->duedate($part)) {
1.229 www 473: return &mt("Due")." " .timeToHumanString($res->duedate($part));
1.66 bowersj2 474: } else {
1.229 www 475: return &mt("Open, no due date");
1.66 bowersj2 476: }
1.53 bowersj2 477: }
1.54 bowersj2 478: if ($status == $res->PAST_DUE_ANSWER_LATER) {
1.229 www 479: return &mt("Answer open")." " . timeToHumanString($res->answerdate($part));
1.54 bowersj2 480: }
481: if ($status == $res->PAST_DUE_NO_ANSWER) {
1.229 www 482: return &mt("Was due")." " . timeToHumanString($res->duedate($part));
1.53 bowersj2 483: }
484: if ($status == $res->ANSWER_OPEN) {
1.229 www 485: return &mt("Answer available");
1.53 bowersj2 486: }
1.59 bowersj2 487: if ($status == $res->EXCUSED) {
1.229 www 488: return &mt("Excused by instructor");
1.59 bowersj2 489: }
1.69 bowersj2 490: if ($status == $res->ATTEMPTED) {
1.229 www 491: return &mt("Answer submitted, not yet graded");
1.69 bowersj2 492: }
1.59 bowersj2 493: if ($status == $res->TRIES_LEFT) {
1.79 bowersj2 494: my $tries = $res->tries($part);
495: my $maxtries = $res->maxtries($part);
496: my $triesString = "";
497: if ($tries && $maxtries) {
498: $triesString = "<font size=\"-1\"><i>($tries of $maxtries tries used)</i></font>";
499: if ($maxtries > 1 && $maxtries - $tries == 1) {
500: $triesString = "<b>$triesString</b>";
501: }
502: }
1.244 albertel 503: if ($res->duedate($part)) {
1.229 www 504: return &mt("Due")." " . timeToHumanString($res->duedate($part)) .
1.66 bowersj2 505: " $triesString";
506: } else {
1.229 www 507: return &mt("No due date")." $triesString";
1.66 bowersj2 508: }
1.59 bowersj2 509: }
1.185 bowersj2 510: if ($status == $res->ANSWER_SUBMITTED) {
1.229 www 511: return &mt('Answer submitted');
1.185 bowersj2 512: }
1.53 bowersj2 513: }
514:
1.115 bowersj2 515: # Convenience function, so others can use it: Is the problem due in less then
516: # 24 hours, and still can be done?
517:
1.252 matthew 518: sub dueInLessThan24Hours {
1.115 bowersj2 519: my $res = shift;
520: my $part = shift;
521: my $status = $res->status($part);
522:
1.207 bowersj2 523: return ($status == $res->OPEN() ||
1.115 bowersj2 524: $status == $res->TRIES_LEFT()) &&
1.244 albertel 525: $res->duedate($part) && $res->duedate($part) < time()+(24*60*60) &&
526: $res->duedate($part) > time();
1.115 bowersj2 527: }
528:
529: # Convenience function, so others can use it: Is there only one try remaining for the
530: # part, with more then one try to begin with, not due yet and still can be done?
531: sub lastTry {
532: my $res = shift;
533: my $part = shift;
534:
535: my $tries = $res->tries($part);
536: my $maxtries = $res->maxtries($part);
537: return $tries && $maxtries && $maxtries > 1 &&
1.244 albertel 538: $maxtries - $tries == 1 && $res->duedate($part) &&
539: $res->duedate($part) > time();
1.115 bowersj2 540: }
541:
1.101 bowersj2 542: # This puts a human-readable name on the ENV variable.
1.177 www 543:
1.68 bowersj2 544: sub advancedUser {
1.177 www 545: return $ENV{'request.role.adv'};
1.68 bowersj2 546: }
547:
1.73 bowersj2 548:
549: # timeToHumanString takes a time number and converts it to a
550: # human-readable representation, meant to be used in the following
551: # manner:
552: # print "Due $timestring"
553: # print "Open $timestring"
554: # print "Answer available $timestring"
555: # Very, very, very, VERY English-only... goodness help a localizer on
556: # this func...
1.53 bowersj2 557: sub timeToHumanString {
1.58 albertel 558: my ($time) = @_;
559: # zero, '0' and blank are bad times
1.73 bowersj2 560: if (!$time) {
1.229 www 561: return &mt('never');
1.73 bowersj2 562: }
1.231 www 563: unless (&Apache::lonlocal::current_language()=~/^en/) {
1.237 www 564: return &Apache::lonlocal::locallocaltime($time);
1.229 www 565: }
1.73 bowersj2 566: my $now = time();
567:
568: my @time = localtime($time);
569: my @now = localtime($now);
570:
571: # Positive = future
572: my $delta = $time - $now;
573:
574: my $minute = 60;
575: my $hour = 60 * $minute;
576: my $day = 24 * $hour;
577: my $week = 7 * $day;
578: my $inPast = 0;
579:
580: # Logic in comments:
581: # Is it now? (extremely unlikely)
582: if ( $delta == 0 ) {
583: return "this instant";
584: }
585:
586: if ($delta < 0) {
587: $inPast = 1;
588: $delta = -$delta;
589: }
590:
591: if ( $delta > 0 ) {
1.101 bowersj2 592:
1.73 bowersj2 593: my $tense = $inPast ? " ago" : "";
594: my $prefix = $inPast ? "" : "in ";
1.101 bowersj2 595:
596: # Less then a minute
1.73 bowersj2 597: if ( $delta < $minute ) {
598: if ($delta == 1) { return "${prefix}1 second$tense"; }
599: return "$prefix$delta seconds$tense";
600: }
601:
1.101 bowersj2 602: # Less then an hour
1.73 bowersj2 603: if ( $delta < $hour ) {
604: # If so, use minutes
605: my $minutes = floor($delta / 60);
606: if ($minutes == 1) { return "${prefix}1 minute$tense"; }
607: return "$prefix$minutes minutes$tense";
608: }
609:
610: # Is it less then 24 hours away? If so,
611: # display hours + minutes
612: if ( $delta < $hour * 24) {
613: my $hours = floor($delta / $hour);
614: my $minutes = floor(($delta % $hour) / $minute);
615: my $hourString = "$hours hours";
616: my $minuteString = ", $minutes minutes";
617: if ($hours == 1) {
618: $hourString = "1 hour";
619: }
620: if ($minutes == 1) {
621: $minuteString = ", 1 minute";
622: }
623: if ($minutes == 0) {
624: $minuteString = "";
625: }
626: return "$prefix$hourString$minuteString$tense";
627: }
628:
629: # Less then 5 days away, display day of the week and
630: # HH:MM
631: if ( $delta < $day * 5 ) {
1.85 bowersj2 632: my $timeStr = strftime("%A, %b %e at %I:%M %P", localtime($time));
1.238 albertel 633: $timeStr =~ s/12:00 am/00:00/;
1.73 bowersj2 634: $timeStr =~ s/12:00 pm/noon/;
635: return ($inPast ? "last " : "next ") .
636: $timeStr;
637: }
638:
639: # Is it this year?
640: if ( $time[5] == $now[5]) {
641: # Return on Month Day, HH:MM meridian
642: my $timeStr = strftime("on %A, %b %e at %I:%M %P", localtime($time));
1.238 albertel 643: $timeStr =~ s/12:00 am/00:00/;
1.73 bowersj2 644: $timeStr =~ s/12:00 pm/noon/;
645: return $timeStr;
646: }
647:
648: # Not this year, so show the year
649: my $timeStr = strftime("on %A, %b %e %G at %I:%M %P", localtime($time));
1.238 albertel 650: $timeStr =~ s/12:00 am/00:00/;
1.73 bowersj2 651: $timeStr =~ s/12:00 pm/noon/;
652: return $timeStr;
1.58 albertel 653: }
1.53 bowersj2 654: }
655:
1.51 bowersj2 656:
1.133 bowersj2 657: =pod
658:
1.174 albertel 659: =head1 NAME
660:
1.217 bowersj2 661: Apache::lonnavmap - Subroutines to handle and render the navigation
662: maps
1.174 albertel 663:
664: =head1 SYNOPSIS
665:
666: The main handler generates the navigational listing for the course,
667: the other objects export this information in a usable fashion for
1.205 bowersj2 668: other modules.
1.133 bowersj2 669:
1.216 bowersj2 670: =head1 OVERVIEW
671:
1.217 bowersj2 672: X<lonnavmaps, overview> When a user enters a course, LON-CAPA examines the
1.218 bowersj2 673: course structure and caches it in what is often referred to as the
674: "big hash" X<big hash>. You can see it if you are logged into
675: LON-CAPA, in a course, by going to /adm/test. (You may need to
676: tweak the /home/httpd/lonTabs/htpasswd file to view it.) The
677: content of the hash will be under the heading "Big Hash".
1.216 bowersj2 678:
679: Big Hash contains, among other things, how resources are related
680: to each other (next/previous), what resources are maps, which
681: resources are being chosen to not show to the student (for random
682: selection), and a lot of other things that can take a lot of time
683: to compute due to the amount of data that needs to be collected and
684: processed.
685:
686: Apache::lonnavmaps provides an object model for manipulating this
687: information in a higher-level fashion then directly manipulating
688: the hash. It also provides access to several auxilary functions
689: that aren't necessarily stored in the Big Hash, but are a per-
690: resource sort of value, like whether there is any feedback on
691: a given resource.
692:
693: Apache::lonnavmaps also abstracts away branching, and someday,
694: conditions, for the times where you don't really care about those
695: things.
696:
697: Apache::lonnavmaps also provides fairly powerful routines for
698: rendering navmaps, and last but not least, provides the navmaps
699: view for when the user clicks the NAV button.
700:
701: B<Note>: Apache::lonnavmaps I<only> works for the "currently
702: logged in user"; if you want things like "due dates for another
703: student" lonnavmaps can not directly retrieve information like
704: that. You need the EXT function. This module can still help,
705: because many things, such as the course structure, are constant
706: between users, and Apache::lonnavmaps can help by providing
707: symbs for the EXT call.
708:
709: The rest of this file will cover the provided rendering routines,
710: which can often be used without fiddling with the navmap object at
711: all, then documents the Apache::lonnavmaps::navmap object, which
712: is the key to accessing the Big Hash information, covers the use
713: of the Iterator (which provides the logic for traversing the
714: somewhat-complicated Big Hash data structure), documents the
715: Apache::lonnavmaps::Resource objects that are returned by
716:
1.205 bowersj2 717: =head1 Subroutine: render
1.133 bowersj2 718:
1.174 albertel 719: The navmap renderer package provides a sophisticated rendering of the
720: standard navigation maps interface into HTML. The provided nav map
721: handler is actually just a glorified call to this.
1.133 bowersj2 722:
1.216 bowersj2 723: Because of the large number of parameters this function accepts,
1.174 albertel 724: instead of passing it arguments as is normal, pass it in an anonymous
1.216 bowersj2 725: hash with the desired options.
1.174 albertel 726:
727: The package provides a function called 'render', called as
1.205 bowersj2 728: Apache::lonnavmaps::render({}).
1.51 bowersj2 729:
1.133 bowersj2 730: =head2 Overview of Columns
1.51 bowersj2 731:
1.174 albertel 732: The renderer will build an HTML table for the navmap and return
733: it. The table is consists of several columns, and a row for each
734: resource (or possibly each part). You tell the renderer how many
735: columns to create and what to place in each column, optionally using
1.205 bowersj2 736: one or more of the prepared columns, and the renderer will assemble
1.174 albertel 737: the table.
738:
739: Any additional generally useful column types should be placed in the
740: renderer code here, so anybody can use it anywhere else. Any code
741: specific to the current application (such as the addition of <input>
742: elements in a column) should be placed in the code of the thing using
743: the renderer.
744:
745: At the core of the renderer is the array reference COLS (see Example
746: section below for how to pass this correctly). The COLS array will
747: consist of entries of one of two types of things: Either an integer
748: representing one of the pre-packaged column types, or a sub reference
749: that takes a resource reference, a part number, and a reference to the
750: argument hash passed to the renderer, and returns a string that will
751: be inserted into the HTML representation as it.
752:
1.216 bowersj2 753: All other parameters are ways of either changing how the columns
754: are printing, or which rows are shown.
755:
1.174 albertel 756: The pre-packaged column names are refered to by constants in the
1.205 bowersj2 757: Apache::lonnavmaps namespace. The following currently exist:
1.51 bowersj2 758:
1.174 albertel 759: =over 4
1.51 bowersj2 760:
1.216 bowersj2 761: =item * B<Apache::lonnavmaps::resource>:
1.51 bowersj2 762:
1.174 albertel 763: The general info about the resource: Link, icon for the type, etc. The
1.216 bowersj2 764: first column in the standard nav map display. This column provides the
765: indentation effect seen in the B<NAV> screen. This column also accepts
1.205 bowersj2 766: the following parameters in the renderer hash:
1.51 bowersj2 767:
1.133 bowersj2 768: =over 4
1.51 bowersj2 769:
1.216 bowersj2 770: =item * B<resource_nolink>: default false
1.51 bowersj2 771:
1.216 bowersj2 772: If true, the resource will not be linked. By default, all non-folder
773: resources are linked.
1.174 albertel 774:
1.216 bowersj2 775: =item * B<resource_part_count>: default true
1.51 bowersj2 776:
1.216 bowersj2 777: If true, the resource will show a part count B<if> the full
778: part list is not displayed. (See "condense_parts" later.) If false,
779: the resource will never show a part count.
1.133 bowersj2 780:
1.174 albertel 781: =item * B<resource_no_folder_link>:
1.133 bowersj2 782:
1.174 albertel 783: If true, the resource's folder will not be clickable to open or close
784: it. Default is false. True implies printCloseAll is false, since you
785: can't close or open folders when this is on anyhow.
1.144 bowersj2 786:
1.133 bowersj2 787: =back
1.51 bowersj2 788:
1.225 bowersj2 789: =item * B<Apache::lonnavmaps::communication_status>:
1.174 albertel 790:
791: Whether there is discussion on the resource, email for the user, or
792: (lumped in here) perl errors in the execution of the problem. This is
793: the second column in the main nav map.
794:
1.225 bowersj2 795: =item * B<Apache::lonnavmaps::quick_status>:
1.51 bowersj2 796:
1.216 bowersj2 797: An icon for the status of a problem, with five possible states:
798: Correct, incorrect, open, awaiting grading (for a problem where the
799: computer's grade is suppressed, or the computer can't grade, like
800: essay problem), or none (not open yet, not a problem). The
1.174 albertel 801: third column of the standard navmap.
1.51 bowersj2 802:
1.225 bowersj2 803: =item * B<Apache::lonnavmaps::long_status>:
1.174 albertel 804:
805: A text readout of the details of the current status of the problem,
806: such as "Due in 22 hours". The fourth column of the standard navmap.
1.51 bowersj2 807:
1.225 bowersj2 808: =item * B<Apache::lonnavmaps::part_status_summary>:
809:
810: A text readout summarizing the status of the problem. If it is a
811: single part problem, will display "Correct", "Incorrect",
812: "Not yet open", "Open", "Attempted", or "Error". If there are
813: multiple parts, this will output a string that in HTML will show a
814: status of how many parts are in each status, in color coding, trying
815: to match the colors of the icons within reason.
816:
817: Note this only makes sense if you are I<not> showing parts. If
818: C<showParts> is true (see below), this column will not output
819: anything.
820:
1.133 bowersj2 821: =back
1.51 bowersj2 822:
1.133 bowersj2 823: If you add any others please be sure to document them here.
1.51 bowersj2 824:
1.174 albertel 825: An example of a column renderer that will show the ID number of a
826: resource, along with the part name if any:
1.51 bowersj2 827:
1.133 bowersj2 828: sub {
829: my ($resource, $part, $params) = @_;
830: if ($part) { return '<td>' . $resource->{ID} . ' ' . $part . '</td>'; }
831: return '<td>' . $resource->{ID} . '</td>';
832: }
1.51 bowersj2 833:
1.174 albertel 834: Note these functions are responsible for the TD tags, which allow them
835: to override vertical and horizontal alignment, etc.
1.130 www 836:
1.133 bowersj2 837: =head2 Parameters
1.115 bowersj2 838:
1.217 bowersj2 839: Minimally, you should be
1.174 albertel 840: able to get away with just using 'cols' (to specify the columns
841: shown), 'url' (necessary for the folders to link to the current screen
842: correctly), and possibly 'queryString' if your app calls for it. In
843: that case, maintaining the state of the folders will be done
844: automatically.
1.140 bowersj2 845:
1.133 bowersj2 846: =over 4
1.51 bowersj2 847:
1.216 bowersj2 848: =item * B<iterator>: default: constructs one from %ENV
1.174 albertel 849:
850: A reference to a fresh ::iterator to use from the navmaps. The
851: rendering will reflect the options passed to the iterator, so you can
852: use that to just render a certain part of the course, if you like. If
853: one is not passed, the renderer will attempt to construct one from
854: ENV{'form.filter'} and ENV{'form.condition'} information, plus the
855: 'iterator_map' parameter if any.
856:
1.216 bowersj2 857: =item * B<iterator_map>: default: not used
1.174 albertel 858:
859: If you are letting the renderer do the iterator handling, you can
860: instruct the renderer to render only a particular map by passing it
861: the source of the map you want to process, like
862: '/res/103/jerf/navmap.course.sequence'.
863:
1.216 bowersj2 864: =item * B<navmap>: default: constructs one from %ENV
1.174 albertel 865:
866: A reference to a navmap, used only if an iterator is not passed in. If
867: this is necessary to make an iterator but it is not passed in, a new
868: one will be constructed based on ENV info. This is useful to do basic
869: error checking before passing it off to render.
870:
1.216 bowersj2 871: =item * B<r>: default: must be passed in
1.174 albertel 872:
873: The standard Apache response object. This must be passed to the
874: renderer or the course hash will be locked.
875:
1.216 bowersj2 876: =item * B<cols>: default: empty (useless)
1.174 albertel 877:
878: An array reference
879:
1.216 bowersj2 880: =item * B<showParts>:default true
1.174 albertel 881:
1.216 bowersj2 882: A flag. If true, a line for the resource itself, and a line
1.174 albertel 883: for each part will be displayed. If not, only one line for each
884: resource will be displayed.
885:
1.216 bowersj2 886: =item * B<condenseParts>: default true
1.174 albertel 887:
1.216 bowersj2 888: A flag. If true, if all parts of the problem have the same
1.174 albertel 889: status and that status is Nothing Set, Correct, or Network Failure,
890: then only one line will be displayed for that resource anyhow. If no,
891: all parts will always be displayed. If showParts is 0, this is
892: ignored.
893:
1.216 bowersj2 894: =item * B<jumpCount>: default: determined from %ENV
1.174 albertel 895:
1.216 bowersj2 896: A string identifying the URL to place the anchor 'curloc' at.
897: It is the responsibility of the renderer user to
1.174 albertel 898: ensure that the #curloc is in the URL. By default, determined through
899: the use of the ENV{} 'jump' information, and should normally "just
900: work" correctly.
1.144 bowersj2 901:
1.216 bowersj2 902: =item * B<here>: default: empty string
1.140 bowersj2 903:
1.216 bowersj2 904: A Symb identifying where to place the 'here' marker. The empty
905: string means no marker.
1.92 bowersj2 906:
1.216 bowersj2 907: =item * B<indentString>: default: 25 pixel whitespace image
1.164 bowersj2 908:
1.216 bowersj2 909: A string identifying the indentation string to use.
1.92 bowersj2 910:
1.216 bowersj2 911: =item * B<queryString>: default: empty
1.51 bowersj2 912:
1.174 albertel 913: A string which will be prepended to the query string used when the
1.216 bowersj2 914: folders are opened or closed. You can use this to pass
915: application-specific values.
1.55 bowersj2 916:
1.216 bowersj2 917: =item * B<url>: default: none
1.84 bowersj2 918:
1.174 albertel 919: The url the folders will link to, which should be the current
1.216 bowersj2 920: page. Required if the resource info column is shown, and you
921: are allowing the user to open and close folders.
1.115 bowersj2 922:
1.216 bowersj2 923: =item * B<currentJumpIndex>: default: no jumping
1.55 bowersj2 924:
1.174 albertel 925: Describes the currently-open row number to cause the browser to jump
926: to, because the user just opened that folder. By default, pulled from
927: the Jump information in the ENV{'form.*'}.
1.51 bowersj2 928:
1.216 bowersj2 929: =item * B<printKey>: default: false
1.51 bowersj2 930:
1.174 albertel 931: If true, print the key that appears on the top of the standard
1.216 bowersj2 932: navmaps.
1.139 bowersj2 933:
1.216 bowersj2 934: =item * B<printCloseAll>: default: true
1.140 bowersj2 935:
1.174 albertel 936: If true, print the "Close all folders" or "open all folders"
1.216 bowersj2 937: links.
1.140 bowersj2 938:
1.216 bowersj2 939: =item * B<filterFunc>: default: sub {return 1;} (accept everything)
1.153 bowersj2 940:
1.174 albertel 941: A function that takes the resource object as its only parameter and
942: returns a true or false value. If true, the resource is displayed. If
1.216 bowersj2 943: false, it is simply skipped in the display.
1.174 albertel 944:
1.216 bowersj2 945: =item * B<suppressEmptySequences>: default: false
1.190 bowersj2 946:
947: If you're using a filter function, and displaying sequences to orient
948: the user, then frequently some sequences will be empty. Setting this to
949: true will cause those sequences not to display, so as not to confuse the
950: user into thinking that if the sequence is there there should be things
1.216 bowersj2 951: under it; for example, see the "Show Uncompleted Homework" view on the
952: B<NAV> screen.
1.190 bowersj2 953:
1.216 bowersj2 954: =item * B<suppressNavmaps>: default: false
1.174 albertel 955:
1.216 bowersj2 956: If true, will not display Navigate Content resources.
1.143 bowersj2 957:
1.133 bowersj2 958: =back
1.51 bowersj2 959:
1.133 bowersj2 960: =head2 Additional Info
1.51 bowersj2 961:
1.174 albertel 962: In addition to the parameters you can pass to the renderer, which will
963: be passed through unchange to the column renderers, the renderer will
964: generate the following information which your renderer may find
965: useful:
966:
1.216 bowersj2 967: =over 4
968:
969: =item * B<counter>:
1.145 bowersj2 970:
1.216 bowersj2 971: Contains the number of rows printed. Useful after calling the render
972: function, as you can detect whether anything was printed at all.
973:
974: =item * B<isNewBranch>:
975:
976: Useful for renderers: If this resource is currently the first resource
977: of a new branch, this will be true. The Resource column (leftmost in the
978: navmaps screen) uses this to display the "new branch" icon
1.59 bowersj2 979:
1.133 bowersj2 980: =back
1.59 bowersj2 981:
1.133 bowersj2 982: =cut
1.59 bowersj2 983:
1.133 bowersj2 984: sub resource { return 0; }
985: sub communication_status { return 1; }
986: sub quick_status { return 2; }
987: sub long_status { return 3; }
1.225 bowersj2 988: sub part_status_summary { return 4; }
1.51 bowersj2 989:
1.133 bowersj2 990: sub render_resource {
991: my ($resource, $part, $params) = @_;
1.51 bowersj2 992:
1.133 bowersj2 993: my $nonLinkedText = ''; # stuff after resource title not in link
1.51 bowersj2 994:
1.134 bowersj2 995: my $link = $params->{"resourceLink"};
996: my $src = $resource->src();
997: my $it = $params->{"iterator"};
1.133 bowersj2 998: my $filter = $it->{FILTER};
999:
1000: my $title = $resource->compTitle();
1.258 albertel 1001:
1.133 bowersj2 1002: my $partLabel = "";
1003: my $newBranchText = "";
1004:
1005: # If this is a new branch, label it so
1006: if ($params->{'isNewBranch'}) {
1007: $newBranchText = "<img src='/adm/lonIcons/branch.gif' border='0' />";
1.51 bowersj2 1008: }
1009:
1.133 bowersj2 1010: # links to open and close the folder
1011: my $linkopen = "<a href='$link'>";
1012: my $linkclose = "</a>";
1.51 bowersj2 1013:
1.204 albertel 1014: # Default icon: unknown page
1015: my $icon = "<img src='/adm/lonIcons/unknown.gif' alt='' border='0' />";
1.133 bowersj2 1016:
1017: if ($resource->is_problem()) {
1.192 bowersj2 1018: if ($part eq '0' || $params->{'condensed'}) {
1.133 bowersj2 1019: $icon = '<img src="/adm/lonIcons/problem.gif" alt="" border="0" />';
1020: } else {
1021: $icon = $params->{'indentString'};
1022: }
1.204 albertel 1023: } else {
1.243 albertel 1024: $icon = "<img src='".&Apache::loncommon::icon($resource->src).
1025: "' alt='' border='0' />";
1.133 bowersj2 1026: }
1.51 bowersj2 1027:
1.133 bowersj2 1028: # Display the correct map icon to open or shut map
1029: if ($resource->is_map()) {
1030: my $mapId = $resource->map_pc();
1031: my $nowOpen = !defined($filter->{$mapId});
1032: if ($it->{CONDITION}) {
1033: $nowOpen = !$nowOpen;
1034: }
1.144 bowersj2 1035:
1.205 bowersj2 1036: my $folderType = $resource->is_sequence() ? 'folder' : 'page';
1037:
1.144 bowersj2 1038: if (!$params->{'resource_no_folder_link'}) {
1.205 bowersj2 1039: $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
1.144 bowersj2 1040: $icon = "<img src='/adm/lonIcons/$icon' alt='' border='0' />";
1041:
1042: $linkopen = "<a href='" . $params->{'url'} . '?' .
1043: $params->{'queryString'} . '&filter=';
1044: $linkopen .= ($nowOpen xor $it->{CONDITION}) ?
1045: addToFilter($filter, $mapId) :
1046: removeFromFilter($filter, $mapId);
1047: $linkopen .= "&condition=" . $it->{CONDITION} . '&hereType='
1048: . $params->{'hereType'} . '&here=' .
1049: &Apache::lonnet::escape($params->{'here'}) .
1.159 bowersj2 1050: '&jump=' .
1.144 bowersj2 1051: &Apache::lonnet::escape($resource->symb()) .
1052: "&folderManip=1'>";
1053: } else {
1054: # Don't allow users to manipulate folder
1.205 bowersj2 1055: $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') .
1.144 bowersj2 1056: '.nomanip.gif';
1057: $icon = "<img src='/adm/lonIcons/$icon' alt='' border='0' />";
1058:
1059: $linkopen = "";
1060: $linkclose = "";
1061: }
1.133 bowersj2 1062: }
1.51 bowersj2 1063:
1.133 bowersj2 1064: if ($resource->randomout()) {
1065: $nonLinkedText .= ' <i>(hidden)</i> ';
1066: }
1067:
1068: # We're done preparing and finally ready to start the rendering
1069: my $result = "<td align='left' valign='center'>";
1.140 bowersj2 1070:
1071: my $indentLevel = $params->{'indentLevel'};
1072: if ($newBranchText) { $indentLevel--; }
1073:
1.133 bowersj2 1074: # print indentation
1.140 bowersj2 1075: for (my $i = 0; $i < $indentLevel; $i++) {
1.133 bowersj2 1076: $result .= $params->{'indentString'};
1.84 bowersj2 1077: }
1078:
1.133 bowersj2 1079: # Decide what to display
1080: $result .= "$newBranchText$linkopen$icon$linkclose";
1081:
1082: my $curMarkerBegin = '';
1083: my $curMarkerEnd = '';
1.51 bowersj2 1084:
1.133 bowersj2 1085: # Is this the current resource?
1.158 bowersj2 1086: if (!$params->{'displayedHereMarker'} &&
1087: $resource->symb() eq $params->{'here'} ) {
1.133 bowersj2 1088: $curMarkerBegin = '<font color="red" size="+2">> </font>';
1089: $curMarkerEnd = '<font color="red" size="+2"><</font>';
1.158 bowersj2 1090: $params->{'displayedHereMarker'} = 1;
1.51 bowersj2 1091: }
1092:
1.192 bowersj2 1093: if ($resource->is_problem() && $part ne '0' &&
1.133 bowersj2 1094: !$params->{'condensed'}) {
1.274 matthew 1095: my $displaypart=$resource->part_display($part);
1.245 www 1096: $partLabel = " (Part: $displaypart)";
1097: $link.='#'.&Apache::lonnet::escape($part);
1.133 bowersj2 1098: $title = "";
1.51 bowersj2 1099: }
1100:
1.163 bowersj2 1101: if ($params->{'condensed'} && $resource->countParts() > 1) {
1.133 bowersj2 1102: $nonLinkedText .= ' (' . $resource->countParts() . ' parts)';
1.51 bowersj2 1103: }
1104:
1.268 albertel 1105: my $target;
1106: if ($ENV{'environment.remotenavmap'} eq 'on') {
1107: $target=' target="loncapaclient" ';
1108: }
1.266 raeburn 1109: if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
1.268 albertel 1110: $result .= " $curMarkerBegin<a $target href='$link'>$title$partLabel</a>$curMarkerEnd $nonLinkedText</td>";
1.144 bowersj2 1111: } else {
1112: $result .= " $curMarkerBegin$title$partLabel$curMarkerEnd $nonLinkedText</td>";
1113: }
1.51 bowersj2 1114:
1.133 bowersj2 1115: return $result;
1116: }
1.51 bowersj2 1117:
1.133 bowersj2 1118: sub render_communication_status {
1119: my ($resource, $part, $params) = @_;
1.134 bowersj2 1120: my $discussionHTML = ""; my $feedbackHTML = ""; my $errorHTML = "";
1121:
1122: my $link = $params->{"resourceLink"};
1123: my $linkopen = "<a href='$link'>";
1124: my $linkclose = "</a>";
1125:
1126: if ($resource->hasDiscussion()) {
1127: $discussionHTML = $linkopen .
1128: '<img border="0" src="/adm/lonMisc/chat.gif" />' .
1129: $linkclose;
1130: }
1131:
1132: if ($resource->getFeedback()) {
1133: my $feedback = $resource->getFeedback();
1134: foreach (split(/\,/, $feedback)) {
1135: if ($_) {
1136: $feedbackHTML .= ' <a href="/adm/email?display='
1137: . &Apache::lonnet::escape($_) . '">'
1138: . '<img src="/adm/lonMisc/feedback.gif" '
1139: . 'border="0" /></a>';
1140: }
1141: }
1142: }
1143:
1144: if ($resource->getErrors()) {
1145: my $errors = $resource->getErrors();
1.254 matthew 1146: my $errorcount = 0;
1.134 bowersj2 1147: foreach (split(/,/, $errors)) {
1.254 matthew 1148: last if ($errorcount>=10); # Only output 10 bombs maximum
1.134 bowersj2 1149: if ($_) {
1.254 matthew 1150: $errorcount++;
1.134 bowersj2 1151: $errorHTML .= ' <a href="/adm/email?display='
1152: . &Apache::lonnet::escape($_) . '">'
1153: . '<img src="/adm/lonMisc/bomb.gif" '
1154: . 'border="0" /></a>';
1155: }
1156: }
1.197 bowersj2 1157: }
1158:
1159: if ($params->{'multipart'} && $part != '0') {
1160: $discussionHTML = $feedbackHTML = $errorHTML = '';
1.134 bowersj2 1161: }
1162:
1163: return "<td width=\"75\" align=\"left\" valign=\"center\">$discussionHTML$feedbackHTML$errorHTML </td>";
1164:
1.133 bowersj2 1165: }
1166: sub render_quick_status {
1167: my ($resource, $part, $params) = @_;
1.135 bowersj2 1168: my $result = "";
1169: my $firstDisplayed = !$params->{'condensed'} &&
1170: $params->{'multipart'} && $part eq "0";
1171:
1172: my $link = $params->{"resourceLink"};
1173: my $linkopen = "<a href='$link'>";
1174: my $linkclose = "</a>";
1175:
1176: if ($resource->is_problem() &&
1177: !$firstDisplayed) {
1.224 bowersj2 1178:
1179: my $icon = $statusIconMap{$resource->simpleStatus($part)};
1.135 bowersj2 1180: my $alt = $iconAltTags{$icon};
1181: if ($icon) {
1182: $result .= "<td width='30' valign='center' width='50' align='right'>$linkopen<img width='25' height='25' src='/adm/lonIcons/$icon' border='0' alt='$alt' />$linkclose</td>\n";
1183: } else {
1184: $result .= "<td width='30'> </td>\n";
1185: }
1186: } else { # not problem, no icon
1187: $result .= "<td width='30'> </td>\n";
1188: }
1189:
1190: return $result;
1.133 bowersj2 1191: }
1192: sub render_long_status {
1193: my ($resource, $part, $params) = @_;
1.136 bowersj2 1194: my $result = "<td align='right' valign='center'>\n";
1195: my $firstDisplayed = !$params->{'condensed'} &&
1196: $params->{'multipart'} && $part eq "0";
1197:
1198: my $color;
1.212 bowersj2 1199: if ($resource->is_problem()) {
1.136 bowersj2 1200: $color = $colormap{$resource->status};
1201:
1.252 matthew 1202: if (dueInLessThan24Hours($resource, $part) ||
1.136 bowersj2 1203: lastTry($resource, $part)) {
1204: $color = $hurryUpColor;
1205: }
1206: }
1207:
1208: if ($resource->kind() eq "res" &&
1209: $resource->is_problem() &&
1210: !$firstDisplayed) {
1211: if ($color) {$result .= "<font color=\"$color\"><b>"; }
1212: $result .= getDescription($resource, $part);
1213: if ($color) {$result .= "</b></font>"; }
1214: }
1215: if ($resource->is_map() && advancedUser() && $resource->randompick()) {
1216: $result .= '(randomly select ' . $resource->randompick() .')';
1217: }
1.210 bowersj2 1218:
1.213 bowersj2 1219: # Debugging code
1220: #$result .= " " . $resource->awarded($part) . '/' . $resource->weight($part) .
1221: # ' - Part: ' . $part;
1222:
1.210 bowersj2 1223: $result .= "</td>\n";
1.136 bowersj2 1224:
1225: return $result;
1.51 bowersj2 1226: }
1227:
1.227 bowersj2 1228: # Colors obtained by taking the icons, matching the colors, and
1229: # possibly reducing the Value (HSV) of the color, if it's too bright
1230: # for text, generally by one third or so.
1.225 bowersj2 1231: my %statusColors =
1232: (
1233: $resObj->CLOSED => '#000000',
1.227 bowersj2 1234: $resObj->OPEN => '#998b13',
1235: $resObj->CORRECT => '#26933f',
1236: $resObj->INCORRECT => '#c48207',
1237: $resObj->ATTEMPTED => '#a87510',
1.225 bowersj2 1238: $resObj->ERROR => '#000000'
1239: );
1240: my %statusStrings =
1241: (
1242: $resObj->CLOSED => 'Not yet open',
1243: $resObj->OPEN => 'Open',
1244: $resObj->CORRECT => 'Correct',
1245: $resObj->INCORRECT => 'Incorrect',
1246: $resObj->ATTEMPTED => 'Attempted',
1247: $resObj->ERROR => 'Network Error'
1248: );
1249: my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR);
1250:
1251: use Data::Dumper;
1252: sub render_parts_summary_status {
1253: my ($resource, $part, $params) = @_;
1.256 albertel 1254: if (!$resource->is_problem() && !$resource->contains_problem) { return '<td></td>'; }
1.225 bowersj2 1255: if ($params->{showParts}) {
1256: return '<td></td>';
1257: }
1258:
1259: my $td = "<td align='right'>\n";
1260: my $endtd = "</td>\n";
1.256 albertel 1261: my @probs;
1.225 bowersj2 1262:
1.256 albertel 1263: if ($resource->contains_problem) {
1264: @probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
1265: } else {
1266: @probs=($resource);
1267: }
1268: my $return;
1269: my %overallstatus;
1270: my $totalParts;
1271: foreach my $resource (@probs) {
1272: # If there is a single part, just show the simple status
1273: if ($resource->singlepart()) {
1274: my $status = $resource->simpleStatus(${$resource->parts}[0]);
1275: $overallstatus{$status}++;
1276: $totalParts++;
1277: next;
1278: }
1279: # Now we can be sure the $part doesn't really matter.
1280: my $statusCount = $resource->simpleStatusCount();
1281: my @counts;
1282: foreach my $status (@statuses) {
1283: # decouple display order from the simpleStatusCount order
1284: my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
1285: if ($statusCount->[$slot]) {
1286: $overallstatus{$status}+=$statusCount->[$slot];
1287: $totalParts+=$statusCount->[$slot];
1288: }
1289: }
1290: }
1291: $return.= $td . $totalParts . ' parts: ';
1292: foreach my $status (@statuses) {
1293: if ($overallstatus{$status}) {
1294: $return.="<font color='" . $statusColors{$status} .
1295: "'>" . $overallstatus{$status} . ' '
1.225 bowersj2 1296: . $statusStrings{$status} . "</font>";
1297: }
1298: }
1.256 albertel 1299: $return.= $endtd;
1300: return $return;
1.225 bowersj2 1301: }
1302:
1.133 bowersj2 1303: my @preparedColumns = (\&render_resource, \&render_communication_status,
1.225 bowersj2 1304: \&render_quick_status, \&render_long_status,
1305: \&render_parts_summary_status);
1.132 bowersj2 1306:
1307: sub setDefault {
1308: my ($val, $default) = @_;
1309: if (!defined($val)) { return $default; }
1310: return $val;
1311: }
1312:
1313: sub render {
1314: my $args = shift;
1.140 bowersj2 1315: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
1316: my $result = '';
1317:
1.132 bowersj2 1318: # Configure the renderer.
1319: my $cols = $args->{'cols'};
1320: if (!defined($cols)) {
1321: # no columns, no nav maps.
1322: return '';
1323: }
1.140 bowersj2 1324: my $mustCloseNavMap = 0;
1325: my $navmap;
1326: if (defined($args->{'navmap'})) {
1327: $navmap = $args->{'navmap'};
1328: }
1329:
1.158 bowersj2 1330: my $r = $args->{'r'};
1.140 bowersj2 1331: my $queryString = $args->{'queryString'};
1.159 bowersj2 1332: my $jump = $args->{'jump'};
1.158 bowersj2 1333: my $here = $args->{'here'};
1.153 bowersj2 1334: my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
1.256 albertel 1335: my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
1.140 bowersj2 1336: my $currentJumpDelta = 2; # change this to change how many resources are displayed
1337: # before the current resource when using #current
1338:
1339: # If we were passed 'here' information, we are not rendering
1340: # after a folder manipulation, and we were not passed an
1341: # iterator, make sure we open the folders to show the "here"
1342: # marker
1343: my $filterHash = {};
1344: # Figure out what we're not displaying
1345: foreach (split(/\,/, $ENV{"form.filter"})) {
1346: if ($_) {
1347: $filterHash->{$_} = "1";
1348: }
1349: }
1350:
1.191 bowersj2 1351: # Filter: Remember filter function and add our own filter: Refuse
1352: # to show hidden resources unless the user can see them.
1353: my $userCanSeeHidden = advancedUser();
1354: my $filterFunc = setDefault($args->{'filterFunc'},
1355: sub {return 1;});
1356: if (!$userCanSeeHidden) {
1357: # Without renaming the filterfunc, the server seems to go into
1358: # an infinite loop
1359: my $oldFilterFunc = $filterFunc;
1360: $filterFunc = sub { my $res = shift; return !$res->randomout() &&
1361: &$oldFilterFunc($res);};
1362: }
1363:
1.140 bowersj2 1364: my $condition = 0;
1365: if ($ENV{'form.condition'}) {
1366: $condition = 1;
1367: }
1368:
1369: if (!$ENV{'form.folderManip'} && !defined($args->{'iterator'})) {
1370: # Step 1: Check to see if we have a navmap
1371: if (!defined($navmap)) {
1.221 bowersj2 1372: $navmap = Apache::lonnavmaps::navmap->new();
1.140 bowersj2 1373: $mustCloseNavMap = 1;
1374: }
1375:
1376: # Step two: Locate what kind of here marker is necessary
1377: # Determine where the "here" marker is and where the screen jumps to.
1378:
1.175 bowersj2 1379: if ($ENV{'form.postsymb'}) {
1380: $here = $jump = $ENV{'form.postsymb'};
1.140 bowersj2 1381: } elsif ($ENV{'form.postdata'}) {
1382: # couldn't find a symb, is there a URL?
1383: my $currenturl = $ENV{'form.postdata'};
1.158 bowersj2 1384: #$currenturl=~s/^http\:\/\///;
1385: #$currenturl=~s/^[^\/]+//;
1.140 bowersj2 1386:
1.158 bowersj2 1387: $here = $jump = &Apache::lonnet::symbread($currenturl);
1.276 ! albertel 1388: }
1.158 bowersj2 1389:
1.140 bowersj2 1390: # Step three: Ensure the folders are open
1391: my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
1.222 bowersj2 1392: my $curRes;
1.140 bowersj2 1393: my $found = 0;
1394:
1395: # We only need to do this if we need to open the maps to show the
1396: # current position. This will change the counter so we can't count
1397: # for the jump marker with this loop.
1.222 bowersj2 1398: while (($curRes = $mapIterator->next()) && !$found) {
1.158 bowersj2 1399: if (ref($curRes) && $curRes->symb() eq $here) {
1.140 bowersj2 1400: my $mapStack = $mapIterator->getStack();
1401:
1402: # Ensure the parent maps are open
1403: for my $map (@{$mapStack}) {
1404: if ($condition) {
1405: undef $filterHash->{$map->map_pc()};
1406: } else {
1407: $filterHash->{$map->map_pc()} = 1;
1408: }
1409: }
1410: $found = 1;
1411: }
1412: }
1.159 bowersj2 1413: }
1.140 bowersj2 1414:
1415: if ( !defined($args->{'iterator'}) && $ENV{'form.folderManip'} ) { # we came from a user's manipulation of the nav page
1416: # If this is a click on a folder or something, we want to preserve the "here"
1417: # from the querystring, and get the new "jump" marker
1418: $here = $ENV{'form.here'};
1419: $jump = $ENV{'form.jump'};
1420: }
1421:
1.132 bowersj2 1422: my $it = $args->{'iterator'};
1423: if (!defined($it)) {
1.140 bowersj2 1424: # Construct a default iterator based on $ENV{'form.'} information
1425:
1426: # Step 1: Check to see if we have a navmap
1427: if (!defined($navmap)) {
1.221 bowersj2 1428: $navmap = Apache::lonnavmaps::navmap->new();
1.140 bowersj2 1429: $mustCloseNavMap = 1;
1430: }
1431:
1.144 bowersj2 1432: # See if we're being passed a specific map
1433: if ($args->{'iterator_map'}) {
1434: my $map = $args->{'iterator_map'};
1.145 bowersj2 1435: $map = $navmap->getResourceByUrl($map);
1.144 bowersj2 1436: my $firstResource = $map->map_start();
1437: my $finishResource = $map->map_finish();
1438:
1439: $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
1440: } else {
1441: $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition);
1442: }
1.132 bowersj2 1443: }
1.256 albertel 1444:
1.159 bowersj2 1445: # (re-)Locate the jump point, if any
1.191 bowersj2 1446: # Note this does not take filtering or hidden into account... need
1447: # to be fixed?
1.159 bowersj2 1448: my $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0);
1.222 bowersj2 1449: my $curRes;
1.159 bowersj2 1450: my $foundJump = 0;
1451: my $counter = 0;
1452:
1.222 bowersj2 1453: while (($curRes = $mapIterator->next()) && !$foundJump) {
1.159 bowersj2 1454: if (ref($curRes)) { $counter++; }
1455:
1456: if (ref($curRes) && $jump eq $curRes->symb()) {
1457:
1458: # This is why we have to use the main iterator instead of the
1459: # potentially faster DFS: The count has to be the same, so
1460: # the order has to be the same, which DFS won't give us.
1461: $args->{'currentJumpIndex'} = $counter;
1462: $foundJump = 1;
1463: }
1464: }
1465:
1.132 bowersj2 1466: my $showParts = setDefault($args->{'showParts'}, 1);
1467: my $condenseParts = setDefault($args->{'condenseParts'}, 1);
1.139 bowersj2 1468: # keeps track of when the current resource is found,
1469: # so we can back up a few and put the anchor above the
1470: # current resource
1.140 bowersj2 1471: my $printKey = $args->{'printKey'};
1472: my $printCloseAll = $args->{'printCloseAll'};
1473: if (!defined($printCloseAll)) { $printCloseAll = 1; }
1.144 bowersj2 1474:
1.140 bowersj2 1475: # Print key?
1476: if ($printKey) {
1477: $result .= '<table border="0" cellpadding="2" cellspacing="0">';
1478: my $date=localtime;
1479: $result.='<tr><td align="right" valign="bottom">Key: </td>';
1480: if ($navmap->{LAST_CHECK}) {
1481: $result .=
1.230 www 1482: '<img src="/adm/lonMisc/chat.gif"> '.&mt('New discussion since').' '.
1.140 bowersj2 1483: strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
1484: '</td><td align="center" valign="bottom"> '.
1.230 www 1485: '<img src="/adm/lonMisc/feedback.gif"> '.&mt('New message (click to open)').'<p>'.
1.140 bowersj2 1486: '</td>';
1487: } else {
1488: $result .= '<td align="center" valign="bottom"> '.
1.230 www 1489: '<img src="/adm/lonMisc/chat.gif"> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
1490: ' <img src="/adm/lonMisc/feedback.gif"> '.&mt('New message (click to open)').
1.140 bowersj2 1491: '</td>';
1492: }
1493:
1494: $result .= '</tr></table>';
1495: }
1496:
1.172 bowersj2 1497: if ($printCloseAll && !$args->{'resource_no_folder_link'}) {
1.140 bowersj2 1498: if ($condition) {
1499: $result.="<a href=\"navmaps?condition=0&filter=&$queryString" .
1.158 bowersj2 1500: "&here=" . Apache::lonnet::escape($here) .
1.230 www 1501: "\">".&mt('Close All Folders')."</a>";
1.140 bowersj2 1502: } else {
1503: $result.="<a href=\"navmaps?condition=1&filter=&$queryString" .
1.158 bowersj2 1504: "&here=" . Apache::lonnet::escape($here) .
1.230 www 1505: "\">".&mt('Open All Folders')."</a>";
1.140 bowersj2 1506: }
1.266 raeburn 1507: $result .= "\n";
1508: }
1.140 bowersj2 1509:
1.266 raeburn 1510: # Check for any unread discussions in all resources.
1.267 albertel 1511: if (!$args->{'resource_no_folder_link'}) {
1512: my $totdisc = 0;
1513: my $haveDisc = '';
1514: my @allres=$navmap->retrieveResources();
1515: foreach my $resource (@allres) {
1516: if ($resource->hasDiscussion()) {
1517: my $ressymb;
1518: if ($resource->symb() =~ m-(___adm/\w+/\w+)/(\d+)/bulletinboard$-) {
1519: $ressymb = 'bulletin___'.$2.$1.'/'.$2.'/bulletinboard';
1520: } else {
1521: $ressymb = $resource->symb();
1522: }
1523: $haveDisc .= $ressymb.':';
1524: $totdisc ++;
1525: }
1526: }
1527: if ($totdisc > 0) {
1528: $haveDisc =~ s/:$//;
1529: my %lt = &Apache::lonlocal::texthash(
1530: 'mapr' => 'Mark all posts read',
1531: );
1532: $result .= (<<END);
1533: <a href="javascript:document.clearbubbles.submit()">$lt{'mapr'}</a> <a href="javascript:void(open('/adm/help/NavMaps_MarkPosts_Read.hlp', 'Help_for_NavMaps_MarkPosts', 'menubar=0,toolbar=1,scrollbars=1,width=350,height=400,resizable=yes'))" title="Online Help"><image src="/adm/help/gif/smallHelp.gif" border="0" alt="(Help: NavMaps_MarkPostsLink)" /></a>
1534: <form name="clearbubbles" method="post" action="/adm/feedback">
1535: <input type="hidden" name="navurl" value="$ENV{'QUERY_STRING'}" />
1536: <input type="hidden" name="navmaps" value="$haveDisc" />
1537: </form>
1.266 raeburn 1538: END
1.267 albertel 1539: } else {
1540: $result .= '<br />';
1541: }
1.266 raeburn 1542: }
1.276 ! albertel 1543:
! 1544: if ($args->{'sort_html'}) { $result.=$args->{'sort_html'}; }
! 1545:
1.266 raeburn 1546: $result .= "<br />\n";
1.140 bowersj2 1547: if ($r) {
1548: $r->print($result);
1549: $r->rflush();
1550: $result = "";
1551: }
1.132 bowersj2 1552: # End parameter setting
1.133 bowersj2 1553:
1.132 bowersj2 1554: # Data
1.140 bowersj2 1555: $result .= '<table cellspacing="0" cellpadding="3" border="0" bgcolor="#FFFFFF">' ."\n";
1.132 bowersj2 1556: my $res = "Apache::lonnavmaps::resource";
1557: my %condenseStatuses =
1558: ( $res->NETWORK_FAILURE => 1,
1559: $res->NOTHING_SET => 1,
1560: $res->CORRECT => 1 );
1561: my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.133 bowersj2 1562:
1563: # Shared variables
1564: $args->{'counter'} = 0; # counts the rows
1565: $args->{'indentLevel'} = 0;
1566: $args->{'isNewBranch'} = 0;
1567: $args->{'condensed'} = 0;
1568: $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='/adm/lonIcons/whitespace1.gif' width='25' height='1' alt='' border='0' />");
1569: $args->{'displayedHereMarker'} = 0;
1.132 bowersj2 1570:
1.190 bowersj2 1571: # If we're suppressing empty sequences, look for them here. Use DFS for speed,
1572: # since structure actually doesn't matter, except what map has what resources.
1573: if ($args->{'suppressEmptySequences'}) {
1574: my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
1575: $it->{FIRST_RESOURCE},
1576: $it->{FINISH_RESOURCE},
1577: {}, undef, 1);
1.222 bowersj2 1578: my $depth = 0;
1.190 bowersj2 1579: $dfsit->next();
1580: my $curRes = $dfsit->next();
1581: while ($depth > -1) {
1582: if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
1583: if ($curRes == $dfsit->END_MAP()) { $depth--; }
1584:
1585: if (ref($curRes)) {
1586: # Parallel pre-processing: Do sequences have non-filtered-out children?
1.201 bowersj2 1587: if ($curRes->is_map()) {
1.190 bowersj2 1588: $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
1589: # Sequences themselves do not count as visible children,
1590: # unless those sequences also have visible children.
1591: # This means if a sequence appears, there's a "promise"
1592: # that there's something under it if you open it, somewhere.
1593: } else {
1594: # Not a sequence: if it's filtered, ignore it, otherwise
1595: # rise up the stack and mark the sequences as having children
1596: if (&$filterFunc($curRes)) {
1597: for my $sequence (@{$dfsit->getStack()}) {
1598: $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
1599: }
1600: }
1601: }
1602: }
1603: } continue {
1604: $curRes = $dfsit->next();
1605: }
1606: }
1607:
1.133 bowersj2 1608: my $displayedJumpMarker = 0;
1.132 bowersj2 1609: # Set up iteration.
1610: my $now = time();
1611: my $in24Hours = $now + 24 * 60 * 60;
1612: my $rownum = 0;
1613:
1.141 bowersj2 1614: # export "here" marker information
1615: $args->{'here'} = $here;
1616:
1.222 bowersj2 1617: $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
1.270 albertel 1618: my @resources;
1619: my $code='';# sub { !(shift->is_map();) };
1620: if ($args->{'sort'} eq 'title') {
1.276 ! albertel 1621: my $oldFilterFunc = $filterFunc;
! 1622: my $filterFunc=
! 1623: sub {
! 1624: my ($res)=@_;
! 1625: if ($res->is_map()) { return 0;}
! 1626: return &$oldFilterFunc($res);
! 1627: };
! 1628: @resources=$navmap->retrieveResources(undef,$filterFunc);
1.270 albertel 1629: @resources= sort {lc($a->compTitle) cmp lc($b->compTitle)} @resources;
1630: } elsif ($args->{'sort'} eq 'duedate') {
1631: @resources=$navmap->retrieveResources(undef,
1632: sub { shift->is_problem(); });
1633: @resources= sort
1634: {
1635: if ($a->duedate ne $b->duedate) {
1636: return $a->duedate cmp $b->duedate;
1637: } else {
1638: lc($a->compTitle) cmp lc($b->compTitle)
1639: }
1640: } @resources;
1.276 ! albertel 1641: } else {
! 1642: #unknow sort mechanism or default
! 1643: undef($args->{'sort'});
1.270 albertel 1644: }
1645:
1.276 ! albertel 1646:
1.270 albertel 1647: while (1) {
1648: if ($args->{'sort'}) {
1649: $curRes = shift(@resources);
1650: } else {
1651: $curRes = $it->next($closeAllPages);
1652: }
1653: if (!$curRes) { last; }
1654:
1.132 bowersj2 1655: # Maintain indentation level.
1656: if ($curRes == $it->BEGIN_MAP() ||
1657: $curRes == $it->BEGIN_BRANCH() ) {
1.133 bowersj2 1658: $args->{'indentLevel'}++;
1.132 bowersj2 1659: }
1660: if ($curRes == $it->END_MAP() ||
1661: $curRes == $it->END_BRANCH() ) {
1.133 bowersj2 1662: $args->{'indentLevel'}--;
1.132 bowersj2 1663: }
1664: # Notice new branches
1665: if ($curRes == $it->BEGIN_BRANCH()) {
1.133 bowersj2 1666: $args->{'isNewBranch'} = 1;
1667: }
1668:
1669: # If this isn't an actual resource, continue on
1670: if (!ref($curRes)) {
1671: next;
1.132 bowersj2 1672: }
1.133 bowersj2 1673:
1.143 bowersj2 1674: # If this has been filtered out, continue on
1675: if (!(&$filterFunc($curRes))) {
1676: $args->{'isNewBranch'} = 0; # Don't falsely remember this
1677: next;
1678: }
1.132 bowersj2 1679:
1.190 bowersj2 1680: # If this is an empty sequence and we're filtering them, continue on
1.201 bowersj2 1681: if ($curRes->is_map() && $args->{'suppressEmptySequences'} &&
1.190 bowersj2 1682: !$curRes->{DATA}->{HAS_VISIBLE_CHILDREN}) {
1683: next;
1684: }
1685:
1.153 bowersj2 1686: # If we're suppressing navmaps and this is a navmap, continue on
1687: if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
1688: next;
1689: }
1690:
1.191 bowersj2 1691: $args->{'counter'}++;
1692:
1.132 bowersj2 1693: # Does it have multiple parts?
1.133 bowersj2 1694: $args->{'multipart'} = 0;
1695: $args->{'condensed'} = 0;
1.132 bowersj2 1696: my @parts;
1697:
1698: # Decide what parts to show.
1.133 bowersj2 1699: if ($curRes->is_problem() && $showParts) {
1.132 bowersj2 1700: @parts = @{$curRes->parts()};
1.192 bowersj2 1701: $args->{'multipart'} = $curRes->multipart();
1.132 bowersj2 1702:
1703: if ($condenseParts) { # do the condensation
1704: if (!$curRes->opendate("0")) {
1.162 bowersj2 1705: @parts = ();
1.133 bowersj2 1706: $args->{'condensed'} = 1;
1.132 bowersj2 1707: }
1.133 bowersj2 1708: if (!$args->{'condensed'}) {
1.132 bowersj2 1709: # Decide whether to condense based on similarity
1.192 bowersj2 1710: my $status = $curRes->status($parts[0]);
1711: my $due = $curRes->duedate($parts[0]);
1712: my $open = $curRes->opendate($parts[0]);
1.132 bowersj2 1713: my $statusAllSame = 1;
1714: my $dueAllSame = 1;
1715: my $openAllSame = 1;
1.192 bowersj2 1716: for (my $i = 1; $i < scalar(@parts); $i++) {
1.132 bowersj2 1717: if ($curRes->status($parts[$i]) != $status){
1718: $statusAllSame = 0;
1719: }
1720: if ($curRes->duedate($parts[$i]) != $due ) {
1721: $dueAllSame = 0;
1722: }
1723: if ($curRes->opendate($parts[$i]) != $open) {
1724: $openAllSame = 0;
1725: }
1726: }
1727: # $*allSame is true if all the statuses were
1728: # the same. Now, if they are all the same and
1729: # match one of the statuses to condense, or they
1730: # are all open with the same due date, or they are
1731: # all OPEN_LATER with the same open date, display the
1732: # status of the first non-zero part (to get the 'correct'
1733: # status right, since 0 is never 'correct' or 'open').
1734: if (($statusAllSame && defined($condenseStatuses{$status})) ||
1735: ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
1736: ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
1.192 bowersj2 1737: @parts = ($parts[0]);
1.133 bowersj2 1738: $args->{'condensed'} = 1;
1.132 bowersj2 1739: }
1740: }
1.198 bowersj2 1741: # Multipart problem with one part: always "condense" (happens
1742: # to match the desirable behavior)
1743: if ($curRes->countParts() == 1) {
1744: @parts = ($parts[0]);
1745: $args->{'condensed'} = 1;
1746: }
1.132 bowersj2 1747: }
1.157 bowersj2 1748: }
1.132 bowersj2 1749:
1750: # If the multipart problem was condensed, "forget" it was multipart
1751: if (scalar(@parts) == 1) {
1.133 bowersj2 1752: $args->{'multipart'} = 0;
1.192 bowersj2 1753: } else {
1754: # Add part 0 so we display it correctly.
1755: unshift @parts, '0';
1.132 bowersj2 1756: }
1757:
1758: # Now, we've decided what parts to show. Loop through them and
1759: # show them.
1.192 bowersj2 1760: foreach my $part (@parts) {
1.132 bowersj2 1761: $rownum ++;
1762: my $backgroundColor = $backgroundColors[$rownum % scalar(@backgroundColors)];
1763:
1764: $result .= " <tr bgcolor='$backgroundColor'>\n";
1.134 bowersj2 1765:
1766: # Set up some data about the parts that the cols might want
1767: my $filter = $it->{FILTER};
1.270 albertel 1768: my $src;
1769: if ($args->{'sort'}) {
1770: $src = $curRes->src(); # FIXME this is wrong for .pages
1771: } else {
1772: my $stack = $it->getStack();
1773: $src=getLinkForResource($stack);
1774: }
1.249 www 1775: my $anchor='';
1.270 albertel 1776: if ($src=~s/(\#.*)$//) {
1.249 www 1777: $anchor=$1;
1778: }
1.134 bowersj2 1779: my $srcHasQuestion = $src =~ /\?/;
1780: $args->{"resourceLink"} = $src.
1781: ($srcHasQuestion?'&':'?') .
1.249 www 1782: 'symb=' . &Apache::lonnet::escape($curRes->symb()).
1783: $anchor;
1.270 albertel 1784:
1.132 bowersj2 1785: # Now, display each column.
1786: foreach my $col (@$cols) {
1.139 bowersj2 1787: my $colHTML = '';
1788: if (ref($col)) {
1789: $colHTML .= &$col($curRes, $part, $args);
1790: } else {
1791: $colHTML .= &{$preparedColumns[$col]}($curRes, $part, $args);
1792: }
1.132 bowersj2 1793:
1.133 bowersj2 1794: # If this is the first column and it's time to print
1795: # the anchor, do so
1796: if ($col == $cols->[0] &&
1797: $args->{'counter'} == $args->{'currentJumpIndex'} -
1.139 bowersj2 1798: $currentJumpDelta) {
1799: # Jam the anchor after the <td> tag;
1800: # necessary for valid HTML (which Mozilla requires)
1801: $colHTML =~ s/\>/\>\<a name="curloc" \/\>/;
1.133 bowersj2 1802: $displayedJumpMarker = 1;
1803: }
1.139 bowersj2 1804: $result .= $colHTML . "\n";
1.132 bowersj2 1805: }
1.139 bowersj2 1806: $result .= " </tr>\n";
1.140 bowersj2 1807: $args->{'isNewBranch'} = 0;
1.139 bowersj2 1808: }
1.153 bowersj2 1809:
1.139 bowersj2 1810: if ($r && $rownum % 20 == 0) {
1811: $r->print($result);
1812: $result = "";
1813: $r->rflush();
1.132 bowersj2 1814: }
1.156 bowersj2 1815: } continue {
1.208 bowersj2 1816: if ($r) {
1817: # If we have the connection, make sure the user is still connected
1818: my $c = $r->connection;
1819: if ($c->aborted()) {
1820: # Who cares what we do, nobody will see it anyhow.
1821: return '';
1822: }
1823: }
1.132 bowersj2 1824: }
1825:
1.134 bowersj2 1826: # Print out the part that jumps to #curloc if it exists
1.159 bowersj2 1827: # delay needed because the browser is processing the jump before
1828: # it finishes rendering, so it goes to the wrong place!
1829: # onload might be better, but this routine has no access to that.
1830: # On mozilla, the 0-millisecond timeout seems to prevent this;
1831: # it's quite likely this might fix other browsers, too, and
1832: # certainly won't hurt anything.
1.139 bowersj2 1833: if ($displayedJumpMarker) {
1.247 albertel 1834: $result .= "
1835: <script>
1836: if (location.href.indexOf('#curloc')==-1) {
1837: setTimeout(\"location += '#curloc';\", 0)
1838: }
1839: </script>";
1.134 bowersj2 1840: }
1841:
1.132 bowersj2 1842: $result .= "</table>";
1.140 bowersj2 1843:
1844: if ($r) {
1845: $r->print($result);
1846: $result = "";
1847: $r->rflush();
1848: }
1849:
1.175 bowersj2 1850: if ($mustCloseNavMap) { $navmap->untieHashes(); }
1.132 bowersj2 1851:
1852: return $result;
1853: }
1854:
1.133 bowersj2 1855: 1;
1856:
1857: package Apache::lonnavmaps::navmap;
1858:
1859: =pod
1860:
1.216 bowersj2 1861: =head1 Object: Apache::lonnavmaps::navmap
1.133 bowersj2 1862:
1.217 bowersj2 1863: =head2 Overview
1.133 bowersj2 1864:
1.217 bowersj2 1865: The navmap object's job is to provide access to the resources
1866: in the course as Apache::lonnavmaps::resource objects, and to
1867: query and manage the relationship between those resource objects.
1868:
1869: Generally, you'll use the navmap object in one of three basic ways.
1870: In order of increasing complexity and power:
1871:
1872: =over 4
1873:
1874: =item * C<$navmap-E<gt>getByX>, where X is B<Id>, B<Symb>, B<Url> or B<MapPc>. This provides
1875: various ways to obtain resource objects, based on various identifiers.
1876: Use this when you want to request information about one object or
1877: a handful of resources you already know the identities of, from some
1878: other source. For more about Ids, Symbs, and MapPcs, see the
1879: Resource documentation. Note that Url should be a B<last resort>,
1880: not your first choice; it only works when there is only one
1881: instance of the resource in the course, which only applies to
1882: maps, and even that may change in the future.
1883:
1884: =item * C<my @resources = $navmap-E<gt>retrieveResources(args)>. This
1885: retrieves resources matching some criterion and returns them
1886: in a flat array, with no structure information. Use this when
1887: you are manipulating a series of resources, based on what map
1888: the are in, but do not care about branching, or exactly how
1889: the maps and resources are related. This is the most common case.
1890:
1891: =item * C<$it = $navmap-E<gt>getIterator(args)>. This allows you traverse
1892: the course's navmap in various ways without writing the traversal
1893: code yourself. See iterator documentation below. Use this when
1894: you need to know absolutely everything about the course, including
1895: branches and the precise relationship between maps and resources.
1896:
1897: =back
1898:
1899: =head2 Creation And Destruction
1900:
1901: To create a navmap object, use the following function:
1.133 bowersj2 1902:
1903: =over 4
1904:
1.221 bowersj2 1905: =item * B<Apache::lonnavmaps::navmap-E<gt>new>():
1.133 bowersj2 1906:
1.221 bowersj2 1907: Creates a new navmap object. Returns the navmap object if this is
1908: successful, or B<undef> if not.
1.174 albertel 1909:
1.216 bowersj2 1910: =back
1911:
1.217 bowersj2 1912: When you are done with the $navmap object, you I<must> call
1913: $navmap->untieHashes(), or you'll prevent the current user from using that
1914: course until the web server is restarted. (!)
1915:
1.216 bowersj2 1916: =head2 Methods
1917:
1918: =over 4
1919:
1.174 albertel 1920: =item * B<getIterator>(first, finish, filter, condition):
1921:
1922: See iterator documentation below.
1.133 bowersj2 1923:
1924: =cut
1925:
1926: use strict;
1927: use GDBM_File;
1928:
1929: sub new {
1930: # magic invocation to create a class instance
1931: my $proto = shift;
1932: my $class = ref($proto) || $proto;
1933: my $self = {};
1934:
1935: # Resource cache stores navmap resources as we reference them. We generate
1936: # them on-demand so we don't pay for creating resources unless we use them.
1937: $self->{RESOURCE_CACHE} = {};
1938:
1939: # Network failure flag, if we accessed the course or user opt and
1940: # failed
1941: $self->{NETWORK_FAILURE} = 0;
1942:
1943: # tie the nav hash
1944:
1.168 bowersj2 1945: my %navmaphash;
1946: my %parmhash;
1.220 bowersj2 1947: my $courseFn = $ENV{"request.course.fn"};
1948: if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
1.133 bowersj2 1949: &GDBM_READER(), 0640))) {
1950: return undef;
1951: }
1952:
1.220 bowersj2 1953: if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
1.133 bowersj2 1954: &GDBM_READER(), 0640)))
1955: {
1.170 matthew 1956: untie %{$self->{PARM_HASH}};
1.133 bowersj2 1957: return undef;
1958: }
1959:
1.199 bowersj2 1960: $self->{NAV_HASH} = \%navmaphash;
1.168 bowersj2 1961: $self->{PARM_HASH} = \%parmhash;
1.221 bowersj2 1962: $self->{PARM_CACHE} = {};
1.133 bowersj2 1963:
1964: bless($self);
1965:
1966: return $self;
1967: }
1968:
1.221 bowersj2 1969: sub generate_course_user_opt {
1.133 bowersj2 1970: my $self = shift;
1.221 bowersj2 1971: if ($self->{COURSE_USER_OPT_GENERATED}) { return; }
1.133 bowersj2 1972:
1.221 bowersj2 1973: my $uname=$ENV{'user.name'};
1974: my $udom=$ENV{'user.domain'};
1975: my $uhome=$ENV{'user.home'};
1976: my $cid=$ENV{'request.course.id'};
1977: my $chome=$ENV{'course.'.$cid.'.home'};
1978: my ($cdom,$cnum)=split(/\_/,$cid);
1979:
1980: my $userprefix=$uname.'_'.$udom.'_';
1981:
1982: my %courserdatas; my %useropt; my %courseopt; my %userrdatas;
1983: unless ($uhome eq 'no_host') {
1.133 bowersj2 1984: # ------------------------------------------------- Get coursedata (if present)
1.221 bowersj2 1985: unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
1986: my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
1987: ':resourcedata',$chome);
1988: # Check for network failure
1989: if ( $reply =~ /no.such.host/i || $reply =~ /con_lost/i) {
1990: $self->{NETWORK_FAILURE} = 1;
1991: } elsif ($reply!~/^error\:/) {
1992: $courserdatas{$cid}=$reply;
1993: $courserdatas{$cid.'.last_cache'}=time;
1994: }
1995: }
1996: foreach (split(/\&/,$courserdatas{$cid})) {
1997: my ($name,$value)=split(/\=/,$_);
1998: $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
1999: &Apache::lonnet::unescape($value);
2000: }
1.133 bowersj2 2001: # --------------------------------------------------- Get userdata (if present)
1.221 bowersj2 2002: unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
2003: my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
2004: if ($reply!~/^error\:/) {
2005: $userrdatas{$uname.'___'.$udom}=$reply;
2006: $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
2007: }
2008: # check to see if network failed
2009: elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
2010: {
2011: $self->{NETWORK_FAILURE} = 1;
2012: }
2013: }
2014: foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
2015: my ($name,$value)=split(/\=/,$_);
2016: $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
2017: &Apache::lonnet::unescape($value);
2018: }
2019: $self->{COURSE_OPT} = \%courseopt;
2020: $self->{USER_OPT} = \%useropt;
2021: }
2022:
2023: $self->{COURSE_USER_OPT_GENERATED} = 1;
2024:
2025: return;
2026: }
2027:
2028: sub generate_email_discuss_status {
2029: my $self = shift;
1.259 raeburn 2030: my $symb = shift;
1.221 bowersj2 2031: if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
1.133 bowersj2 2032:
1.221 bowersj2 2033: my $cid=$ENV{'request.course.id'};
2034: my ($cdom,$cnum)=split(/\_/,$cid);
2035:
2036: my %emailstatus = &Apache::lonnet::dump('email_status');
2037: my $logoutTime = $emailstatus{'logout'};
2038: my $courseLeaveTime = $emailstatus{'logout_'.$ENV{'request.course.id'}};
2039: $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
2040: $courseLeaveTime : $logoutTime);
2041: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
2042: $cdom, $cnum);
1.259 raeburn 2043: my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss',
2044: $ENV{'user.domain'},$ENV{'user.name'},'lastread');
2045: my %lastreadtime = ();
2046: foreach (keys %lastread) {
2047: my $key = $_;
2048: $key =~ s/_lastread$//;
2049: $lastreadtime{$key} = $lastread{$_};
2050: }
2051:
1.221 bowersj2 2052: my %feedback=();
2053: my %error=();
2054: my $keys = &Apache::lonnet::reply('keys:'.
2055: $ENV{'user.domain'}.':'.
2056: $ENV{'user.name'}.':nohist_email',
2057: $ENV{'user.home'});
2058:
2059: foreach my $msgid (split(/\&/, $keys)) {
2060: $msgid=&Apache::lonnet::unescape($msgid);
2061: my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
2062: if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
2063: my ($what,$url)=($1,$2);
2064: my %status=
2065: &Apache::lonnet::get('email_status',[$msgid]);
2066: if ($status{$msgid}=~/^error\:/) {
2067: $status{$msgid}='';
2068: }
2069:
2070: if (($status{$msgid} eq 'new') ||
2071: (!$status{$msgid})) {
2072: if ($what eq 'Error') {
2073: $error{$url}.=','.$msgid;
2074: } else {
2075: $feedback{$url}.=','.$msgid;
2076: }
2077: }
2078: }
1.211 bowersj2 2079: }
1.221 bowersj2 2080:
2081: $self->{FEEDBACK} = \%feedback;
2082: $self->{ERROR_MSG} = \%error; # what is this? JB
2083: $self->{DISCUSSION_TIME} = \%discussiontime;
2084: $self->{EMAIL_STATUS} = \%emailstatus;
1.259 raeburn 2085: $self->{LAST_READ} = \%lastreadtime;
1.221 bowersj2 2086:
2087: $self->{EMAIL_DISCUSS_GENERATED} = 1;
2088: }
2089:
2090: sub get_user_data {
2091: my $self = shift;
2092: if ($self->{RETRIEVED_USER_DATA}) { return; }
1.211 bowersj2 2093:
1.221 bowersj2 2094: # Retrieve performance data on problems
2095: my %student_data = Apache::lonnet::currentdump($ENV{'request.course.id'},
2096: $ENV{'user.domain'},
2097: $ENV{'user.name'});
2098: $self->{STUDENT_DATA} = \%student_data;
1.133 bowersj2 2099:
1.221 bowersj2 2100: $self->{RETRIEVED_USER_DATA} = 1;
1.133 bowersj2 2101: }
2102:
2103: # Internal function: Takes a key to look up in the nav hash and implements internal
2104: # memory caching of that key.
2105: sub navhash {
2106: my $self = shift; my $key = shift;
2107: return $self->{NAV_HASH}->{$key};
2108: }
2109:
1.217 bowersj2 2110: =pod
2111:
2112: =item * B<courseMapDefined>(): Returns true if the course map is defined,
2113: false otherwise. Undefined course maps indicate an error somewhere in
2114: LON-CAPA, and you will not be able to proceed with using the navmap.
2115: See the B<NAV> screen for an example of using this.
2116:
2117: =cut
2118:
1.133 bowersj2 2119: # Checks to see if coursemap is defined, matching test in old lonnavmaps
2120: sub courseMapDefined {
2121: my $self = shift;
2122: my $uri = &Apache::lonnet::clutter($ENV{'request.course.uri'});
2123:
2124: my $firstres = $self->navhash("map_start_$uri");
2125: my $lastres = $self->navhash("map_finish_$uri");
2126: return $firstres && $lastres;
2127: }
2128:
2129: sub getIterator {
2130: my $self = shift;
2131: my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
2132: shift, undef, shift);
2133: return $iterator;
2134: }
2135:
2136: # unties the hash when done
2137: sub untieHashes {
1.168 bowersj2 2138: my $self = shift;
1.170 matthew 2139: untie %{$self->{NAV_HASH}};
2140: untie %{$self->{PARM_HASH}};
1.133 bowersj2 2141: }
2142:
2143: # Private method: Does the given resource (as a symb string) have
2144: # current discussion? Returns 0 if chat/mail data not extracted.
2145: sub hasDiscussion {
2146: my $self = shift;
2147: my $symb = shift;
1.221 bowersj2 2148:
2149: $self->generate_email_discuss_status();
2150:
1.133 bowersj2 2151: if (!defined($self->{DISCUSSION_TIME})) { return 0; }
2152:
2153: #return defined($self->{DISCUSSION_TIME}->{$symb});
1.259 raeburn 2154:
2155: # backward compatibility (bulletin boards used to be 'wrapped')
2156: my $ressymb = $symb;
2157: if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
1.266 raeburn 2158: unless ($ressymb =~ m|adm/wrapper/adm|) {
1.259 raeburn 2159: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
2160: }
2161: }
2162:
2163: if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
2164: return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
2165: } else {
1.266 raeburn 2166: # return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_CHECK}; # v.1.1 behavior
2167: return $self->{DISCUSSION_TIME}->{$ressymb} > 0; # in 1.2 will display speech bubble icons for all items with posts until marked as read (even if read in v 1.1).
1.259 raeburn 2168: }
1.133 bowersj2 2169: }
2170:
2171: # Private method: Does the given resource (as a symb string) have
2172: # current feedback? Returns the string in the feedback hash, which
2173: # will be false if it does not exist.
2174: sub getFeedback {
2175: my $self = shift;
2176: my $symb = shift;
2177:
1.221 bowersj2 2178: $self->generate_email_discuss_status();
2179:
1.133 bowersj2 2180: if (!defined($self->{FEEDBACK})) { return ""; }
2181:
2182: return $self->{FEEDBACK}->{$symb};
2183: }
2184:
2185: # Private method: Get the errors for that resource (by source).
2186: sub getErrors {
2187: my $self = shift;
2188: my $src = shift;
1.221 bowersj2 2189:
2190: $self->generate_email_discuss_status();
2191:
1.133 bowersj2 2192: if (!defined($self->{ERROR_MSG})) { return ""; }
2193: return $self->{ERROR_MSG}->{$src};
2194: }
2195:
2196: =pod
2197:
1.174 albertel 2198: =item * B<getById>(id):
2199:
2200: Based on the ID of the resource (1.1, 3.2, etc.), get a resource
2201: object for that resource. This method, or other methods that use it
2202: (as in the resource object) is the only proper way to obtain a
2203: resource object.
1.133 bowersj2 2204:
1.194 bowersj2 2205: =item * B<getBySymb>(symb):
2206:
2207: Based on the symb of the resource, get a resource object for that
2208: resource. This is one of the proper ways to get a resource object.
2209:
2210: =item * B<getMapByMapPc>(map_pc):
2211:
2212: Based on the map_pc of the resource, get a resource object for
2213: the given map. This is one of the proper ways to get a resource object.
2214:
1.133 bowersj2 2215: =cut
2216:
2217: # The strategy here is to cache the resource objects, and only construct them
2218: # as we use them. The real point is to prevent reading any more from the tied
2219: # hash then we have to, which should hopefully alleviate speed problems.
2220:
2221: sub getById {
2222: my $self = shift;
2223: my $id = shift;
2224:
2225: if (defined ($self->{RESOURCE_CACHE}->{$id}))
2226: {
2227: return $self->{RESOURCE_CACHE}->{$id};
2228: }
2229:
2230: # resource handles inserting itself into cache.
2231: # Not clear why the quotes are necessary, but as of this
2232: # writing it doesn't work without them.
2233: return "Apache::lonnavmaps::resource"->new($self, $id);
1.132 bowersj2 2234: }
1.133 bowersj2 2235:
1.172 bowersj2 2236: sub getBySymb {
2237: my $self = shift;
2238: my $symb = shift;
1.228 albertel 2239: my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);
1.172 bowersj2 2240: my $map = $self->getResourceByUrl($mapUrl);
2241: return $self->getById($map->map_pc() . '.' . $id);
1.194 bowersj2 2242: }
2243:
2244: sub getByMapPc {
2245: my $self = shift;
2246: my $map_pc = shift;
2247: my $map_id = $self->{NAV_HASH}->{'map_id_' . $map_pc};
2248: $map_id = $self->{NAV_HASH}->{'ids_' . $map_id};
2249: return $self->getById($map_id);
1.172 bowersj2 2250: }
2251:
1.133 bowersj2 2252: =pod
2253:
1.174 albertel 2254: =item * B<firstResource>():
2255:
2256: Returns a resource object reference corresponding to the first
2257: resource in the navmap.
1.133 bowersj2 2258:
2259: =cut
2260:
2261: sub firstResource {
2262: my $self = shift;
2263: my $firstResource = $self->navhash('map_start_' .
2264: &Apache::lonnet::clutter($ENV{'request.course.uri'}));
2265: return $self->getById($firstResource);
1.132 bowersj2 2266: }
1.133 bowersj2 2267:
2268: =pod
2269:
1.174 albertel 2270: =item * B<finishResource>():
2271:
2272: Returns a resource object reference corresponding to the last resource
2273: in the navmap.
1.133 bowersj2 2274:
2275: =cut
2276:
2277: sub finishResource {
2278: my $self = shift;
2279: my $firstResource = $self->navhash('map_finish_' .
2280: &Apache::lonnet::clutter($ENV{'request.course.uri'}));
2281: return $self->getById($firstResource);
1.132 bowersj2 2282: }
1.133 bowersj2 2283:
2284: # Parmval reads the parm hash and cascades the lookups. parmval_real does
2285: # the actual lookup; parmval caches the results.
2286: sub parmval {
2287: my $self = shift;
2288: my ($what,$symb)=@_;
2289: my $hashkey = $what."|||".$symb;
2290:
2291: if (defined($self->{PARM_CACHE}->{$hashkey})) {
2292: return $self->{PARM_CACHE}->{$hashkey};
2293: }
2294:
2295: my $result = $self->parmval_real($what, $symb);
2296: $self->{PARM_CACHE}->{$hashkey} = $result;
2297: return $result;
1.132 bowersj2 2298: }
2299:
1.133 bowersj2 2300: sub parmval_real {
2301: my $self = shift;
1.219 albertel 2302: my ($what,$symb,$recurse) = @_;
1.133 bowersj2 2303:
1.221 bowersj2 2304: # Make sure the {USER_OPT} and {COURSE_OPT} hashes are populated
2305: $self->generate_course_user_opt();
2306:
1.133 bowersj2 2307: my $cid=$ENV{'request.course.id'};
2308: my $csec=$ENV{'request.course.sec'};
2309: my $uname=$ENV{'user.name'};
2310: my $udom=$ENV{'user.domain'};
2311:
2312: unless ($symb) { return ''; }
2313: my $result='';
2314:
1.226 www 2315: my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
1.133 bowersj2 2316:
2317: # ----------------------------------------------------- Cascading lookup scheme
2318: my $rwhat=$what;
2319: $what=~s/^parameter\_//;
2320: $what=~s/\_/\./;
2321:
2322: my $symbparm=$symb.'.'.$what;
2323: my $mapparm=$mapname.'___(all).'.$what;
2324: my $usercourseprefix=$uname.'_'.$udom.'_'.$cid;
2325:
2326: my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
2327: my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
2328: my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
2329:
2330: my $courselevel= $usercourseprefix.'.'.$what;
2331: my $courselevelr=$usercourseprefix.'.'.$symbparm;
2332: my $courselevelm=$usercourseprefix.'.'.$mapparm;
2333:
2334: my $useropt = $self->{USER_OPT};
2335: my $courseopt = $self->{COURSE_OPT};
2336: my $parmhash = $self->{PARM_HASH};
2337:
2338: # ---------------------------------------------------------- first, check user
2339: if ($uname and defined($useropt)) {
2340: if (defined($$useropt{$courselevelr})) { return $$useropt{$courselevelr}; }
2341: if (defined($$useropt{$courselevelm})) { return $$useropt{$courselevelm}; }
2342: if (defined($$useropt{$courselevel})) { return $$useropt{$courselevel}; }
2343: }
2344:
2345: # ------------------------------------------------------- second, check course
2346: if ($csec and defined($courseopt)) {
2347: if (defined($$courseopt{$seclevelr})) { return $$courseopt{$seclevelr}; }
2348: if (defined($$courseopt{$seclevelm})) { return $$courseopt{$seclevelm}; }
2349: if (defined($$courseopt{$seclevel})) { return $$courseopt{$seclevel}; }
2350: }
2351:
2352: if (defined($courseopt)) {
2353: if (defined($$courseopt{$courselevelr})) { return $$courseopt{$courselevelr}; }
2354: if (defined($$courseopt{$courselevelm})) { return $$courseopt{$courselevelm}; }
2355: if (defined($$courseopt{$courselevel})) { return $$courseopt{$courselevel}; }
2356: }
2357:
2358: # ----------------------------------------------------- third, check map parms
2359:
2360: my $thisparm=$$parmhash{$symbparm};
2361: if (defined($thisparm)) { return $thisparm; }
2362:
2363: # ----------------------------------------------------- fourth , check default
2364:
1.246 albertel 2365: my $meta_rwhat=$rwhat;
2366: $meta_rwhat=~s/\./_/g;
2367: my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
2368: if (defined($default)) { return $default}
2369: $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
1.133 bowersj2 2370: if (defined($default)) { return $default}
2371:
2372: # --------------------------------------------------- fifth , cascade up parts
2373:
2374: my ($space,@qualifier)=split(/\./,$rwhat);
2375: my $qualifier=join('.',@qualifier);
2376: unless ($space eq '0') {
1.160 albertel 2377: my @parts=split(/_/,$space);
2378: my $id=pop(@parts);
2379: my $part=join('_',@parts);
2380: if ($part eq '') { $part='0'; }
1.219 albertel 2381: my $partgeneral=$self->parmval($part.".$qualifier",$symb,1);
1.160 albertel 2382: if (defined($partgeneral)) { return $partgeneral; }
1.133 bowersj2 2383: }
1.219 albertel 2384: if ($recurse) { return undef; }
2385: my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$what);
2386: if (defined($pack_def)) { return $pack_def; }
1.133 bowersj2 2387: return '';
1.145 bowersj2 2388: }
2389:
1.174 albertel 2390: =pod
1.145 bowersj2 2391:
1.174 albertel 2392: =item * B<getResourceByUrl>(url):
1.145 bowersj2 2393:
1.174 albertel 2394: Retrieves a resource object by URL of the resource. If passed a
2395: resource object, it will simply return it, so it is safe to use this
2396: method in code like "$res = $navmap->getResourceByUrl($res)", if
2397: you're not sure if $res is already an object, or just a URL. If the
2398: resource appears multiple times in the course, only the first instance
2399: will be returned. As a result, this is probably useful only for maps.
2400:
2401: =item * B<retrieveResources>(map, filterFunc, recursive, bailout):
2402:
2403: The map is a specification of a map to retreive the resources from,
2404: either as a url or as an object. The filterFunc is a reference to a
2405: function that takes a resource object as its one argument and returns
2406: true if the resource should be included, or false if it should not
2407: be. If recursive is true, the map will be recursively examined,
2408: otherwise it will not be. If bailout is true, the function will return
2409: as soon as it finds a resource, if false it will finish. By default,
2410: the map is the top-level map of the course, filterFunc is a function
2411: that always returns 1, recursive is true, bailout is false. The
2412: resources will be returned in a list containing the resource objects
2413: for the corresponding resources, with B<no structure information> in
2414: the list; regardless of branching, recursion, etc., it will be a flat
2415: list.
2416:
2417: Thus, this is suitable for cases where you don't want the structure,
2418: just a list of all resources. It is also suitable for finding out how
2419: many resources match a given description; for this use, if all you
2420: want to know is if I<any> resources match the description, the bailout
2421: parameter will allow you to avoid potentially expensive enumeration of
2422: all matching resources.
1.145 bowersj2 2423:
1.256 albertel 2424: =item * B<hasResource>(map, filterFunc, recursive):
1.145 bowersj2 2425:
1.174 albertel 2426: Convience method for
1.146 bowersj2 2427:
2428: scalar(retrieveResources($map, $filterFunc, $recursive, 1)) > 0
2429:
1.174 albertel 2430: which will tell whether the map has resources matching the description
2431: in the filter function.
1.146 bowersj2 2432:
1.145 bowersj2 2433: =cut
2434:
2435: sub getResourceByUrl {
2436: my $self = shift;
2437: my $resUrl = shift;
2438:
2439: if (ref($resUrl)) { return $resUrl; }
2440:
2441: $resUrl = &Apache::lonnet::clutter($resUrl);
2442: my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
2443: if ($resId =~ /,/) {
2444: $resId = (split (/,/, $resId))[0];
2445: }
2446: if (!$resId) { return ''; }
2447: return $self->getById($resId);
2448: }
2449:
2450: sub retrieveResources {
2451: my $self = shift;
2452: my $map = shift;
2453: my $filterFunc = shift;
2454: if (!defined ($filterFunc)) {
2455: $filterFunc = sub {return 1;};
2456: }
2457: my $recursive = shift;
2458: if (!defined($recursive)) { $recursive = 1; }
2459: my $bailout = shift;
2460: if (!defined($bailout)) { $bailout = 0; }
2461:
2462: # Create the necessary iterator.
2463: if (!ref($map)) { # assume it's a url of a map.
1.172 bowersj2 2464: $map = $self->getResourceByUrl($map);
1.145 bowersj2 2465: }
2466:
1.213 bowersj2 2467: # If nothing was passed, assume top-level map
2468: if (!$map) {
2469: $map = $self->getById('0.0');
2470: }
2471:
1.145 bowersj2 2472: # Check the map's validity.
1.213 bowersj2 2473: if (!$map->is_map()) {
1.145 bowersj2 2474: # Oh, to throw an exception.... how I'd love that!
2475: return ();
2476: }
2477:
1.146 bowersj2 2478: # Get an iterator.
2479: my $it = $self->getIterator($map->map_start(), $map->map_finish(),
1.215 bowersj2 2480: undef, $recursive);
1.146 bowersj2 2481:
2482: my @resources = ();
2483:
2484: # Run down the iterator and collect the resources.
1.222 bowersj2 2485: my $curRes;
2486:
2487: while ($curRes = $it->next()) {
1.146 bowersj2 2488: if (ref($curRes)) {
2489: if (!&$filterFunc($curRes)) {
2490: next;
2491: }
2492:
2493: push @resources, $curRes;
2494:
2495: if ($bailout) {
2496: return @resources;
2497: }
2498: }
2499:
2500: }
2501:
2502: return @resources;
2503: }
2504:
2505: sub hasResource {
2506: my $self = shift;
2507: my $map = shift;
2508: my $filterFunc = shift;
2509: my $recursive = shift;
2510:
2511: return scalar($self->retrieveResources($map, $filterFunc, $recursive, 1)) > 0;
1.133 bowersj2 2512: }
1.51 bowersj2 2513:
2514: 1;
2515:
2516: package Apache::lonnavmaps::iterator;
2517:
2518: =pod
2519:
2520: =back
2521:
1.174 albertel 2522: =head1 Object: navmap Iterator
1.51 bowersj2 2523:
1.174 albertel 2524: An I<iterator> encapsulates the logic required to traverse a data
2525: structure. navmap uses an iterator to traverse the course map
2526: according to the criteria you wish to use.
2527:
2528: To obtain an iterator, call the B<getIterator>() function of a
2529: B<navmap> object. (Do not instantiate Apache::lonnavmaps::iterator
2530: directly.) This will return a reference to the iterator:
1.51 bowersj2 2531:
2532: C<my $resourceIterator = $navmap-E<gt>getIterator();>
2533:
2534: To get the next thing from the iterator, call B<next>:
2535:
2536: C<my $nextThing = $resourceIterator-E<gt>next()>
2537:
2538: getIterator behaves as follows:
2539:
2540: =over 4
2541:
1.174 albertel 2542: =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop, returnTopMap):
2543:
2544: All parameters are optional. firstResource is a resource reference
2545: corresponding to where the iterator should start. It defaults to
2546: navmap->firstResource() for the corresponding nav map. finishResource
2547: corresponds to where you want the iterator to end, defaulting to
2548: navmap->finishResource(). filterHash is a hash used as a set
2549: containing strings representing the resource IDs, defaulting to
2550: empty. Condition is a 1 or 0 that sets what to do with the filter
1.205 bowersj2 2551: hash: If a 0, then only resources that exist IN the filterHash will be
1.174 albertel 2552: recursed on. If it is a 1, only resources NOT in the filterHash will
2553: be recursed on. Defaults to 0. forceTop is a boolean value. If it is
2554: false (default), the iterator will only return the first level of map
2555: that is not just a single, 'redirecting' map. If true, the iterator
2556: will return all information, starting with the top-level map,
2557: regardless of content. returnTopMap, if true (default false), will
2558: cause the iterator to return the top-level map object (resource 0.0)
2559: before anything else.
2560:
2561: Thus, by default, only top-level resources will be shown. Change the
2562: condition to a 1 without changing the hash, and all resources will be
2563: shown. Changing the condition to 1 and including some values in the
2564: hash will allow you to selectively suppress parts of the navmap, while
2565: leaving it on 0 and adding things to the hash will allow you to
2566: selectively add parts of the nav map. See the handler code for
2567: examples.
2568:
2569: The iterator will return either a reference to a resource object, or a
2570: token representing something in the map, such as the beginning of a
2571: new branch. The possible tokens are:
2572:
2573: =over 4
1.51 bowersj2 2574:
1.222 bowersj2 2575: =item * B<END_ITERATOR>:
2576:
2577: The iterator has returned all that it's going to. Further calls to the
2578: iterator will just produce more of these. This is a "false" value, and
2579: is the only false value the iterator which will be returned, so it can
2580: be used as a loop sentinel.
2581:
1.217 bowersj2 2582: =item * B<BEGIN_MAP>:
1.51 bowersj2 2583:
1.174 albertel 2584: A new map is being recursed into. This is returned I<after> the map
2585: resource itself is returned.
1.51 bowersj2 2586:
1.217 bowersj2 2587: =item * B<END_MAP>:
1.174 albertel 2588:
2589: The map is now done.
1.51 bowersj2 2590:
1.217 bowersj2 2591: =item * B<BEGIN_BRANCH>:
1.70 bowersj2 2592:
1.174 albertel 2593: A branch is now starting. The next resource returned will be the first
2594: in that branch.
1.70 bowersj2 2595:
1.217 bowersj2 2596: =item * B<END_BRANCH>:
1.70 bowersj2 2597:
1.174 albertel 2598: The branch is now done.
1.51 bowersj2 2599:
2600: =back
2601:
1.174 albertel 2602: The tokens are retreivable via methods on the iterator object, i.e.,
2603: $iterator->END_MAP.
1.70 bowersj2 2604:
1.174 albertel 2605: Maps can contain empty resources. The iterator will automatically skip
2606: over such resources, but will still treat the structure
2607: correctly. Thus, a complicated map with several branches, but
2608: consisting entirely of empty resources except for one beginning or
2609: ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,
2610: but only one resource will be returned.
1.116 bowersj2 2611:
1.242 matthew 2612: =back
2613:
1.222 bowersj2 2614: =head2 Normal Usage
2615:
2616: Normal usage of the iterator object is to do the following:
2617:
2618: my $it = $navmap->getIterator([your params here]);
2619: my $curRes;
2620: while ($curRes = $it->next()) {
2621: [your logic here]
2622: }
2623:
2624: Note that inside of the loop, it's frequently useful to check if
2625: "$curRes" is a reference or not with the reference function; only
2626: resource objects will be references, and any non-references will
2627: be the tokens described above.
2628:
2629: Also note there is some old code floating around that trys to track
2630: the depth of the iterator to see when it's done; do not copy that
2631: code. It is difficult to get right and harder to understand then
2632: this. They should be migrated to this new style.
1.51 bowersj2 2633:
2634: =cut
2635:
2636: # Here are the tokens for the iterator:
2637:
1.222 bowersj2 2638: sub END_ITERATOR { return 0; }
1.51 bowersj2 2639: sub BEGIN_MAP { return 1; } # begining of a new map
2640: sub END_MAP { return 2; } # end of the map
2641: sub BEGIN_BRANCH { return 3; } # beginning of a branch
2642: sub END_BRANCH { return 4; } # end of a branch
1.89 bowersj2 2643: sub FORWARD { return 1; } # go forward
2644: sub BACKWARD { return 2; }
1.51 bowersj2 2645:
1.96 bowersj2 2646: sub min {
2647: (my $a, my $b) = @_;
2648: if ($a < $b) { return $a; } else { return $b; }
2649: }
2650:
1.94 bowersj2 2651: sub new {
2652: # magic invocation to create a class instance
2653: my $proto = shift;
2654: my $class = ref($proto) || $proto;
2655: my $self = {};
2656:
2657: $self->{NAV_MAP} = shift;
2658: return undef unless ($self->{NAV_MAP});
2659:
2660: # Handle the parameters
2661: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
2662: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
2663:
2664: # If the given resources are just the ID of the resource, get the
2665: # objects
2666: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
2667: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
2668: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
2669: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
2670:
2671: $self->{FILTER} = shift;
2672:
2673: # A hash, used as a set, of resource already seen
2674: $self->{ALREADY_SEEN} = shift;
2675: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
2676: $self->{CONDITION} = shift;
2677:
1.116 bowersj2 2678: # Do we want to automatically follow "redirection" maps?
2679: $self->{FORCE_TOP} = shift;
2680:
1.162 bowersj2 2681: # Do we want to return the top-level map object (resource 0.0)?
2682: $self->{RETURN_0} = shift;
2683: # have we done that yet?
2684: $self->{HAVE_RETURNED_0} = 0;
2685:
1.94 bowersj2 2686: # Now, we need to pre-process the map, by walking forward and backward
2687: # over the parts of the map we're going to look at.
1.96 bowersj2 2688:
1.97 bowersj2 2689: # The processing steps are exactly the same, except for a few small
2690: # changes, so I bundle those up in the following list of two elements:
2691: # (direction_to_iterate, VAL_name, next_resource_method_to_call,
2692: # first_resource).
2693: # This prevents writing nearly-identical code twice.
2694: my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext',
2695: 'FIRST_RESOURCE'],
2696: [BACKWARD(), 'BOT_UP_VAL', 'getPrevious',
2697: 'FINISH_RESOURCE'] );
2698:
1.98 bowersj2 2699: my $maxDepth = 0; # tracks max depth
2700:
1.116 bowersj2 2701: # If there is only one resource in this map, and it's a map, we
2702: # want to remember that, so the user can ask for the first map
2703: # that isn't just a redirector.
2704: my $resource; my $resourceCount = 0;
2705:
1.209 bowersj2 2706: # Documentation on this algorithm can be found in the CVS repository at
2707: # /docs/lonnavdocs; these "**#**" markers correspond to documentation
2708: # in that file.
1.107 bowersj2 2709: # **1**
2710:
1.97 bowersj2 2711: foreach my $pass (@iterations) {
2712: my $direction = $pass->[0];
2713: my $valName = $pass->[1];
2714: my $nextResourceMethod = $pass->[2];
2715: my $firstResourceName = $pass->[3];
2716:
2717: my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP},
2718: $self->{FIRST_RESOURCE},
2719: $self->{FINISH_RESOURCE},
2720: {}, undef, 0, $direction);
1.96 bowersj2 2721:
1.97 bowersj2 2722: # prime the recursion
2723: $self->{$firstResourceName}->{DATA}->{$valName} = 0;
1.222 bowersj2 2724: $iterator->next();
1.97 bowersj2 2725: my $curRes = $iterator->next();
1.222 bowersj2 2726: my $depth = 1;
2727: while ($depth > 0) {
2728: if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
2729: if ($curRes == $iterator->END_MAP()) { $depth--; }
2730:
1.97 bowersj2 2731: if (ref($curRes)) {
1.116 bowersj2 2732: # If there's only one resource, this will save it
1.117 bowersj2 2733: # we have to filter empty resources from consideration here,
2734: # or even "empty", redirecting maps have two (start & finish)
2735: # or three (start, finish, plus redirector)
2736: if($direction == FORWARD && $curRes->src()) {
2737: $resource = $curRes; $resourceCount++;
2738: }
1.97 bowersj2 2739: my $resultingVal = $curRes->{DATA}->{$valName};
2740: my $nextResources = $curRes->$nextResourceMethod();
1.116 bowersj2 2741: my $nextCount = scalar(@{$nextResources});
1.104 bowersj2 2742:
1.116 bowersj2 2743: if ($nextCount == 1) { # **3**
1.97 bowersj2 2744: my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
2745: $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
2746: }
2747:
1.116 bowersj2 2748: if ($nextCount > 1) { # **4**
1.97 bowersj2 2749: foreach my $res (@{$nextResources}) {
2750: my $current = $res->{DATA}->{$valName} || 999999999;
2751: $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
2752: }
2753: }
2754: }
1.96 bowersj2 2755:
1.107 bowersj2 2756: # Assign the final val (**2**)
1.97 bowersj2 2757: if (ref($curRes) && $direction == BACKWARD()) {
1.98 bowersj2 2758: my $finalDepth = min($curRes->{DATA}->{TOP_DOWN_VAL},
2759: $curRes->{DATA}->{BOT_UP_VAL});
2760:
2761: $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
2762: if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
1.190 bowersj2 2763: }
1.222 bowersj2 2764:
2765: $curRes = $iterator->next();
1.96 bowersj2 2766: }
2767: }
1.94 bowersj2 2768:
1.116 bowersj2 2769: # Check: Was this only one resource, a map?
1.255 albertel 2770: if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) {
1.116 bowersj2 2771: my $firstResource = $resource->map_start();
2772: my $finishResource = $resource->map_finish();
2773: return
2774: Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
2775: $finishResource, $self->{FILTER},
2776: $self->{ALREADY_SEEN},
2777: $self->{CONDITION}, 0);
2778:
2779: }
2780:
1.98 bowersj2 2781: # Set up some bookkeeping information.
2782: $self->{CURRENT_DEPTH} = 0;
2783: $self->{MAX_DEPTH} = $maxDepth;
2784: $self->{STACK} = [];
2785: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
1.222 bowersj2 2786: $self->{FINISHED} = 0; # When true, the iterator has finished
1.98 bowersj2 2787:
2788: for (my $i = 0; $i <= $self->{MAX_DEPTH}; $i++) {
2789: push @{$self->{STACK}}, [];
2790: }
2791:
1.107 bowersj2 2792: # Prime the recursion w/ the first resource **5**
1.98 bowersj2 2793: push @{$self->{STACK}->[0]}, $self->{FIRST_RESOURCE};
2794: $self->{ALREADY_SEEN}->{$self->{FIRST_RESOURCE}->{ID}} = 1;
2795:
2796: bless ($self);
2797:
2798: return $self;
2799: }
2800:
2801: sub next {
2802: my $self = shift;
1.256 albertel 2803: my $closeAllPages=shift;
1.222 bowersj2 2804: if ($self->{FINISHED}) {
2805: return END_ITERATOR();
2806: }
2807:
1.162 bowersj2 2808: # If we want to return the top-level map object, and haven't yet,
2809: # do so.
2810: if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0}) {
2811: $self->{HAVE_RETURNED_0} = 1;
2812: return $self->{NAV_MAP}->getById('0.0');
2813: }
1.98 bowersj2 2814:
2815: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
2816: # grab the next from the recursive iterator
1.256 albertel 2817: my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
1.98 bowersj2 2818:
2819: # is it a begin or end map? If so, update the depth
2820: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
2821: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
2822:
2823: # Are we back at depth 0? If so, stop recursing
2824: if ($self->{RECURSIVE_DEPTH} == 0) {
2825: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
2826: }
2827:
2828: return $next;
2829: }
2830:
2831: if (defined($self->{FORCE_NEXT})) {
2832: my $tmp = $self->{FORCE_NEXT};
2833: $self->{FORCE_NEXT} = undef;
2834: return $tmp;
2835: }
2836:
2837: # Have we not yet begun? If not, return BEGIN_MAP and
2838: # remember we've started.
2839: if ( !$self->{STARTED} ) {
2840: $self->{STARTED} = 1;
2841: return $self->BEGIN_MAP();
2842: }
2843:
2844: # Here's the guts of the iterator.
2845:
2846: # Find the next resource, if any.
2847: my $found = 0;
2848: my $i = $self->{MAX_DEPTH};
2849: my $newDepth;
2850: my $here;
2851: while ( $i >= 0 && !$found ) {
1.107 bowersj2 2852: if ( scalar(@{$self->{STACK}->[$i]}) > 0 ) { # **6**
2853: $here = pop @{$self->{STACK}->[$i]}; # **7**
1.98 bowersj2 2854: $found = 1;
2855: $newDepth = $i;
2856: }
2857: $i--;
2858: }
2859:
2860: # If we still didn't find anything, we're done.
2861: if ( !$found ) {
2862: # We need to get back down to the correct branch depth
2863: if ( $self->{CURRENT_DEPTH} > 0 ) {
2864: $self->{CURRENT_DEPTH}--;
2865: return END_BRANCH();
2866: } else {
1.222 bowersj2 2867: $self->{FINISHED} = 1;
1.98 bowersj2 2868: return END_MAP();
2869: }
2870: }
2871:
1.104 bowersj2 2872: # If this is not a resource, it must be an END_BRANCH marker we want
2873: # to return directly.
1.107 bowersj2 2874: if (!ref($here)) { # **8**
1.104 bowersj2 2875: if ($here == END_BRANCH()) { # paranoia, in case of later extension
2876: $self->{CURRENT_DEPTH}--;
2877: return $here;
2878: }
2879: }
2880:
2881: # Otherwise, it is a resource and it's safe to store in $self->{HERE}
2882: $self->{HERE} = $here;
2883:
1.98 bowersj2 2884: # Get to the right level
2885: if ( $self->{CURRENT_DEPTH} > $newDepth ) {
2886: push @{$self->{STACK}->[$newDepth]}, $here;
2887: $self->{CURRENT_DEPTH}--;
2888: return END_BRANCH();
2889: }
2890: if ( $self->{CURRENT_DEPTH} < $newDepth) {
2891: push @{$self->{STACK}->[$newDepth]}, $here;
2892: $self->{CURRENT_DEPTH}++;
2893: return BEGIN_BRANCH();
2894: }
2895:
2896: # If we made it here, we have the next resource, and we're at the
2897: # right branch level. So let's examine the resource for where
2898: # we can get to from here.
2899:
2900: # So we need to look at all the resources we can get to from here,
2901: # categorize them if we haven't seen them, remember if we have a new
2902: my $nextUnfiltered = $here->getNext();
1.104 bowersj2 2903: my $maxDepthAdded = -1;
2904:
1.98 bowersj2 2905: for (@$nextUnfiltered) {
2906: if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
1.104 bowersj2 2907: my $depth = $_->{DATA}->{DISPLAY_DEPTH};
2908: push @{$self->{STACK}->[$depth]}, $_;
1.98 bowersj2 2909: $self->{ALREADY_SEEN}->{$_->{ID}} = 1;
1.104 bowersj2 2910: if ($maxDepthAdded < $depth) { $maxDepthAdded = $depth; }
1.98 bowersj2 2911: }
2912: }
1.104 bowersj2 2913:
2914: # Is this the end of a branch? If so, all of the resources examined above
2915: # led to lower levels then the one we are currently at, so we push a END_BRANCH
2916: # marker onto the stack so we don't forget.
2917: # Example: For the usual A(BC)(DE)F case, when the iterator goes down the
2918: # BC branch and gets to C, it will see F as the only next resource, but it's
2919: # one level lower. Thus, this is the end of the branch, since there are no
2920: # more resources added to this level or above.
1.111 bowersj2 2921: # We don't do this if the examined resource is the finish resource,
2922: # because the condition given above is true, but the "END_MAP" will
2923: # take care of things and we should already be at depth 0.
1.104 bowersj2 2924: my $isEndOfBranch = $maxDepthAdded < $self->{CURRENT_DEPTH};
1.111 bowersj2 2925: if ($isEndOfBranch && $here != $self->{FINISH_RESOURCE}) { # **9**
1.104 bowersj2 2926: push @{$self->{STACK}->[$self->{CURRENT_DEPTH}]}, END_BRANCH();
2927: }
2928:
1.98 bowersj2 2929: # That ends the main iterator logic. Now, do we want to recurse
2930: # down this map (if this resource is a map)?
1.256 albertel 2931: if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
1.98 bowersj2 2932: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
2933: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
2934: my $firstResource = $self->{HERE}->map_start();
2935: my $finishResource = $self->{HERE}->map_finish();
2936:
2937: $self->{RECURSIVE_ITERATOR} =
2938: Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
2939: $finishResource, $self->{FILTER},
2940: $self->{ALREADY_SEEN}, $self->{CONDITION});
2941: }
2942:
1.116 bowersj2 2943: # If this is a blank resource, don't actually return it.
1.117 bowersj2 2944: # Should you ever find you need it, make sure to add an option to the code
2945: # that you can use; other things depend on this behavior.
1.138 bowersj2 2946: my $browsePriv = $self->{HERE}->browsePriv();
2947: if (!$self->{HERE}->src() ||
2948: (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
1.256 albertel 2949: return $self->next($closeAllPages);
1.116 bowersj2 2950: }
2951:
1.98 bowersj2 2952: return $self->{HERE};
2953:
2954: }
2955:
2956: =pod
2957:
1.174 albertel 2958: The other method available on the iterator is B<getStack>, which
2959: returns an array populated with the current 'stack' of maps, as
2960: references to the resource objects. Example: This is useful when
2961: making the navigation map, as we need to check whether we are under a
2962: page map to see if we need to link directly to the resource, or to the
2963: page. The first elements in the array will correspond to the top of
2964: the stack (most inclusive map).
1.98 bowersj2 2965:
2966: =cut
2967:
2968: sub getStack {
2969: my $self=shift;
2970:
2971: my @stack;
2972:
2973: $self->populateStack(\@stack);
2974:
2975: return \@stack;
2976: }
2977:
2978: # Private method: Calls the iterators recursively to populate the stack.
2979: sub populateStack {
2980: my $self=shift;
2981: my $stack = shift;
2982:
2983: push @$stack, $self->{HERE} if ($self->{HERE});
2984:
2985: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
2986: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
2987: }
1.94 bowersj2 2988: }
2989:
2990: 1;
2991:
2992: package Apache::lonnavmaps::DFSiterator;
2993:
1.100 bowersj2 2994: # Not documented in the perldoc: This is a simple iterator that just walks
2995: # through the nav map and presents the resources in a depth-first search
2996: # fashion, ignorant of conditionals, randomized resources, etc. It presents
2997: # BEGIN_MAP and END_MAP, but does not understand branches at all. It is
2998: # useful for pre-processing of some kind, and is in fact used by the main
2999: # iterator that way, but that's about it.
3000: # One could imagine merging this into the init routine of the main iterator,
1.251 www 3001: # but this might as well be left separate, since it is possible some other
1.100 bowersj2 3002: # use might be found for it. - Jeremy
1.94 bowersj2 3003:
1.117 bowersj2 3004: # Unlike the main iterator, this DOES return all resources, even blank ones.
3005: # The main iterator needs them to correctly preprocess the map.
3006:
1.94 bowersj2 3007: sub BEGIN_MAP { return 1; } # begining of a new map
3008: sub END_MAP { return 2; } # end of the map
3009: sub FORWARD { return 1; } # go forward
3010: sub BACKWARD { return 2; }
3011:
1.100 bowersj2 3012: # Params: Nav map ref, first resource id/ref, finish resource id/ref,
3013: # filter hash ref (or undef), already seen hash or undef, condition
3014: # (as in main iterator), direction FORWARD or BACKWARD (undef->forward).
1.51 bowersj2 3015: sub new {
3016: # magic invocation to create a class instance
3017: my $proto = shift;
3018: my $class = ref($proto) || $proto;
3019: my $self = {};
3020:
3021: $self->{NAV_MAP} = shift;
3022: return undef unless ($self->{NAV_MAP});
3023:
3024: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
3025: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
3026:
3027: # If the given resources are just the ID of the resource, get the
3028: # objects
3029: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
3030: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
3031: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
3032: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
3033:
3034: $self->{FILTER} = shift;
3035:
3036: # A hash, used as a set, of resource already seen
3037: $self->{ALREADY_SEEN} = shift;
1.140 bowersj2 3038: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
1.63 bowersj2 3039: $self->{CONDITION} = shift;
1.89 bowersj2 3040: $self->{DIRECTION} = shift || FORWARD();
1.51 bowersj2 3041:
1.100 bowersj2 3042: # Flag: Have we started yet?
1.51 bowersj2 3043: $self->{STARTED} = 0;
3044:
3045: # Should we continue calling the recursive iterator, if any?
3046: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3047: # The recursive iterator, if any
3048: $self->{RECURSIVE_ITERATOR} = undef;
3049: # Are we recursing on a map, or a branch?
3050: $self->{RECURSIVE_MAP} = 1; # we'll manually unset this when recursing on branches
3051: # And the count of how deep it is, so that this iterator can keep track of
3052: # when to pick back up again.
3053: $self->{RECURSIVE_DEPTH} = 0;
3054:
3055: # For keeping track of our branches, we maintain our own stack
1.100 bowersj2 3056: $self->{STACK} = [];
1.51 bowersj2 3057:
3058: # Start with the first resource
1.89 bowersj2 3059: if ($self->{DIRECTION} == FORWARD) {
1.100 bowersj2 3060: push @{$self->{STACK}}, $self->{FIRST_RESOURCE};
1.89 bowersj2 3061: } else {
1.100 bowersj2 3062: push @{$self->{STACK}}, $self->{FINISH_RESOURCE};
1.89 bowersj2 3063: }
1.51 bowersj2 3064:
3065: bless($self);
3066: return $self;
3067: }
3068:
3069: sub next {
3070: my $self = shift;
3071:
3072: # Are we using a recursive iterator? If so, pull from that and
3073: # watch the depth; we want to resume our level at the correct time.
1.98 bowersj2 3074: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
1.51 bowersj2 3075: # grab the next from the recursive iterator
3076: my $next = $self->{RECURSIVE_ITERATOR}->next();
3077:
3078: # is it a begin or end map? Update depth if so
3079: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
3080: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
3081:
3082: # Are we back at depth 0? If so, stop recursing.
3083: if ($self->{RECURSIVE_DEPTH} == 0) {
3084: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3085: }
3086:
3087: return $next;
3088: }
3089:
3090: # Is there a current resource to grab? If not, then return
1.100 bowersj2 3091: # END_MAP, which will end the iterator.
3092: if (scalar(@{$self->{STACK}}) == 0) {
3093: return $self->END_MAP();
1.51 bowersj2 3094: }
3095:
3096: # Have we not yet begun? If not, return BEGIN_MAP and
3097: # remember that we've started.
3098: if ( !$self->{STARTED} ) {
3099: $self->{STARTED} = 1;
3100: return $self->BEGIN_MAP;
3101: }
3102:
3103: # Get the next resource in the branch
1.100 bowersj2 3104: $self->{HERE} = pop @{$self->{STACK}};
1.52 bowersj2 3105:
1.100 bowersj2 3106: # remember that we've seen this, so we don't return it again later
1.51 bowersj2 3107: $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
3108:
3109: # Get the next possible resources
1.90 bowersj2 3110: my $nextUnfiltered;
1.89 bowersj2 3111: if ($self->{DIRECTION} == FORWARD()) {
1.90 bowersj2 3112: $nextUnfiltered = $self->{HERE}->getNext();
1.89 bowersj2 3113: } else {
1.90 bowersj2 3114: $nextUnfiltered = $self->{HERE}->getPrevious();
1.89 bowersj2 3115: }
1.51 bowersj2 3116: my $next = [];
3117:
3118: # filter the next possibilities to remove things we've
1.100 bowersj2 3119: # already seen.
1.51 bowersj2 3120: foreach (@$nextUnfiltered) {
1.52 bowersj2 3121: if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
3122: push @$next, $_;
3123: }
1.51 bowersj2 3124: }
3125:
3126: while (@$next) {
1.100 bowersj2 3127: # copy the next possibilities over to the stack
3128: push @{$self->{STACK}}, shift @$next;
1.51 bowersj2 3129: }
3130:
3131: # If this is a map and we want to recurse down it... (not filtered out)
1.70 bowersj2 3132: if ($self->{HERE}->is_map() &&
1.63 bowersj2 3133: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
1.51 bowersj2 3134: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
3135: my $firstResource = $self->{HERE}->map_start();
3136: my $finishResource = $self->{HERE}->map_finish();
3137:
3138: $self->{RECURSIVE_ITERATOR} =
1.94 bowersj2 3139: Apache::lonnavmaps::DFSiterator->new ($self->{NAV_MAP}, $firstResource,
1.63 bowersj2 3140: $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
1.91 bowersj2 3141: $self->{CONDITION}, $self->{DIRECTION});
1.51 bowersj2 3142: }
3143:
3144: return $self->{HERE};
1.190 bowersj2 3145: }
3146:
3147: # Identical to the full iterator methods of the same name. Hate to copy/paste
3148: # but I also hate to "inherit" either iterator from the other.
3149:
3150: sub getStack {
3151: my $self=shift;
3152:
3153: my @stack;
3154:
3155: $self->populateStack(\@stack);
3156:
3157: return \@stack;
3158: }
3159:
3160: # Private method: Calls the iterators recursively to populate the stack.
3161: sub populateStack {
3162: my $self=shift;
3163: my $stack = shift;
3164:
3165: push @$stack, $self->{HERE} if ($self->{HERE});
3166:
3167: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3168: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
3169: }
1.51 bowersj2 3170: }
3171:
1.1 www 3172: 1;
1.2 www 3173:
1.51 bowersj2 3174: package Apache::lonnavmaps::resource;
3175:
3176: use Apache::lonnet;
3177:
3178: =pod
3179:
1.217 bowersj2 3180: =head1 Object: resource
1.51 bowersj2 3181:
1.217 bowersj2 3182: X<resource, navmap object>
1.174 albertel 3183: A resource object encapsulates a resource in a resource map, allowing
3184: easy manipulation of the resource, querying the properties of the
3185: resource (including user properties), and represents a reference that
3186: can be used as the canonical representation of the resource by
3187: lonnavmap clients like renderers.
3188:
3189: A resource only makes sense in the context of a navmap, as some of the
3190: data is stored in the navmap object.
3191:
3192: You will probably never need to instantiate this object directly. Use
3193: Apache::lonnavmaps::navmap, and use the "start" method to obtain the
3194: starting resource.
1.51 bowersj2 3195:
1.188 bowersj2 3196: Resource objects respect the parameter_hiddenparts, which suppresses
3197: various parts according to the wishes of the map author. As of this
3198: writing, there is no way to override this parameter, and suppressed
3199: parts will never be returned, nor will their response types or ids be
3200: stored.
3201:
1.217 bowersj2 3202: =head2 Overview
1.51 bowersj2 3203:
1.217 bowersj2 3204: A B<Resource> is the most granular type of object in LON-CAPA that can
3205: be included in a course. It can either be a particular resource, like
3206: an HTML page, external resource, problem, etc., or it can be a
3207: container sequence, such as a "page" or a "map".
3208:
3209: To see a sequence from the user's point of view, please see the
3210: B<Creating a Course: Maps and Sequences> chapter of the Author's
3211: Manual.
3212:
3213: A Resource Object, once obtained from a navmap object via a B<getBy*>
3214: method of the navmap, or from an iterator, allows you to query
3215: information about that resource.
3216:
3217: Generally, you do not ever want to create a resource object yourself,
3218: so creation has been left undocumented. Always retrieve resources
3219: from navmap objects.
3220:
3221: =head3 Identifying Resources
3222:
3223: X<big hash>Every resource is identified by a Resource ID in the big hash that is
3224: unique to that resource for a given course. X<resource ID, in big hash>
3225: The Resource ID has the form #.#, where the first number is the same
3226: for every resource in a map, and the second is unique. For instance,
3227: for a course laid out like this:
3228:
3229: * Problem 1
3230: * Map
3231: * Resource 2
3232: * Resource 3
3233:
3234: C<Problem 1> and C<Map> will share a first number, and C<Resource 2>
3235: C<Resource 3> will share a first number. The second number may end up
3236: re-used between the two groups.
3237:
3238: The resource ID is only used in the big hash, but can be used in the
3239: context of a course to identify a resource easily. (For instance, the
3240: printing system uses it to record which resources from a sequence you
3241: wish to print.)
3242:
3243: X<symb> X<resource, symb>
3244: All resources also have B<symb>s, which uniquely identify a resource
3245: in a course. Many internal LON-CAPA functions expect a symb. A symb
3246: carries along with it the URL of the resource, and the map it appears
3247: in. Symbs are much larger then resource IDs.
1.51 bowersj2 3248:
3249: =cut
3250:
3251: sub new {
3252: # magic invocation to create a class instance
3253: my $proto = shift;
3254: my $class = ref($proto) || $proto;
3255: my $self = {};
3256:
3257: $self->{NAV_MAP} = shift;
3258: $self->{ID} = shift;
3259:
3260: # Store this new resource in the parent nav map's cache.
3261: $self->{NAV_MAP}->{RESOURCE_CACHE}->{$self->{ID}} = $self;
1.66 bowersj2 3262: $self->{RESOURCE_ERROR} = 0;
1.51 bowersj2 3263:
3264: # A hash that can be used by two-pass algorithms to store data
3265: # about this resource in. Not used by the resource object
3266: # directly.
3267: $self->{DATA} = {};
3268:
3269: bless($self);
3270:
3271: return $self;
3272: }
3273:
1.70 bowersj2 3274: # private function: simplify the NAV_HASH lookups we keep doing
3275: # pass the name, and to automatically append my ID, pass a true val on the
3276: # second param
3277: sub navHash {
3278: my $self = shift;
3279: my $param = shift;
3280: my $id = shift;
1.115 bowersj2 3281: return $self->{NAV_MAP}->navhash($param . ($id?$self->{ID}:""));
1.70 bowersj2 3282: }
3283:
1.51 bowersj2 3284: =pod
3285:
1.217 bowersj2 3286: =head2 Methods
1.70 bowersj2 3287:
1.217 bowersj2 3288: Once you have a resource object, here's what you can do with it:
3289:
3290: =head3 Attribute Retrieval
3291:
3292: Every resource has certain attributes that can be retrieved and used:
1.70 bowersj2 3293:
3294: =over 4
3295:
1.217 bowersj2 3296: =item * B<ID>: Every resource has an ID that is unique for that
3297: resource in the course it is in. The ID is actually in the hash
3298: representing the resource, so for a resource object $res, obtain
3299: it via C<$res->{ID}).
3300:
1.174 albertel 3301: =item * B<compTitle>:
3302:
3303: Returns a "composite title", that is equal to $res->title() if the
3304: resource has a title, and is otherwise the last part of the URL (e.g.,
3305: "problem.problem").
3306:
3307: =item * B<ext>:
3308:
3309: Returns true if the resource is external.
3310:
3311: =item * B<kind>:
3312:
3313: Returns the kind of the resource from the compiled nav map.
3314:
3315: =item * B<randomout>:
1.106 bowersj2 3316:
1.174 albertel 3317: Returns true if this resource was chosen to NOT be shown to the user
3318: by the random map selection feature. In other words, this is usually
3319: false.
1.70 bowersj2 3320:
1.174 albertel 3321: =item * B<randompick>:
1.70 bowersj2 3322:
1.174 albertel 3323: Returns true for a map if the randompick feature is being used on the
3324: map. (?)
1.70 bowersj2 3325:
1.174 albertel 3326: =item * B<src>:
1.51 bowersj2 3327:
1.174 albertel 3328: Returns the source for the resource.
1.70 bowersj2 3329:
1.174 albertel 3330: =item * B<symb>:
1.70 bowersj2 3331:
1.174 albertel 3332: Returns the symb for the resource.
1.70 bowersj2 3333:
1.174 albertel 3334: =item * B<title>:
1.70 bowersj2 3335:
1.174 albertel 3336: Returns the title of the resource.
3337:
1.51 bowersj2 3338: =back
3339:
3340: =cut
3341:
3342: # These info functions can be used directly, as they don't return
3343: # resource information.
1.85 bowersj2 3344: sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); }
1.70 bowersj2 3345: sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; }
1.85 bowersj2 3346: sub from { my $self=shift; return $self->navHash("from_", 1); }
1.217 bowersj2 3347: # considered private and undocumented
1.51 bowersj2 3348: sub goesto { my $self=shift; return $self->navHash("goesto_", 1); }
3349: sub kind { my $self=shift; return $self->navHash("kind_", 1); }
1.68 bowersj2 3350: sub randomout { my $self=shift; return $self->navHash("randomout_", 1); }
3351: sub randompick {
3352: my $self = shift;
3353: return $self->{NAV_MAP}->{PARM_HASH}->{$self->symb .
3354: '.0.parameter_randompick'};
3355: }
1.51 bowersj2 3356: sub src {
3357: my $self=shift;
3358: return $self->navHash("src_", 1);
3359: }
3360: sub symb {
3361: my $self=shift;
3362: (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
3363: my $symbSrc = &Apache::lonnet::declutter($self->src());
1.223 albertel 3364: my $symb = &Apache::lonnet::declutter($self->navHash('map_id_'.$first))
1.51 bowersj2 3365: . '___' . $second . '___' . $symbSrc;
1.223 albertel 3366: return &Apache::lonnet::symbclean($symb);
1.51 bowersj2 3367: }
1.213 bowersj2 3368: sub title {
3369: my $self=shift;
3370: if ($self->{ID} eq '0.0') {
3371: # If this is the top-level map, return the title of the course
3372: # since this map can not be titled otherwise.
3373: return $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
3374: }
3375: return $self->navHash("title_", 1); }
1.217 bowersj2 3376: # considered private and undocumented
1.70 bowersj2 3377: sub to { my $self=shift; return $self->navHash("to_", 1); }
1.106 bowersj2 3378: sub compTitle {
3379: my $self = shift;
3380: my $title = $self->title();
1.176 www 3381: $title=~s/\&colon\;/\:/gs;
1.106 bowersj2 3382: if (!$title) {
3383: $title = $self->src();
3384: $title = substr($title, rindex($title, '/') + 1);
3385: }
3386: return $title;
3387: }
1.70 bowersj2 3388: =pod
3389:
3390: B<Predicate Testing the Resource>
3391:
3392: These methods are shortcuts to deciding if a given resource has a given property.
3393:
3394: =over 4
3395:
1.174 albertel 3396: =item * B<is_map>:
3397:
3398: Returns true if the resource is a map type.
3399:
3400: =item * B<is_problem>:
1.70 bowersj2 3401:
1.174 albertel 3402: Returns true if the resource is a problem type, false
3403: otherwise. (Looks at the extension on the src field; might need more
3404: to work correctly.)
1.70 bowersj2 3405:
1.174 albertel 3406: =item * B<is_page>:
1.70 bowersj2 3407:
1.174 albertel 3408: Returns true if the resource is a page.
3409:
3410: =item * B<is_sequence>:
3411:
3412: Returns true if the resource is a sequence.
1.70 bowersj2 3413:
3414: =back
3415:
3416: =cut
3417:
1.256 albertel 3418: sub hasResource {
3419: my $self = shift;
3420: return $self->{NAV_MAP}->hasResource(@_);
3421: }
3422:
3423: sub retrieveResources {
3424: my $self = shift;
3425: return $self->{NAV_MAP}->retrieveResources(@_);
3426: }
1.70 bowersj2 3427:
3428: sub is_html {
1.51 bowersj2 3429: my $self=shift;
3430: my $src = $self->src();
1.70 bowersj2 3431: return ($src =~ /html$/);
1.51 bowersj2 3432: }
1.70 bowersj2 3433: sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
3434: sub is_page {
1.51 bowersj2 3435: my $self=shift;
3436: my $src = $self->src();
1.205 bowersj2 3437: return $self->navHash("is_map_", 1) &&
3438: $self->navHash("map_type_" . $self->map_pc()) eq 'page';
1.51 bowersj2 3439: }
1.70 bowersj2 3440: sub is_problem {
1.51 bowersj2 3441: my $self=shift;
3442: my $src = $self->src();
1.256 albertel 3443: return ($src =~ /\.(problem|exam|quiz|assess|survey|form|library)$/)
3444: }
3445: sub contains_problem {
3446: my $self=shift;
3447: if ($self->is_page()) {
3448: my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
3449: return $hasProblem;
3450: }
3451: return 0;
1.51 bowersj2 3452: }
1.70 bowersj2 3453: sub is_sequence {
1.51 bowersj2 3454: my $self=shift;
3455: my $src = $self->src();
1.205 bowersj2 3456: return $self->navHash("is_map_", 1) &&
3457: $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
1.51 bowersj2 3458: }
1.261 matthew 3459: sub is_survey {
3460: my $self = shift();
3461: my $part = shift();
1.263 albertel 3462: if ($self->parmval('type',$part) eq 'survey') {
1.261 matthew 3463: return 1;
3464: }
1.263 albertel 3465: if ($self->src() =~ /\.(survey)$/) {
1.261 matthew 3466: return 1;
3467: }
3468: return 0;
3469: }
1.51 bowersj2 3470:
1.266 raeburn 3471: sub is_empty_sequence {
3472: my $self=shift;
3473: my $src = $self->src();
3474: return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
3475: }
3476:
1.101 bowersj2 3477: # Private method: Shells out to the parmval in the nav map, handler parts.
1.51 bowersj2 3478: sub parmval {
3479: my $self = shift;
3480: my $what = shift;
1.185 bowersj2 3481: my $part = shift;
3482: if (!defined($part)) {
3483: $part = '0';
3484: }
1.51 bowersj2 3485: return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->symb());
3486: }
3487:
1.70 bowersj2 3488: =pod
3489:
3490: B<Map Methods>
3491:
1.174 albertel 3492: These methods are useful for getting information about the map
3493: properties of the resource, if the resource is a map (B<is_map>).
1.70 bowersj2 3494:
3495: =over 4
3496:
1.174 albertel 3497: =item * B<map_finish>:
3498:
3499: Returns a reference to a resource object corresponding to the finish
3500: resource of the map.
1.70 bowersj2 3501:
1.174 albertel 3502: =item * B<map_pc>:
1.70 bowersj2 3503:
1.174 albertel 3504: Returns the pc value of the map, which is the first number that
3505: appears in the resource ID of the resources in the map, and is the
3506: number that appears around the middle of the symbs of the resources in
3507: that map.
1.70 bowersj2 3508:
1.174 albertel 3509: =item * B<map_start>:
3510:
3511: Returns a reference to a resource object corresponding to the start
3512: resource of the map.
3513:
3514: =item * B<map_type>:
3515:
3516: Returns a string with the type of the map in it.
1.70 bowersj2 3517:
3518: =back
1.51 bowersj2 3519:
1.70 bowersj2 3520: =cut
1.51 bowersj2 3521:
3522: sub map_finish {
3523: my $self = shift;
3524: my $src = $self->src();
1.144 bowersj2 3525: $src = Apache::lonnet::clutter($src);
1.51 bowersj2 3526: my $res = $self->navHash("map_finish_$src", 0);
3527: $res = $self->{NAV_MAP}->getById($res);
3528: return $res;
3529: }
1.70 bowersj2 3530: sub map_pc {
3531: my $self = shift;
3532: my $src = $self->src();
3533: return $self->navHash("map_pc_$src", 0);
3534: }
1.51 bowersj2 3535: sub map_start {
3536: my $self = shift;
3537: my $src = $self->src();
1.144 bowersj2 3538: $src = Apache::lonnet::clutter($src);
1.51 bowersj2 3539: my $res = $self->navHash("map_start_$src", 0);
3540: $res = $self->{NAV_MAP}->getById($res);
3541: return $res;
3542: }
3543: sub map_type {
3544: my $self = shift;
3545: my $pc = $self->map_pc();
3546: return $self->navHash("map_type_$pc", 0);
3547: }
3548:
3549: #####
3550: # Property queries
3551: #####
3552:
3553: # These functions will be responsible for returning the CORRECT
3554: # VALUE for the parameter, no matter what. So while they may look
3555: # like direct calls to parmval, they can be more then that.
3556: # So, for instance, the duedate function should use the "duedatetype"
3557: # information, rather then the resource object user.
3558:
3559: =pod
3560:
3561: =head2 Resource Parameters
3562:
1.174 albertel 3563: In order to use the resource parameters correctly, the nav map must
3564: have been instantiated with genCourseAndUserOptions set to true, so
3565: the courseopt and useropt is read correctly. Then, you can call these
3566: functions to get the relevant parameters for the resource. Each
3567: function defaults to part "0", but can be directed to another part by
3568: passing the part as the parameter.
3569:
3570: These methods are responsible for getting the parameter correct, not
3571: merely reflecting the contents of the GDBM hashes. As we move towards
3572: dates relative to other dates, these methods should be updated to
3573: reflect that. (Then, anybody using these methods will not have to update
3574: their code.)
3575:
3576: =over 4
3577:
3578: =item * B<acc>:
3579:
3580: Get the Client IP/Name Access Control information.
1.51 bowersj2 3581:
1.174 albertel 3582: =item * B<answerdate>:
1.51 bowersj2 3583:
1.174 albertel 3584: Get the answer-reveal date for the problem.
3585:
1.211 bowersj2 3586: =item * B<awarded>:
3587:
3588: Gets the awarded value for the problem part. Requires genUserData set to
3589: true when the navmap object was created.
3590:
1.174 albertel 3591: =item * B<duedate>:
3592:
3593: Get the due date for the problem.
3594:
3595: =item * B<tries>:
3596:
3597: Get the number of tries the student has used on the problem.
3598:
3599: =item * B<maxtries>:
3600:
3601: Get the number of max tries allowed.
3602:
3603: =item * B<opendate>:
1.51 bowersj2 3604:
1.174 albertel 3605: Get the open date for the problem.
1.51 bowersj2 3606:
1.174 albertel 3607: =item * B<sig>:
1.51 bowersj2 3608:
1.174 albertel 3609: Get the significant figures setting.
1.51 bowersj2 3610:
1.174 albertel 3611: =item * B<tol>:
1.51 bowersj2 3612:
1.174 albertel 3613: Get the tolerance for the problem.
1.51 bowersj2 3614:
1.174 albertel 3615: =item * B<tries>:
1.51 bowersj2 3616:
1.174 albertel 3617: Get the number of tries the user has already used on the problem.
1.51 bowersj2 3618:
1.174 albertel 3619: =item * B<type>:
1.51 bowersj2 3620:
1.174 albertel 3621: Get the question type for the problem.
1.70 bowersj2 3622:
1.174 albertel 3623: =item * B<weight>:
1.51 bowersj2 3624:
1.174 albertel 3625: Get the weight for the problem.
1.51 bowersj2 3626:
3627: =back
3628:
3629: =cut
3630:
3631: sub acc {
3632: (my $self, my $part) = @_;
3633: return $self->parmval("acc", $part);
3634: }
3635: sub answerdate {
3636: (my $self, my $part) = @_;
3637: # Handle intervals
3638: if ($self->parmval("answerdate.type", $part) eq 'date_interval') {
3639: return $self->duedate($part) +
3640: $self->parmval("answerdate", $part);
3641: }
3642: return $self->parmval("answerdate", $part);
1.106 bowersj2 3643: }
1.211 bowersj2 3644: sub awarded {
3645: my $self = shift; my $part = shift;
1.221 bowersj2 3646: $self->{NAV_MAP}->get_user_data();
1.211 bowersj2 3647: if (!defined($part)) { $part = '0'; }
3648: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->symb()}->{'resource.'.$part.'.awarded'};
3649: }
1.51 bowersj2 3650: sub duedate {
3651: (my $self, my $part) = @_;
1.260 albertel 3652: my $interval=$self->parmval("interval", $part);
3653: if ($interval) {
3654: my $first_access=&Apache::lonnet::get_first_access('map',$self->symb);
3655: if ($first_access) { return ($first_access+$interval); }
3656: }
1.51 bowersj2 3657: return $self->parmval("duedate", $part);
3658: }
3659: sub maxtries {
3660: (my $self, my $part) = @_;
3661: return $self->parmval("maxtries", $part);
3662: }
3663: sub opendate {
3664: (my $self, my $part) = @_;
3665: if ($self->parmval("opendate.type", $part) eq 'date_interval') {
3666: return $self->duedate($part) -
3667: $self->parmval("opendate", $part);
3668: }
3669: return $self->parmval("opendate");
3670: }
1.185 bowersj2 3671: sub problemstatus {
3672: (my $self, my $part) = @_;
1.236 bowersj2 3673: return lc $self->parmval("problemstatus", $part);
1.185 bowersj2 3674: }
1.51 bowersj2 3675: sub sig {
3676: (my $self, my $part) = @_;
3677: return $self->parmval("sig", $part);
3678: }
3679: sub tol {
3680: (my $self, my $part) = @_;
3681: return $self->parmval("tol", $part);
3682: }
1.108 bowersj2 3683: sub tries {
3684: my $self = shift;
3685: my $tries = $self->queryRestoreHash('tries', shift);
3686: if (!defined($tries)) { return '0';}
1.51 bowersj2 3687: return $tries;
3688: }
1.70 bowersj2 3689: sub type {
3690: (my $self, my $part) = @_;
3691: return $self->parmval("type", $part);
3692: }
1.109 bowersj2 3693: sub weight {
3694: my $self = shift; my $part = shift;
1.211 bowersj2 3695: if (!defined($part)) { $part = '0'; }
3696: return &Apache::lonnet::EXT('resource.'.$part.'.weight',
3697: $self->symb(), $ENV{'user.domain'},
3698: $ENV{'user.name'},
3699: $ENV{'request.course.sec'});
1.274 matthew 3700: }
3701: sub part_display {
3702: my $self= shift(); my $partID = shift();
3703: if (! defined($partID)) { $partID = '0'; }
3704: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
3705: $self->symb);
3706: if (! defined($display) || $display eq '') {
3707: $display = $partID;
3708: }
3709: return $display;
1.70 bowersj2 3710: }
1.51 bowersj2 3711:
3712: # Multiple things need this
3713: sub getReturnHash {
3714: my $self = shift;
3715:
3716: if (!defined($self->{RETURN_HASH})) {
1.84 bowersj2 3717: my %tmpHash = &Apache::lonnet::restore($self->symb());
1.51 bowersj2 3718: $self->{RETURN_HASH} = \%tmpHash;
3719: }
3720: }
3721:
3722: ######
3723: # Status queries
3724: ######
3725:
3726: # These methods query the status of problems.
3727:
3728: # If we need to count parts, this function determines the number of
3729: # parts from the metadata. When called, it returns a reference to a list
3730: # of strings corresponding to the parts. (Thus, using it in a scalar context
3731: # tells you how many parts you have in the problem:
3732: # $partcount = scalar($resource->countParts());
3733: # Don't use $self->{PARTS} directly because you don't know if it's been
3734: # computed yet.
3735:
3736: =pod
3737:
3738: =head2 Resource misc
3739:
3740: Misc. functions for the resource.
3741:
3742: =over 4
3743:
1.174 albertel 3744: =item * B<hasDiscussion>:
1.59 bowersj2 3745:
1.174 albertel 3746: Returns a false value if there has been discussion since the user last
3747: logged in, true if there has. Always returns false if the discussion
3748: data was not extracted when the nav map was constructed.
3749:
3750: =item * B<getFeedback>:
3751:
3752: Gets the feedback for the resource and returns the raw feedback string
3753: for the resource, or the null string if there is no feedback or the
3754: email data was not extracted when the nav map was constructed. Usually
3755: used like this:
1.59 bowersj2 3756:
3757: for (split(/\,/, $res->getFeedback())) {
3758: my $link = &Apache::lonnet::escape($_);
3759: ...
3760:
3761: and use the link as appropriate.
3762:
3763: =cut
3764:
3765: sub hasDiscussion {
3766: my $self = shift;
3767: return $self->{NAV_MAP}->hasDiscussion($self->symb());
3768: }
3769:
3770: sub getFeedback {
3771: my $self = shift;
1.124 bowersj2 3772: my $source = $self->src();
1.125 bowersj2 3773: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.124 bowersj2 3774: return $self->{NAV_MAP}->getFeedback($source);
3775: }
3776:
3777: sub getErrors {
3778: my $self = shift;
3779: my $source = $self->src();
3780: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
3781: return $self->{NAV_MAP}->getErrors($source);
1.59 bowersj2 3782: }
3783:
3784: =pod
3785:
1.174 albertel 3786: =item * B<parts>():
1.51 bowersj2 3787:
1.174 albertel 3788: Returns a list reference containing sorted strings corresponding to
1.193 bowersj2 3789: each part of the problem. Single part problems have only a part '0'.
3790: Multipart problems do not return their part '0', since they typically
3791: do not really matter.
1.174 albertel 3792:
3793: =item * B<countParts>():
3794:
3795: Returns the number of parts of the problem a student can answer. Thus,
3796: for single part problems, returns 1. For multipart, it returns the
1.193 bowersj2 3797: number of parts in the problem, not including psuedo-part 0.
1.51 bowersj2 3798:
1.192 bowersj2 3799: =item * B<multipart>():
3800:
1.193 bowersj2 3801: Returns true if the problem is multipart, false otherwise. Use this instead
3802: of countParts if all you want is multipart/not multipart.
1.192 bowersj2 3803:
1.187 bowersj2 3804: =item * B<responseType>($part):
3805:
3806: Returns the response type of the part, without the word "response" on the
3807: end. Example return values: 'string', 'essay', 'numeric', etc.
3808:
1.193 bowersj2 3809: =item * B<responseIds>($part):
1.187 bowersj2 3810:
1.193 bowersj2 3811: Retreives the response IDs for the given part as an array reference containing
3812: strings naming the response IDs. This may be empty.
1.187 bowersj2 3813:
1.51 bowersj2 3814: =back
3815:
3816: =cut
3817:
3818: sub parts {
3819: my $self = shift;
3820:
1.192 bowersj2 3821: if ($self->ext) { return []; }
1.67 bowersj2 3822:
1.51 bowersj2 3823: $self->extractParts();
3824: return $self->{PARTS};
3825: }
3826:
3827: sub countParts {
3828: my $self = shift;
3829:
3830: my $parts = $self->parts();
1.191 bowersj2 3831:
3832: # If I left this here, then it's not necessary.
3833: #my $delta = 0;
3834: #for my $part (@$parts) {
3835: # if ($part eq '0') { $delta--; }
3836: #}
1.66 bowersj2 3837:
3838: if ($self->{RESOURCE_ERROR}) {
3839: return 0;
3840: }
3841:
1.191 bowersj2 3842: return scalar(@{$parts}); # + $delta;
1.192 bowersj2 3843: }
3844:
3845: sub multipart {
3846: my $self = shift;
3847: return $self->countParts() > 1;
1.51 bowersj2 3848: }
3849:
1.225 bowersj2 3850: sub singlepart {
3851: my $self = shift;
3852: return $self->countParts() == 1;
3853: }
3854:
1.187 bowersj2 3855: sub responseType {
1.184 bowersj2 3856: my $self = shift;
3857: my $part = shift;
3858:
3859: $self->extractParts();
1.235 albertel 3860: if (defined($self->{RESPONSE_TYPES}->{$part})) {
3861: return @{$self->{RESPONSE_TYPES}->{$part}};
3862: } else {
3863: return undef;
3864: }
1.187 bowersj2 3865: }
3866:
1.193 bowersj2 3867: sub responseIds {
1.187 bowersj2 3868: my $self = shift;
3869: my $part = shift;
3870:
3871: $self->extractParts();
1.235 albertel 3872: if (defined($self->{RESPONSE_IDS}->{$part})) {
3873: return @{$self->{RESPONSE_IDS}->{$part}};
3874: } else {
3875: return undef;
3876: }
1.184 bowersj2 3877: }
3878:
3879: # Private function: Extracts the parts information, both part names and
1.187 bowersj2 3880: # part types, and saves it.
1.51 bowersj2 3881: sub extractParts {
3882: my $self = shift;
3883:
1.153 bowersj2 3884: return if (defined($self->{PARTS}));
1.67 bowersj2 3885: return if ($self->ext);
1.51 bowersj2 3886:
3887: $self->{PARTS} = [];
3888:
1.181 bowersj2 3889: my %parts;
3890:
1.82 bowersj2 3891: # Retrieve part count, if this is a problem
3892: if ($self->is_problem()) {
1.240 albertel 3893: my $partorder = &Apache::lonnet::metadata($self->src(), 'partorder');
1.152 matthew 3894: my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
1.181 bowersj2 3895:
1.239 bowersj2 3896: if ($partorder) {
3897: my @parts;
3898: for my $part (split (/,/,$partorder)) {
3899: if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) {
3900: push @parts, $part;
1.241 albertel 3901: $parts{$part} = 1;
1.239 bowersj2 3902: }
3903: }
3904: $self->{PARTS} = \@parts;
3905: } else {
3906: if (!$metadata) {
3907: $self->{RESOURCE_ERROR} = 1;
3908: $self->{PARTS} = [];
3909: $self->{PART_TYPE} = {};
3910: return;
3911: }
3912: foreach (split(/\,/,$metadata)) {
3913: if ($_ =~ /^part_(.*)$/) {
3914: my $part = $1;
3915: # This floods the logs if it blows up
3916: if (defined($parts{$part})) {
1.241 albertel 3917: &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->symb());
3918: }
1.239 bowersj2 3919:
3920: # check to see if part is turned off.
3921:
3922: if (!Apache::loncommon::check_if_partid_hidden($part, $self->symb())) {
3923: $parts{$part} = 1;
3924: }
3925: }
3926: }
3927: my @sortedParts = sort keys %parts;
3928: $self->{PARTS} = \@sortedParts;
1.51 bowersj2 3929: }
1.82 bowersj2 3930:
1.187 bowersj2 3931:
3932: my %responseIdHash;
3933: my %responseTypeHash;
3934:
1.189 bowersj2 3935:
3936: # Init the responseIdHash
3937: foreach (@{$self->{PARTS}}) {
3938: $responseIdHash{$_} = [];
3939: }
3940:
1.187 bowersj2 3941: # Now, the unfortunate thing about this is that parts, part name, and
1.239 bowersj2 3942: # response id are delimited by underscores, but both the part
1.187 bowersj2 3943: # name and response id can themselves have underscores in them.
3944: # So we have to use our knowlege of part names to figure out
3945: # where the part names begin and end, and even then, it is possible
3946: # to construct ambiguous situations.
3947: foreach (split /,/, $metadata) {
3948: if ($_ =~ /^([a-zA-Z]+)response_(.*)/) {
3949: my $responseType = $1;
3950: my $partStuff = $2;
3951: my $partIdSoFar = '';
3952: my @partChunks = split /_/, $partStuff;
3953: my $i = 0;
3954: for ($i = 0; $i < scalar(@partChunks); $i++) {
3955: if ($partIdSoFar) { $partIdSoFar .= '_'; }
3956: $partIdSoFar .= $partChunks[$i];
3957: if ($parts{$partIdSoFar}) {
3958: my @otherChunks = @partChunks[$i+1..$#partChunks];
3959: my $responseId = join('_', @otherChunks);
1.188 bowersj2 3960: push @{$responseIdHash{$partIdSoFar}}, $responseId;
1.233 matthew 3961: push @{$responseTypeHash{$partIdSoFar}}, $responseType;
1.187 bowersj2 3962: }
3963: }
3964: }
3965: }
1.264 albertel 3966: my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
3967: if ($resorder) {
3968: my @resorder=split(/,/,$resorder);
3969: foreach my $part (keys(%responseIdHash)) {
3970: my %resids = map { ($_,1) } @{ $responseIdHash{$part} };
3971: my @neworder;
3972: foreach my $possibleid (@resorder) {
3973: if (exists($resids{$possibleid})) {
3974: push(@neworder,$possibleid);
3975: }
3976: }
3977: $responseIdHash{$part}=\@neworder;
3978: }
3979: }
1.187 bowersj2 3980: $self->{RESPONSE_IDS} = \%responseIdHash;
3981: $self->{RESPONSE_TYPES} = \%responseTypeHash;
1.154 bowersj2 3982: }
3983:
1.51 bowersj2 3984: return;
3985: }
3986:
3987: =pod
3988:
3989: =head2 Resource Status
3990:
1.174 albertel 3991: Problem resources have status information, reflecting their various
3992: dates and completion statuses.
1.51 bowersj2 3993:
1.174 albertel 3994: There are two aspects to the status: the date-related information and
3995: the completion information.
1.51 bowersj2 3996:
1.174 albertel 3997: Idiomatic usage of these two methods would probably look something
3998: like
1.51 bowersj2 3999:
4000: foreach ($resource->parts()) {
4001: my $dateStatus = $resource->getDateStatus($_);
4002: my $completionStatus = $resource->getCompletionStatus($_);
4003:
1.70 bowersj2 4004: or
4005:
4006: my $status = $resource->status($_);
4007:
1.51 bowersj2 4008: ... use it here ...
4009: }
4010:
1.174 albertel 4011: Which you use depends on exactly what you are looking for. The
4012: status() function has been optimized for the nav maps display and may
4013: not precisely match what you need elsewhere.
1.101 bowersj2 4014:
1.174 albertel 4015: The symbolic constants shown below can be accessed through the
4016: resource object: C<$res->OPEN>.
1.101 bowersj2 4017:
1.51 bowersj2 4018: =over 4
4019:
1.174 albertel 4020: =item * B<getDateStatus>($part):
4021:
4022: ($part defaults to 0). A convenience function that returns a symbolic
4023: constant telling you about the date status of the part. The possible
4024: return values are:
1.51 bowersj2 4025:
4026: =back
4027:
4028: B<Date Codes>
4029:
4030: =over 4
4031:
1.174 albertel 4032: =item * B<OPEN_LATER>:
4033:
4034: The problem will be opened later.
4035:
4036: =item * B<OPEN>:
4037:
4038: Open and not yet due.
4039:
1.51 bowersj2 4040:
1.174 albertel 4041: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 4042:
1.174 albertel 4043: The due date has passed, but the answer date has not yet arrived.
1.59 bowersj2 4044:
1.174 albertel 4045: =item * B<PAST_DUE_NO_ANSWER>:
1.54 bowersj2 4046:
1.174 albertel 4047: The due date has passed and there is no answer opening date set.
1.51 bowersj2 4048:
1.174 albertel 4049: =item * B<ANSWER_OPEN>:
1.51 bowersj2 4050:
1.174 albertel 4051: The answer date is here.
4052:
4053: =item * B<NETWORK_FAILURE>:
4054:
4055: The information is unknown due to network failure.
1.51 bowersj2 4056:
4057: =back
4058:
4059: =cut
4060:
4061: # Apparently the compiler optimizes these into constants automatically
1.54 bowersj2 4062: sub OPEN_LATER { return 0; }
4063: sub OPEN { return 1; }
4064: sub PAST_DUE_NO_ANSWER { return 2; }
4065: sub PAST_DUE_ANSWER_LATER { return 3; }
4066: sub ANSWER_OPEN { return 4; }
4067: sub NOTHING_SET { return 5; }
4068: sub NETWORK_FAILURE { return 100; }
4069:
4070: # getDateStatus gets the date status for a given problem part.
4071: # Because answer date, due date, and open date are fully independent
4072: # (i.e., it is perfectly possible to *only* have an answer date),
4073: # we have to completely cover the 3x3 maxtrix of (answer, due, open) x
4074: # (past, future, none given). This function handles this with a decision
4075: # tree. Read the comments to follow the decision tree.
1.51 bowersj2 4076:
4077: sub getDateStatus {
4078: my $self = shift;
4079: my $part = shift;
4080: $part = "0" if (!defined($part));
1.54 bowersj2 4081:
4082: # Always return network failure if there was one.
1.51 bowersj2 4083: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
4084:
4085: my $now = time();
4086:
1.53 bowersj2 4087: my $open = $self->opendate($part);
4088: my $due = $self->duedate($part);
4089: my $answer = $self->answerdate($part);
4090:
4091: if (!$open && !$due && !$answer) {
4092: # no data on the problem at all
4093: # should this be the same as "open later"? think multipart.
4094: return $self->NOTHING_SET;
4095: }
1.59 bowersj2 4096: if (!$open || $now < $open) {return $self->OPEN_LATER}
4097: if (!$due || $now < $due) {return $self->OPEN}
4098: if ($answer && $now < $answer) {return $self->PAST_DUE_ANSWER_LATER}
4099: if ($answer) { return $self->ANSWER_OPEN; }
1.54 bowersj2 4100: return PAST_DUE_NO_ANSWER;
1.51 bowersj2 4101: }
4102:
4103: =pod
4104:
4105: B<>
4106:
4107: =over 4
4108:
1.174 albertel 4109: =item * B<getCompletionStatus>($part):
1.51 bowersj2 4110:
1.174 albertel 4111: ($part defaults to 0.) A convenience function that returns a symbolic
4112: constant telling you about the completion status of the part, with the
4113: following possible results:
4114:
4115: =back
1.51 bowersj2 4116:
4117: B<Completion Codes>
4118:
4119: =over 4
4120:
1.174 albertel 4121: =item * B<NOT_ATTEMPTED>:
4122:
4123: Has not been attempted at all.
4124:
4125: =item * B<INCORRECT>:
4126:
4127: Attempted, but wrong by student.
1.51 bowersj2 4128:
1.174 albertel 4129: =item * B<INCORRECT_BY_OVERRIDE>:
1.51 bowersj2 4130:
1.174 albertel 4131: Attempted, but wrong by instructor override.
1.51 bowersj2 4132:
1.174 albertel 4133: =item * B<CORRECT>:
1.51 bowersj2 4134:
1.174 albertel 4135: Correct or correct by instructor.
1.51 bowersj2 4136:
1.174 albertel 4137: =item * B<CORRECT_BY_OVERRIDE>:
1.51 bowersj2 4138:
1.174 albertel 4139: Correct by instructor override.
1.51 bowersj2 4140:
1.174 albertel 4141: =item * B<EXCUSED>:
4142:
4143: Excused. Not yet implemented.
4144:
4145: =item * B<NETWORK_FAILURE>:
4146:
4147: Information not available due to network failure.
4148:
4149: =item * B<ATTEMPTED>:
4150:
4151: Attempted, and not yet graded.
1.69 bowersj2 4152:
1.51 bowersj2 4153: =back
4154:
4155: =cut
4156:
1.53 bowersj2 4157: sub NOT_ATTEMPTED { return 10; }
4158: sub INCORRECT { return 11; }
4159: sub INCORRECT_BY_OVERRIDE { return 12; }
4160: sub CORRECT { return 13; }
4161: sub CORRECT_BY_OVERRIDE { return 14; }
4162: sub EXCUSED { return 15; }
1.69 bowersj2 4163: sub ATTEMPTED { return 16; }
1.51 bowersj2 4164:
4165: sub getCompletionStatus {
4166: my $self = shift;
4167: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
4168:
1.108 bowersj2 4169: my $status = $self->queryRestoreHash('solved', shift);
1.51 bowersj2 4170:
1.251 www 4171: # Left as separate if statements in case we ever do more with this
1.51 bowersj2 4172: if ($status eq 'correct_by_student') {return $self->CORRECT;}
4173: if ($status eq 'correct_by_override') {return $self->CORRECT_BY_OVERRIDE; }
4174: if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
4175: if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
4176: if ($status eq 'excused') {return $self->EXCUSED; }
1.69 bowersj2 4177: if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
1.51 bowersj2 4178: return $self->NOT_ATTEMPTED;
1.108 bowersj2 4179: }
4180:
4181: sub queryRestoreHash {
4182: my $self = shift;
4183: my $hashentry = shift;
4184: my $part = shift;
1.185 bowersj2 4185: $part = "0" if (!defined($part) || $part eq '');
1.108 bowersj2 4186: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
4187:
4188: $self->getReturnHash();
4189:
4190: return $self->{RETURN_HASH}->{'resource.'.$part.'.'.$hashentry};
1.51 bowersj2 4191: }
4192:
4193: =pod
4194:
4195: B<Composite Status>
4196:
1.174 albertel 4197: Along with directly returning the date or completion status, the
4198: resource object includes a convenience function B<status>() that will
4199: combine the two status tidbits into one composite status that can
1.191 bowersj2 4200: represent the status of the resource as a whole. This method represents
4201: the concept of the thing we want to display to the user on the nav maps
4202: screen, which is a combination of completion and open status. The precise logic is
1.174 albertel 4203: documented in the comments of the status method. The following results
4204: may be returned, all available as methods on the resource object
1.185 bowersj2 4205: ($res->NETWORK_FAILURE): In addition to the return values that match
4206: the date or completion status, this function can return "ANSWER_SUBMITTED"
4207: if that problemstatus parameter value is set to No, suppressing the
4208: incorrect/correct feedback.
1.51 bowersj2 4209:
4210: =over 4
4211:
1.174 albertel 4212: =item * B<NETWORK_FAILURE>:
4213:
4214: The network has failed and the information is not available.
1.51 bowersj2 4215:
1.174 albertel 4216: =item * B<NOTHING_SET>:
1.53 bowersj2 4217:
1.174 albertel 4218: No dates have been set for this problem (part) at all. (Because only
4219: certain parts of a multi-part problem may be assigned, this can not be
4220: collapsed into "open later", as we do not know a given part will EVER
4221: be opened. For single part, this is the same as "OPEN_LATER".)
1.51 bowersj2 4222:
1.174 albertel 4223: =item * B<CORRECT>:
1.51 bowersj2 4224:
1.174 albertel 4225: For any reason at all, the part is considered correct.
1.54 bowersj2 4226:
1.174 albertel 4227: =item * B<EXCUSED>:
1.51 bowersj2 4228:
1.174 albertel 4229: For any reason at all, the problem is excused.
1.51 bowersj2 4230:
1.174 albertel 4231: =item * B<PAST_DUE_NO_ANSWER>:
1.51 bowersj2 4232:
1.174 albertel 4233: The problem is past due, not considered correct, and no answer date is
4234: set.
1.51 bowersj2 4235:
1.174 albertel 4236: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 4237:
1.174 albertel 4238: The problem is past due, not considered correct, and an answer date in
4239: the future is set.
1.51 bowersj2 4240:
1.174 albertel 4241: =item * B<ANSWER_OPEN>:
4242:
4243: The problem is past due, not correct, and the answer is now available.
4244:
4245: =item * B<OPEN_LATER>:
4246:
4247: The problem is not yet open.
4248:
4249: =item * B<TRIES_LEFT>:
4250:
4251: The problem is open, has been tried, is not correct, but there are
4252: tries left.
4253:
4254: =item * B<INCORRECT>:
4255:
4256: The problem is open, and all tries have been used without getting the
4257: correct answer.
4258:
4259: =item * B<OPEN>:
4260:
4261: The item is open and not yet tried.
4262:
4263: =item * B<ATTEMPTED>:
4264:
4265: The problem has been attempted.
1.69 bowersj2 4266:
1.185 bowersj2 4267: =item * B<ANSWER_SUBMITTED>:
4268:
4269: An answer has been submitted, but the student should not see it.
4270:
1.51 bowersj2 4271: =back
4272:
4273: =cut
4274:
1.185 bowersj2 4275: sub TRIES_LEFT { return 20; }
4276: sub ANSWER_SUBMITTED { return 21; }
1.51 bowersj2 4277:
4278: sub status {
4279: my $self = shift;
4280: my $part = shift;
4281: if (!defined($part)) { $part = "0"; }
4282: my $completionStatus = $self->getCompletionStatus($part);
4283: my $dateStatus = $self->getDateStatus($part);
4284:
4285: # What we have is a two-dimensional matrix with 4 entries on one
4286: # dimension and 5 entries on the other, which we want to colorize,
1.54 bowersj2 4287: # plus network failure and "no date data at all".
1.51 bowersj2 4288:
1.222 bowersj2 4289: #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }
1.53 bowersj2 4290: if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
1.51 bowersj2 4291:
1.236 bowersj2 4292: my $suppressFeedback = $self->problemstatus($part) eq 'no';
4293: # If there's an answer date and we're past it, don't
4294: # suppress the feedback; student should know
4295: if ($self->answerdate($part) && $self->answerdate($part) < time()) {
4296: $suppressFeedback = 0;
4297: }
1.185 bowersj2 4298:
1.51 bowersj2 4299: # There are a few whole rows we can dispose of:
1.53 bowersj2 4300: if ($completionStatus == CORRECT ||
4301: $completionStatus == CORRECT_BY_OVERRIDE ) {
1.185 bowersj2 4302: return $suppressFeedback? ANSWER_SUBMITTED : CORRECT;
1.69 bowersj2 4303: }
4304:
4305: if ($completionStatus == ATTEMPTED) {
4306: return ATTEMPTED;
1.53 bowersj2 4307: }
4308:
4309: # If it's EXCUSED, then return that no matter what
4310: if ($completionStatus == EXCUSED) {
4311: return EXCUSED;
1.51 bowersj2 4312: }
4313:
1.53 bowersj2 4314: if ($dateStatus == NOTHING_SET) {
4315: return NOTHING_SET;
1.51 bowersj2 4316: }
4317:
1.69 bowersj2 4318: # Now we're down to a 4 (incorrect, incorrect_override, not_attempted)
4319: # by 4 matrix (date statuses).
1.51 bowersj2 4320:
1.54 bowersj2 4321: if ($dateStatus == PAST_DUE_ANSWER_LATER ||
1.59 bowersj2 4322: $dateStatus == PAST_DUE_NO_ANSWER ) {
1.272 albertel 4323: return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus;
1.51 bowersj2 4324: }
4325:
1.53 bowersj2 4326: if ($dateStatus == ANSWER_OPEN) {
4327: return ANSWER_OPEN;
1.51 bowersj2 4328: }
4329:
4330: # Now: (incorrect, incorrect_override, not_attempted) x
4331: # (open_later), (open)
4332:
1.53 bowersj2 4333: if ($dateStatus == OPEN_LATER) {
4334: return OPEN_LATER;
1.51 bowersj2 4335: }
4336:
4337: # If it's WRONG...
1.53 bowersj2 4338: if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE) {
1.51 bowersj2 4339: # and there are TRIES LEFT:
1.79 bowersj2 4340: if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
1.222 bowersj2 4341: return $suppressFeedback ? ANSWER_SUBMITTED : TRIES_LEFT;
1.51 bowersj2 4342: }
1.185 bowersj2 4343: return $suppressFeedback ? ANSWER_SUBMITTED : INCORRECT; # otherwise, return orange; student can't fix this
1.51 bowersj2 4344: }
4345:
4346: # Otherwise, it's untried and open
1.53 bowersj2 4347: return OPEN;
1.224 bowersj2 4348: }
4349:
4350: sub CLOSED { return 23; }
4351: sub ERROR { return 24; }
4352:
4353: =pod
4354:
4355: B<Simple Status>
4356:
4357: Convenience method B<simpleStatus> provides a "simple status" for the resource.
4358: "Simple status" corresponds to "which icon is shown on the
4359: Navmaps". There are six "simple" statuses:
4360:
4361: =over 4
4362:
4363: =item * B<CLOSED>: The problem is currently closed. (No icon shown.)
4364:
4365: =item * B<OPEN>: The problem is open and unattempted.
4366:
4367: =item * B<CORRECT>: The problem is correct for any reason.
4368:
4369: =item * B<INCORRECT>: The problem is incorrect and can still be
4370: completed successfully.
4371:
4372: =item * B<ATTEMPTED>: The problem has been attempted, but the student
4373: does not know if they are correct. (The ellipsis icon.)
4374:
4375: =item * B<ERROR>: There is an error retrieving information about this
4376: problem.
4377:
4378: =back
4379:
4380: =cut
4381:
4382: # This hash maps the composite status to this simple status, and
4383: # can be used directly, if you like
4384: my %compositeToSimple =
4385: (
4386: NETWORK_FAILURE() => ERROR,
4387: NOTHING_SET() => CLOSED,
4388: CORRECT() => CORRECT,
4389: EXCUSED() => CORRECT,
4390: PAST_DUE_NO_ANSWER() => INCORRECT,
4391: PAST_DUE_ANSWER_LATER() => INCORRECT,
4392: ANSWER_OPEN() => INCORRECT,
4393: OPEN_LATER() => CLOSED,
4394: TRIES_LEFT() => OPEN,
4395: INCORRECT() => INCORRECT,
4396: OPEN() => OPEN,
4397: ATTEMPTED() => ATTEMPTED,
4398: ANSWER_SUBMITTED() => ATTEMPTED
4399: );
4400:
4401: sub simpleStatus {
4402: my $self = shift;
4403: my $part = shift;
4404: my $status = $self->status($part);
4405: return $compositeToSimple{$status};
1.225 bowersj2 4406: }
4407:
4408: =pod
4409:
4410: B<simpleStatusCount> will return an array reference containing, in
4411: this order, the number of OPEN, CLOSED, CORRECT, INCORRECT, ATTEMPTED,
4412: and ERROR parts the given problem has.
4413:
4414: =cut
4415:
4416: # This maps the status to the slot we want to increment
4417: my %statusToSlotMap =
4418: (
4419: OPEN() => 0,
4420: CLOSED() => 1,
4421: CORRECT() => 2,
4422: INCORRECT() => 3,
4423: ATTEMPTED() => 4,
4424: ERROR() => 5
4425: );
4426:
4427: sub statusToSlot { return $statusToSlotMap{shift()}; }
4428:
4429: sub simpleStatusCount {
4430: my $self = shift;
4431:
4432: my @counts = (0, 0, 0, 0, 0, 0, 0);
4433: foreach my $part (@{$self->parts()}) {
4434: $counts[$statusToSlotMap{$self->simpleStatus($part)}]++;
4435: }
4436:
4437: return \@counts;
1.191 bowersj2 4438: }
4439:
4440: =pod
4441:
4442: B<Completable>
4443:
4444: The completable method represents the concept of I<whether the student can
4445: currently do the problem>. If the student can do the problem, which means
4446: that it is open, there are tries left, and if the problem is manually graded
4447: or the grade is suppressed via problemstatus, the student has not tried it
4448: yet, then the method returns 1. Otherwise, it returns 0, to indicate that
4449: either the student has tried it and there is no feedback, or that for
4450: some reason it is no longer completable (not open yet, successfully completed,
4451: out of tries, etc.). As an example, this is used as the filter for the
4452: "Uncompleted Homework" option for the nav maps.
4453:
4454: If this does not quite meet your needs, do not fiddle with it (unless you are
4455: fixing it to better match the student's conception of "completable" because
4456: it's broken somehow)... make a new method.
4457:
4458: =cut
4459:
4460: sub completable {
4461: my $self = shift;
4462: if (!$self->is_problem()) { return 0; }
4463: my $partCount = $self->countParts();
4464:
4465: foreach my $part (@{$self->parts()}) {
4466: if ($part eq '0' && $partCount != 1) { next; }
4467: my $status = $self->status($part);
4468: # "If any of the parts are open, or have tries left (implies open),
4469: # and it is not "attempted" (manually graded problem), it is
4470: # not "complete"
1.216 bowersj2 4471: if ($self->getCompletionStatus($part) == ATTEMPTED() ||
4472: $status == ANSWER_SUBMITTED() ) {
4473: # did this part already, as well as we can
4474: next;
4475: }
4476: if ($status == OPEN() || $status == TRIES_LEFT()) {
4477: return 1;
4478: }
1.191 bowersj2 4479: }
4480:
4481: # If all the parts were complete, so was this problem.
1.216 bowersj2 4482: return 0;
1.51 bowersj2 4483: }
4484:
4485: =pod
4486:
4487: =head2 Resource/Nav Map Navigation
4488:
4489: =over 4
4490:
1.174 albertel 4491: =item * B<getNext>():
4492:
4493: Retreive an array of the possible next resources after this
4494: one. Always returns an array, even in the one- or zero-element case.
4495:
4496: =item * B<getPrevious>():
1.85 bowersj2 4497:
1.174 albertel 4498: Retreive an array of the possible previous resources from this
4499: one. Always returns an array, even in the one- or zero-element case.
1.51 bowersj2 4500:
4501: =cut
4502:
4503: sub getNext {
4504: my $self = shift;
4505: my @branches;
4506: my $to = $self->to();
1.85 bowersj2 4507: foreach my $branch ( split(/,/, $to) ) {
1.51 bowersj2 4508: my $choice = $self->{NAV_MAP}->getById($branch);
4509: my $next = $choice->goesto();
4510: $next = $self->{NAV_MAP}->getById($next);
4511:
1.131 bowersj2 4512: push @branches, $next;
1.85 bowersj2 4513: }
4514: return \@branches;
4515: }
4516:
4517: sub getPrevious {
4518: my $self = shift;
4519: my @branches;
4520: my $from = $self->from();
4521: foreach my $branch ( split /,/, $from) {
4522: my $choice = $self->{NAV_MAP}->getById($branch);
4523: my $prev = $choice->comesfrom();
4524: $prev = $self->{NAV_MAP}->getById($prev);
4525:
1.131 bowersj2 4526: push @branches, $prev;
1.51 bowersj2 4527: }
4528: return \@branches;
1.131 bowersj2 4529: }
4530:
4531: sub browsePriv {
4532: my $self = shift;
4533: if (defined($self->{BROWSE_PRIV})) {
4534: return $self->{BROWSE_PRIV};
4535: }
4536:
4537: $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre', $self->src());
1.51 bowersj2 4538: }
4539:
4540: =pod
1.2 www 4541:
1.51 bowersj2 4542: =back
1.2 www 4543:
1.51 bowersj2 4544: =cut
1.2 www 4545:
1.51 bowersj2 4546: 1;
1.2 www 4547:
1.51 bowersj2 4548: __END__
1.2 www 4549:
4550:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>