Annotation of loncom/interface/lonnavmaps.pm, revision 1.528
1.481 foxr 1: # The LearningOnline Network with CAPA
1.2 www 2: # Navigate Maps Handler
1.1 www 3: #
1.528 ! raeburn 4: # $Id: lonnavmaps.pm,v 1.527 2017/02/18 23:39:16 raeburn 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.416 jms 30: =pod
31:
32: =head1 NAME
33:
1.435 raeburn 34: Apache::lonnavmaps - Subroutines to handle and render the navigation
1.416 jms 35:
36: =head1 SYNOPSIS
37:
38: Handles navigational maps.
39:
40: The main handler generates the navigational listing for the course,
41: the other objects export this information in a usable fashion for
42: other modules.
43:
44:
45: This is part of the LearningOnline Network with CAPA project
46: described at http://www.lon-capa.org.
47:
48:
49: =head1 OVERVIEW
50:
1.439 wenzelju 51: X<lonnavmaps, overview> When a user enters a course, LON-CAPA examines the
1.416 jms 52: course structure and caches it in what is often referred to as the
53: "big hash" X<big hash>. You can see it if you are logged into
54: LON-CAPA, in a course, by going to /adm/test. (You may need to
55: tweak the /home/httpd/lonTabs/htpasswd file to view it.) The
56: content of the hash will be under the heading "Big Hash".
57:
58: Big Hash contains, among other things, how resources are related
59: to each other (next/previous), what resources are maps, which
60: resources are being chosen to not show to the student (for random
61: selection), and a lot of other things that can take a lot of time
62: to compute due to the amount of data that needs to be collected and
63: processed.
64:
65: Apache::lonnavmaps provides an object model for manipulating this
66: information in a higher-level fashion than directly manipulating
67: the hash. It also provides access to several auxilary functions
68: that aren't necessarily stored in the Big Hash, but are a per-
69: resource sort of value, like whether there is any feedback on
70: a given resource.
71:
72: Apache::lonnavmaps also abstracts away branching, and someday,
73: conditions, for the times where you don't really care about those
74: things.
75:
76: Apache::lonnavmaps also provides fairly powerful routines for
77: rendering navmaps, and last but not least, provides the navmaps
78: view for when the user clicks the NAV button.
79:
80: B<Note>: Apache::lonnavmaps I<only> works for the "currently
81: logged in user"; if you want things like "due dates for another
82: student" lonnavmaps can not directly retrieve information like
83: that. You need the EXT function. This module can still help,
84: because many things, such as the course structure, are constant
85: between users, and Apache::lonnavmaps can help by providing
86: symbs for the EXT call.
87:
88: The rest of this file will cover the provided rendering routines,
89: which can often be used without fiddling with the navmap object at
90: all, then documents the Apache::lonnavmaps::navmap object, which
91: is the key to accessing the Big Hash information, covers the use
92: of the Iterator (which provides the logic for traversing the
93: somewhat-complicated Big Hash data structure), documents the
94: Apache::lonnavmaps::Resource objects that are returned by
95:
96: =head1 Subroutine: render
97:
98: The navmap renderer package provides a sophisticated rendering of the
99: standard navigation maps interface into HTML. The provided nav map
100: handler is actually just a glorified call to this.
101:
102: Because of the large number of parameters this function accepts,
103: instead of passing it arguments as is normal, pass it in an anonymous
104: hash with the desired options.
105:
106: The package provides a function called 'render', called as
107: Apache::lonnavmaps::render({}).
108:
109: =head2 Overview of Columns
110:
111: The renderer will build an HTML table for the navmap and return
112: it. The table consists of several columns, and a row for each
113: resource (or possibly each part). You tell the renderer how many
114: columns to create and what to place in each column, optionally using
115: one or more of the prepared columns, and the renderer will assemble
116: the table.
117:
118: Any additional generally useful column types should be placed in the
119: renderer code here, so anybody can use it anywhere else. Any code
120: specific to the current application (such as the addition of <input>
121: elements in a column) should be placed in the code of the thing using
122: the renderer.
123:
124: At the core of the renderer is the array reference COLS (see Example
125: section below for how to pass this correctly). The COLS array will
126: consist of entries of one of two types of things: Either an integer
127: representing one of the pre-packaged column types, or a sub reference
128: that takes a resource reference, a part number, and a reference to the
129: argument hash passed to the renderer, and returns a string that will
130: be inserted into the HTML representation as it.
131:
132: All other parameters are ways of either changing how the columns
133: are printing, or which rows are shown.
134:
135: The pre-packaged column names are refered to by constants in the
136: Apache::lonnavmaps namespace. The following currently exist:
137:
138: =over 4
139:
140: =item * B<Apache::lonnavmaps::resource>:
141:
142: The general info about the resource: Link, icon for the type, etc. The
143: first column in the standard nav map display. This column provides the
144: indentation effect seen in the B<NAV> screen. This column also accepts
145: the following parameters in the renderer hash:
146:
147: =over 4
148:
149: =item * B<resource_nolink>: default false
150:
151: If true, the resource will not be linked. By default, all non-folder
152: resources are linked.
153:
154: =item * B<resource_part_count>: default true
155:
156: If true, the resource will show a part count B<if> the full
157: part list is not displayed. (See "condense_parts" later.) If false,
158: the resource will never show a part count.
159:
160: =item * B<resource_no_folder_link>:
161:
162: If true, the resource's folder will not be clickable to open or close
163: it. Default is false. True implies printCloseAll is false, since you
164: can't close or open folders when this is on anyhow.
165:
1.493 raeburn 166: =item * B<map_no_edit_link>:
167:
168: If true, the title of the folder or page will not be followed by an
169: icon/link to direct editing of a folder or composite page, originally
170: added via the Course Editor.
171:
1.416 jms 172: =back
173:
174: =item * B<Apache::lonnavmaps::communication_status>:
175:
176: Whether there is discussion on the resource, email for the user, or
177: (lumped in here) perl errors in the execution of the problem. This is
178: the second column in the main nav map.
179:
180: =item * B<Apache::lonnavmaps::quick_status>:
181:
182: An icon for the status of a problem, with five possible states:
183: Correct, incorrect, open, awaiting grading (for a problem where the
184: computer's grade is suppressed, or the computer can't grade, like
185: essay problem), or none (not open yet, not a problem). The
186: third column of the standard navmap.
187:
188: =item * B<Apache::lonnavmaps::long_status>:
189:
190: A text readout of the details of the current status of the problem,
191: such as "Due in 22 hours". The fourth column of the standard navmap.
192:
193: =item * B<Apache::lonnavmaps::part_status_summary>:
194:
195: A text readout summarizing the status of the problem. If it is a
196: single part problem, will display "Correct", "Incorrect",
197: "Not yet open", "Open", "Attempted", or "Error". If there are
198: multiple parts, this will output a string that in HTML will show a
199: status of how many parts are in each status, in color coding, trying
200: to match the colors of the icons within reason.
1.1 www 201:
1.416 jms 202: Note this only makes sense if you are I<not> showing parts. If
203: C<showParts> is true (see below), this column will not output
204: anything.
1.2 www 205:
1.416 jms 206: =back
1.133 bowersj2 207:
1.416 jms 208: If you add any others please be sure to document them here.
1.133 bowersj2 209:
1.416 jms 210: An example of a column renderer that will show the ID number of a
211: resource, along with the part name if any:
1.140 bowersj2 212:
1.416 jms 213: sub {
214: my ($resource, $part, $params) = @_;
215: if ($part) { return '<td>' . $resource->{ID} . ' ' . $part . '</td>'; }
216: return '<td>' . $resource->{ID} . '</td>';
217: }
1.135 bowersj2 218:
1.416 jms 219: Note these functions are responsible for the TD tags, which allow them
220: to override vertical and horizontal alignment, etc.
1.133 bowersj2 221:
1.416 jms 222: =head2 Parameters
1.130 www 223:
1.416 jms 224: Minimally, you should be
225: able to get away with just using 'cols' (to specify the columns
226: shown), 'url' (necessary for the folders to link to the current screen
227: correctly), and possibly 'queryString' if your app calls for it. In
228: that case, maintaining the state of the folders will be done
229: automatically.
1.268 albertel 230:
1.416 jms 231: =over 4
1.268 albertel 232:
1.483 raeburn 233: =item * B<iterator>: default: constructs one from %env
1.51 bowersj2 234:
1.416 jms 235: A reference to a fresh ::iterator to use from the navmaps. The
236: rendering will reflect the options passed to the iterator, so you can
237: use that to just render a certain part of the course, if you like. If
238: one is not passed, the renderer will attempt to construct one from
239: env{'form.filter'} and env{'form.condition'} information, plus the
240: 'iterator_map' parameter if any.
1.51 bowersj2 241:
1.416 jms 242: =item * B<iterator_map>: default: not used
1.51 bowersj2 243:
1.416 jms 244: If you are letting the renderer do the iterator handling, you can
245: instruct the renderer to render only a particular map by passing it
246: the source of the map you want to process, like
247: '/res/103/jerf/navmap.course.sequence'.
1.51 bowersj2 248:
1.416 jms 249: =item * B<include_top_level_map>: default: false
1.51 bowersj2 250:
1.416 jms 251: If you need to include the top level map (meaning the course) in the
252: rendered output set this to true
1.51 bowersj2 253:
1.416 jms 254: =item * B<navmap>: default: constructs one from %env
1.51 bowersj2 255:
1.416 jms 256: A reference to a navmap, used only if an iterator is not passed in. If
257: this is necessary to make an iterator but it is not passed in, a new
258: one will be constructed based on env info. This is useful to do basic
259: error checking before passing it off to render.
1.51 bowersj2 260:
1.416 jms 261: =item * B<r>: default: must be passed in
1.53 bowersj2 262:
1.416 jms 263: The standard Apache response object. This must be passed to the
264: renderer or the course hash will be locked.
1.53 bowersj2 265:
1.416 jms 266: =item * B<cols>: default: empty (useless)
1.407 raeburn 267:
1.416 jms 268: An array reference
1.53 bowersj2 269:
1.416 jms 270: =item * B<showParts>:default true
1.115 bowersj2 271:
1.416 jms 272: A flag. If true, a line for the resource itself, and a line
273: for each part will be displayed. If not, only one line for each
274: resource will be displayed.
1.115 bowersj2 275:
1.416 jms 276: =item * B<condenseParts>: default true
1.115 bowersj2 277:
1.416 jms 278: A flag. If true, if all parts of the problem have the same
279: status and that status is Nothing Set, Correct, or Network Failure,
280: then only one line will be displayed for that resource anyhow. If no,
281: all parts will always be displayed. If showParts is 0, this is
282: ignored.
1.115 bowersj2 283:
1.416 jms 284: =item * B<jumpCount>: default: determined from %env
1.115 bowersj2 285:
1.416 jms 286: A string identifying the URL to place the anchor 'curloc' at.
287: It is the responsibility of the renderer user to
288: ensure that the #curloc is in the URL. By default, determined through
289: the use of the env{} 'jump' information, and should normally "just
290: work" correctly.
1.177 www 291:
1.416 jms 292: =item * B<here>: default: empty string
1.68 bowersj2 293:
1.416 jms 294: A Symb identifying where to place the 'here' marker. The empty
295: string means no marker.
1.73 bowersj2 296:
1.416 jms 297: =item * B<indentString>: default: 25 pixel whitespace image
1.347 www 298:
1.416 jms 299: A string identifying the indentation string to use.
1.347 www 300:
1.416 jms 301: =item * B<queryString>: default: empty
1.346 foxr 302:
1.416 jms 303: A string which will be prepended to the query string used when the
304: folders are opened or closed. You can use this to pass
305: application-specific values.
1.73 bowersj2 306:
1.416 jms 307: =item * B<url>: default: none
1.73 bowersj2 308:
1.416 jms 309: The url the folders will link to, which should be the current
310: page. Required if the resource info column is shown, and you
311: are allowing the user to open and close folders.
1.73 bowersj2 312:
1.416 jms 313: =item * B<currentJumpIndex>: default: no jumping
1.73 bowersj2 314:
1.416 jms 315: Describes the currently-open row number to cause the browser to jump
316: to, because the user just opened that folder. By default, pulled from
317: the Jump information in the env{'form.*'}.
1.73 bowersj2 318:
1.416 jms 319: =item * B<printKey>: default: false
1.101 bowersj2 320:
1.416 jms 321: If true, print the key that appears on the top of the standard
322: navmaps.
1.73 bowersj2 323:
1.416 jms 324: =item * B<printCloseAll>: default: true
1.73 bowersj2 325:
1.416 jms 326: If true, print the "Close all folders" or "open all folders"
327: links.
1.403 albertel 328:
1.416 jms 329: =item * B<filterFunc>: default: sub {return 1;} (accept everything)
1.346 foxr 330:
1.416 jms 331: A function that takes the resource object as its only parameter and
332: returns a true or false value. If true, the resource is displayed. If
333: false, it is simply skipped in the display.
1.346 foxr 334:
1.416 jms 335: =item * B<suppressEmptySequences>: default: false
1.346 foxr 336:
1.416 jms 337: If you're using a filter function, and displaying sequences to orient
338: the user, then frequently some sequences will be empty. Setting this to
339: true will cause those sequences not to display, so as not to confuse the
340: user into thinking that if the sequence is there there should be things
341: under it; for example, see the "Show Uncompleted Homework" view on the
342: B<NAV> screen.
1.73 bowersj2 343:
1.416 jms 344: =item * B<suppressNavmaps>: default: false
1.53 bowersj2 345:
1.416 jms 346: If true, will not display Navigate Content resources.
1.51 bowersj2 347:
1.416 jms 348: =back
1.133 bowersj2 349:
1.416 jms 350: =head2 Additional Info
1.174 albertel 351:
1.416 jms 352: In addition to the parameters you can pass to the renderer, which will
353: be passed through unchange to the column renderers, the renderer will
354: generate the following information which your renderer may find
355: useful:
1.174 albertel 356:
1.416 jms 357: =over 4
1.174 albertel 358:
1.416 jms 359: =item * B<counter>:
1.133 bowersj2 360:
1.416 jms 361: Contains the number of rows printed. Useful after calling the render
362: function, as you can detect whether anything was printed at all.
1.216 bowersj2 363:
1.416 jms 364: =item * B<isNewBranch>:
1.216 bowersj2 365:
1.416 jms 366: Useful for renderers: If this resource is currently the first resource
367: of a new branch, this will be true. The Resource column (leftmost in the
368: navmaps screen) uses this to display the "new branch" icon
1.216 bowersj2 369:
1.416 jms 370: =back
1.216 bowersj2 371:
1.416 jms 372: =cut
1.216 bowersj2 373:
374:
1.416 jms 375: =head1 SUBROUTINES
1.216 bowersj2 376:
1.416 jms 377: =over
1.216 bowersj2 378:
1.416 jms 379: =item update()
1.133 bowersj2 380:
1.416 jms 381: =item addToFilter()
1.133 bowersj2 382:
1.416 jms 383: Convenience functions: Returns a string that adds or subtracts
384: the second argument from the first hash, appropriate for the
385: query string that determines which folders to recurse on
1.174 albertel 386:
1.416 jms 387: =item removeFromFilter()
1.51 bowersj2 388:
1.416 jms 389: =item getLinkForResource()
1.51 bowersj2 390:
1.416 jms 391: Convenience function: Given a stack returned from getStack on the iterator,
392: return the correct src() value.
1.174 albertel 393:
1.416 jms 394: =item getDescription()
1.174 albertel 395:
1.416 jms 396: Convenience function: This separates the logic of how to create
397: the problem text strings ("Due: DATE", "Open: DATE", "Not yet assigned",
398: etc.) into a separate function. It takes a resource object as the
399: first parameter, and the part number of the resource as the second.
400: It's basically a big switch statement on the status of the resource.
1.174 albertel 401:
1.416 jms 402: =item dueInLessThan24Hours()
1.216 bowersj2 403:
1.416 jms 404: Convenience function, so others can use it: Is the problem due in less than 24 hours, and still can be done?
1.51 bowersj2 405:
1.416 jms 406: =item lastTry()
1.51 bowersj2 407:
1.416 jms 408: Convenience function, so others can use it: Is there only one try remaining for the
409: part, with more than one try to begin with, not due yet and still can be done?
1.51 bowersj2 410:
1.416 jms 411: =item advancedUser()
1.51 bowersj2 412:
1.416 jms 413: This puts a human-readable name on the env variable.
1.51 bowersj2 414:
1.416 jms 415: =item timeToHumanString()
1.51 bowersj2 416:
1.416 jms 417: timeToHumanString takes a time number and converts it to a
418: human-readable representation, meant to be used in the following
419: manner:
1.174 albertel 420:
1.416 jms 421: =over 4
1.51 bowersj2 422:
1.416 jms 423: =item * print "Due $timestring"
1.133 bowersj2 424:
1.416 jms 425: =item * print "Open $timestring"
1.133 bowersj2 426:
1.416 jms 427: =item * print "Answer available $timestring"
1.144 bowersj2 428:
1.133 bowersj2 429: =back
1.51 bowersj2 430:
1.416 jms 431: Very, very, very, VERY English-only... goodness help a localizer on
432: this func...
1.174 albertel 433:
1.417 jms 434: =item resource()
1.174 albertel 435:
1.417 jms 436: returns 0
1.51 bowersj2 437:
1.417 jms 438: =item communication_status()
1.51 bowersj2 439:
1.417 jms 440: returns 1
1.174 albertel 441:
1.417 jms 442: =item quick_status()
1.51 bowersj2 443:
1.417 jms 444: returns 2
1.225 bowersj2 445:
1.417 jms 446: =item long_status()
1.225 bowersj2 447:
1.417 jms 448: returns 3
1.225 bowersj2 449:
1.417 jms 450: =item part_status_summary()
1.51 bowersj2 451:
1.417 jms 452: returns 4
1.51 bowersj2 453:
1.417 jms 454: =item render_resource()
1.51 bowersj2 455:
1.417 jms 456: =item render_communication_status()
1.51 bowersj2 457:
1.417 jms 458: =item render_quick_status()
459:
460: =item render_long_status()
461:
462: =item render_parts_summary_status()
463:
464: =item setDefault()
465:
466: =item cmp_title()
467:
468: =item render()
469:
470: =item add_linkitem()
471:
1.476 raeburn 472: =item show_linkitems_toolbar()
1.130 www 473:
1.416 jms 474: =back
1.115 bowersj2 475:
1.416 jms 476: =cut
1.140 bowersj2 477:
1.416 jms 478: package Apache::lonnavmaps;
1.51 bowersj2 479:
1.416 jms 480: use strict;
481: use GDBM_File;
482: use Apache::loncommon();
483: use Apache::lonenc();
484: use Apache::lonlocal;
485: use Apache::lonnet;
1.465 foxr 486: use Apache::lonmap;
1.443 foxr 487:
1.416 jms 488: use POSIX qw (floor strftime);
489: use Time::HiRes qw( gettimeofday tv_interval );
490: use LONCAPA;
491: use DateTime();
1.486 raeburn 492: use HTML::Entities;
1.465 foxr 493:
494: # For debugging
495:
1.499 raeburn 496: #use Data::Dumper;
1.465 foxr 497:
498:
1.416 jms 499: # symbolic constants
500: sub SYMB { return 1; }
501: sub URL { return 2; }
502: sub NOTHING { return 3; }
1.174 albertel 503:
1.416 jms 504: # Some data
1.174 albertel 505:
1.416 jms 506: my $resObj = "Apache::lonnavmaps::resource";
1.174 albertel 507:
1.443 foxr 508: # Keep these mappings in sync with lonquickgrades, which usesthe colors
1.416 jms 509: # instead of the icons.
510: my %statusIconMap =
511: (
512: $resObj->CLOSED => '',
513: $resObj->OPEN => 'navmap.open.gif',
514: $resObj->CORRECT => 'navmap.correct.gif',
515: $resObj->PARTIALLY_CORRECT => 'navmap.partial.gif',
516: $resObj->INCORRECT => 'navmap.wrong.gif',
517: $resObj->ATTEMPTED => 'navmap.ellipsis.gif',
518: $resObj->ERROR => ''
519: );
1.401 albertel 520:
1.438 wenzelju 521: my %iconAltTags = #texthash does not work here
1.439 wenzelju 522: ( 'navmap.correct.gif' => 'Correct',
523: 'navmap.wrong.gif' => 'Incorrect',
1.462 christia 524: 'navmap.open.gif' => 'Is Open',
1.439 wenzelju 525: 'navmap.partial.gif' => 'Partially Correct',
526: 'navmap.ellipsis.gif' => 'Attempted',
527: );
1.401 albertel 528:
1.416 jms 529: # Defines a status->color mapping, null string means don't color
530: my %colormap =
531: ( $resObj->NETWORK_FAILURE => '',
532: $resObj->CORRECT => '',
533: $resObj->EXCUSED => '#3333FF',
534: $resObj->PAST_DUE_ANSWER_LATER => '',
535: $resObj->PAST_DUE_NO_ANSWER => '',
536: $resObj->ANSWER_OPEN => '#006600',
537: $resObj->OPEN_LATER => '',
538: $resObj->TRIES_LEFT => '',
539: $resObj->INCORRECT => '',
540: $resObj->OPEN => '',
541: $resObj->NOTHING_SET => '',
542: $resObj->ATTEMPTED => '',
1.450 raeburn 543: $resObj->CREDIT_ATTEMPTED => '',
1.416 jms 544: $resObj->ANSWER_SUBMITTED => '',
545: $resObj->PARTIALLY_CORRECT => '#006600'
546: );
547: # And a special case in the nav map; what to do when the assignment
548: # is not yet done and due in less than 24 hours
549: my $hurryUpColor = "#FF0000";
1.174 albertel 550:
1.416 jms 551: sub addToFilter {
552: my $hashIn = shift;
553: my $addition = shift;
554: my %hash = %$hashIn;
555: $hash{$addition} = 1;
1.174 albertel 556:
1.416 jms 557: return join (",", keys(%hash));
558: }
1.174 albertel 559:
1.416 jms 560: sub removeFromFilter {
561: my $hashIn = shift;
562: my $subtraction = shift;
563: my %hash = %$hashIn;
1.174 albertel 564:
1.416 jms 565: delete $hash{$subtraction};
566: return join(",", keys(%hash));
567: }
1.174 albertel 568:
1.416 jms 569: sub getLinkForResource {
570: my $stack = shift;
571: my $res;
1.174 albertel 572:
1.416 jms 573: # Check to see if there are any pages in the stack
574: foreach $res (@$stack) {
575: if (defined($res)) {
576: my $anchor;
577: if ($res->is_page()) {
578: foreach my $item (@$stack) { if (defined($item)) { $anchor = $item; } }
579: $anchor=&escape($anchor->shown_symb());
580: return ($res->link(),$res->shown_symb(),$anchor);
581: }
582: # in case folder was skipped over as "only sequence"
583: my ($map,$id,$src)=&Apache::lonnet::decode_symb($res->symb());
584: if ($map=~/\.page$/) {
585: my $url=&Apache::lonnet::clutter($map);
1.437 foxr 586: $anchor=&escape($res->shown_symb());
1.416 jms 587: return ($url,$res->shown_symb(),$anchor);
588: }
589: }
590: }
1.174 albertel 591:
1.416 jms 592: # Failing that, return the src of the last resource that is defined
593: # (when we first recurse on a map, it puts an undefined resource
594: # on the bottom because $self->{HERE} isn't defined yet, and we
595: # want the src for the map anyhow)
596: foreach my $item (@$stack) {
597: if (defined($item)) { $res = $item; }
598: }
1.174 albertel 599:
1.416 jms 600: if ($res) {
601: return ($res->link(),$res->shown_symb());
602: }
603: return;
604: }
1.174 albertel 605:
1.417 jms 606:
1.140 bowersj2 607:
1.416 jms 608: sub getDescription {
609: my $res = shift;
610: my $part = shift;
611: my $status = $res->status($part);
1.92 bowersj2 612:
1.416 jms 613: my $open = $res->opendate($part);
614: my $due = $res->duedate($part);
615: my $answer = $res->answerdate($part);
1.164 bowersj2 616:
1.416 jms 617: if ($status == $res->NETWORK_FAILURE) {
618: return &mt("Having technical difficulties; please check status later");
619: }
620: if ($status == $res->NOTHING_SET) {
1.494 raeburn 621: return &Apache::lonhtmlcommon::direct_parm_link(&mt('Not currently assigned'),$res->symb(),'opendate',$part);
1.416 jms 622: }
623: if ($status == $res->OPEN_LATER) {
1.467 www 624: return &mt("Open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($open,'start'),$res->symb(),'opendate',$part));
1.416 jms 625: }
1.509 raeburn 626: my $slotinfo;
1.432 raeburn 627: if ($res->simpleStatus($part) == $res->OPEN) {
628: unless (&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) {
629: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
1.509 raeburn 630: my $slotmsg;
1.432 raeburn 631: if ($slot_status == $res->UNKNOWN) {
1.509 raeburn 632: $slotmsg = &mt('Reservation status unknown');
1.432 raeburn 633: } elsif ($slot_status == $res->RESERVED) {
1.509 raeburn 634: $slotmsg = &mt('Reserved - ends [_1]',
1.433 bisitz 635: timeToHumanString($slot_time,'end'));
1.432 raeburn 636: } elsif ($slot_status == $res->RESERVED_LOCATION) {
1.509 raeburn 637: $slotmsg = &mt('Reserved - specific location(s) - ends [_1]',
1.433 bisitz 638: timeToHumanString($slot_time,'end'));
1.432 raeburn 639: } elsif ($slot_status == $res->RESERVED_LATER) {
1.509 raeburn 640: $slotmsg = &mt('Reserved - next open [_1]',
1.433 bisitz 641: timeToHumanString($slot_time,'start'));
1.432 raeburn 642: } elsif ($slot_status == $res->RESERVABLE) {
1.509 raeburn 643: $slotmsg = &mt('Reservable, reservations close [_1]',
1.433 bisitz 644: timeToHumanString($slot_time,'end'));
1.432 raeburn 645: } elsif ($slot_status == $res->RESERVABLE_LATER) {
1.509 raeburn 646: $slotmsg = &mt('Reservable, reservations open [_1]',
1.433 bisitz 647: timeToHumanString($slot_time,'start'));
1.432 raeburn 648: } elsif ($slot_status == $res->NOT_IN_A_SLOT) {
1.509 raeburn 649: $slotmsg = &mt('Reserve a time/place to work');
1.432 raeburn 650: } elsif ($slot_status == $res->NOTRESERVABLE) {
1.509 raeburn 651: $slotmsg = &mt('Reservation not available');
1.432 raeburn 652: } elsif ($slot_status == $res->WAITING_FOR_GRADE) {
1.509 raeburn 653: $slotmsg = &mt('Submission in grading queue');
654: }
655: if ($slotmsg) {
656: if ($res->is_task() || !$due) {
657: return $slotmsg;
658: }
659: $slotinfo = (' ' x 2).'('.$slotmsg.')';
1.432 raeburn 660: }
661: }
662: }
1.416 jms 663: if ($status == $res->OPEN) {
664: if ($due) {
665: if ($res->is_practice()) {
1.509 raeburn 666: return &mt("Closes [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'duedate',$part)).$slotinfo;
1.416 jms 667: } else {
1.509 raeburn 668: return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)).$slotinfo;
1.416 jms 669: }
670: } else {
1.509 raeburn 671: return &Apache::lonhtmlcommon::direct_parm_link(&mt("Open, no due date"),$res->symb(),'duedate',$part).$slotinfo;
1.416 jms 672: }
673: }
674: if ($status == $res->PAST_DUE_ANSWER_LATER) {
1.467 www 675: return &mt("Answer open [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($answer,'start'),$res->symb(),'answerdate',$part));
1.416 jms 676: }
677: if ($status == $res->PAST_DUE_NO_ANSWER) {
678: if ($res->is_practice()) {
1.467 www 679: return &mt("Closed [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'start'),$res->symb(),'answerdate,duedate',$part));
1.416 jms 680: } else {
1.467 www 681: return &mt("Was due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'answerdate,duedate',$part));
1.416 jms 682: }
683: }
684: if (($status == $res->ANSWER_OPEN || $status == $res->PARTIALLY_CORRECT)
685: && $res->handgrade($part) ne 'yes') {
1.455 www 686: return &Apache::lonhtmlcommon::direct_parm_link(&mt("Answer available"),$res->symb(),'answerdate,duedate',$part);
1.416 jms 687: }
688: if ($status == $res->EXCUSED) {
689: return &mt("Excused by instructor");
690: }
691: if ($status == $res->ATTEMPTED) {
1.444 raeburn 692: if ($res->is_anonsurvey($part) || $res->is_survey($part)) {
693: return &mt("Survey submission recorded");
694: } else {
695: return &mt("Answer submitted, not yet graded");
696: }
1.416 jms 697: }
1.450 raeburn 698: if ($status == $res->CREDIT_ATTEMPTED) {
699: if ($res->is_anonsurvey($part) || $res->is_survey($part)) {
700: return &mt("Credit for survey submission");
701: }
702: }
1.416 jms 703: if ($status == $res->TRIES_LEFT) {
704: my $tries = $res->tries($part);
705: my $maxtries = $res->maxtries($part);
706: my $triesString = "";
707: if ($tries && $maxtries) {
1.488 bisitz 708: $triesString = '<span class="LC_fontsize_medium"><i>('.&mt('[_1] of [quant,_2,try,tries] used',$tries,$maxtries).')</i></span>';
1.416 jms 709: if ($maxtries > 1 && $maxtries - $tries == 1) {
710: $triesString = "<b>$triesString</b>";
711: }
712: }
713: if ($due) {
1.467 www 714: return &mt("Due [_1]",&Apache::lonhtmlcommon::direct_parm_link(&timeToHumanString($due,'end'),$res->symb(),'duedate',$part)) .
1.416 jms 715: " $triesString";
716: } else {
1.455 www 717: return &Apache::lonhtmlcommon::direct_parm_link(&mt("No due date"),$res->symb(),'duedate',$part)." $triesString";
1.416 jms 718: }
719: }
720: if ($status == $res->ANSWER_SUBMITTED) {
721: return &mt('Answer submitted');
722: }
723: }
1.92 bowersj2 724:
1.51 bowersj2 725:
1.416 jms 726: sub dueInLessThan24Hours {
727: my $res = shift;
728: my $part = shift;
729: my $status = $res->status($part);
1.55 bowersj2 730:
1.416 jms 731: return ($status == $res->OPEN() ||
732: $status == $res->TRIES_LEFT()) &&
733: $res->duedate($part) && $res->duedate($part) < time()+(24*60*60) &&
734: $res->duedate($part) > time();
735: }
1.84 bowersj2 736:
1.417 jms 737:
1.416 jms 738: sub lastTry {
739: my $res = shift;
740: my $part = shift;
1.115 bowersj2 741:
1.416 jms 742: my $tries = $res->tries($part);
743: my $maxtries = $res->maxtries($part);
744: return $tries && $maxtries && $maxtries > 1 &&
745: $maxtries - $tries == 1 && $res->duedate($part) &&
746: $res->duedate($part) > time();
747: }
1.55 bowersj2 748:
1.51 bowersj2 749:
1.416 jms 750: sub advancedUser {
751: return $env{'request.role.adv'};
752: }
1.51 bowersj2 753:
1.416 jms 754: sub timeToHumanString {
755: my ($time,$type,$format) = @_;
1.153 bowersj2 756:
1.416 jms 757: # zero, '0' and blank are bad times
758: if (!$time) {
759: return &mt('never');
760: }
761: unless (&Apache::lonlocal::current_language()=~/^en/) {
762: return &Apache::lonlocal::locallocaltime($time);
763: }
764: my $now = time();
1.174 albertel 765:
1.416 jms 766: # Positive = future
767: my $delta = $time - $now;
1.190 bowersj2 768:
1.416 jms 769: my $minute = 60;
770: my $hour = 60 * $minute;
771: my $day = 24 * $hour;
772: my $week = 7 * $day;
773: my $inPast = 0;
1.190 bowersj2 774:
1.416 jms 775: # Logic in comments:
776: # Is it now? (extremely unlikely)
777: if ( $delta == 0 ) {
778: return "this instant";
779: }
1.174 albertel 780:
1.416 jms 781: if ($delta < 0) {
782: $inPast = 1;
783: $delta = -$delta;
784: }
1.143 bowersj2 785:
1.416 jms 786: if ( $delta > 0 ) {
1.51 bowersj2 787:
1.416 jms 788: my $tense = $inPast ? " ago" : "";
789: my $prefix = $inPast ? "" : "in ";
790:
791: # Less than a minute
792: if ( $delta < $minute ) {
793: if ($delta == 1) { return "${prefix}1 second$tense"; }
794: return "$prefix$delta seconds$tense";
795: }
1.51 bowersj2 796:
1.416 jms 797: # Less than an hour
798: if ( $delta < $hour ) {
1.464 raeburn 799: # If so, use minutes; or minutes, seconds (if format requires)
1.416 jms 800: my $minutes = floor($delta / 60);
1.464 raeburn 801: if (($format ne '') && ($format =~ /\%(T|S)/)) {
802: my $display;
803: if ($minutes == 1) {
804: $display = "${prefix}1 minute";
805: } else {
806: $display = "$prefix$minutes minutes";
807: }
808: my $seconds = $delta % $minute;
809: if ($seconds == 0) {
810: $display .= $tense;
811: } elsif ($seconds == 1) {
812: $display .= ", 1 second$tense";
813: } else {
814: $display .= ", $seconds seconds$tense";
815: }
816: return $display;
817: }
1.416 jms 818: if ($minutes == 1) { return "${prefix}1 minute$tense"; }
819: return "$prefix$minutes minutes$tense";
820: }
821:
822: # Is it less than 24 hours away? If so,
1.464 raeburn 823: # display hours + minutes, (and + seconds, if format specified it)
1.416 jms 824: if ( $delta < $hour * 24) {
825: my $hours = floor($delta / $hour);
826: my $minutes = floor(($delta % $hour) / $minute);
827: my $hourString = "$hours hours";
828: my $minuteString = ", $minutes minutes";
829: if ($hours == 1) {
830: $hourString = "1 hour";
831: }
832: if ($minutes == 1) {
833: $minuteString = ", 1 minute";
834: }
835: if ($minutes == 0) {
836: $minuteString = "";
837: }
1.464 raeburn 838: if (($format ne '') && ($format =~ /\%(T|S)/)) {
839: my $display = "$prefix$hourString$minuteString";
840: my $seconds = $delta-(($hours * $hour)+($minutes * $minute));
841: if ($seconds == 0) {
842: $display .= $tense;
843: } elsif ($seconds == 1) {
844: $display .= ", 1 second$tense";
845: } else {
846: $display .= ", $seconds seconds$tense";
847: }
848: return $display;
849: }
1.416 jms 850: return "$prefix$hourString$minuteString$tense";
851: }
1.174 albertel 852:
1.464 raeburn 853: # Date/time is more than 24 hours away
854:
1.416 jms 855: my $dt = DateTime->from_epoch(epoch => $time)
856: ->set_time_zone(&Apache::lonlocal::gettimezone());
1.216 bowersj2 857:
1.464 raeburn 858: # If there's a caller supplied format, use it, unless it only displays
859: # H:M:S or H:M.
1.145 bowersj2 860:
1.464 raeburn 861: if (($format ne '') && ($format ne '%T') && ($format ne '%R')) {
1.416 jms 862: my $timeStr = $dt->strftime($format);
863: return $timeStr.' ('.$dt->time_zone_short_name().')';
864: }
1.216 bowersj2 865:
1.416 jms 866: # Less than 5 days away, display day of the week and
867: # HH:MM
1.216 bowersj2 868:
1.416 jms 869: if ( $delta < $day * 5 ) {
870: my $timeStr = $dt->strftime("%A, %b %e at %I:%M %P (%Z)");
871: $timeStr =~ s/12:00 am/00:00/;
872: $timeStr =~ s/12:00 pm/noon/;
873: return ($inPast ? "last " : "this ") .
874: $timeStr;
875: }
876:
877: my $conjunction='on';
878: if ($type eq 'start') {
879: $conjunction='at';
880: } elsif ($type eq 'end') {
881: $conjunction='by';
882: }
883: # Is it this year?
884: my $dt_now = DateTime->from_epoch(epoch => $now)
885: ->set_time_zone(&Apache::lonlocal::gettimezone());
886: if ( $dt->year() == $dt_now->year()) {
887: # Return on Month Day, HH:MM meridian
888: my $timeStr = $dt->strftime("$conjunction %A, %b %e at %I:%M %P (%Z)");
889: $timeStr =~ s/12:00 am/00:00/;
890: $timeStr =~ s/12:00 pm/noon/;
891: return $timeStr;
892: }
1.59 bowersj2 893:
1.416 jms 894: # Not this year, so show the year
895: my $timeStr =
896: $dt->strftime("$conjunction %A, %b %e %Y at %I:%M %P (%Z)");
897: $timeStr =~ s/12:00 am/00:00/;
898: $timeStr =~ s/12:00 pm/noon/;
899: return $timeStr;
900: }
901: }
1.59 bowersj2 902:
903:
1.133 bowersj2 904: sub resource { return 0; }
905: sub communication_status { return 1; }
906: sub quick_status { return 2; }
907: sub long_status { return 3; }
1.225 bowersj2 908: sub part_status_summary { return 4; }
1.51 bowersj2 909:
1.133 bowersj2 910: sub render_resource {
911: my ($resource, $part, $params) = @_;
1.51 bowersj2 912:
1.477 raeburn 913: my $editmapLink;
1.133 bowersj2 914: my $nonLinkedText = ''; # stuff after resource title not in link
1.51 bowersj2 915:
1.134 bowersj2 916: my $link = $params->{"resourceLink"};
1.512 raeburn 917: if ($resource->ext()) {
918: $link =~ s/\#.+(\?)/$1/g;
919: }
1.306 foxr 920:
921: # The URL part is not escaped at this point, but the symb is...
922:
1.134 bowersj2 923: my $src = $resource->src();
924: my $it = $params->{"iterator"};
1.133 bowersj2 925: my $filter = $it->{FILTER};
926:
927: my $title = $resource->compTitle();
1.258 albertel 928:
1.133 bowersj2 929: my $partLabel = "";
930: my $newBranchText = "";
1.298 albertel 931: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1.133 bowersj2 932: # If this is a new branch, label it so
933: if ($params->{'isNewBranch'}) {
1.429 droeschl 934: $newBranchText = "<img src='$location/branch.gif' alt=".mt('Branch')." />";
1.51 bowersj2 935: }
936:
1.133 bowersj2 937: # links to open and close the folder
1.306 foxr 938:
1.427 droeschl 939: my $whitespace = $location.'/whitespace_21.gif';
940: my $linkopen = "<img src='$whitespace' alt='' />"."<a href=\"$link\">";
1.133 bowersj2 941: my $linkclose = "</a>";
1.51 bowersj2 942:
1.204 albertel 943: # Default icon: unknown page
1.426 droeschl 944: my $icon = "<img class=\"LC_contentImage\" src='$location/unknown.gif' alt='' />";
1.133 bowersj2 945:
946: if ($resource->is_problem()) {
1.192 bowersj2 947: if ($part eq '0' || $params->{'condensed'}) {
1.426 droeschl 948: $icon = '<img class="LC_contentImage" src="'.$location.'/';
1.389 albertel 949: if ($resource->is_task()) {
950: $icon .= 'task.gif" alt="'.&mt('Task');
951: } else {
952: $icon .= 'problem.gif" alt="'.&mt('Problem');
953: }
1.426 droeschl 954: $icon .='" />';
1.133 bowersj2 955: } else {
956: $icon = $params->{'indentString'};
957: }
1.204 albertel 958: } else {
1.426 droeschl 959: $icon = "<img class=\"LC_contentImage\" src='".&Apache::loncommon::icon($resource->src)."' alt='' />";
1.133 bowersj2 960: }
1.51 bowersj2 961:
1.133 bowersj2 962: # Display the correct map icon to open or shut map
963: if ($resource->is_map()) {
964: my $mapId = $resource->map_pc();
965: my $nowOpen = !defined($filter->{$mapId});
966: if ($it->{CONDITION}) {
967: $nowOpen = !$nowOpen;
968: }
1.426 droeschl 969:
1.205 bowersj2 970: my $folderType = $resource->is_sequence() ? 'folder' : 'page';
1.362 www 971: my $title=$resource->title;
1.426 droeschl 972: $title=~s/\"/\&qout;/g;
1.144 bowersj2 973: if (!$params->{'resource_no_folder_link'}) {
1.205 bowersj2 974: $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
1.426 droeschl 975: $icon = "<img src='$location/arrow." . ($nowOpen ? 'closed' : 'open') . ".gif' alt='' />"
976: ."<img class=\"LC_contentImage\" src='$location/$icon' alt=\""
977: .($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
1.349 foxr 978: $linkopen = "<a href=\"" . $params->{'url'} . '?' .
1.392 albertel 979: $params->{'queryString'} . '&filter=';
1.144 bowersj2 980: $linkopen .= ($nowOpen xor $it->{CONDITION}) ?
981: addToFilter($filter, $mapId) :
982: removeFromFilter($filter, $mapId);
1.392 albertel 983: $linkopen .= "&condition=" . $it->{CONDITION} . '&hereType='
984: . $params->{'hereType'} . '&here=' .
1.384 www 985: &escape($params->{'here'}) .
1.392 albertel 986: '&jump=' .
1.384 www 987: &escape($resource->symb()) .
1.392 albertel 988: "&folderManip=1\">";
1.306 foxr 989:
1.144 bowersj2 990: } else {
991: # Don't allow users to manipulate folder
1.426 droeschl 992: $icon = "navmap.$folderType." . ($nowOpen ? 'closed' : 'open') . '.gif';
1.427 droeschl 993: $icon = "<img class=\"LC_space\" src='$whitespace' alt='' />"."<img class=\"LC_contentImage\" src='$location/$icon' alt=\"".($nowOpen ? &mt('Open Folder') : &mt('Close Folder')).' '.$title."\" />";
1.144 bowersj2 994:
995: $linkopen = "";
996: $linkclose = "";
997: }
1.525 raeburn 998: if (((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
999: (&Apache::lonnet::allowed('cev',$env{'request.course.id'}))) &&
1.477 raeburn 1000: ($resource->symb=~/\_\_\_[^\_]+\_\_\_uploaded/)) {
1.493 raeburn 1001: if (!$params->{'map_no_edit_link'}) {
1002: my $icon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
1003: $editmapLink=' '.
1.495 raeburn 1004: '<a href="/adm/coursedocs?command=directnav&symb='.&escape($resource->symb()).'">'.
1.477 raeburn 1005: '<img src="'.$icon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
1006: '</a>';
1.493 raeburn 1007: }
1.477 raeburn 1008: }
1.518 raeburn 1009: if ($params->{'mapHidden'} || $resource->randomout()) {
1010: $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
1011: }
1012: } else {
1013: if ($resource->randomout()) {
1014: $nonLinkedText .= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
1015: }
1.133 bowersj2 1016: }
1.342 albertel 1017: if (!$resource->condval()) {
1.458 bisitz 1018: $nonLinkedText .= ' <span class="LC_info">('.&mt('conditionally hidden').')</span> ';
1.342 albertel 1019: }
1.413 www 1020: if (($resource->is_practice()) && ($resource->is_raw_problem())) {
1.488 bisitz 1021: $nonLinkedText .=' <span class="LC_info"><b>'.&mt('not graded').'</b></span>';
1.412 www 1022: }
1.426 droeschl 1023:
1.133 bowersj2 1024: # We're done preparing and finally ready to start the rendering
1.426 droeschl 1025: my $result = '<td class="LC_middle">';
1026: my $newfolderType = $resource->is_sequence() ? 'folder' : 'page';
1027:
1.140 bowersj2 1028: my $indentLevel = $params->{'indentLevel'};
1029: if ($newBranchText) { $indentLevel--; }
1030:
1.133 bowersj2 1031: # print indentation
1.140 bowersj2 1032: for (my $i = 0; $i < $indentLevel; $i++) {
1.133 bowersj2 1033: $result .= $params->{'indentString'};
1.84 bowersj2 1034: }
1035:
1.133 bowersj2 1036: # Decide what to display
1037: $result .= "$newBranchText$linkopen$icon$linkclose";
1038:
1039: my $curMarkerBegin = '';
1040: my $curMarkerEnd = '';
1.51 bowersj2 1041:
1.133 bowersj2 1042: # Is this the current resource?
1.158 bowersj2 1043: if (!$params->{'displayedHereMarker'} &&
1044: $resource->symb() eq $params->{'here'} ) {
1.477 raeburn 1045: unless ($resource->is_map()) {
1046: $curMarkerBegin = '<span class="LC_current_nav_location">';
1047: $curMarkerEnd = '</span>';
1048: }
1.424 schulted 1049: $params->{'displayedHereMarker'} = 1;
1.51 bowersj2 1050: }
1051:
1.192 bowersj2 1052: if ($resource->is_problem() && $part ne '0' &&
1.133 bowersj2 1053: !$params->{'condensed'}) {
1.274 matthew 1054: my $displaypart=$resource->part_display($part);
1.363 albertel 1055: $partLabel = " (".&mt('Part: [_1]', $displaypart).")";
1.384 www 1056: if ($link!~/\#/) { $link.='#'.&escape($part); }
1.133 bowersj2 1057: $title = "";
1.51 bowersj2 1058: }
1059:
1.163 bowersj2 1060: if ($params->{'condensed'} && $resource->countParts() > 1) {
1.363 albertel 1061: $nonLinkedText .= ' ('.&mt('[_1] parts', $resource->countParts()).')';
1.51 bowersj2 1062: }
1063:
1.266 raeburn 1064: if (!$params->{'resource_nolink'} && !$resource->is_sequence() && !$resource->is_empty_sequence) {
1.490 raeburn 1065: $result .= "$curMarkerBegin<a href=\"$link\">$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";
1.144 bowersj2 1066: } else {
1.477 raeburn 1067: $result .= "$curMarkerBegin$linkopen$title$partLabel</a>$curMarkerEnd$editmapLink$nonLinkedText</td>";
1.144 bowersj2 1068: }
1.51 bowersj2 1069:
1.133 bowersj2 1070: return $result;
1071: }
1.51 bowersj2 1072:
1.133 bowersj2 1073: sub render_communication_status {
1074: my ($resource, $part, $params) = @_;
1.134 bowersj2 1075: my $discussionHTML = ""; my $feedbackHTML = ""; my $errorHTML = "";
1076:
1077: my $link = $params->{"resourceLink"};
1.445 droeschl 1078: my $linkopen = "<a href=\"$link\">";
1.134 bowersj2 1079: my $linkclose = "</a>";
1.298 albertel 1080: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
1.477 raeburn 1081:
1.134 bowersj2 1082: if ($resource->hasDiscussion()) {
1083: $discussionHTML = $linkopen .
1.442 wenzelju 1084: '<img alt="'.&mt('New Discussion').'" src="'.$location.'/chat.gif" title="'.&mt('New Discussion').'"/>' .
1.134 bowersj2 1085: $linkclose;
1086: }
1087:
1088: if ($resource->getFeedback()) {
1089: my $feedback = $resource->getFeedback();
1.394 raeburn 1090: foreach my $msgid (split(/\,/, $feedback)) {
1091: if ($msgid) {
1.445 droeschl 1092: $feedbackHTML .= ' <a href="/adm/email?display='
1.394 raeburn 1093: . &escape($msgid) . '">'
1.442 wenzelju 1094: . '<img alt="'.&mt('New E-mail').'" src="'.$location.'/feedback.gif" title="'.&mt('New E-mail').'"/></a>';
1.134 bowersj2 1095: }
1096: }
1097: }
1098:
1099: if ($resource->getErrors()) {
1100: my $errors = $resource->getErrors();
1.254 matthew 1101: my $errorcount = 0;
1.394 raeburn 1102: foreach my $msgid (split(/,/, $errors)) {
1.254 matthew 1103: last if ($errorcount>=10); # Only output 10 bombs maximum
1.394 raeburn 1104: if ($msgid) {
1.254 matthew 1105: $errorcount++;
1.445 droeschl 1106: $errorHTML .= ' <a href="/adm/email?display='
1.394 raeburn 1107: . &escape($msgid) . '">'
1.442 wenzelju 1108: . '<img alt="'.&mt('New Error').'" src="'.$location.'/bomb.gif" title="'.&mt('New Error').'"/></a>';
1.134 bowersj2 1109: }
1110: }
1.197 bowersj2 1111: }
1112:
1113: if ($params->{'multipart'} && $part != '0') {
1114: $discussionHTML = $feedbackHTML = $errorHTML = '';
1.134 bowersj2 1115: }
1.426 droeschl 1116: return "<td class=\"LC_middle\">$discussionHTML$feedbackHTML$errorHTML </td>";
1.134 bowersj2 1117:
1.133 bowersj2 1118: }
1119: sub render_quick_status {
1120: my ($resource, $part, $params) = @_;
1.135 bowersj2 1121: my $result = "";
1122: my $firstDisplayed = !$params->{'condensed'} &&
1123: $params->{'multipart'} && $part eq "0";
1124:
1125: my $link = $params->{"resourceLink"};
1.445 droeschl 1126: my $linkopen = "<a href=\"$link\">";
1.135 bowersj2 1127: my $linkclose = "</a>";
1.426 droeschl 1128:
1129: $result .= '<td class="LC_middle">';
1.135 bowersj2 1130: if ($resource->is_problem() &&
1131: !$firstDisplayed) {
1.224 bowersj2 1132: my $icon = $statusIconMap{$resource->simpleStatus($part)};
1.135 bowersj2 1133: my $alt = $iconAltTags{$icon};
1134: if ($icon) {
1.298 albertel 1135: my $location=
1136: &Apache::loncommon::lonhttpdurl("/adm/lonIcons/$icon");
1.438 wenzelju 1137: $result .= $linkopen.'<img src="'.$location.'" alt="'.&mt($alt).'" title="'.&mt($alt).'" />'.$linkclose;
1.135 bowersj2 1138: } else {
1.426 droeschl 1139: $result .= " ";
1.135 bowersj2 1140: }
1141: } else { # not problem, no icon
1.426 droeschl 1142: $result .= " ";
1.135 bowersj2 1143: }
1.426 droeschl 1144: $result .= "</td>\n";
1.135 bowersj2 1145: return $result;
1.133 bowersj2 1146: }
1147: sub render_long_status {
1148: my ($resource, $part, $params) = @_;
1.426 droeschl 1149: my $result = '<td class="LC_middle LC_right">';
1.136 bowersj2 1150: my $firstDisplayed = !$params->{'condensed'} &&
1151: $params->{'multipart'} && $part eq "0";
1152:
1153: my $color;
1.488 bisitz 1154: my $info = '';
1.402 albertel 1155: if ($resource->is_problem() || $resource->is_practice()) {
1.136 bowersj2 1156: $color = $colormap{$resource->status};
1.502 raeburn 1157:
1158: if (dueInLessThan24Hours($resource, $part)) {
1.136 bowersj2 1159: $color = $hurryUpColor;
1.488 bisitz 1160: $info = ' title="'.&mt('Due in less than 24 hours!').'"';
1.502 raeburn 1161: } elsif (lastTry($resource, $part)) {
1162: unless (($resource->problemstatus($part) eq 'no') ||
1163: ($resource->problemstatus($part) eq 'no_feedback_ever')) {
1164: $color = $hurryUpColor;
1165: $info = ' title="'.&mt('One try remaining!').'"';
1166: }
1167: }
1.136 bowersj2 1168: }
1169:
1.463 raeburn 1170: if ($resource->kind() eq "res" &&
1171: $resource->is_raw_problem() &&
1172: !$firstDisplayed) {
1.488 bisitz 1173: if ($color) {$result .= '<span style="color:'.$color.'"'.$info.'><b>'; }
1.136 bowersj2 1174: $result .= getDescription($resource, $part);
1.488 bisitz 1175: if ($color) {$result .= "</b></span>"; }
1.136 bowersj2 1176: }
1.402 albertel 1177: if ($resource->is_map() && &advancedUser() && $resource->randompick()) {
1.400 albertel 1178: $result .= &mt('(randomly select [_1])', $resource->randompick());
1179: }
1180: if ($resource->is_map() && &advancedUser() && $resource->randomorder()) {
1181: $result .= &mt('(randomly ordered)');
1.136 bowersj2 1182: }
1.210 bowersj2 1183:
1.213 bowersj2 1184: # Debugging code
1185: #$result .= " " . $resource->awarded($part) . '/' . $resource->weight($part) .
1186: # ' - Part: ' . $part;
1187:
1.210 bowersj2 1188: $result .= "</td>\n";
1.136 bowersj2 1189:
1190: return $result;
1.51 bowersj2 1191: }
1192:
1.227 bowersj2 1193: # Colors obtained by taking the icons, matching the colors, and
1194: # possibly reducing the Value (HSV) of the color, if it's too bright
1195: # for text, generally by one third or so.
1.225 bowersj2 1196: my %statusColors =
1197: (
1198: $resObj->CLOSED => '#000000',
1.227 bowersj2 1199: $resObj->OPEN => '#998b13',
1200: $resObj->CORRECT => '#26933f',
1201: $resObj->INCORRECT => '#c48207',
1202: $resObj->ATTEMPTED => '#a87510',
1.225 bowersj2 1203: $resObj->ERROR => '#000000'
1204: );
1205: my %statusStrings =
1206: (
1207: $resObj->CLOSED => 'Not yet open',
1208: $resObj->OPEN => 'Open',
1209: $resObj->CORRECT => 'Correct',
1210: $resObj->INCORRECT => 'Incorrect',
1211: $resObj->ATTEMPTED => 'Attempted',
1212: $resObj->ERROR => 'Network Error'
1213: );
1214: my @statuses = ($resObj->CORRECT, $resObj->ATTEMPTED, $resObj->INCORRECT, $resObj->OPEN, $resObj->CLOSED, $resObj->ERROR);
1215:
1216: sub render_parts_summary_status {
1217: my ($resource, $part, $params) = @_;
1.256 albertel 1218: if (!$resource->is_problem() && !$resource->contains_problem) { return '<td></td>'; }
1.225 bowersj2 1219: if ($params->{showParts}) {
1220: return '<td></td>';
1221: }
1222:
1223: my $td = "<td align='right'>\n";
1224: my $endtd = "</td>\n";
1.256 albertel 1225: my @probs;
1.225 bowersj2 1226:
1.256 albertel 1227: if ($resource->contains_problem) {
1228: @probs=$resource->retrieveResources($resource,sub { $_[0]->is_problem() },1,0);
1229: } else {
1230: @probs=($resource);
1231: }
1232: my $return;
1233: my %overallstatus;
1234: my $totalParts;
1235: foreach my $resource (@probs) {
1236: # If there is a single part, just show the simple status
1237: if ($resource->singlepart()) {
1238: my $status = $resource->simpleStatus(${$resource->parts}[0]);
1239: $overallstatus{$status}++;
1240: $totalParts++;
1241: next;
1242: }
1243: # Now we can be sure the $part doesn't really matter.
1244: my $statusCount = $resource->simpleStatusCount();
1245: my @counts;
1246: foreach my $status (@statuses) {
1247: # decouple display order from the simpleStatusCount order
1248: my $slot = Apache::lonnavmaps::resource::statusToSlot($status);
1249: if ($statusCount->[$slot]) {
1250: $overallstatus{$status}+=$statusCount->[$slot];
1251: $totalParts+=$statusCount->[$slot];
1252: }
1253: }
1254: }
1255: $return.= $td . $totalParts . ' parts: ';
1256: foreach my $status (@statuses) {
1.488 bisitz 1257: if ($overallstatus{$status}) {
1258: $return.='<span style="color:' . $statusColors{$status}
1259: . '">' . $overallstatus{$status} . ' '
1260: . $statusStrings{$status} . '</span>';
1261: }
1.225 bowersj2 1262: }
1.256 albertel 1263: $return.= $endtd;
1264: return $return;
1.225 bowersj2 1265: }
1266:
1.133 bowersj2 1267: my @preparedColumns = (\&render_resource, \&render_communication_status,
1.225 bowersj2 1268: \&render_quick_status, \&render_long_status,
1269: \&render_parts_summary_status);
1.132 bowersj2 1270:
1271: sub setDefault {
1272: my ($val, $default) = @_;
1273: if (!defined($val)) { return $default; }
1274: return $val;
1275: }
1276:
1.296 albertel 1277: sub cmp_title {
1278: my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle));
1279: $atitle=~s/^\s*//;
1280: $btitle=~s/^\s*//;
1281: return $atitle cmp $btitle;
1282: }
1283:
1.132 bowersj2 1284: sub render {
1285: my $args = shift;
1.140 bowersj2 1286: &Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
1287: my $result = '';
1.132 bowersj2 1288: # Configure the renderer.
1289: my $cols = $args->{'cols'};
1290: if (!defined($cols)) {
1291: # no columns, no nav maps.
1292: return '';
1293: }
1.140 bowersj2 1294: my $navmap;
1295: if (defined($args->{'navmap'})) {
1296: $navmap = $args->{'navmap'};
1297: }
1298:
1.158 bowersj2 1299: my $r = $args->{'r'};
1.140 bowersj2 1300: my $queryString = $args->{'queryString'};
1.159 bowersj2 1301: my $jump = $args->{'jump'};
1.158 bowersj2 1302: my $here = $args->{'here'};
1.153 bowersj2 1303: my $suppressNavmap = setDefault($args->{'suppressNavmap'}, 0);
1.256 albertel 1304: my $closeAllPages = setDefault($args->{'closeAllPages'}, 0);
1.140 bowersj2 1305: my $currentJumpDelta = 2; # change this to change how many resources are displayed
1306: # before the current resource when using #current
1307:
1308: # If we were passed 'here' information, we are not rendering
1309: # after a folder manipulation, and we were not passed an
1310: # iterator, make sure we open the folders to show the "here"
1311: # marker
1312: my $filterHash = {};
1313: # Figure out what we're not displaying
1.394 raeburn 1314: foreach my $item (split(/\,/, $env{"form.filter"})) {
1315: if ($item) {
1316: $filterHash->{$item} = "1";
1.140 bowersj2 1317: }
1318: }
1319:
1.191 bowersj2 1320: # Filter: Remember filter function and add our own filter: Refuse
1321: # to show hidden resources unless the user can see them.
1322: my $userCanSeeHidden = advancedUser();
1323: my $filterFunc = setDefault($args->{'filterFunc'},
1324: sub {return 1;});
1325: if (!$userCanSeeHidden) {
1326: # Without renaming the filterfunc, the server seems to go into
1327: # an infinite loop
1328: my $oldFilterFunc = $filterFunc;
1329: $filterFunc = sub { my $res = shift; return !$res->randomout() &&
1330: &$oldFilterFunc($res);};
1331: }
1332:
1.140 bowersj2 1333: my $condition = 0;
1.320 albertel 1334: if ($env{'form.condition'}) {
1.140 bowersj2 1335: $condition = 1;
1336: }
1337:
1.320 albertel 1338: if (!$env{'form.folderManip'} && !defined($args->{'iterator'})) {
1.140 bowersj2 1339: # Step 1: Check to see if we have a navmap
1340: if (!defined($navmap)) {
1.221 bowersj2 1341: $navmap = Apache::lonnavmaps::navmap->new();
1.340 albertel 1342: if (!defined($navmap)) {
1.423 raeburn 1343: # no longer in course
1.388 albertel 1344: return '<span class="LC_error">'.&mt('No course selected').'</span><br />
1.362 www 1345: <a href="/adm/roles">'.&mt('Select a course').'</a><br />';
1.340 albertel 1346: }
1347: }
1.140 bowersj2 1348:
1349: # Step two: Locate what kind of here marker is necessary
1350: # Determine where the "here" marker is and where the screen jumps to.
1351:
1.332 albertel 1352: if ($env{'form.postsymb'} ne '') {
1.320 albertel 1353: $here = $jump = &Apache::lonnet::symbclean($env{'form.postsymb'});
1.332 albertel 1354: } elsif ($env{'form.postdata'} ne '') {
1.140 bowersj2 1355: # couldn't find a symb, is there a URL?
1.320 albertel 1356: my $currenturl = $env{'form.postdata'};
1.158 bowersj2 1357: #$currenturl=~s/^http\:\/\///;
1358: #$currenturl=~s/^[^\/]+//;
1.140 bowersj2 1359:
1.158 bowersj2 1360: $here = $jump = &Apache::lonnet::symbread($currenturl);
1.331 albertel 1361: }
1362: if ($here eq '') {
1.317 albertel 1363: my $last;
1.320 albertel 1364: if (tie(my %hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.317 albertel 1365: &GDBM_READER(),0640)) {
1366: $last=$hash{'last_known'};
1367: untie(%hash);
1368: }
1369: if ($last) { $here = $jump = $last; }
1370: }
1.158 bowersj2 1371:
1.140 bowersj2 1372: # Step three: Ensure the folders are open
1373: my $mapIterator = $navmap->getIterator(undef, undef, undef, 1);
1.222 bowersj2 1374: my $curRes;
1.140 bowersj2 1375: my $found = 0;
1376:
1377: # We only need to do this if we need to open the maps to show the
1378: # current position. This will change the counter so we can't count
1379: # for the jump marker with this loop.
1.294 albertel 1380: while ($here && ($curRes = $mapIterator->next()) && !$found) {
1.158 bowersj2 1381: if (ref($curRes) && $curRes->symb() eq $here) {
1.140 bowersj2 1382: my $mapStack = $mapIterator->getStack();
1383:
1384: # Ensure the parent maps are open
1385: for my $map (@{$mapStack}) {
1386: if ($condition) {
1387: undef $filterHash->{$map->map_pc()};
1388: } else {
1389: $filterHash->{$map->map_pc()} = 1;
1390: }
1391: }
1392: $found = 1;
1393: }
1394: }
1.159 bowersj2 1395: }
1.140 bowersj2 1396:
1.320 albertel 1397: if ( !defined($args->{'iterator'}) && $env{'form.folderManip'} ) { # we came from a user's manipulation of the nav page
1.140 bowersj2 1398: # If this is a click on a folder or something, we want to preserve the "here"
1399: # from the querystring, and get the new "jump" marker
1.320 albertel 1400: $here = $env{'form.here'};
1401: $jump = $env{'form.jump'};
1.140 bowersj2 1402: }
1403:
1.132 bowersj2 1404: my $it = $args->{'iterator'};
1405: if (!defined($it)) {
1.320 albertel 1406: # Construct a default iterator based on $env{'form.'} information
1.140 bowersj2 1407:
1408: # Step 1: Check to see if we have a navmap
1409: if (!defined($navmap)) {
1.221 bowersj2 1410: $navmap = Apache::lonnavmaps::navmap->new();
1.423 raeburn 1411: if (!defined($navmap)) {
1412: # no longer in course
1413: return '<span class="LC_error">'.&mt('No course selected').'</span><br />
1414: <a href="/adm/roles">'.&mt('Select a course').'</a><br />';
1415: }
1.140 bowersj2 1416: }
1417:
1.144 bowersj2 1418: # See if we're being passed a specific map
1419: if ($args->{'iterator_map'}) {
1420: my $map = $args->{'iterator_map'};
1.145 bowersj2 1421: $map = $navmap->getResourceByUrl($map);
1.144 bowersj2 1422: my $firstResource = $map->map_start();
1423: my $finishResource = $map->map_finish();
1424:
1425: $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
1426: } else {
1.401 albertel 1427: $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'});
1.144 bowersj2 1428: }
1.132 bowersj2 1429: }
1.256 albertel 1430:
1.159 bowersj2 1431: # (re-)Locate the jump point, if any
1.191 bowersj2 1432: # Note this does not take filtering or hidden into account... need
1433: # to be fixed?
1.159 bowersj2 1434: my $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0);
1.222 bowersj2 1435: my $curRes;
1.159 bowersj2 1436: my $foundJump = 0;
1437: my $counter = 0;
1438:
1.222 bowersj2 1439: while (($curRes = $mapIterator->next()) && !$foundJump) {
1.159 bowersj2 1440: if (ref($curRes)) { $counter++; }
1441:
1442: if (ref($curRes) && $jump eq $curRes->symb()) {
1443:
1444: # This is why we have to use the main iterator instead of the
1445: # potentially faster DFS: The count has to be the same, so
1446: # the order has to be the same, which DFS won't give us.
1447: $args->{'currentJumpIndex'} = $counter;
1448: $foundJump = 1;
1449: }
1450: }
1451:
1.132 bowersj2 1452: my $showParts = setDefault($args->{'showParts'}, 1);
1453: my $condenseParts = setDefault($args->{'condenseParts'}, 1);
1.139 bowersj2 1454: # keeps track of when the current resource is found,
1455: # so we can back up a few and put the anchor above the
1456: # current resource
1.140 bowersj2 1457: my $printKey = $args->{'printKey'};
1458: my $printCloseAll = $args->{'printCloseAll'};
1459: if (!defined($printCloseAll)) { $printCloseAll = 1; }
1.425 schulted 1460:
1.140 bowersj2 1461: # Print key?
1462: if ($printKey) {
1463: $result .= '<table border="0" cellpadding="2" cellspacing="0">';
1464: $result.='<tr><td align="right" valign="bottom">Key: </td>';
1.298 albertel 1465: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
1.140 bowersj2 1466: if ($navmap->{LAST_CHECK}) {
1467: $result .=
1.434 bisitz 1468: '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('New discussion since').' '.
1.140 bowersj2 1469: strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
1470: '</td><td align="center" valign="bottom"> '.
1.434 bisitz 1471: '<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').'<p>'.
1.140 bowersj2 1472: '</td>';
1473: } else {
1474: $result .= '<td align="center" valign="bottom"> '.
1.434 bisitz 1475: '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
1476: ' <img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').
1.140 bowersj2 1477: '</td>';
1478: }
1479:
1480: $result .= '</tr></table>';
1481: }
1482:
1.172 bowersj2 1483: if ($printCloseAll && !$args->{'resource_no_folder_link'}) {
1.281 albertel 1484: my ($link,$text);
1.140 bowersj2 1485: if ($condition) {
1.446 raeburn 1486: $link='navmaps?condition=0&filter=&'.$queryString.
1.449 bisitz 1487: '&here='.&escape($here);
1.377 www 1488: $text='Close all folders';
1.140 bowersj2 1489: } else {
1.446 raeburn 1490: $link='navmaps?condition=1&filter=&'.$queryString.
1.449 bisitz 1491: '&here='.&escape($here);
1.377 www 1492: $text='Open all folders';
1.281 albertel 1493: }
1.446 raeburn 1494: if ($env{'form.register'}) {
1495: $link .= '&register='.$env{'form.register'};
1496: }
1.281 albertel 1497: if ($args->{'caller'} eq 'navmapsdisplay') {
1.478 raeburn 1498: unless ($args->{'notools'}) {
1499: &add_linkitem($args->{'linkitems'},'changefolder',
1500: "location.href='$link'",$text);
1501: }
1.281 albertel 1502: } else {
1.446 raeburn 1503: $result.= '<a href="'.$link.'">'.&mt($text).'</a>';
1.281 albertel 1504: }
1.266 raeburn 1505: $result .= "\n";
1506: }
1.140 bowersj2 1507:
1.266 raeburn 1508: # Check for any unread discussions in all resources.
1.478 raeburn 1509: if (($args->{'caller'} eq 'navmapsdisplay') && (!$args->{'notools'})) {
1.296 albertel 1510: &add_linkitem($args->{'linkitems'},'clearbubbles',
1511: 'document.clearbubbles.submit()',
1512: 'Mark all posts read');
1.297 albertel 1513: my $time=time;
1.486 raeburn 1514: my $querystr = &HTML::Entities::encode($ENV{'QUERY_STRING'},'<>&"');
1.296 albertel 1515: $result .= (<<END);
1516: <form name="clearbubbles" method="post" action="/adm/feedback">
1.486 raeburn 1517: <input type="hidden" name="navurl" value="$querystr" />
1.297 albertel 1518: <input type="hidden" name="navtime" value="$time" />
1.296 albertel 1519: END
1.446 raeburn 1520: if ($env{'form.register'}) {
1521: $result .= '<input type="hidden" name="register" value="'.$env{'form.register'}.'" />';
1522: }
1.296 albertel 1523: if ($args->{'sort'} eq 'discussion') {
1524: my $totdisc = 0;
1525: my $haveDisc = '';
1526: my @allres=$navmap->retrieveResources();
1527: foreach my $resource (@allres) {
1528: if ($resource->hasDiscussion()) {
1.323 albertel 1529: $haveDisc .= $resource->wrap_symb().':';
1.296 albertel 1530: $totdisc ++;
1.267 albertel 1531: }
1532: }
1.296 albertel 1533: if ($totdisc > 0) {
1534: $haveDisc =~ s/:$//;
1535: $result .= (<<END);
1536: <input type="hidden" name="navmaps" value="$haveDisc" />
1537: </form>
1538: END
1539: }
1.297 albertel 1540: }
1541: $result.='</form>';
1.478 raeburn 1542: }
1543: if (($args->{'caller'} eq 'navmapsdisplay') &&
1.525 raeburn 1544: ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
1545: (&Apache::lonnet::allowed('cev',$env{'request.course.id'})))) {
1.478 raeburn 1546: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1547: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1548: if ($env{'course.'.$env{'request.course.id'}.'.url'} eq
1549: "uploaded/$cdom/$cnum/default.sequence") {
1550: &add_linkitem($args->{'linkitems'},'edittoplevel',
1551: "javascript:gocmd('/adm/coursedocs','editdocs');",
1552: 'Content Editor');
1.475 raeburn 1553: }
1.266 raeburn 1554: }
1.276 albertel 1555:
1.281 albertel 1556: if ($args->{'caller'} eq 'navmapsdisplay') {
1.476 raeburn 1557: $result .= &show_linkitems_toolbar($args,$condition);
1.281 albertel 1558: } elsif ($args->{'sort_html'}) {
1559: $result.=$args->{'sort_html'};
1560: }
1.276 albertel 1561:
1.425 schulted 1562: #$result .= "<br />\n";
1.140 bowersj2 1563: if ($r) {
1564: $r->print($result);
1565: $r->rflush();
1566: $result = "";
1567: }
1.132 bowersj2 1568: # End parameter setting
1.425 schulted 1569:
1570: $result .= "<br />\n";
1571:
1.132 bowersj2 1572: # Data
1.431 schulted 1573: $result.=&Apache::loncommon::start_data_table("LC_tableOfContent");
1.426 droeschl 1574:
1.132 bowersj2 1575: my $res = "Apache::lonnavmaps::resource";
1576: my %condenseStatuses =
1577: ( $res->NETWORK_FAILURE => 1,
1578: $res->NOTHING_SET => 1,
1579: $res->CORRECT => 1 );
1.133 bowersj2 1580:
1581: # Shared variables
1582: $args->{'counter'} = 0; # counts the rows
1583: $args->{'indentLevel'} = 0;
1584: $args->{'isNewBranch'} = 0;
1.426 droeschl 1585: $args->{'condensed'} = 0;
1586:
1.428 droeschl 1587: my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
1.426 droeschl 1588: $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='$location' alt='' />");
1.133 bowersj2 1589: $args->{'displayedHereMarker'} = 0;
1.132 bowersj2 1590:
1.518 raeburn 1591: # If we're suppressing empty sequences, look for them here.
1592: # We also do this even if $args->{'suppressEmptySequences'}
1593: # is not true, so we can hide empty sequences for which the
1594: # hiddenresource parameter is set to yes (at map level), or
1595: # mark as hidden for users who have $userCanSeeHidden.
1596: # Use DFS for speed, since structure actually doesn't matter,
1597: # except what map has what resources.
1598:
1599: my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
1600: $it->{FIRST_RESOURCE},
1601: $it->{FINISH_RESOURCE},
1602: {}, undef, 1);
1603: my $depth = 0;
1604: $dfsit->next();
1605: my $curRes = $dfsit->next();
1606: while ($depth > -1) {
1607: if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
1608: if ($curRes == $dfsit->END_MAP()) { $depth--; }
1609:
1610: if (ref($curRes)) {
1611: # Parallel pre-processing: Do sequences have non-filtered-out children?
1612: if ($curRes->is_map()) {
1613: $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
1614: # Sequences themselves do not count as visible children,
1615: # unless those sequences also have visible children.
1616: # This means if a sequence appears, there's a "promise"
1617: # that there's something under it if you open it, somewhere.
1618: } elsif ($curRes->src()) {
1619: # Not a sequence: if it's filtered, ignore it, otherwise
1620: # rise up the stack and mark the sequences as having children
1621: if (&$filterFunc($curRes)) {
1622: for my $sequence (@{$dfsit->getStack()}) {
1623: $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
1.190 bowersj2 1624: }
1625: }
1626: }
1627: }
1.518 raeburn 1628: } continue {
1629: $curRes = $dfsit->next();
1.190 bowersj2 1630: }
1631:
1.133 bowersj2 1632: my $displayedJumpMarker = 0;
1.132 bowersj2 1633: # Set up iteration.
1634: my $now = time();
1635: my $in24Hours = $now + 24 * 60 * 60;
1636: my $rownum = 0;
1637:
1.141 bowersj2 1638: # export "here" marker information
1639: $args->{'here'} = $here;
1640:
1.222 bowersj2 1641: $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
1.270 albertel 1642: my @resources;
1643: my $code='';# sub { !(shift->is_map();) };
1644: if ($args->{'sort'} eq 'title') {
1.276 albertel 1645: my $oldFilterFunc = $filterFunc;
1646: my $filterFunc=
1647: sub {
1648: my ($res)=@_;
1649: if ($res->is_map()) { return 0;}
1650: return &$oldFilterFunc($res);
1651: };
1652: @resources=$navmap->retrieveResources(undef,$filterFunc);
1.296 albertel 1653: @resources= sort { &cmp_title($a,$b) } @resources;
1654: } elsif ($args->{'sort'} eq 'duedate') {
1655: my $oldFilterFunc = $filterFunc;
1656: my $filterFunc=
1657: sub {
1658: my ($res)=@_;
1659: if (!$res->is_problem()) { return 0;}
1660: return &$oldFilterFunc($res);
1661: };
1662: @resources=$navmap->retrieveResources(undef,$filterFunc);
1.289 raeburn 1663: @resources= sort {
1.270 albertel 1664: if ($a->duedate ne $b->duedate) {
1665: return $a->duedate cmp $b->duedate;
1666: }
1.296 albertel 1667: my $value=&cmp_title($a,$b);
1668: return $value;
1.270 albertel 1669: } @resources;
1.296 albertel 1670: } elsif ($args->{'sort'} eq 'discussion') {
1671: my $oldFilterFunc = $filterFunc;
1672: my $filterFunc=
1673: sub {
1674: my ($res)=@_;
1675: if (!$res->hasDiscussion() &&
1676: !$res->getFeedback() &&
1677: !$res->getErrors()) { return 0;}
1678: return &$oldFilterFunc($res);
1679: };
1680: @resources=$navmap->retrieveResources(undef,$filterFunc);
1681: @resources= sort { &cmp_title($a,$b) } @resources;
1.276 albertel 1682: } else {
1683: #unknow sort mechanism or default
1684: undef($args->{'sort'});
1.270 albertel 1685: }
1686:
1.527 raeburn 1687: # Determine if page will be served with https in case
1688: # it contains a syllabus which uses an external URL
1689: # which points at an http site.
1690:
1691: my ($is_ssl,$cdom,$cnum);
1692: if ($ENV{'SERVER_PORT'} == 443) {
1693: $is_ssl = 1;
1694: }
1695: if ($env{'request.course.id'}) {
1696: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1697: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1698: }
1.276 albertel 1699:
1.270 albertel 1700: while (1) {
1701: if ($args->{'sort'}) {
1702: $curRes = shift(@resources);
1703: } else {
1704: $curRes = $it->next($closeAllPages);
1705: }
1706: if (!$curRes) { last; }
1707:
1.132 bowersj2 1708: # Maintain indentation level.
1709: if ($curRes == $it->BEGIN_MAP() ||
1710: $curRes == $it->BEGIN_BRANCH() ) {
1.133 bowersj2 1711: $args->{'indentLevel'}++;
1.132 bowersj2 1712: }
1713: if ($curRes == $it->END_MAP() ||
1714: $curRes == $it->END_BRANCH() ) {
1.133 bowersj2 1715: $args->{'indentLevel'}--;
1.132 bowersj2 1716: }
1717: # Notice new branches
1718: if ($curRes == $it->BEGIN_BRANCH()) {
1.133 bowersj2 1719: $args->{'isNewBranch'} = 1;
1720: }
1721:
1722: # If this isn't an actual resource, continue on
1723: if (!ref($curRes)) {
1724: next;
1.132 bowersj2 1725: }
1.133 bowersj2 1726:
1.143 bowersj2 1727: # If this has been filtered out, continue on
1728: if (!(&$filterFunc($curRes))) {
1729: $args->{'isNewBranch'} = 0; # Don't falsely remember this
1730: next;
1731: }
1.132 bowersj2 1732:
1.190 bowersj2 1733: # If this is an empty sequence and we're filtering them, continue on
1.518 raeburn 1734: $args->{'mapHidden'} = 0;
1735: if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {
1736: if ($args->{'suppressEmptySequences'}) {
1737: next;
1738: } else {
1739: my $mapname = &Apache::lonnet::declutter($curRes->src());
1740: $mapname = &Apache::lonnet::deversion($mapname);
1741: if (lc($navmap->get_mapparam(undef,$mapname,"0.hiddenresource")) eq 'yes') {
1742: if ($userCanSeeHidden) {
1743: $args->{'mapHidden'} = 1;
1744: } else {
1745: next;
1746: }
1747: }
1748: }
1.190 bowersj2 1749: }
1750:
1.153 bowersj2 1751: # If we're suppressing navmaps and this is a navmap, continue on
1752: if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
1753: next;
1754: }
1755:
1.191 bowersj2 1756: $args->{'counter'}++;
1757:
1.132 bowersj2 1758: # Does it have multiple parts?
1.133 bowersj2 1759: $args->{'multipart'} = 0;
1760: $args->{'condensed'} = 0;
1.132 bowersj2 1761: my @parts;
1762:
1763: # Decide what parts to show.
1.133 bowersj2 1764: if ($curRes->is_problem() && $showParts) {
1.132 bowersj2 1765: @parts = @{$curRes->parts()};
1.192 bowersj2 1766: $args->{'multipart'} = $curRes->multipart();
1.132 bowersj2 1767:
1768: if ($condenseParts) { # do the condensation
1.133 bowersj2 1769: if (!$args->{'condensed'}) {
1.132 bowersj2 1770: # Decide whether to condense based on similarity
1.192 bowersj2 1771: my $status = $curRes->status($parts[0]);
1772: my $due = $curRes->duedate($parts[0]);
1773: my $open = $curRes->opendate($parts[0]);
1.132 bowersj2 1774: my $statusAllSame = 1;
1775: my $dueAllSame = 1;
1776: my $openAllSame = 1;
1.192 bowersj2 1777: for (my $i = 1; $i < scalar(@parts); $i++) {
1.132 bowersj2 1778: if ($curRes->status($parts[$i]) != $status){
1779: $statusAllSame = 0;
1780: }
1781: if ($curRes->duedate($parts[$i]) != $due ) {
1782: $dueAllSame = 0;
1783: }
1784: if ($curRes->opendate($parts[$i]) != $open) {
1785: $openAllSame = 0;
1786: }
1787: }
1788: # $*allSame is true if all the statuses were
1789: # the same. Now, if they are all the same and
1790: # match one of the statuses to condense, or they
1791: # are all open with the same due date, or they are
1792: # all OPEN_LATER with the same open date, display the
1793: # status of the first non-zero part (to get the 'correct'
1794: # status right, since 0 is never 'correct' or 'open').
1795: if (($statusAllSame && defined($condenseStatuses{$status})) ||
1796: ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
1797: ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
1.192 bowersj2 1798: @parts = ($parts[0]);
1.133 bowersj2 1799: $args->{'condensed'} = 1;
1.132 bowersj2 1800: }
1801: }
1.198 bowersj2 1802: # Multipart problem with one part: always "condense" (happens
1803: # to match the desirable behavior)
1804: if ($curRes->countParts() == 1) {
1805: @parts = ($parts[0]);
1806: $args->{'condensed'} = 1;
1807: }
1.132 bowersj2 1808: }
1.157 bowersj2 1809: }
1.132 bowersj2 1810:
1811: # If the multipart problem was condensed, "forget" it was multipart
1812: if (scalar(@parts) == 1) {
1.133 bowersj2 1813: $args->{'multipart'} = 0;
1.192 bowersj2 1814: } else {
1815: # Add part 0 so we display it correctly.
1816: unshift @parts, '0';
1.132 bowersj2 1817: }
1.310 albertel 1818:
1819: {
1820: my ($src,$symb,$anchor,$stack);
1821: if ($args->{'sort'}) {
1822: my $it = $navmap->getIterator(undef, undef, undef, 1);
1823: while ( my $res=$it->next()) {
1824: if (ref($res) &&
1825: $res->symb() eq $curRes->symb()) { last; }
1826: }
1827: $stack=$it->getStack();
1828: } else {
1829: $stack=$it->getStack();
1830: }
1831: ($src,$symb,$anchor)=getLinkForResource($stack);
1.527 raeburn 1832: my $srcHasQuestion = $src =~ /\?/;
1833: if ($env{'request.course.id'}) {
1834: if (($src =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) && ($is_ssl) &&
1835: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.528 ! raeburn 1836: my $hostname = $r->hostname();
! 1837: if ($hostname ne '') {
! 1838: $src = 'http://'.$hostname.$src;
! 1839: }
1.527 raeburn 1840: $src .= ($srcHasQuestion? '&' : '?') . 'usehttp=1';
1841: $srcHasQuestion = 1;
1842: }
1843: }
1.310 albertel 1844: if (defined($anchor)) { $anchor='#'.$anchor; }
1845: $args->{"resourceLink"} = $src.
1.449 bisitz 1846: ($srcHasQuestion?'&':'?') .
1.384 www 1847: 'symb=' . &escape($symb).$anchor;
1.310 albertel 1848: }
1.132 bowersj2 1849: # Now, we've decided what parts to show. Loop through them and
1850: # show them.
1.192 bowersj2 1851: foreach my $part (@parts) {
1.132 bowersj2 1852: $rownum ++;
1853:
1.431 schulted 1854: $result .= &Apache::loncommon::start_data_table_row();
1.134 bowersj2 1855:
1856: # Set up some data about the parts that the cols might want
1857: my $filter = $it->{FILTER};
1.270 albertel 1858:
1.132 bowersj2 1859: # Now, display each column.
1860: foreach my $col (@$cols) {
1.139 bowersj2 1861: my $colHTML = '';
1862: if (ref($col)) {
1863: $colHTML .= &$col($curRes, $part, $args);
1864: } else {
1865: $colHTML .= &{$preparedColumns[$col]}($curRes, $part, $args);
1866: }
1.132 bowersj2 1867:
1.133 bowersj2 1868: # If this is the first column and it's time to print
1869: # the anchor, do so
1870: if ($col == $cols->[0] &&
1871: $args->{'counter'} == $args->{'currentJumpIndex'} -
1.139 bowersj2 1872: $currentJumpDelta) {
1873: # Jam the anchor after the <td> tag;
1874: # necessary for valid HTML (which Mozilla requires)
1875: $colHTML =~ s/\>/\>\<a name="curloc" \/\>/;
1.133 bowersj2 1876: $displayedJumpMarker = 1;
1877: }
1.139 bowersj2 1878: $result .= $colHTML . "\n";
1.132 bowersj2 1879: }
1.431 schulted 1880: $result .= &Apache::loncommon::end_data_table_row();
1.140 bowersj2 1881: $args->{'isNewBranch'} = 0;
1.139 bowersj2 1882: }
1.153 bowersj2 1883:
1.139 bowersj2 1884: if ($r && $rownum % 20 == 0) {
1885: $r->print($result);
1886: $result = "";
1887: $r->rflush();
1.132 bowersj2 1888: }
1.156 bowersj2 1889: } continue {
1.208 bowersj2 1890: if ($r) {
1891: # If we have the connection, make sure the user is still connected
1892: my $c = $r->connection;
1893: if ($c->aborted()) {
1894: # Who cares what we do, nobody will see it anyhow.
1895: return '';
1896: }
1897: }
1.132 bowersj2 1898: }
1.486 raeburn 1899:
1900: $result.=&Apache::loncommon::end_data_table();
1.132 bowersj2 1901:
1.134 bowersj2 1902: # Print out the part that jumps to #curloc if it exists
1.159 bowersj2 1903: # delay needed because the browser is processing the jump before
1904: # it finishes rendering, so it goes to the wrong place!
1905: # onload might be better, but this routine has no access to that.
1906: # On mozilla, the 0-millisecond timeout seems to prevent this;
1907: # it's quite likely this might fix other browsers, too, and
1908: # certainly won't hurt anything.
1.139 bowersj2 1909: if ($displayedJumpMarker) {
1.449 bisitz 1910: $result .= &Apache::lonhtmlcommon::scripttag("
1.247 albertel 1911: if (location.href.indexOf('#curloc')==-1) {
1912: setTimeout(\"location += '#curloc';\", 0)
1913: }
1.449 bisitz 1914: ");
1.134 bowersj2 1915: }
1916:
1.140 bowersj2 1917: if ($r) {
1918: $r->print($result);
1919: $result = "";
1920: $r->rflush();
1921: }
1922:
1.132 bowersj2 1923: return $result;
1924: }
1925:
1.281 albertel 1926: sub add_linkitem {
1927: my ($linkitems,$name,$cmd,$text)=@_;
1928: $$linkitems{$name}{'cmd'}=$cmd;
1929: $$linkitems{$name}{'text'}=&mt($text);
1930: }
1931:
1.430 schulted 1932: sub show_linkitems_toolbar {
1.476 raeburn 1933: my ($args,$condition) = @_;
1.478 raeburn 1934: my $result;
1.476 raeburn 1935: if (ref($args) eq 'HASH') {
1936: if (ref($args->{'linkitems'}) eq 'HASH') {
1.478 raeburn 1937: my $numlinks = scalar(keys(%{$args->{'linkitems'}}));
1938: if ($numlinks > 1) {
1939: $result = '<td>'.
1940: &Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',
1941: undef,'RAT').
1942: '</td>'.
1943: '<td> </td>'.
1944: '<td class="LC_middle">'.&mt('Tools:').'</td>';
1945: }
1946: $result .= '<td align="left">'."\n".
1947: '<ul id="LC_toolbar">';
1.476 raeburn 1948: my @linkorder = ('firsthomework','everything','uncompleted',
1949: 'changefolder','clearbubbles','edittoplevel');
1950: foreach my $link (@linkorder) {
1951: if (ref($args->{'linkitems'}{$link}) eq 'HASH') {
1952: if ($args->{'linkitems'}{$link}{'text'} ne '') {
1953: $args->{'linkitems'}{$link}{'cmd'}=~s/"/'/g;
1954: if ($args->{'linkitems'}{$link}{'cmd'}) {
1.478 raeburn 1955: my $link_id = 'LC_content_toolbar_'.$link;
1.476 raeburn 1956: if ($link eq 'changefolder') {
1957: if ($condition) {
1958: $link_id='LC_content_toolbar_changefolder_toggled';
1959: } else {
1960: $link_id='LC_content_toolbar_changefolder';
1961: }
1962: }
1963: $result .= '<li><a href="#" '.
1964: 'onclick="'.$args->{'linkitems'}{$link}{'cmd'}.'" '.
1965: 'id="'.$link_id.'" '.
1966: 'class="LC_toolbarItem" '.
1967: 'title="'.$args->{'linkitems'}{$link}{'text'}.'">'.
1968: '</a></li>'."\n";
1.446 raeburn 1969: }
1970: }
1971: }
1972: }
1.476 raeburn 1973: $result .= '</ul>'.
1.486 raeburn 1974: '</td>';
1.478 raeburn 1975: if (($numlinks==1) && (exists($args->{'linkitems'}{'edittoplevel'}))) {
1976: $result .= '<td><a href="'.$args->{'linkitems'}{'edittoplevel'}{'cmd'}.'">'.
1977: &mt('Content Editor').'</a></td>';
1978: }
1.476 raeburn 1979: }
1980: if ($args->{'sort_html'}) {
1981: $result .= '<td> </td><td> </td><td> </td>'.
1982: '<td align="right">'.$args->{'sort_html'}.'</td>';
1.446 raeburn 1983: }
1.430 schulted 1984: }
1.478 raeburn 1985: if ($result) {
1986: $result = "<table><tr>$result</tr></table>";
1987: }
1.430 schulted 1988: return $result;
1989: }
1990:
1.133 bowersj2 1991: 1;
1992:
1.418 jms 1993:
1994:
1995:
1996:
1997:
1998:
1999:
2000:
1.133 bowersj2 2001: package Apache::lonnavmaps::navmap;
2002:
2003: =pod
2004:
1.216 bowersj2 2005: =head1 Object: Apache::lonnavmaps::navmap
1.133 bowersj2 2006:
1.217 bowersj2 2007: =head2 Overview
1.133 bowersj2 2008:
1.217 bowersj2 2009: The navmap object's job is to provide access to the resources
2010: in the course as Apache::lonnavmaps::resource objects, and to
2011: query and manage the relationship between those resource objects.
2012:
2013: Generally, you'll use the navmap object in one of three basic ways.
2014: In order of increasing complexity and power:
2015:
2016: =over 4
2017:
1.358 albertel 2018: =item * C<$navmap-E<gt>getByX>, where X is B<Id>, B<Symb> or B<MapPc> and getResourceByUrl. This provides
1.217 bowersj2 2019: various ways to obtain resource objects, based on various identifiers.
2020: Use this when you want to request information about one object or
2021: a handful of resources you already know the identities of, from some
2022: other source. For more about Ids, Symbs, and MapPcs, see the
2023: Resource documentation. Note that Url should be a B<last resort>,
1.358 albertel 2024: not your first choice; it only really works when there is only one
1.217 bowersj2 2025: instance of the resource in the course, which only applies to
1.358 albertel 2026: maps, and even that may change in the future (see the B<getResourceByUrl>
2027: documentation for more details.)
1.217 bowersj2 2028:
2029: =item * C<my @resources = $navmap-E<gt>retrieveResources(args)>. This
2030: retrieves resources matching some criterion and returns them
2031: in a flat array, with no structure information. Use this when
2032: you are manipulating a series of resources, based on what map
2033: the are in, but do not care about branching, or exactly how
2034: the maps and resources are related. This is the most common case.
2035:
2036: =item * C<$it = $navmap-E<gt>getIterator(args)>. This allows you traverse
2037: the course's navmap in various ways without writing the traversal
2038: code yourself. See iterator documentation below. Use this when
2039: you need to know absolutely everything about the course, including
2040: branches and the precise relationship between maps and resources.
2041:
2042: =back
2043:
2044: =head2 Creation And Destruction
2045:
2046: To create a navmap object, use the following function:
1.133 bowersj2 2047:
2048: =over 4
2049:
1.221 bowersj2 2050: =item * B<Apache::lonnavmaps::navmap-E<gt>new>():
1.133 bowersj2 2051:
1.221 bowersj2 2052: Creates a new navmap object. Returns the navmap object if this is
2053: successful, or B<undef> if not.
1.174 albertel 2054:
1.216 bowersj2 2055: =back
2056:
2057: =head2 Methods
2058:
2059: =over 4
2060:
1.174 albertel 2061: =item * B<getIterator>(first, finish, filter, condition):
2062:
2063: See iterator documentation below.
1.133 bowersj2 2064:
2065: =cut
2066:
2067: use strict;
2068: use GDBM_File;
1.320 albertel 2069: use Apache::lonnet;
1.397 albertel 2070: use LONCAPA;
1.133 bowersj2 2071:
2072: sub new {
2073: # magic invocation to create a class instance
2074: my $proto = shift;
2075: my $class = ref($proto) || $proto;
2076: my $self = {};
1.501 raeburn 2077: bless($self); # So we can call change_user if necessary
1.133 bowersj2 2078:
1.453 www 2079: $self->{USERNAME} = shift || $env{'user.name'};
2080: $self->{DOMAIN} = shift || $env{'user.domain'};
1.491 raeburn 2081: $self->{CODE} = shift;
1.496 raeburn 2082: $self->{NOHIDE} = shift;
1.453 www 2083:
1.465 foxr 2084:
2085:
1.133 bowersj2 2086: # Resource cache stores navmap resources as we reference them. We generate
2087: # them on-demand so we don't pay for creating resources unless we use them.
2088: $self->{RESOURCE_CACHE} = {};
2089:
2090: # Network failure flag, if we accessed the course or user opt and
2091: # failed
2092: $self->{NETWORK_FAILURE} = 0;
2093:
1.465 foxr 2094: # We can only tie the nav hash as done below if the username/domain
2095: # match the env one. Otherwise change_user does everything we need...since we can't
1.501 raeburn 2096: # assume there are course hashes for the specific requested user:domain
2097: # Note: change_user is also called if we need the nav hash when printing CODEd
2098: # assignments or printing an exam, in which the enclosing folder for the items in
2099: # the exam has hidden set.
1.465 foxr 2100: #
1.133 bowersj2 2101:
1.501 raeburn 2102: if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'}) &&
2103: !$self->{CODE} && !$self->{NOHIDE}) {
1.465 foxr 2104:
2105: # tie the nav hash
2106:
2107: my %navmaphash;
2108: my %parmhash;
2109: my $courseFn = $env{"request.course.fn"};
2110: if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
2111: &GDBM_READER(), 0640))) {
2112: return undef;
2113: }
2114:
2115: if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
2116: &GDBM_READER(), 0640)))
2117: {
2118: untie %{$self->{PARM_HASH}};
2119: return undef;
2120: }
2121:
2122: $self->{NAV_HASH} = \%navmaphash;
2123: $self->{PARM_HASH} = \%parmhash;
2124: $self->{PARM_CACHE} = {};
2125: } else {
1.496 raeburn 2126: $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE});
1.133 bowersj2 2127: }
1.470 foxr 2128:
1.465 foxr 2129: return $self;
2130: }
2131:
2132: #
2133: # In some instances it is useful to be able to dynamically change the
2134: # username/domain associated with a navmap (e.g. to navigate for someone
2135: # else besides the current user...if sufficiently privileged.
2136: # Parameters:
2137: # user - New user.
2138: # domain- Domain the user belongs to.
1.491 raeburn 2139: # code - Anonymous CODE in use.
1.465 foxr 2140: # Implicit inputs:
2141: #
2142: sub change_user {
2143: my $self = shift;
2144: $self->{USERNAME} = shift;
2145: $self->{DOMAIN} = shift;
1.491 raeburn 2146: $self->{CODE} = shift;
1.496 raeburn 2147: $self->{NOHIDE} = shift;
1.465 foxr 2148:
2149: # If the hashes are already tied make sure to break that bond:
2150:
2151: untie %{$self->{NAV_HASH}};
2152: untie %{$self->{PARM_HASH}};
2153:
2154: # The assumption is that we have to
2155: # use lonmap here to re-read the hash and from it reconstruct
2156: # new big and parameter hashes. An implicit assumption at this time
2157: # is that the course file is probably not created locally yet
2158: # an that we will therefore just read without tying.
2159:
2160: my ($cdom, $cnum) = split(/\_/, $env{'request.course.id'});
2161:
2162: my %big_hash;
1.496 raeburn 2163: &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}, \%big_hash);
1.465 foxr 2164: $self->{NAV_HASH} = \%big_hash;
2165:
1.470 foxr 2166:
2167:
1.514 raeburn 2168: # Now clear the parm cache and reconstruct the parm hash from the big_hash
1.465 foxr 2169: # param.xxxx keys.
2170:
2171: $self->{PARM_CACHE} = {};
1.133 bowersj2 2172:
1.465 foxr 2173: my %parm_hash = {};
1.504 raeburn 2174: foreach my $key (keys(%big_hash)) {
1.465 foxr 2175: if ($key =~ /^param\./) {
2176: my $param_key = $key;
2177: $param_key =~ s/^param\.//;
2178: $parm_hash{$param_key} = $big_hash{$key};
2179: }
1.133 bowersj2 2180: }
2181:
1.465 foxr 2182: $self->{PARM_HASH} = \%parm_hash;
2183:
1.500 raeburn 2184: }
1.133 bowersj2 2185:
1.221 bowersj2 2186: sub generate_course_user_opt {
1.133 bowersj2 2187: my $self = shift;
1.221 bowersj2 2188: if ($self->{COURSE_USER_OPT_GENERATED}) { return; }
1.133 bowersj2 2189:
1.453 www 2190: my $uname=$self->{USERNAME};
2191: my $udom=$self->{DOMAIN};
2192:
1.320 albertel 2193: my $cid=$env{'request.course.id'};
1.326 albertel 2194: my $cdom=$env{'course.'.$cid.'.domain'};
2195: my $cnum=$env{'course.'.$cid.'.num'};
1.221 bowersj2 2196:
1.133 bowersj2 2197: # ------------------------------------------------- Get coursedata (if present)
1.326 albertel 2198: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
2199: # Check for network failure
2200: if (!ref($courseopt)) {
2201: if ( $courseopt =~ /no.such.host/i || $courseopt =~ /con_lost/i) {
1.324 albertel 2202: $self->{NETWORK_FAILURE} = 1;
1.221 bowersj2 2203: }
1.326 albertel 2204: undef($courseopt);
2205: }
1.325 albertel 2206:
1.133 bowersj2 2207: # --------------------------------------------------- Get userdata (if present)
1.325 albertel 2208:
1.326 albertel 2209: my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
2210: # Check for network failure
2211: if (!ref($useropt)) {
2212: if ( $useropt =~ /no.such.host/i || $useropt =~ /con_lost/i) {
1.324 albertel 2213: $self->{NETWORK_FAILURE} = 1;
1.221 bowersj2 2214: }
1.326 albertel 2215: undef($useropt);
1.221 bowersj2 2216: }
2217:
1.326 albertel 2218: $self->{COURSE_OPT} = $courseopt;
2219: $self->{USER_OPT} = $useropt;
2220:
1.221 bowersj2 2221: $self->{COURSE_USER_OPT_GENERATED} = 1;
2222:
2223: return;
2224: }
2225:
1.485 foxr 2226:
2227:
1.221 bowersj2 2228: sub generate_email_discuss_status {
2229: my $self = shift;
1.259 raeburn 2230: my $symb = shift;
1.221 bowersj2 2231: if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
1.133 bowersj2 2232:
1.320 albertel 2233: my $cid=$env{'request.course.id'};
1.326 albertel 2234: my $cdom=$env{'course.'.$cid.'.domain'};
2235: my $cnum=$env{'course.'.$cid.'.num'};
1.221 bowersj2 2236:
1.454 www 2237: my %emailstatus = &Apache::lonnet::dump('email_status',$self->{DOMAIN},$self->{USERNAME});
1.221 bowersj2 2238: my $logoutTime = $emailstatus{'logout'};
1.320 albertel 2239: my $courseLeaveTime = $emailstatus{'logout_'.$env{'request.course.id'}};
1.221 bowersj2 2240: $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
2241: $courseLeaveTime : $logoutTime);
2242: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
2243: $cdom, $cnum);
1.259 raeburn 2244: my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss',
1.453 www 2245: $self->{DOMAIN},$self->{USERNAME},'lastread');
1.259 raeburn 2246: my %lastreadtime = ();
1.504 raeburn 2247: foreach my $key (keys(%lastread)) {
1.394 raeburn 2248: my $shortkey = $key;
2249: $shortkey =~ s/_lastread$//;
2250: $lastreadtime{$shortkey} = $lastread{$key};
1.259 raeburn 2251: }
2252:
1.221 bowersj2 2253: my %feedback=();
2254: my %error=();
1.453 www 2255: my @keys = &Apache::lonnet::getkeys('nohist_email',$self->{DOMAIN},
2256: $self->{USERNAME});
1.221 bowersj2 2257:
1.325 albertel 2258: foreach my $msgid (@keys) {
1.295 albertel 2259: if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
1.395 raeburn 2260: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
2261: $symb,$error) = &Apache::lonmsg::unpackmsgid($msgid);
1.396 raeburn 2262: &Apache::lonenc::check_decrypt(\$symb);
2263: if (($fromcid ne '') && ($fromcid ne $cid)) {
2264: next;
2265: }
1.395 raeburn 2266: if (defined($symb)) {
2267: if (defined($error) && $error == 1) {
2268: $error{$symb}.=','.$msgid;
2269: } else {
2270: $feedback{$symb}.=','.$msgid;
2271: }
2272: } else {
2273: my $plain=
2274: &LONCAPA::unescape(&LONCAPA::unescape($msgid));
2275: if ($plain=~/ \[([^\]]+)\]\:/) {
2276: my $url=$1;
2277: if ($plain=~/\:Error \[/) {
2278: $error{$url}.=','.$msgid;
2279: } else {
2280: $feedback{$url}.=','.$msgid;
2281: }
2282: }
2283: }
1.221 bowersj2 2284: }
1.211 bowersj2 2285: }
1.221 bowersj2 2286:
1.395 raeburn 2287: #symbs of resources that have feedbacks (will be urls pre-2.3)
1.221 bowersj2 2288: $self->{FEEDBACK} = \%feedback;
1.395 raeburn 2289: #or errors (will be urls pre 2.3)
1.295 albertel 2290: $self->{ERROR_MSG} = \%error;
1.221 bowersj2 2291: $self->{DISCUSSION_TIME} = \%discussiontime;
2292: $self->{EMAIL_STATUS} = \%emailstatus;
1.259 raeburn 2293: $self->{LAST_READ} = \%lastreadtime;
1.221 bowersj2 2294:
2295: $self->{EMAIL_DISCUSS_GENERATED} = 1;
2296: }
2297:
2298: sub get_user_data {
2299: my $self = shift;
2300: if ($self->{RETRIEVED_USER_DATA}) { return; }
1.211 bowersj2 2301:
1.221 bowersj2 2302: # Retrieve performance data on problems
1.320 albertel 2303: my %student_data = Apache::lonnet::currentdump($env{'request.course.id'},
1.453 www 2304: $self->{DOMAIN},
2305: $self->{USERNAME});
1.221 bowersj2 2306: $self->{STUDENT_DATA} = \%student_data;
1.133 bowersj2 2307:
1.221 bowersj2 2308: $self->{RETRIEVED_USER_DATA} = 1;
1.133 bowersj2 2309: }
2310:
1.354 raeburn 2311: sub get_discussion_data {
2312: my $self = shift;
2313: if ($self->{RETRIEVED_DISCUSSION_DATA}) {
1.366 albertel 2314: return $self->{DISCUSSION_DATA};
1.354 raeburn 2315: }
1.366 albertel 2316:
2317: $self->generate_email_discuss_status();
2318:
1.354 raeburn 2319: my $cid=$env{'request.course.id'};
2320: my $cdom=$env{'course.'.$cid.'.domain'};
2321: my $cnum=$env{'course.'.$cid.'.num'};
2322: # Retrieve discussion data for resources in course
1.367 albertel 2323: my %discussion_data = &Apache::lonnet::dumpstore($cid,$cdom,$cnum);
1.366 albertel 2324:
2325:
1.354 raeburn 2326: $self->{DISCUSSION_DATA} = \%discussion_data;
2327: $self->{RETRIEVED_DISCUSSION_DATA} = 1;
2328: return $self->{DISCUSSION_DATA};
2329: }
2330:
2331:
1.133 bowersj2 2332: # Internal function: Takes a key to look up in the nav hash and implements internal
2333: # memory caching of that key.
2334: sub navhash {
2335: my $self = shift; my $key = shift;
2336: return $self->{NAV_HASH}->{$key};
2337: }
2338:
1.217 bowersj2 2339: =pod
2340:
2341: =item * B<courseMapDefined>(): Returns true if the course map is defined,
2342: false otherwise. Undefined course maps indicate an error somewhere in
2343: LON-CAPA, and you will not be able to proceed with using the navmap.
2344: See the B<NAV> screen for an example of using this.
2345:
2346: =cut
2347:
1.133 bowersj2 2348: # Checks to see if coursemap is defined, matching test in old lonnavmaps
2349: sub courseMapDefined {
2350: my $self = shift;
1.320 albertel 2351: my $uri = &Apache::lonnet::clutter($env{'request.course.uri'});
1.133 bowersj2 2352:
2353: my $firstres = $self->navhash("map_start_$uri");
2354: my $lastres = $self->navhash("map_finish_$uri");
2355: return $firstres && $lastres;
2356: }
2357:
2358: sub getIterator {
2359: my $self = shift;
2360: my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
1.314 albertel 2361: shift, undef, shift,
2362: shift, shift);
1.133 bowersj2 2363: return $iterator;
2364: }
2365:
2366: # Private method: Does the given resource (as a symb string) have
2367: # current discussion? Returns 0 if chat/mail data not extracted.
2368: sub hasDiscussion {
2369: my $self = shift;
2370: my $symb = shift;
1.221 bowersj2 2371: $self->generate_email_discuss_status();
2372:
1.133 bowersj2 2373: if (!defined($self->{DISCUSSION_TIME})) { return 0; }
2374:
2375: #return defined($self->{DISCUSSION_TIME}->{$symb});
1.259 raeburn 2376:
1.323 albertel 2377: # backward compatibility (bulletin boards used to be 'wrapped')
2378: my $ressymb = $self->wrap_symb($symb);
1.259 raeburn 2379: if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
2380: return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
2381: } else {
1.266 raeburn 2382: # return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_CHECK}; # v.1.1 behavior
2383: 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 2384: }
1.133 bowersj2 2385: }
2386:
1.366 albertel 2387: sub last_post_time {
2388: my $self = shift;
2389: my $symb = shift;
2390: my $ressymb = $self->wrap_symb($symb);
2391: return $self->{DISCUSSION_TIME}->{$ressymb};
2392: }
2393:
1.393 raeburn 2394: sub discussion_info {
1.366 albertel 2395: my $self = shift;
2396: my $symb = shift;
1.393 raeburn 2397: my $filter = shift;
1.366 albertel 2398:
2399: $self->get_discussion_data();
1.372 raeburn 2400:
1.366 albertel 2401: my $ressymb = $self->wrap_symb($symb);
1.372 raeburn 2402: # keys used to store bulletinboard postings use 'unwrapped' symb.
1.397 albertel 2403: my $discsymb = &escape($self->unwrap_symb($ressymb));
1.372 raeburn 2404: my $version = $self->{DISCUSSION_DATA}{'version:'.$discsymb};
1.366 albertel 2405: if (!$version) { return; }
2406:
2407: my $prevread = $self->{LAST_READ}{$ressymb};
2408:
1.393 raeburn 2409: my $count = 0;
1.366 albertel 2410: my $hiddenflag = 0;
2411: my $deletedflag = 0;
1.393 raeburn 2412: my ($hidden,$deleted,%info);
1.366 albertel 2413:
2414: for (my $id=$version; $id>0; $id--) {
1.372 raeburn 2415: my $vkeys=$self->{DISCUSSION_DATA}{$id.':keys:'.$discsymb};
1.366 albertel 2416: my @keys=split(/:/,$vkeys);
2417: if (grep(/^hidden$/ ,@keys)) {
2418: if (!$hiddenflag) {
1.372 raeburn 2419: $hidden = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':hidden'};
1.366 albertel 2420: $hiddenflag = 1;
2421: }
2422: } elsif (grep(/^deleted$/,@keys)) {
2423: if (!$deletedflag) {
1.372 raeburn 2424: $deleted = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':deleted'};
1.366 albertel 2425: $deletedflag = 1;
2426: }
2427: } else {
1.393 raeburn 2428: if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
2429: if ($filter eq 'unread') {
2430: if ($prevread >= $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}) {
2431: next;
2432: }
2433: }
2434: $count++;
2435: $info{$count}{'subject'} =
2436: $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':subject'};
2437: $info{$count}{'id'} = $id;
2438: $info{$count}{'timestamp'} = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'};
2439: }
1.366 albertel 2440: }
2441: }
2442: if (wantarray) {
1.393 raeburn 2443: return ($count,%info);
1.366 albertel 2444: }
1.393 raeburn 2445: return $count;
1.366 albertel 2446: }
2447:
1.321 raeburn 2448: sub wrap_symb {
1.322 albertel 2449: my $self = shift;
1.321 raeburn 2450: my $symb = shift;
1.373 albertel 2451: if ($symb =~ m-___(adm/[^/]+/[^/]+/)(\d+)(/bulletinboard)$-) {
1.322 albertel 2452: unless ($symb =~ m|adm/wrapper/adm|) {
2453: $symb = 'bulletin___'.$2.'___adm/wrapper/'.$1.$2.$3;
1.321 raeburn 2454: }
2455: }
1.322 albertel 2456: return $symb;
1.321 raeburn 2457: }
2458:
1.372 raeburn 2459: sub unwrap_symb {
2460: my $self = shift;
2461: my $ressymb = shift;
2462: my $discsymb = $ressymb;
1.373 albertel 2463: if ($ressymb =~ m-^(bulletin___\d+___)adm/wrapper/(adm/[^/]+/[^/]+/\d+/bulletinboard)$-) {
1.372 raeburn 2464: $discsymb = $1.$2;
2465: }
2466: return $discsymb;
2467: }
2468:
1.322 albertel 2469: # Private method: Does the given resource (as a symb string) have
2470: # current feedback? Returns the string in the feedback hash, which
2471: # will be false if it does not exist.
2472:
1.133 bowersj2 2473: sub getFeedback {
2474: my $self = shift;
2475: my $symb = shift;
1.395 raeburn 2476: my $source = shift;
1.133 bowersj2 2477:
1.221 bowersj2 2478: $self->generate_email_discuss_status();
2479:
1.133 bowersj2 2480: if (!defined($self->{FEEDBACK})) { return ""; }
2481:
1.395 raeburn 2482: my $feedback;
2483: if ($self->{FEEDBACK}->{$symb}) {
2484: $feedback = $self->{FEEDBACK}->{$symb};
2485: if ($self->{FEEDBACK}->{$source}) {
2486: $feedback .= ','.$self->{FEEDBACK}->{$source};
2487: }
2488: } else {
2489: if ($self->{FEEDBACK}->{$source}) {
2490: $feedback = $self->{FEEDBACK}->{$source};
2491: }
2492: }
2493: return $feedback;
1.133 bowersj2 2494: }
2495:
2496: # Private method: Get the errors for that resource (by source).
2497: sub getErrors {
2498: my $self = shift;
1.395 raeburn 2499: my $symb = shift;
1.133 bowersj2 2500: my $src = shift;
1.221 bowersj2 2501:
2502: $self->generate_email_discuss_status();
2503:
1.133 bowersj2 2504: if (!defined($self->{ERROR_MSG})) { return ""; }
1.395 raeburn 2505:
2506: my $errors;
2507: if ($self->{ERROR_MSG}->{$symb}) {
2508: $errors = $self->{ERROR_MSG}->{$symb};
2509: if ($self->{ERROR_MSG}->{$src}) {
2510: $errors .= ','.$self->{ERROR_MSG}->{$src};
2511: }
2512: } else {
2513: if ($self->{ERROR_MSG}->{$src}) {
2514: $errors = $self->{ERROR_MSG}->{$src};
2515: }
2516: }
2517: return $errors;
1.133 bowersj2 2518: }
2519:
2520: =pod
2521:
1.174 albertel 2522: =item * B<getById>(id):
2523:
2524: Based on the ID of the resource (1.1, 3.2, etc.), get a resource
2525: object for that resource. This method, or other methods that use it
2526: (as in the resource object) is the only proper way to obtain a
2527: resource object.
1.133 bowersj2 2528:
1.194 bowersj2 2529: =item * B<getBySymb>(symb):
2530:
2531: Based on the symb of the resource, get a resource object for that
2532: resource. This is one of the proper ways to get a resource object.
2533:
1.448 raeburn 2534: =item * B<getByMapPc>(map_pc):
1.194 bowersj2 2535:
2536: Based on the map_pc of the resource, get a resource object for
2537: the given map. This is one of the proper ways to get a resource object.
2538:
1.133 bowersj2 2539: =cut
2540:
2541: # The strategy here is to cache the resource objects, and only construct them
2542: # as we use them. The real point is to prevent reading any more from the tied
1.398 banghart 2543: # hash than we have to, which should hopefully alleviate speed problems.
1.133 bowersj2 2544:
2545: sub getById {
2546: my $self = shift;
2547: my $id = shift;
2548:
2549: if (defined ($self->{RESOURCE_CACHE}->{$id}))
2550: {
2551: return $self->{RESOURCE_CACHE}->{$id};
2552: }
2553:
2554: # resource handles inserting itself into cache.
2555: # Not clear why the quotes are necessary, but as of this
2556: # writing it doesn't work without them.
2557: return "Apache::lonnavmaps::resource"->new($self, $id);
1.132 bowersj2 2558: }
1.133 bowersj2 2559:
1.172 bowersj2 2560: sub getBySymb {
2561: my $self = shift;
2562: my $symb = shift;
1.277 matthew 2563:
1.228 albertel 2564: my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);
1.172 bowersj2 2565: my $map = $self->getResourceByUrl($mapUrl);
1.277 matthew 2566: my $returnvalue = undef;
2567: if (ref($map)) {
2568: $returnvalue = $self->getById($map->map_pc() .'.'.$id);
2569: }
2570: return $returnvalue;
1.194 bowersj2 2571: }
2572:
2573: sub getByMapPc {
2574: my $self = shift;
2575: my $map_pc = shift;
2576: my $map_id = $self->{NAV_HASH}->{'map_id_' . $map_pc};
2577: $map_id = $self->{NAV_HASH}->{'ids_' . $map_id};
2578: return $self->getById($map_id);
1.172 bowersj2 2579: }
2580:
1.133 bowersj2 2581: =pod
2582:
1.174 albertel 2583: =item * B<firstResource>():
2584:
2585: Returns a resource object reference corresponding to the first
2586: resource in the navmap.
1.133 bowersj2 2587:
2588: =cut
2589:
2590: sub firstResource {
2591: my $self = shift;
2592: my $firstResource = $self->navhash('map_start_' .
1.320 albertel 2593: &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133 bowersj2 2594: return $self->getById($firstResource);
1.132 bowersj2 2595: }
1.133 bowersj2 2596:
2597: =pod
2598:
1.174 albertel 2599: =item * B<finishResource>():
2600:
2601: Returns a resource object reference corresponding to the last resource
2602: in the navmap.
1.133 bowersj2 2603:
2604: =cut
2605:
2606: sub finishResource {
2607: my $self = shift;
2608: my $firstResource = $self->navhash('map_finish_' .
1.320 albertel 2609: &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133 bowersj2 2610: return $self->getById($firstResource);
1.132 bowersj2 2611: }
1.133 bowersj2 2612:
2613: # Parmval reads the parm hash and cascades the lookups. parmval_real does
2614: # the actual lookup; parmval caches the results.
2615: sub parmval {
2616: my $self = shift;
1.399 albertel 2617: my ($what,$symb,$recurse)=@_;
1.133 bowersj2 2618: my $hashkey = $what."|||".$symb;
1.459 foxr 2619: my $cache = $self->{PARM_CACHE};
1.133 bowersj2 2620: if (defined($self->{PARM_CACHE}->{$hashkey})) {
1.411 raeburn 2621: if (ref($self->{PARM_CACHE}->{$hashkey}) eq 'ARRAY') {
2622: if (defined($self->{PARM_CACHE}->{$hashkey}->[0])) {
2623: if (wantarray) {
2624: return @{$self->{PARM_CACHE}->{$hashkey}};
2625: } else {
2626: return $self->{PARM_CACHE}->{$hashkey}->[0];
2627: }
2628: }
2629: } else {
2630: return $self->{PARM_CACHE}->{$hashkey};
2631: }
1.133 bowersj2 2632: }
1.515 raeburn 2633:
1.399 albertel 2634: my $result = $self->parmval_real($what, $symb, $recurse);
1.133 bowersj2 2635: $self->{PARM_CACHE}->{$hashkey} = $result;
1.405 albertel 2636: if (wantarray) {
1.411 raeburn 2637: return @{$result};
1.405 albertel 2638: }
2639: return $result->[0];
1.132 bowersj2 2640: }
2641:
1.485 foxr 2642:
1.133 bowersj2 2643: sub parmval_real {
2644: my $self = shift;
1.219 albertel 2645: my ($what,$symb,$recurse) = @_;
1.133 bowersj2 2646:
1.485 foxr 2647:
1.221 bowersj2 2648: # Make sure the {USER_OPT} and {COURSE_OPT} hashes are populated
2649: $self->generate_course_user_opt();
2650:
1.320 albertel 2651: my $cid=$env{'request.course.id'};
2652: my $csec=$env{'request.course.sec'};
1.350 raeburn 2653: my $cgroup='';
2654: my @cgrps=split(/:/,$env{'request.course.groups'});
2655: if (@cgrps > 0) {
2656: @cgrps = sort(@cgrps);
2657: $cgroup = $cgrps[0];
2658: }
1.453 www 2659: my $uname=$self->{USERNAME};
2660: my $udom=$self->{DOMAIN};
1.133 bowersj2 2661:
1.405 albertel 2662: unless ($symb) { return ['']; }
1.133 bowersj2 2663: my $result='';
2664:
1.226 www 2665: my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
1.383 albertel 2666: $mapname = &Apache::lonnet::deversion($mapname);
1.515 raeburn 2667: my ($recursed,@recurseup);
2668:
1.133 bowersj2 2669: # ----------------------------------------------------- Cascading lookup scheme
2670: my $rwhat=$what;
2671: $what=~s/^parameter\_//;
2672: $what=~s/\_/\./;
2673:
2674: my $symbparm=$symb.'.'.$what;
1.515 raeburn 2675: my $recurseparm=$mapname.'___(rec).'.$what;
1.133 bowersj2 2676: my $mapparm=$mapname.'___(all).'.$what;
1.325 albertel 2677: my $usercourseprefix=$cid;
1.515 raeburn 2678:
1.485 foxr 2679:
2680:
1.350 raeburn 2681: my $grplevel=$usercourseprefix.'.['.$cgroup.'].'.$what;
2682: my $grplevelr=$usercourseprefix.'.['.$cgroup.'].'.$symbparm;
1.515 raeburn 2683: my $grpleveli=$usercourseprefix.'.['.$cgroup.'].'.$recurseparm;
1.350 raeburn 2684: my $grplevelm=$usercourseprefix.'.['.$cgroup.'].'.$mapparm;
2685:
1.485 foxr 2686:
1.133 bowersj2 2687: my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
2688: my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
1.515 raeburn 2689: my $secleveli=$usercourseprefix.'.['.$csec.'].'.$recurseparm;
1.133 bowersj2 2690: my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
2691:
1.485 foxr 2692:
1.133 bowersj2 2693: my $courselevel= $usercourseprefix.'.'.$what;
2694: my $courselevelr=$usercourseprefix.'.'.$symbparm;
1.515 raeburn 2695: my $courseleveli=$usercourseprefix.'.'.$recurseparm;
1.133 bowersj2 2696: my $courselevelm=$usercourseprefix.'.'.$mapparm;
2697:
1.485 foxr 2698:
1.133 bowersj2 2699: my $useropt = $self->{USER_OPT};
2700: my $courseopt = $self->{COURSE_OPT};
2701: my $parmhash = $self->{PARM_HASH};
2702:
2703: # ---------------------------------------------------------- first, check user
2704: if ($uname and defined($useropt)) {
1.405 albertel 2705: if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; }
2706: if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; }
1.515 raeburn 2707: if (defined($$useropt{$courseleveli})) { return [$$useropt{$courseleveli},'map']; }
2708: unless ($recursed) {
2709: @recurseup = $self->recurseup_maps($mapname);
2710: $recursed = 1;
2711: }
2712: foreach my $item (@recurseup) {
2713: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526 raeburn 2714: if (defined($$useropt{$norecursechk})) {
2715: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2716: return [$$useropt{$norecursechk},'map'];
2717: } else {
2718: last;
2719: }
2720: }
1.515 raeburn 2721: my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
2722: if (defined($$useropt{$recursechk})) { return [$$useropt{$recursechk},'map']; }
2723: }
1.405 albertel 2724: if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; }
1.133 bowersj2 2725: }
2726:
2727: # ------------------------------------------------------- second, check course
1.350 raeburn 2728: if ($cgroup ne '' and defined($courseopt)) {
1.405 albertel 2729: if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; }
2730: if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; }
1.515 raeburn 2731: if (defined($$courseopt{$grpleveli})) { return [$$courseopt{$grpleveli},'map']; }
2732: unless ($recursed) {
2733: @recurseup = $self->recurseup_maps($mapname);
2734: $recursed = 1;
2735: }
2736: foreach my $item (@recurseup) {
2737: my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
1.526 raeburn 2738: if (defined($$courseopt{$norecursechk})) {
2739: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2740: return [$$courseopt{$norecursechk},'map'];
2741: } else {
2742: last;
2743: }
2744: }
1.515 raeburn 2745: my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
2746: if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }
2747: }
1.405 albertel 2748: if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; }
1.350 raeburn 2749: }
2750:
1.515 raeburn 2751: if ($csec ne '' and defined($courseopt)) {
1.405 albertel 2752: if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; }
2753: if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; }
1.515 raeburn 2754: if (defined($$courseopt{$secleveli})) { return [$$courseopt{$secleveli},'map']; }
2755: unless ($recursed) {
2756: @recurseup = $self->recurseup_maps($mapname);
2757: $recursed = 1;
2758: }
2759: foreach my $item (@recurseup) {
2760: my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
1.526 raeburn 2761: if (defined($$courseopt{$norecursechk})) {
2762: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2763: return [$$courseopt{$norecursechk},'map'];
2764: } else {
2765: last;
2766: }
2767: }
1.515 raeburn 2768: my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
2769: if (defined($$courseopt{$recursechk})) { return [$$courseopt{$recursechk},'map']; }
2770: }
1.405 albertel 2771: if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; }
1.133 bowersj2 2772: }
2773:
2774: if (defined($courseopt)) {
1.405 albertel 2775: if (defined($$courseopt{$courselevelr})) { return [$$courseopt{$courselevelr},'resource']; }
1.133 bowersj2 2776: }
2777:
2778: # ----------------------------------------------------- third, check map parms
2779:
2780: my $thisparm=$$parmhash{$symbparm};
1.405 albertel 2781: if (defined($thisparm)) { return [$thisparm,'map']; }
1.133 bowersj2 2782:
2783: # ----------------------------------------------------- fourth , check default
2784:
1.246 albertel 2785: my $meta_rwhat=$rwhat;
2786: $meta_rwhat=~s/\./_/g;
2787: my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
1.405 albertel 2788: if (defined($default)) { return [$default,'resource']}
1.246 albertel 2789: $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
1.405 albertel 2790: if (defined($default)) { return [$default,'resource']}
1.315 albertel 2791: # --------------------------------------------------- fifth, check more course
2792: if (defined($courseopt)) {
1.405 albertel 2793: if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; }
1.515 raeburn 2794: if (defined($$courseopt{$courseleveli})) { return [$$courseopt{$courseleveli},'map']; }
2795: unless ($recursed) {
2796: @recurseup = $self->recurseup_maps($mapname);
2797: $recursed = 1;
2798: }
2799: foreach my $item (@recurseup) {
2800: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526 raeburn 2801: if (defined($$courseopt{$norecursechk})) {
2802: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2803: return [$$courseopt{$norecursechk},'map'];
2804: } else {
2805: last;
2806: }
2807: }
1.515 raeburn 2808: my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
2809: if (defined($$courseopt{$recursechk})) {
2810: return [$$courseopt{$recursechk},'map'];
2811: }
2812: }
1.405 albertel 2813: if (defined($$courseopt{$courselevel})) {
2814: my $ret = [$$courseopt{$courselevel},'course'];
2815: return $ret;
2816: }
1.315 albertel 2817: }
2818: # --------------------------------------------------- sixth , cascade up parts
1.133 bowersj2 2819:
2820: my ($space,@qualifier)=split(/\./,$rwhat);
2821: my $qualifier=join('.',@qualifier);
2822: unless ($space eq '0') {
1.160 albertel 2823: my @parts=split(/_/,$space);
2824: my $id=pop(@parts);
2825: my $part=join('_',@parts);
2826: if ($part eq '') { $part='0'; }
1.405 albertel 2827: my @partgeneral=$self->parmval($part.".$qualifier",$symb,1);
2828: if (defined($partgeneral[0])) { return \@partgeneral; }
1.133 bowersj2 2829: }
1.405 albertel 2830: if ($recurse) { return []; }
1.399 albertel 2831: my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat);
1.405 albertel 2832: if (defined($pack_def)) { return [$pack_def,'resource']; }
2833: return [''];
1.145 bowersj2 2834: }
1.515 raeburn 2835:
2836: sub recurseup_maps {
2837: my ($self,$mapname) = @_;
2838: my @recurseup;
1.517 raeburn 2839: if ($mapname) {
1.519 raeburn 2840: my $res = $self->getResourceByUrl($mapname);
2841: if (ref($res)) {
2842: my @pcs = split(/,/,$res->map_hierarchy());
2843: shift(@pcs);
2844: if (@pcs) {
2845: @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs);
2846: }
1.517 raeburn 2847: }
1.515 raeburn 2848: }
2849: return @recurseup;
2850: }
2851:
1.485 foxr 2852: #
2853: # Determines the open/close dates for printing a map that
2854: # encloses a resource.
2855: #
2856: sub map_printdates {
2857: my ($self, $res, $part) = @_;
2858:
2859:
2860:
2861:
2862:
1.518 raeburn 2863: my $opendate = $self->get_mapparam($res->symb(),'',"$part.printstartdate");
2864: my $closedate= $self->get_mapparam($res->symb(),'',"$part.printenddate");
1.485 foxr 2865:
2866:
2867: return ($opendate, $closedate);
2868: }
2869:
2870: sub get_mapparam {
1.518 raeburn 2871: my ($self, $symb, $mapname, $what) = @_;
1.485 foxr 2872:
2873: # Ensure the course option hash is populated:
2874:
2875: $self->generate_course_user_opt();
2876:
2877: # Get the course id and section if there is one.
2878:
2879: my $cid=$env{'request.course.id'};
2880: my $csec=$env{'request.course.sec'};
2881: my $cgroup='';
2882: my @cgrps=split(/:/,$env{'request.course.groups'});
2883: if (@cgrps > 0) {
2884: @cgrps = sort(@cgrps);
2885: $cgroup = $cgrps[0];
2886: }
2887: my $uname=$self->{USERNAME};
2888: my $udom=$self->{DOMAIN};
2889:
1.518 raeburn 2890: unless ($symb || $mapname) { return; }
1.485 foxr 2891: my $result='';
1.516 raeburn 2892: my ($recursed,@recurseup);
1.485 foxr 2893:
2894:
2895: # Figure out which map we are in.
2896:
1.518 raeburn 2897: if ($symb && !$mapname) {
2898: my ($id,$fn);
2899: ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
2900: $mapname = &Apache::lonnet::deversion($mapname);
2901: }
1.485 foxr 2902:
2903:
2904: my $rwhat=$what;
2905: $what=~s/^parameter\_//;
2906: $what=~s/\_/\./;
2907:
2908: # Build the hash keys for the lookup:
2909:
2910: my $mapparm=$mapname.'___(all).'.$what;
1.515 raeburn 2911: my $recurseparm=$mapname.'___(rec).'.$what;
1.485 foxr 2912: my $usercourseprefix=$cid;
2913:
2914:
1.515 raeburn 2915: my $grplevelm = "$usercourseprefix.[$cgroup].$mapparm";
2916: my $seclevelm = "$usercourseprefix.[$csec].$mapparm";
2917: my $courselevelm = "$usercourseprefix.$mapparm";
2918:
2919: my $grpleveli = "$usercourseprefix.[$cgroup].$recurseparm";
2920: my $secleveli = "$usercourseprefix.[$csec].$recurseparm";
2921: my $courseleveli = "$usercourseprefix.$recurseparm";
1.485 foxr 2922:
2923: # Get handy references to the hashes we need in $self:
2924:
2925: my $useropt = $self->{USER_OPT};
2926: my $courseopt = $self->{COURSE_OPT};
2927: my $parmhash = $self->{PARM_HASH};
2928:
2929: # Check per user
2930:
2931:
2932:
2933: if ($uname and defined($useropt)) {
1.515 raeburn 2934: if (defined($$useropt{$courselevelm})) {
2935: return $$useropt{$courselevelm};
1.485 foxr 2936: }
1.515 raeburn 2937: if (defined($$useropt{$courseleveli})) {
2938: return $$useropt{$courseleveli};
2939: }
1.516 raeburn 2940: unless ($recursed) {
2941: @recurseup = $self->recurseup_maps($mapname);
2942: $recursed = 1;
2943: }
2944: foreach my $item (@recurseup) {
2945: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526 raeburn 2946: if (defined($$useropt{$norecursechk})) {
2947: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2948: return $$useropt{$norecursechk};
2949: } else {
2950: last;
2951: }
2952: }
1.516 raeburn 2953: my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
2954: if (defined($$useropt{$recursechk})) {
2955: return $$useropt{$recursechk};
2956: }
2957: }
1.485 foxr 2958: }
2959:
2960: # Check course -- group
2961:
2962:
2963:
2964: if ($cgroup ne '' and defined ($courseopt)) {
1.515 raeburn 2965: if (defined($$courseopt{$grplevelm})) {
2966: return $$courseopt{$grplevelm};
1.485 foxr 2967: }
1.515 raeburn 2968: if (defined($$courseopt{$grpleveli})) {
2969: return $$courseopt{$grpleveli};
2970: }
1.516 raeburn 2971: unless ($recursed) {
2972: @recurseup = $self->recurseup_maps($mapname);
2973: $recursed = 1;
2974: }
2975: foreach my $item (@recurseup) {
2976: my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
1.526 raeburn 2977: if (defined($$courseopt{$norecursechk})) {
2978: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
2979: return $$courseopt{$norecursechk};
2980: } else {
2981: last;
2982: }
2983: }
1.516 raeburn 2984: my $recursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(rec).'.$what;
2985: if (defined($$courseopt{$recursechk})) {
2986: return $$courseopt{$recursechk};
2987: }
2988: }
1.485 foxr 2989: }
2990:
2991: # Check course -- section
2992:
2993:
1.516 raeburn 2994: if ($csec ne '' and defined($courseopt)) {
1.515 raeburn 2995: if (defined($$courseopt{$seclevelm})) {
2996: return $$courseopt{$seclevelm};
1.485 foxr 2997: }
1.515 raeburn 2998: if (defined($$courseopt{$secleveli})) {
2999: return $$courseopt{$secleveli};
3000: }
1.516 raeburn 3001: unless ($recursed) {
3002: @recurseup = $self->recurseup_maps($mapname);
3003: $recursed = 1;
3004: }
3005: foreach my $item (@recurseup) {
3006: my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
1.526 raeburn 3007: if (defined($$courseopt{$norecursechk})) {
3008: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3009: return $$courseopt{$norecursechk};
3010: } else {
3011: last;
3012: }
3013: }
1.516 raeburn 3014: my $recursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(rec).'.$what;
3015: if (defined($$courseopt{$recursechk})) {
3016: return $$courseopt{$recursechk};
3017: }
3018: }
1.485 foxr 3019: }
3020: # Check the map parameters themselves:
3021:
1.518 raeburn 3022: if ($symb) {
3023: my $symbparm=$symb.'.'.$what;
3024: my $thisparm = $$parmhash{$symbparm};
3025: if (defined($thisparm)) {
3026: return $thisparm;
3027: }
1.485 foxr 3028: }
3029:
3030:
3031: # Additional course parameters:
3032:
3033: if (defined($courseopt)) {
1.515 raeburn 3034: if (defined($$courseopt{$courselevelm})) {
3035: return $$courseopt{$courselevelm};
1.485 foxr 3036: }
1.516 raeburn 3037: unless ($recursed) {
3038: @recurseup = $self->recurseup_maps($mapname);
3039: $recursed = 1;
3040: }
3041: if (@recurseup) {
3042: foreach my $item (@recurseup) {
3043: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
1.526 raeburn 3044: if (defined($$courseopt{$norecursechk})) {
3045: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3046: return $$courseopt{$norecursechk};
3047: } else {
3048: last;
3049: }
3050: }
1.516 raeburn 3051: my $recursechk=$usercourseprefix.'.'.$item.'___(rec).'.$what;
3052: if (defined($$courseopt{$recursechk})) {
3053: return $$courseopt{$recursechk};
3054: }
3055: }
3056: }
1.485 foxr 3057: }
1.516 raeburn 3058: return undef; # Undefined if we got here.
1.485 foxr 3059: }
3060:
3061: sub course_printdates {
3062: my ($self, $symb, $part) = @_;
3063:
3064:
3065: my $opendate = $self->getcourseparam($symb, $part . '.printstartdate');
3066: my $closedate = $self->getcourseparam($symb, $part . '.printenddate');
3067: return ($opendate, $closedate);
3068:
3069: }
3070:
3071: sub getcourseparam {
3072: my ($self, $symb, $what) = @_;
3073:
3074: $self->generate_course_user_opt(); # If necessary populate the hashes.
3075:
3076: my $uname = $self->{USERNAME};
3077: my $udom = $self->{DOMAIN};
3078:
3079: # Course, section, group ids come from the env:
3080:
3081: my $cid = $env{'request.course.id'};
3082: my $csec = $env{'request.course.sec'};
3083: my $cgroup = ''; # Assume no group
3084:
3085: my @cgroups = split(/:/, $env{'request.course.groups'});
3086: if(@cgroups > 0) {
3087: @cgroups = sort(@cgroups);
3088: $cgroup = $cgroups[0]; # There is a course group.
3089: }
3090: my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
3091: $mapname = &Apache::lonnet::deversion($mapname);
3092:
3093: #
3094: # Make the various lookup keys:
3095: #
3096:
3097: $what=~s/^parameter\_//;
3098: $what=~s/\_/\./;
3099:
3100: # Local refs to the hashes we're going to look at:
3101:
3102: my $useropt = $self->{USER_OPT};
3103: my $courseopt = $self->{COURSE_OPT};
3104:
3105: #
3106: # We want the course level stuff from the way
3107: # parmval_real operates
1.513 raeburn 3108: # TODO: Factor some of this stuff out of
1.485 foxr 3109: # both parmval_real and here
3110: #
3111: my $courselevel = $cid . '.' . $what;
3112: my $grplevel = $cid . '.[' . $cgroup . ']' . $what;
3113: my $seclevel = $cid . '.[' . $csec . ']' . $what;
3114:
3115:
3116: # Try for the user's course level option:
3117:
3118: if ($uname and defined($useropt)) {
3119: if (defined($$useropt{$courselevel})) {
3120: return $$useropt{$courselevel};
3121: }
3122: }
3123: # Try for the group's course level option:
3124:
1.513 raeburn 3125: if ($cgroup ne '' and defined($courseopt)) {
1.485 foxr 3126: if (defined($$courseopt{$grplevel})) {
3127: return $$courseopt{$grplevel};
3128: }
3129: }
3130:
3131: # Try for section level parameters:
3132:
1.513 raeburn 3133: if ($csec ne '' and defined($courseopt)) {
1.485 foxr 3134: if (defined($$courseopt{$seclevel})) {
3135: return $$courseopt{$seclevel};
3136: }
3137: }
1.513 raeburn 3138: # Try for 'additional' course parameters:
1.485 foxr 3139:
3140: if (defined($courseopt)) {
3141: if (defined($$courseopt{$courselevel})) {
3142: return $$courseopt{$courselevel};
3143: }
3144: }
3145: return undef;
3146:
3147: }
3148:
1.145 bowersj2 3149:
1.174 albertel 3150: =pod
1.145 bowersj2 3151:
1.352 raeburn 3152: =item * B<getResourceByUrl>(url,multiple):
1.145 bowersj2 3153:
1.352 raeburn 3154: Retrieves a resource object by URL of the resource, unless the optional
1.398 banghart 3155: multiple parameter is included in which case an array of resource
1.352 raeburn 3156: objects is returned. If passed a resource object, it will simply return
3157: it, so it is safe to use this method in code like
3158: "$res = $navmap->getResourceByUrl($res)"
3159: if you're not sure if $res is already an object, or just a URL. If the
3160: resource appears multiple times in the course, only the first instance
3161: will be returned (useful for maps), unless the multiple parameter has
3162: been included, in which case all instances are returned in an array.
1.174 albertel 3163:
1.505 raeburn 3164: =item * B<retrieveResources>(map, filterFunc, recursive, bailout, showall, noblockcheck):
1.174 albertel 3165:
3166: The map is a specification of a map to retreive the resources from,
3167: either as a url or as an object. The filterFunc is a reference to a
3168: function that takes a resource object as its one argument and returns
3169: true if the resource should be included, or false if it should not
3170: be. If recursive is true, the map will be recursively examined,
3171: otherwise it will not be. If bailout is true, the function will return
1.314 albertel 3172: as soon as it finds a resource, if false it will finish. If showall is
1.505 raeburn 3173: true it will not hide maps that contain nothing but one other map. The
3174: noblockcheck arg is propagated to become the sixth arg in the call to
3175: lonnet::allowed when checking a resource's availability during collection
3176: of resources using the iterator. noblockcheck needs to be true if
3177: retrieveResources() was called by a routine that itself was called by
3178: lonnet::allowed, in order to avoid recursion. By default the map
3179: is the top-level map of the course, filterFunc is a function that
3180: always returns 1, recursive is true, bailout is false, showall is
3181: false. The resources will be returned in a list containing the
3182: resource objects for the corresponding resources, with B<no structure
3183: information> in the list; regardless of branching, recursion, etc.,
3184: it will be a flat list.
1.174 albertel 3185:
3186: Thus, this is suitable for cases where you don't want the structure,
3187: just a list of all resources. It is also suitable for finding out how
3188: many resources match a given description; for this use, if all you
3189: want to know is if I<any> resources match the description, the bailout
3190: parameter will allow you to avoid potentially expensive enumeration of
3191: all matching resources.
1.145 bowersj2 3192:
1.318 albertel 3193: =item * B<hasResource>(map, filterFunc, recursive, showall):
1.145 bowersj2 3194:
1.398 banghart 3195: Convenience method for
1.146 bowersj2 3196:
1.318 albertel 3197: scalar(retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0
1.146 bowersj2 3198:
1.174 albertel 3199: which will tell whether the map has resources matching the description
3200: in the filter function.
1.146 bowersj2 3201:
1.352 raeburn 3202: =item * B<usedVersion>(url):
3203:
3204: Retrieves version infomation for a url. Returns the version (a number, or
3205: the string "mostrecent") for resources which have version information in
3206: the big hash.
1.448 raeburn 3207:
1.145 bowersj2 3208: =cut
3209:
1.277 matthew 3210:
1.145 bowersj2 3211: sub getResourceByUrl {
3212: my $self = shift;
3213: my $resUrl = shift;
1.352 raeburn 3214: my $multiple = shift;
1.145 bowersj2 3215:
3216: if (ref($resUrl)) { return $resUrl; }
3217:
3218: $resUrl = &Apache::lonnet::clutter($resUrl);
3219: my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
1.352 raeburn 3220: if (!$resId) { return ''; }
3221: if ($multiple) {
3222: my @resources = ();
3223: my @resIds = split (/,/, $resId);
3224: foreach my $id (@resIds) {
1.353 raeburn 3225: my $resourceId = $self->getById($id);
3226: if ($resourceId) {
3227: push(@resources,$resourceId);
1.352 raeburn 3228: }
3229: }
3230: return @resources;
3231: } else {
3232: if ($resId =~ /,/) {
3233: $resId = (split (/,/, $resId))[0];
3234: }
3235: return $self->getById($resId);
1.145 bowersj2 3236: }
3237: }
3238:
3239: sub retrieveResources {
3240: my $self = shift;
3241: my $map = shift;
3242: my $filterFunc = shift;
3243: if (!defined ($filterFunc)) {
3244: $filterFunc = sub {return 1;};
3245: }
3246: my $recursive = shift;
3247: if (!defined($recursive)) { $recursive = 1; }
3248: my $bailout = shift;
3249: if (!defined($bailout)) { $bailout = 0; }
1.314 albertel 3250: my $showall = shift;
1.506 raeburn 3251: my $noblockcheck = shift;
1.145 bowersj2 3252: # Create the necessary iterator.
3253: if (!ref($map)) { # assume it's a url of a map.
1.172 bowersj2 3254: $map = $self->getResourceByUrl($map);
1.145 bowersj2 3255: }
3256:
1.213 bowersj2 3257: # If nothing was passed, assume top-level map
3258: if (!$map) {
3259: $map = $self->getById('0.0');
3260: }
3261:
1.145 bowersj2 3262: # Check the map's validity.
1.213 bowersj2 3263: if (!$map->is_map()) {
1.145 bowersj2 3264: # Oh, to throw an exception.... how I'd love that!
3265: return ();
3266: }
3267:
1.146 bowersj2 3268: # Get an iterator.
3269: my $it = $self->getIterator($map->map_start(), $map->map_finish(),
1.314 albertel 3270: undef, $recursive, $showall);
1.146 bowersj2 3271:
3272: my @resources = ();
3273:
1.400 albertel 3274: if (&$filterFunc($map)) {
3275: push(@resources, $map);
3276: }
3277:
1.146 bowersj2 3278: # Run down the iterator and collect the resources.
1.222 bowersj2 3279: my $curRes;
3280:
1.505 raeburn 3281: while ($curRes = $it->next(undef,$noblockcheck)) {
1.146 bowersj2 3282: if (ref($curRes)) {
3283: if (!&$filterFunc($curRes)) {
3284: next;
3285: }
3286:
1.400 albertel 3287: push(@resources, $curRes);
1.146 bowersj2 3288:
3289: if ($bailout) {
3290: return @resources;
3291: }
3292: }
3293:
3294: }
3295:
3296: return @resources;
3297: }
3298:
3299: sub hasResource {
3300: my $self = shift;
3301: my $map = shift;
3302: my $filterFunc = shift;
3303: my $recursive = shift;
1.318 albertel 3304: my $showall = shift;
1.146 bowersj2 3305:
1.318 albertel 3306: return scalar($self->retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0;
1.133 bowersj2 3307: }
1.51 bowersj2 3308:
1.352 raeburn 3309: sub usedVersion {
3310: my $self = shift;
3311: my $linkurl = shift;
3312: return $self->navhash("version_$linkurl");
3313: }
3314:
1.51 bowersj2 3315: 1;
3316:
3317: package Apache::lonnavmaps::iterator;
1.365 albertel 3318: use Scalar::Util qw(weaken);
1.320 albertel 3319: use Apache::lonnet;
3320:
1.51 bowersj2 3321: =pod
3322:
3323: =back
3324:
1.174 albertel 3325: =head1 Object: navmap Iterator
1.51 bowersj2 3326:
1.174 albertel 3327: An I<iterator> encapsulates the logic required to traverse a data
3328: structure. navmap uses an iterator to traverse the course map
3329: according to the criteria you wish to use.
3330:
3331: To obtain an iterator, call the B<getIterator>() function of a
3332: B<navmap> object. (Do not instantiate Apache::lonnavmaps::iterator
3333: directly.) This will return a reference to the iterator:
1.51 bowersj2 3334:
3335: C<my $resourceIterator = $navmap-E<gt>getIterator();>
3336:
3337: To get the next thing from the iterator, call B<next>:
3338:
3339: C<my $nextThing = $resourceIterator-E<gt>next()>
3340:
3341: getIterator behaves as follows:
3342:
3343: =over 4
3344:
1.174 albertel 3345: =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop, returnTopMap):
3346:
3347: All parameters are optional. firstResource is a resource reference
3348: corresponding to where the iterator should start. It defaults to
3349: navmap->firstResource() for the corresponding nav map. finishResource
3350: corresponds to where you want the iterator to end, defaulting to
3351: navmap->finishResource(). filterHash is a hash used as a set
3352: containing strings representing the resource IDs, defaulting to
3353: empty. Condition is a 1 or 0 that sets what to do with the filter
1.205 bowersj2 3354: hash: If a 0, then only resources that exist IN the filterHash will be
1.174 albertel 3355: recursed on. If it is a 1, only resources NOT in the filterHash will
3356: be recursed on. Defaults to 0. forceTop is a boolean value. If it is
3357: false (default), the iterator will only return the first level of map
3358: that is not just a single, 'redirecting' map. If true, the iterator
3359: will return all information, starting with the top-level map,
3360: regardless of content. returnTopMap, if true (default false), will
3361: cause the iterator to return the top-level map object (resource 0.0)
3362: before anything else.
3363:
3364: Thus, by default, only top-level resources will be shown. Change the
3365: condition to a 1 without changing the hash, and all resources will be
3366: shown. Changing the condition to 1 and including some values in the
3367: hash will allow you to selectively suppress parts of the navmap, while
3368: leaving it on 0 and adding things to the hash will allow you to
3369: selectively add parts of the nav map. See the handler code for
3370: examples.
3371:
3372: The iterator will return either a reference to a resource object, or a
3373: token representing something in the map, such as the beginning of a
3374: new branch. The possible tokens are:
3375:
3376: =over 4
1.51 bowersj2 3377:
1.222 bowersj2 3378: =item * B<END_ITERATOR>:
3379:
3380: The iterator has returned all that it's going to. Further calls to the
3381: iterator will just produce more of these. This is a "false" value, and
3382: is the only false value the iterator which will be returned, so it can
3383: be used as a loop sentinel.
3384:
1.217 bowersj2 3385: =item * B<BEGIN_MAP>:
1.51 bowersj2 3386:
1.174 albertel 3387: A new map is being recursed into. This is returned I<after> the map
3388: resource itself is returned.
1.51 bowersj2 3389:
1.217 bowersj2 3390: =item * B<END_MAP>:
1.174 albertel 3391:
3392: The map is now done.
1.51 bowersj2 3393:
1.217 bowersj2 3394: =item * B<BEGIN_BRANCH>:
1.70 bowersj2 3395:
1.174 albertel 3396: A branch is now starting. The next resource returned will be the first
3397: in that branch.
1.70 bowersj2 3398:
1.217 bowersj2 3399: =item * B<END_BRANCH>:
1.70 bowersj2 3400:
1.174 albertel 3401: The branch is now done.
1.51 bowersj2 3402:
3403: =back
3404:
1.174 albertel 3405: The tokens are retreivable via methods on the iterator object, i.e.,
3406: $iterator->END_MAP.
1.70 bowersj2 3407:
1.174 albertel 3408: Maps can contain empty resources. The iterator will automatically skip
3409: over such resources, but will still treat the structure
3410: correctly. Thus, a complicated map with several branches, but
3411: consisting entirely of empty resources except for one beginning or
3412: ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,
3413: but only one resource will be returned.
1.116 bowersj2 3414:
1.242 matthew 3415: =back
3416:
1.222 bowersj2 3417: =head2 Normal Usage
3418:
3419: Normal usage of the iterator object is to do the following:
3420:
3421: my $it = $navmap->getIterator([your params here]);
3422: my $curRes;
3423: while ($curRes = $it->next()) {
3424: [your logic here]
3425: }
3426:
3427: Note that inside of the loop, it's frequently useful to check if
3428: "$curRes" is a reference or not with the reference function; only
3429: resource objects will be references, and any non-references will
3430: be the tokens described above.
3431:
1.505 raeburn 3432: The next() routine can take two (optional) arguments:
3433: closeAllPages - if true will not recurse down a .page
3434: noblockcheck - passed to browsePriv() for passing as sixth arg to
3435: call to lonnet::allowed. This needs to be set if retrieveResources
3436: was already called from another routine called within lonnet::allowed,
3437: so as to prevent recursion.
3438:
1.506 raeburn 3439: Also note there is some old code floating around that tries to track
1.222 bowersj2 3440: the depth of the iterator to see when it's done; do not copy that
1.398 banghart 3441: code. It is difficult to get right and harder to understand than
1.222 bowersj2 3442: this. They should be migrated to this new style.
1.51 bowersj2 3443:
3444: =cut
3445:
3446: # Here are the tokens for the iterator:
3447:
1.222 bowersj2 3448: sub END_ITERATOR { return 0; }
1.51 bowersj2 3449: sub BEGIN_MAP { return 1; } # begining of a new map
3450: sub END_MAP { return 2; } # end of the map
3451: sub BEGIN_BRANCH { return 3; } # beginning of a branch
3452: sub END_BRANCH { return 4; } # end of a branch
1.89 bowersj2 3453: sub FORWARD { return 1; } # go forward
3454: sub BACKWARD { return 2; }
1.51 bowersj2 3455:
1.96 bowersj2 3456: sub min {
3457: (my $a, my $b) = @_;
3458: if ($a < $b) { return $a; } else { return $b; }
3459: }
3460:
1.94 bowersj2 3461: sub new {
3462: # magic invocation to create a class instance
3463: my $proto = shift;
3464: my $class = ref($proto) || $proto;
3465: my $self = {};
3466:
1.300 albertel 3467: weaken($self->{NAV_MAP} = shift);
1.94 bowersj2 3468: return undef unless ($self->{NAV_MAP});
3469:
1.454 www 3470: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
3471: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
3472:
1.94 bowersj2 3473: # Handle the parameters
3474: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
3475: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
3476:
3477: # If the given resources are just the ID of the resource, get the
3478: # objects
3479: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
3480: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
3481: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
3482: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
3483:
3484: $self->{FILTER} = shift;
3485:
3486: # A hash, used as a set, of resource already seen
3487: $self->{ALREADY_SEEN} = shift;
3488: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
3489: $self->{CONDITION} = shift;
3490:
1.116 bowersj2 3491: # Do we want to automatically follow "redirection" maps?
3492: $self->{FORCE_TOP} = shift;
3493:
1.162 bowersj2 3494: # Do we want to return the top-level map object (resource 0.0)?
3495: $self->{RETURN_0} = shift;
3496: # have we done that yet?
3497: $self->{HAVE_RETURNED_0} = 0;
3498:
1.94 bowersj2 3499: # Now, we need to pre-process the map, by walking forward and backward
3500: # over the parts of the map we're going to look at.
1.96 bowersj2 3501:
1.97 bowersj2 3502: # The processing steps are exactly the same, except for a few small
3503: # changes, so I bundle those up in the following list of two elements:
3504: # (direction_to_iterate, VAL_name, next_resource_method_to_call,
3505: # first_resource).
3506: # This prevents writing nearly-identical code twice.
3507: my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext',
3508: 'FIRST_RESOURCE'],
3509: [BACKWARD(), 'BOT_UP_VAL', 'getPrevious',
3510: 'FINISH_RESOURCE'] );
3511:
1.98 bowersj2 3512: my $maxDepth = 0; # tracks max depth
3513:
1.116 bowersj2 3514: # If there is only one resource in this map, and it's a map, we
3515: # want to remember that, so the user can ask for the first map
3516: # that isn't just a redirector.
3517: my $resource; my $resourceCount = 0;
3518:
1.209 bowersj2 3519: # Documentation on this algorithm can be found in the CVS repository at
3520: # /docs/lonnavdocs; these "**#**" markers correspond to documentation
3521: # in that file.
1.107 bowersj2 3522: # **1**
3523:
1.97 bowersj2 3524: foreach my $pass (@iterations) {
3525: my $direction = $pass->[0];
3526: my $valName = $pass->[1];
3527: my $nextResourceMethod = $pass->[2];
3528: my $firstResourceName = $pass->[3];
3529:
3530: my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP},
3531: $self->{FIRST_RESOURCE},
3532: $self->{FINISH_RESOURCE},
3533: {}, undef, 0, $direction);
1.96 bowersj2 3534:
1.97 bowersj2 3535: # prime the recursion
3536: $self->{$firstResourceName}->{DATA}->{$valName} = 0;
1.222 bowersj2 3537: $iterator->next();
1.97 bowersj2 3538: my $curRes = $iterator->next();
1.222 bowersj2 3539: my $depth = 1;
3540: while ($depth > 0) {
3541: if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
3542: if ($curRes == $iterator->END_MAP()) { $depth--; }
3543:
1.97 bowersj2 3544: if (ref($curRes)) {
1.116 bowersj2 3545: # If there's only one resource, this will save it
1.117 bowersj2 3546: # we have to filter empty resources from consideration here,
3547: # or even "empty", redirecting maps have two (start & finish)
3548: # or three (start, finish, plus redirector)
3549: if($direction == FORWARD && $curRes->src()) {
3550: $resource = $curRes; $resourceCount++;
3551: }
1.97 bowersj2 3552: my $resultingVal = $curRes->{DATA}->{$valName};
3553: my $nextResources = $curRes->$nextResourceMethod();
1.116 bowersj2 3554: my $nextCount = scalar(@{$nextResources});
1.104 bowersj2 3555:
1.116 bowersj2 3556: if ($nextCount == 1) { # **3**
1.97 bowersj2 3557: my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
3558: $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
3559: }
3560:
1.116 bowersj2 3561: if ($nextCount > 1) { # **4**
1.97 bowersj2 3562: foreach my $res (@{$nextResources}) {
3563: my $current = $res->{DATA}->{$valName} || 999999999;
3564: $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
3565: }
3566: }
3567: }
1.96 bowersj2 3568:
1.107 bowersj2 3569: # Assign the final val (**2**)
1.97 bowersj2 3570: if (ref($curRes) && $direction == BACKWARD()) {
1.98 bowersj2 3571: my $finalDepth = min($curRes->{DATA}->{TOP_DOWN_VAL},
3572: $curRes->{DATA}->{BOT_UP_VAL});
3573:
3574: $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
3575: if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
1.190 bowersj2 3576: }
1.222 bowersj2 3577:
3578: $curRes = $iterator->next();
1.96 bowersj2 3579: }
3580: }
1.94 bowersj2 3581:
1.116 bowersj2 3582: # Check: Was this only one resource, a map?
1.255 albertel 3583: if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) {
1.116 bowersj2 3584: my $firstResource = $resource->map_start();
3585: my $finishResource = $resource->map_finish();
1.500 raeburn 3586: return Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
3587: $finishResource, $self->{FILTER},
3588: $self->{ALREADY_SEEN},
3589: $self->{CONDITION},
3590: $self->{FORCE_TOP});
1.116 bowersj2 3591: }
3592:
1.98 bowersj2 3593: # Set up some bookkeeping information.
3594: $self->{CURRENT_DEPTH} = 0;
3595: $self->{MAX_DEPTH} = $maxDepth;
3596: $self->{STACK} = [];
3597: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
1.222 bowersj2 3598: $self->{FINISHED} = 0; # When true, the iterator has finished
1.98 bowersj2 3599:
3600: for (my $i = 0; $i <= $self->{MAX_DEPTH}; $i++) {
3601: push @{$self->{STACK}}, [];
3602: }
3603:
1.107 bowersj2 3604: # Prime the recursion w/ the first resource **5**
1.98 bowersj2 3605: push @{$self->{STACK}->[0]}, $self->{FIRST_RESOURCE};
3606: $self->{ALREADY_SEEN}->{$self->{FIRST_RESOURCE}->{ID}} = 1;
3607:
3608: bless ($self);
3609: return $self;
3610: }
3611:
3612: sub next {
3613: my $self = shift;
1.256 albertel 3614: my $closeAllPages=shift;
1.505 raeburn 3615: my $noblockcheck = shift;
1.222 bowersj2 3616: if ($self->{FINISHED}) {
3617: return END_ITERATOR();
3618: }
3619:
1.162 bowersj2 3620: # If we want to return the top-level map object, and haven't yet,
3621: # do so.
3622: if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0}) {
3623: $self->{HAVE_RETURNED_0} = 1;
1.470 foxr 3624: my $nextTopLevel = $self->{NAV_MAP}->getById('0.0');
1.162 bowersj2 3625: return $self->{NAV_MAP}->getById('0.0');
3626: }
1.401 albertel 3627: if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0_BEGIN_MAP}) {
3628: $self->{HAVE_RETURNED_0_BEGIN_MAP} = 1;
3629: return $self->BEGIN_MAP();
3630: }
1.98 bowersj2 3631:
3632: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3633: # grab the next from the recursive iterator
1.256 albertel 3634: my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
1.98 bowersj2 3635:
3636: # is it a begin or end map? If so, update the depth
3637: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
3638: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
3639:
3640: # Are we back at depth 0? If so, stop recursing
3641: if ($self->{RECURSIVE_DEPTH} == 0) {
3642: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3643: }
3644: return $next;
3645: }
3646:
3647: if (defined($self->{FORCE_NEXT})) {
3648: my $tmp = $self->{FORCE_NEXT};
3649: $self->{FORCE_NEXT} = undef;
3650: return $tmp;
3651: }
3652:
3653: # Have we not yet begun? If not, return BEGIN_MAP and
3654: # remember we've started.
3655: if ( !$self->{STARTED} ) {
3656: $self->{STARTED} = 1;
3657: return $self->BEGIN_MAP();
3658: }
3659:
3660: # Here's the guts of the iterator.
3661:
3662: # Find the next resource, if any.
3663: my $found = 0;
3664: my $i = $self->{MAX_DEPTH};
3665: my $newDepth;
3666: my $here;
3667: while ( $i >= 0 && !$found ) {
1.107 bowersj2 3668: if ( scalar(@{$self->{STACK}->[$i]}) > 0 ) { # **6**
3669: $here = pop @{$self->{STACK}->[$i]}; # **7**
1.98 bowersj2 3670: $found = 1;
3671: $newDepth = $i;
3672: }
3673: $i--;
3674: }
3675:
3676: # If we still didn't find anything, we're done.
3677: if ( !$found ) {
3678: # We need to get back down to the correct branch depth
3679: if ( $self->{CURRENT_DEPTH} > 0 ) {
3680: $self->{CURRENT_DEPTH}--;
3681: return END_BRANCH();
3682: } else {
1.222 bowersj2 3683: $self->{FINISHED} = 1;
1.98 bowersj2 3684: return END_MAP();
3685: }
3686: }
3687:
1.104 bowersj2 3688: # If this is not a resource, it must be an END_BRANCH marker we want
3689: # to return directly.
1.107 bowersj2 3690: if (!ref($here)) { # **8**
1.104 bowersj2 3691: if ($here == END_BRANCH()) { # paranoia, in case of later extension
3692: $self->{CURRENT_DEPTH}--;
3693: return $here;
3694: }
3695: }
3696:
3697: # Otherwise, it is a resource and it's safe to store in $self->{HERE}
3698: $self->{HERE} = $here;
3699:
1.98 bowersj2 3700: # Get to the right level
3701: if ( $self->{CURRENT_DEPTH} > $newDepth ) {
3702: push @{$self->{STACK}->[$newDepth]}, $here;
3703: $self->{CURRENT_DEPTH}--;
3704: return END_BRANCH();
3705: }
3706: if ( $self->{CURRENT_DEPTH} < $newDepth) {
3707: push @{$self->{STACK}->[$newDepth]}, $here;
3708: $self->{CURRENT_DEPTH}++;
3709: return BEGIN_BRANCH();
3710: }
3711:
3712: # If we made it here, we have the next resource, and we're at the
3713: # right branch level. So let's examine the resource for where
3714: # we can get to from here.
3715:
3716: # So we need to look at all the resources we can get to from here,
3717: # categorize them if we haven't seen them, remember if we have a new
3718: my $nextUnfiltered = $here->getNext();
1.470 foxr 3719:
3720:
1.104 bowersj2 3721: my $maxDepthAdded = -1;
3722:
1.98 bowersj2 3723: for (@$nextUnfiltered) {
3724: if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
1.104 bowersj2 3725: my $depth = $_->{DATA}->{DISPLAY_DEPTH};
3726: push @{$self->{STACK}->[$depth]}, $_;
1.98 bowersj2 3727: $self->{ALREADY_SEEN}->{$_->{ID}} = 1;
1.104 bowersj2 3728: if ($maxDepthAdded < $depth) { $maxDepthAdded = $depth; }
1.98 bowersj2 3729: }
3730: }
1.104 bowersj2 3731:
3732: # Is this the end of a branch? If so, all of the resources examined above
1.398 banghart 3733: # led to lower levels than the one we are currently at, so we push a END_BRANCH
1.104 bowersj2 3734: # marker onto the stack so we don't forget.
3735: # Example: For the usual A(BC)(DE)F case, when the iterator goes down the
3736: # BC branch and gets to C, it will see F as the only next resource, but it's
3737: # one level lower. Thus, this is the end of the branch, since there are no
3738: # more resources added to this level or above.
1.111 bowersj2 3739: # We don't do this if the examined resource is the finish resource,
3740: # because the condition given above is true, but the "END_MAP" will
3741: # take care of things and we should already be at depth 0.
1.104 bowersj2 3742: my $isEndOfBranch = $maxDepthAdded < $self->{CURRENT_DEPTH};
1.111 bowersj2 3743: if ($isEndOfBranch && $here != $self->{FINISH_RESOURCE}) { # **9**
1.104 bowersj2 3744: push @{$self->{STACK}->[$self->{CURRENT_DEPTH}]}, END_BRANCH();
3745: }
3746:
1.98 bowersj2 3747: # That ends the main iterator logic. Now, do we want to recurse
3748: # down this map (if this resource is a map)?
1.256 albertel 3749: if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
1.98 bowersj2 3750: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
3751: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
3752: my $firstResource = $self->{HERE}->map_start();
3753: my $finishResource = $self->{HERE}->map_finish();
3754: $self->{RECURSIVE_ITERATOR} =
3755: Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
3756: $finishResource, $self->{FILTER},
1.314 albertel 3757: $self->{ALREADY_SEEN},
3758: $self->{CONDITION},
3759: $self->{FORCE_TOP});
1.98 bowersj2 3760: }
3761:
1.116 bowersj2 3762: # If this is a blank resource, don't actually return it.
1.117 bowersj2 3763: # Should you ever find you need it, make sure to add an option to the code
3764: # that you can use; other things depend on this behavior.
1.505 raeburn 3765: my $browsePriv = $self->{HERE}->browsePriv($noblockcheck);
1.138 bowersj2 3766: if (!$self->{HERE}->src() ||
3767: (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
1.256 albertel 3768: return $self->next($closeAllPages);
1.116 bowersj2 3769: }
3770:
1.98 bowersj2 3771: return $self->{HERE};
3772:
3773: }
3774:
3775: =pod
3776:
1.174 albertel 3777: The other method available on the iterator is B<getStack>, which
3778: returns an array populated with the current 'stack' of maps, as
3779: references to the resource objects. Example: This is useful when
3780: making the navigation map, as we need to check whether we are under a
3781: page map to see if we need to link directly to the resource, or to the
3782: page. The first elements in the array will correspond to the top of
3783: the stack (most inclusive map).
1.98 bowersj2 3784:
3785: =cut
3786:
3787: sub getStack {
3788: my $self=shift;
3789:
3790: my @stack;
3791:
3792: $self->populateStack(\@stack);
3793:
3794: return \@stack;
3795: }
3796:
3797: # Private method: Calls the iterators recursively to populate the stack.
3798: sub populateStack {
3799: my $self=shift;
3800: my $stack = shift;
3801:
3802: push @$stack, $self->{HERE} if ($self->{HERE});
3803:
3804: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3805: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
3806: }
1.94 bowersj2 3807: }
3808:
3809: 1;
3810:
3811: package Apache::lonnavmaps::DFSiterator;
1.365 albertel 3812: use Scalar::Util qw(weaken);
1.320 albertel 3813: use Apache::lonnet;
3814:
1.100 bowersj2 3815: # Not documented in the perldoc: This is a simple iterator that just walks
3816: # through the nav map and presents the resources in a depth-first search
3817: # fashion, ignorant of conditionals, randomized resources, etc. It presents
3818: # BEGIN_MAP and END_MAP, but does not understand branches at all. It is
3819: # useful for pre-processing of some kind, and is in fact used by the main
3820: # iterator that way, but that's about it.
3821: # One could imagine merging this into the init routine of the main iterator,
1.251 www 3822: # but this might as well be left separate, since it is possible some other
1.100 bowersj2 3823: # use might be found for it. - Jeremy
1.94 bowersj2 3824:
1.117 bowersj2 3825: # Unlike the main iterator, this DOES return all resources, even blank ones.
3826: # The main iterator needs them to correctly preprocess the map.
3827:
1.94 bowersj2 3828: sub BEGIN_MAP { return 1; } # begining of a new map
3829: sub END_MAP { return 2; } # end of the map
3830: sub FORWARD { return 1; } # go forward
3831: sub BACKWARD { return 2; }
3832:
1.100 bowersj2 3833: # Params: Nav map ref, first resource id/ref, finish resource id/ref,
3834: # filter hash ref (or undef), already seen hash or undef, condition
3835: # (as in main iterator), direction FORWARD or BACKWARD (undef->forward).
1.51 bowersj2 3836: sub new {
3837: # magic invocation to create a class instance
3838: my $proto = shift;
3839: my $class = ref($proto) || $proto;
3840: my $self = {};
3841:
1.300 albertel 3842: weaken($self->{NAV_MAP} = shift);
1.51 bowersj2 3843: return undef unless ($self->{NAV_MAP});
3844:
1.454 www 3845: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
3846: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
3847:
1.51 bowersj2 3848: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
3849: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
3850:
3851: # If the given resources are just the ID of the resource, get the
3852: # objects
3853: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
3854: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
3855: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
3856: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
3857:
3858: $self->{FILTER} = shift;
3859:
3860: # A hash, used as a set, of resource already seen
3861: $self->{ALREADY_SEEN} = shift;
1.140 bowersj2 3862: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
1.63 bowersj2 3863: $self->{CONDITION} = shift;
1.89 bowersj2 3864: $self->{DIRECTION} = shift || FORWARD();
1.51 bowersj2 3865:
1.100 bowersj2 3866: # Flag: Have we started yet?
1.51 bowersj2 3867: $self->{STARTED} = 0;
3868:
3869: # Should we continue calling the recursive iterator, if any?
3870: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3871: # The recursive iterator, if any
3872: $self->{RECURSIVE_ITERATOR} = undef;
3873: # Are we recursing on a map, or a branch?
3874: $self->{RECURSIVE_MAP} = 1; # we'll manually unset this when recursing on branches
3875: # And the count of how deep it is, so that this iterator can keep track of
3876: # when to pick back up again.
3877: $self->{RECURSIVE_DEPTH} = 0;
3878:
3879: # For keeping track of our branches, we maintain our own stack
1.100 bowersj2 3880: $self->{STACK} = [];
1.51 bowersj2 3881:
3882: # Start with the first resource
1.89 bowersj2 3883: if ($self->{DIRECTION} == FORWARD) {
1.100 bowersj2 3884: push @{$self->{STACK}}, $self->{FIRST_RESOURCE};
1.89 bowersj2 3885: } else {
1.100 bowersj2 3886: push @{$self->{STACK}}, $self->{FINISH_RESOURCE};
1.89 bowersj2 3887: }
1.51 bowersj2 3888:
3889: bless($self);
3890: return $self;
3891: }
3892:
3893: sub next {
3894: my $self = shift;
3895:
3896: # Are we using a recursive iterator? If so, pull from that and
3897: # watch the depth; we want to resume our level at the correct time.
1.98 bowersj2 3898: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
1.51 bowersj2 3899: # grab the next from the recursive iterator
3900: my $next = $self->{RECURSIVE_ITERATOR}->next();
3901:
3902: # is it a begin or end map? Update depth if so
3903: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
3904: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
3905:
3906: # Are we back at depth 0? If so, stop recursing.
3907: if ($self->{RECURSIVE_DEPTH} == 0) {
3908: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3909: }
3910:
3911: return $next;
3912: }
3913:
3914: # Is there a current resource to grab? If not, then return
1.100 bowersj2 3915: # END_MAP, which will end the iterator.
3916: if (scalar(@{$self->{STACK}}) == 0) {
3917: return $self->END_MAP();
1.51 bowersj2 3918: }
3919:
3920: # Have we not yet begun? If not, return BEGIN_MAP and
3921: # remember that we've started.
3922: if ( !$self->{STARTED} ) {
3923: $self->{STARTED} = 1;
3924: return $self->BEGIN_MAP;
3925: }
3926:
3927: # Get the next resource in the branch
1.100 bowersj2 3928: $self->{HERE} = pop @{$self->{STACK}};
1.52 bowersj2 3929:
1.100 bowersj2 3930: # remember that we've seen this, so we don't return it again later
1.51 bowersj2 3931: $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
3932:
3933: # Get the next possible resources
1.90 bowersj2 3934: my $nextUnfiltered;
1.89 bowersj2 3935: if ($self->{DIRECTION} == FORWARD()) {
1.90 bowersj2 3936: $nextUnfiltered = $self->{HERE}->getNext();
1.89 bowersj2 3937: } else {
1.90 bowersj2 3938: $nextUnfiltered = $self->{HERE}->getPrevious();
1.89 bowersj2 3939: }
1.51 bowersj2 3940: my $next = [];
3941:
3942: # filter the next possibilities to remove things we've
1.100 bowersj2 3943: # already seen.
1.394 raeburn 3944: foreach my $item (@$nextUnfiltered) {
3945: if (!defined($self->{ALREADY_SEEN}->{$item->{ID}})) {
3946: push @$next, $item;
1.52 bowersj2 3947: }
1.51 bowersj2 3948: }
3949:
3950: while (@$next) {
1.100 bowersj2 3951: # copy the next possibilities over to the stack
3952: push @{$self->{STACK}}, shift @$next;
1.51 bowersj2 3953: }
3954:
3955: # If this is a map and we want to recurse down it... (not filtered out)
1.70 bowersj2 3956: if ($self->{HERE}->is_map() &&
1.63 bowersj2 3957: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
1.51 bowersj2 3958: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
3959: my $firstResource = $self->{HERE}->map_start();
3960: my $finishResource = $self->{HERE}->map_finish();
3961:
3962: $self->{RECURSIVE_ITERATOR} =
1.94 bowersj2 3963: Apache::lonnavmaps::DFSiterator->new ($self->{NAV_MAP}, $firstResource,
1.63 bowersj2 3964: $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
1.91 bowersj2 3965: $self->{CONDITION}, $self->{DIRECTION});
1.51 bowersj2 3966: }
3967:
3968: return $self->{HERE};
1.190 bowersj2 3969: }
3970:
3971: # Identical to the full iterator methods of the same name. Hate to copy/paste
3972: # but I also hate to "inherit" either iterator from the other.
3973:
3974: sub getStack {
3975: my $self=shift;
3976:
3977: my @stack;
3978:
3979: $self->populateStack(\@stack);
3980:
3981: return \@stack;
3982: }
3983:
3984: # Private method: Calls the iterators recursively to populate the stack.
3985: sub populateStack {
3986: my $self=shift;
3987: my $stack = shift;
3988:
3989: push @$stack, $self->{HERE} if ($self->{HERE});
3990:
3991: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3992: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
3993: }
1.51 bowersj2 3994: }
3995:
1.1 www 3996: 1;
1.2 www 3997:
1.51 bowersj2 3998: package Apache::lonnavmaps::resource;
1.365 albertel 3999: use Scalar::Util qw(weaken);
1.51 bowersj2 4000: use Apache::lonnet;
4001:
4002: =pod
4003:
1.217 bowersj2 4004: =head1 Object: resource
1.51 bowersj2 4005:
1.217 bowersj2 4006: X<resource, navmap object>
1.174 albertel 4007: A resource object encapsulates a resource in a resource map, allowing
4008: easy manipulation of the resource, querying the properties of the
4009: resource (including user properties), and represents a reference that
4010: can be used as the canonical representation of the resource by
4011: lonnavmap clients like renderers.
4012:
4013: A resource only makes sense in the context of a navmap, as some of the
4014: data is stored in the navmap object.
4015:
4016: You will probably never need to instantiate this object directly. Use
4017: Apache::lonnavmaps::navmap, and use the "start" method to obtain the
4018: starting resource.
1.51 bowersj2 4019:
1.188 bowersj2 4020: Resource objects respect the parameter_hiddenparts, which suppresses
4021: various parts according to the wishes of the map author. As of this
4022: writing, there is no way to override this parameter, and suppressed
4023: parts will never be returned, nor will their response types or ids be
4024: stored.
4025:
1.217 bowersj2 4026: =head2 Overview
1.51 bowersj2 4027:
1.217 bowersj2 4028: A B<Resource> is the most granular type of object in LON-CAPA that can
4029: be included in a course. It can either be a particular resource, like
4030: an HTML page, external resource, problem, etc., or it can be a
4031: container sequence, such as a "page" or a "map".
4032:
4033: To see a sequence from the user's point of view, please see the
4034: B<Creating a Course: Maps and Sequences> chapter of the Author's
4035: Manual.
4036:
4037: A Resource Object, once obtained from a navmap object via a B<getBy*>
4038: method of the navmap, or from an iterator, allows you to query
4039: information about that resource.
4040:
4041: Generally, you do not ever want to create a resource object yourself,
4042: so creation has been left undocumented. Always retrieve resources
4043: from navmap objects.
4044:
4045: =head3 Identifying Resources
4046:
4047: X<big hash>Every resource is identified by a Resource ID in the big hash that is
4048: unique to that resource for a given course. X<resource ID, in big hash>
4049: The Resource ID has the form #.#, where the first number is the same
4050: for every resource in a map, and the second is unique. For instance,
4051: for a course laid out like this:
4052:
4053: * Problem 1
4054: * Map
4055: * Resource 2
4056: * Resource 3
4057:
4058: C<Problem 1> and C<Map> will share a first number, and C<Resource 2>
4059: C<Resource 3> will share a first number. The second number may end up
4060: re-used between the two groups.
4061:
4062: The resource ID is only used in the big hash, but can be used in the
4063: context of a course to identify a resource easily. (For instance, the
4064: printing system uses it to record which resources from a sequence you
4065: wish to print.)
4066:
4067: X<symb> X<resource, symb>
4068: All resources also have B<symb>s, which uniquely identify a resource
4069: in a course. Many internal LON-CAPA functions expect a symb. A symb
4070: carries along with it the URL of the resource, and the map it appears
1.398 banghart 4071: in. Symbs are much larger than resource IDs.
1.51 bowersj2 4072:
4073: =cut
4074:
4075: sub new {
4076: # magic invocation to create a class instance
4077: my $proto = shift;
4078: my $class = ref($proto) || $proto;
4079: my $self = {};
4080:
1.300 albertel 4081: weaken($self->{NAV_MAP} = shift);
1.51 bowersj2 4082: $self->{ID} = shift;
4083:
1.454 www 4084: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
4085: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
4086:
1.51 bowersj2 4087: # Store this new resource in the parent nav map's cache.
4088: $self->{NAV_MAP}->{RESOURCE_CACHE}->{$self->{ID}} = $self;
1.66 bowersj2 4089: $self->{RESOURCE_ERROR} = 0;
1.51 bowersj2 4090:
1.479 raeburn 4091: $self->{DUEDATE_CACHE} = undef;
4092:
1.51 bowersj2 4093: # A hash that can be used by two-pass algorithms to store data
4094: # about this resource in. Not used by the resource object
4095: # directly.
4096: $self->{DATA} = {};
1.508 damieng 4097:
1.51 bowersj2 4098: bless($self);
4099:
1.508 damieng 4100: # This is a speed optimization, to avoid calling symb() too often.
4101: $self->{SYMB} = $self->symb();
1.515 raeburn 4102:
1.51 bowersj2 4103: return $self;
4104: }
4105:
1.70 bowersj2 4106: # private function: simplify the NAV_HASH lookups we keep doing
4107: # pass the name, and to automatically append my ID, pass a true val on the
4108: # second param
4109: sub navHash {
4110: my $self = shift;
4111: my $param = shift;
4112: my $id = shift;
1.441 raeburn 4113: my $arg = $param . ($id?$self->{ID}:"");
1.451 raeburn 4114: if (ref($self) && ref($self->{NAV_MAP}) && defined($arg)) {
1.441 raeburn 4115: return $self->{NAV_MAP}->navhash($arg);
4116: }
4117: return;
1.70 bowersj2 4118: }
4119:
1.51 bowersj2 4120: =pod
4121:
1.217 bowersj2 4122: =head2 Methods
1.70 bowersj2 4123:
1.217 bowersj2 4124: Once you have a resource object, here's what you can do with it:
4125:
4126: =head3 Attribute Retrieval
4127:
4128: Every resource has certain attributes that can be retrieved and used:
1.70 bowersj2 4129:
4130: =over 4
4131:
1.217 bowersj2 4132: =item * B<ID>: Every resource has an ID that is unique for that
4133: resource in the course it is in. The ID is actually in the hash
4134: representing the resource, so for a resource object $res, obtain
4135: it via C<$res->{ID}).
4136:
1.174 albertel 4137: =item * B<compTitle>:
4138:
4139: Returns a "composite title", that is equal to $res->title() if the
4140: resource has a title, and is otherwise the last part of the URL (e.g.,
4141: "problem.problem").
4142:
4143: =item * B<ext>:
4144:
4145: Returns true if the resource is external.
4146:
4147: =item * B<kind>:
4148:
4149: Returns the kind of the resource from the compiled nav map.
4150:
4151: =item * B<randomout>:
1.106 bowersj2 4152:
1.174 albertel 4153: Returns true if this resource was chosen to NOT be shown to the user
4154: by the random map selection feature. In other words, this is usually
4155: false.
1.70 bowersj2 4156:
1.174 albertel 4157: =item * B<randompick>:
1.70 bowersj2 4158:
1.400 albertel 4159: Returns the number of randomly picked items for a map if the randompick
4160: feature is being used on the map.
4161:
4162: =item * B<randomorder>:
4163:
4164: Returns true for a map if the randomorder feature is being used on the
4165: map.
1.70 bowersj2 4166:
1.174 albertel 4167: =item * B<src>:
1.51 bowersj2 4168:
1.174 albertel 4169: Returns the source for the resource.
1.70 bowersj2 4170:
1.174 albertel 4171: =item * B<symb>:
1.70 bowersj2 4172:
1.174 albertel 4173: Returns the symb for the resource.
1.70 bowersj2 4174:
1.174 albertel 4175: =item * B<title>:
1.70 bowersj2 4176:
1.174 albertel 4177: Returns the title of the resource.
4178:
1.51 bowersj2 4179: =back
4180:
4181: =cut
4182:
4183: # These info functions can be used directly, as they don't return
4184: # resource information.
1.85 bowersj2 4185: sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); }
1.303 albertel 4186: sub encrypted { my $self=shift; return $self->navHash("encrypted_", 1); }
1.70 bowersj2 4187: sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; }
1.85 bowersj2 4188: sub from { my $self=shift; return $self->navHash("from_", 1); }
1.217 bowersj2 4189: # considered private and undocumented
1.51 bowersj2 4190: sub goesto { my $self=shift; return $self->navHash("goesto_", 1); }
4191: sub kind { my $self=shift; return $self->navHash("kind_", 1); }
1.68 bowersj2 4192: sub randomout { my $self=shift; return $self->navHash("randomout_", 1); }
4193: sub randompick {
4194: my $self = shift;
1.410 raeburn 4195: my $randompick = $self->parmval('randompick');
4196: return $randompick;
1.68 bowersj2 4197: }
1.400 albertel 4198: sub randomorder {
4199: my $self = shift;
1.410 raeburn 4200: my $randomorder = $self->parmval('randomorder');
4201: return ($randomorder =~ /^yes$/i);
1.400 albertel 4202: }
1.303 albertel 4203: sub link {
4204: my $self=shift;
4205: if ($self->encrypted()) { return &Apache::lonenc::encrypted($self->src); }
4206: return $self->src;
4207: }
1.51 bowersj2 4208: sub src {
4209: my $self=shift;
4210: return $self->navHash("src_", 1);
4211: }
1.303 albertel 4212: sub shown_symb {
4213: my $self=shift;
1.508 damieng 4214: if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->{SYMB});}
4215: return $self->{SYMB};
1.303 albertel 4216: }
1.328 www 4217: sub id {
4218: my $self=shift;
4219: return $self->{ID};
4220: }
4221: sub enclosing_map_src {
4222: my $self=shift;
4223: (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
4224: return $self->navHash('map_id_'.$first);
4225: }
1.51 bowersj2 4226: sub symb {
4227: my $self=shift;
1.523 damieng 4228: if (defined $self->{SYMB}) { return $self->{SYMB}; }
1.51 bowersj2 4229: (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
4230: my $symbSrc = &Apache::lonnet::declutter($self->src());
1.223 albertel 4231: my $symb = &Apache::lonnet::declutter($self->navHash('map_id_'.$first))
1.51 bowersj2 4232: . '___' . $second . '___' . $symbSrc;
1.223 albertel 4233: return &Apache::lonnet::symbclean($symb);
1.51 bowersj2 4234: }
1.321 raeburn 4235: sub wrap_symb {
4236: my $self = shift;
1.508 damieng 4237: return $self->{NAV_MAP}->wrap_symb($self->{SYMB});
1.321 raeburn 4238: }
1.213 bowersj2 4239: sub title {
4240: my $self=shift;
4241: if ($self->{ID} eq '0.0') {
4242: # If this is the top-level map, return the title of the course
4243: # since this map can not be titled otherwise.
1.320 albertel 4244: return $env{'course.'.$env{'request.course.id'}.'.description'};
1.213 bowersj2 4245: }
4246: return $self->navHash("title_", 1); }
1.217 bowersj2 4247: # considered private and undocumented
1.70 bowersj2 4248: sub to { my $self=shift; return $self->navHash("to_", 1); }
1.301 albertel 4249: sub condition {
4250: my $self=shift;
4251: my $undercond=$self->navHash("undercond_", 1);
4252: if (!defined($undercond)) { return 1; };
4253: my $condid=$self->navHash("condid_$undercond");
4254: if (!defined($condid)) { return 1; };
4255: my $condition=&Apache::lonnet::directcondval($condid);
4256: return $condition;
4257: }
1.342 albertel 4258: sub condval {
4259: my $self=shift;
1.359 albertel 4260: my ($pathname,$filename) =
4261: &Apache::lonnet::split_uri_for_cond($self->src());
1.342 albertel 4262:
4263: my $match=($env{'acc.res.'.$env{'request.course.id'}.'.'.$pathname}=~
4264: /\&\Q$filename\E\:([\d\|]+)\&/);
4265: if ($match) {
4266: return &Apache::lonnet::condval($1);
4267: }
4268: return 0;
4269: }
1.106 bowersj2 4270: sub compTitle {
4271: my $self = shift;
4272: my $title = $self->title();
1.176 www 4273: $title=~s/\&colon\;/\:/gs;
1.106 bowersj2 4274: if (!$title) {
4275: $title = $self->src();
4276: $title = substr($title, rindex($title, '/') + 1);
4277: }
4278: return $title;
4279: }
1.399 albertel 4280:
1.70 bowersj2 4281: =pod
4282:
4283: B<Predicate Testing the Resource>
4284:
4285: These methods are shortcuts to deciding if a given resource has a given property.
4286:
4287: =over 4
4288:
1.174 albertel 4289: =item * B<is_map>:
4290:
4291: Returns true if the resource is a map type.
4292:
4293: =item * B<is_problem>:
1.70 bowersj2 4294:
1.174 albertel 4295: Returns true if the resource is a problem type, false
4296: otherwise. (Looks at the extension on the src field; might need more
4297: to work correctly.)
1.70 bowersj2 4298:
1.174 albertel 4299: =item * B<is_page>:
1.70 bowersj2 4300:
1.174 albertel 4301: Returns true if the resource is a page.
4302:
4303: =item * B<is_sequence>:
4304:
4305: Returns true if the resource is a sequence.
1.70 bowersj2 4306:
4307: =back
4308:
4309: =cut
4310:
1.256 albertel 4311: sub hasResource {
4312: my $self = shift;
4313: return $self->{NAV_MAP}->hasResource(@_);
4314: }
4315:
4316: sub retrieveResources {
4317: my $self = shift;
4318: return $self->{NAV_MAP}->retrieveResources(@_);
4319: }
1.70 bowersj2 4320:
1.369 albertel 4321: sub is_exam {
4322: my ($self,$part) = @_;
1.410 raeburn 4323: my $type = $self->parmval('type',$part);
4324: if ($type eq 'exam') {
1.369 albertel 4325: return 1;
4326: }
4327: if ($self->src() =~ /\.(exam)$/) {
4328: return 1;
4329: }
4330: return 0;
4331: }
1.70 bowersj2 4332: sub is_html {
1.51 bowersj2 4333: my $self=shift;
4334: my $src = $self->src();
1.70 bowersj2 4335: return ($src =~ /html$/);
1.51 bowersj2 4336: }
1.70 bowersj2 4337: sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
4338: sub is_page {
1.51 bowersj2 4339: my $self=shift;
4340: my $src = $self->src();
1.205 bowersj2 4341: return $self->navHash("is_map_", 1) &&
4342: $self->navHash("map_type_" . $self->map_pc()) eq 'page';
1.51 bowersj2 4343: }
1.361 albertel 4344: sub is_practice {
4345: my $self=shift;
4346: my ($part) = @_;
1.410 raeburn 4347: my $type = $self->parmval('type',$part);
4348: if ($type eq 'practice') {
1.361 albertel 4349: return 1;
4350: }
4351: return 0;
4352: }
1.70 bowersj2 4353: sub is_problem {
1.51 bowersj2 4354: my $self=shift;
4355: my $src = $self->src();
1.466 www 4356: if ($src =~ /$LONCAPA::assess_re/) {
1.361 albertel 4357: return !($self->is_practice());
4358: }
4359: return 0;
1.256 albertel 4360: }
1.443 foxr 4361: #
4362: # The has below is the set of status that are considered 'incomplete'
4363: #
4364: my %incomplete_hash =
4365: (
4366: TRIES_LEFT() => 1,
4367: OPEN() => 1,
4368: ATTEMPTED() => 1
4369:
4370: );
4371: #
4372: # Return tru if a problem is incomplete... for now incomplete means that
4373: # any part of the problem is incomplete.
4374: # Note that if the resources is not a problem, 0 is returned.
4375: #
4376: sub is_incomplete {
4377: my $self = shift;
4378: if ($self->is_problem()) {
4379: foreach my $part (@{$self->parts()}) {
4380: if (exists($incomplete_hash{$self->status($part)})) {
4381: return 1;
4382: }
4383: }
4384: }
4385: return 0;
4386:
4387: }
1.413 www 4388: sub is_raw_problem {
4389: my $self=shift;
4390: my $src = $self->src();
1.466 www 4391: if ($src =~ /$LONCAPA::assess_re/) {
1.413 www 4392: return 1;
4393: }
4394: return 0;
4395: }
4396:
1.256 albertel 4397: sub contains_problem {
4398: my $self=shift;
4399: if ($self->is_page()) {
4400: my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
4401: return $hasProblem;
4402: }
4403: return 0;
1.51 bowersj2 4404: }
1.401 albertel 4405: sub map_contains_problem {
4406: my $self=shift;
4407: if ($self->is_map()) {
4408: my $has_problem=
4409: $self->hasResource($self,sub { $_[0]->is_problem() },1);
4410: return $has_problem;
4411: }
4412: return 0;
4413: }
1.70 bowersj2 4414: sub is_sequence {
1.51 bowersj2 4415: my $self=shift;
1.205 bowersj2 4416: return $self->navHash("is_map_", 1) &&
1.426 droeschl 4417: $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
1.51 bowersj2 4418: }
1.261 matthew 4419: sub is_survey {
4420: my $self = shift();
4421: my $part = shift();
1.410 raeburn 4422: my $type = $self->parmval('type',$part);
1.444 raeburn 4423: if (($type eq 'survey') || ($type eq 'surveycred')) {
1.261 matthew 4424: return 1;
4425: }
1.263 albertel 4426: if ($self->src() =~ /\.(survey)$/) {
1.261 matthew 4427: return 1;
4428: }
4429: return 0;
4430: }
1.444 raeburn 4431: sub is_anonsurvey {
4432: my $self = shift();
4433: my $part = shift();
4434: my $type = $self->parmval('type',$part);
4435: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
4436: return 1;
4437: }
4438: return 0;
4439: }
1.360 albertel 4440: sub is_task {
4441: my $self=shift;
4442: my $src = $self->src();
4443: return ($src =~ /\.(task)$/)
4444: }
1.51 bowersj2 4445:
1.266 raeburn 4446: sub is_empty_sequence {
4447: my $self=shift;
4448: my $src = $self->src();
4449: return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
4450: }
4451:
1.101 bowersj2 4452: # Private method: Shells out to the parmval in the nav map, handler parts.
1.51 bowersj2 4453: sub parmval {
4454: my $self = shift;
4455: my $what = shift;
1.185 bowersj2 4456: my $part = shift;
4457: if (!defined($part)) {
4458: $part = '0';
4459: }
1.508 damieng 4460: return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->{SYMB});
1.51 bowersj2 4461: }
4462:
1.70 bowersj2 4463: =pod
4464:
4465: B<Map Methods>
4466:
1.174 albertel 4467: These methods are useful for getting information about the map
4468: properties of the resource, if the resource is a map (B<is_map>).
1.70 bowersj2 4469:
4470: =over 4
4471:
1.174 albertel 4472: =item * B<map_finish>:
4473:
4474: Returns a reference to a resource object corresponding to the finish
4475: resource of the map.
1.70 bowersj2 4476:
1.174 albertel 4477: =item * B<map_pc>:
1.70 bowersj2 4478:
1.174 albertel 4479: Returns the pc value of the map, which is the first number that
4480: appears in the resource ID of the resources in the map, and is the
4481: number that appears around the middle of the symbs of the resources in
4482: that map.
1.70 bowersj2 4483:
1.174 albertel 4484: =item * B<map_start>:
4485:
4486: Returns a reference to a resource object corresponding to the start
4487: resource of the map.
4488:
4489: =item * B<map_type>:
4490:
4491: Returns a string with the type of the map in it.
1.70 bowersj2 4492:
1.497 raeburn 4493: =item * B<map_hierarchy>:
1.448 raeburn 4494:
4495: Returns a string with a comma-separated ordered list of map_pc IDs
4496: for the hierarchy of maps containing a map, with the top level
4497: map first, then descending to deeper levels, with the enclosing map last.
4498:
1.70 bowersj2 4499: =back
1.51 bowersj2 4500:
1.70 bowersj2 4501: =cut
1.51 bowersj2 4502:
4503: sub map_finish {
4504: my $self = shift;
4505: my $src = $self->src();
1.381 albertel 4506: $src = &Apache::lonnet::clutter($src);
1.51 bowersj2 4507: my $res = $self->navHash("map_finish_$src", 0);
4508: $res = $self->{NAV_MAP}->getById($res);
4509: return $res;
4510: }
1.70 bowersj2 4511: sub map_pc {
4512: my $self = shift;
1.381 albertel 4513: my $src = $self->src();
1.70 bowersj2 4514: return $self->navHash("map_pc_$src", 0);
4515: }
1.51 bowersj2 4516: sub map_start {
4517: my $self = shift;
4518: my $src = $self->src();
1.381 albertel 4519: $src = &Apache::lonnet::clutter($src);
1.51 bowersj2 4520: my $res = $self->navHash("map_start_$src", 0);
4521: $res = $self->{NAV_MAP}->getById($res);
4522: return $res;
4523: }
4524: sub map_type {
4525: my $self = shift;
4526: my $pc = $self->map_pc();
4527: return $self->navHash("map_type_$pc", 0);
4528: }
1.448 raeburn 4529: sub map_hierarchy {
4530: my $self = shift;
4531: my $pc = $self->map_pc();
4532: return $self->navHash("map_hierarchy_$pc", 0);
4533: }
1.51 bowersj2 4534:
4535: #####
4536: # Property queries
4537: #####
4538:
4539: # These functions will be responsible for returning the CORRECT
4540: # VALUE for the parameter, no matter what. So while they may look
1.398 banghart 4541: # like direct calls to parmval, they can be more than that.
1.51 bowersj2 4542: # So, for instance, the duedate function should use the "duedatetype"
1.398 banghart 4543: # information, rather than the resource object user.
1.51 bowersj2 4544:
4545: =pod
4546:
4547: =head2 Resource Parameters
4548:
1.174 albertel 4549: In order to use the resource parameters correctly, the nav map must
4550: have been instantiated with genCourseAndUserOptions set to true, so
4551: the courseopt and useropt is read correctly. Then, you can call these
4552: functions to get the relevant parameters for the resource. Each
4553: function defaults to part "0", but can be directed to another part by
4554: passing the part as the parameter.
4555:
4556: These methods are responsible for getting the parameter correct, not
4557: merely reflecting the contents of the GDBM hashes. As we move towards
4558: dates relative to other dates, these methods should be updated to
4559: reflect that. (Then, anybody using these methods will not have to update
4560: their code.)
4561:
4562: =over 4
4563:
1.485 foxr 4564:
1.459 foxr 4565: =item * B<printable>
4566:
4567: returns true if the current date is such that the
4568: specified resource part is printable.
4569:
1.485 foxr 4570:
1.459 foxr 4571: =item * B<resprintable>
4572:
4573: Returns true if all parts in the resource are printable making the
4574: entire resource printable.
4575:
4576: =item * B<acc>
1.174 albertel 4577:
4578: Get the Client IP/Name Access Control information.
1.51 bowersj2 4579:
1.174 albertel 4580: =item * B<answerdate>:
1.51 bowersj2 4581:
1.174 albertel 4582: Get the answer-reveal date for the problem.
4583:
1.211 bowersj2 4584: =item * B<awarded>:
4585:
4586: Gets the awarded value for the problem part. Requires genUserData set to
4587: true when the navmap object was created.
4588:
1.174 albertel 4589: =item * B<duedate>:
4590:
4591: Get the due date for the problem.
4592:
4593: =item * B<tries>:
4594:
4595: Get the number of tries the student has used on the problem.
4596:
4597: =item * B<maxtries>:
4598:
4599: Get the number of max tries allowed.
4600:
4601: =item * B<opendate>:
1.51 bowersj2 4602:
1.174 albertel 4603: Get the open date for the problem.
1.51 bowersj2 4604:
1.174 albertel 4605: =item * B<sig>:
1.51 bowersj2 4606:
1.174 albertel 4607: Get the significant figures setting.
1.51 bowersj2 4608:
1.174 albertel 4609: =item * B<tol>:
1.51 bowersj2 4610:
1.174 albertel 4611: Get the tolerance for the problem.
1.51 bowersj2 4612:
1.174 albertel 4613: =item * B<tries>:
1.51 bowersj2 4614:
1.174 albertel 4615: Get the number of tries the user has already used on the problem.
1.51 bowersj2 4616:
1.174 albertel 4617: =item * B<type>:
1.51 bowersj2 4618:
1.174 albertel 4619: Get the question type for the problem.
1.70 bowersj2 4620:
1.174 albertel 4621: =item * B<weight>:
1.51 bowersj2 4622:
1.174 albertel 4623: Get the weight for the problem.
1.51 bowersj2 4624:
4625: =back
4626:
4627: =cut
4628:
1.485 foxr 4629:
4630:
4631:
1.459 foxr 4632: sub printable {
4633:
4634: my ($self, $part) = @_;
4635:
4636: # The following cases apply:
1.487 foxr 4637: # - If a start date is not set, it is replaced by the open date.
4638: # - Ditto for start/open replaced by content open.
4639: # - If neither start nor printdates are set the part is printable.
1.459 foxr 4640: # - Start date set but no end date: Printable if now >= start date.
4641: # - End date set but no start date: Printable if now <= end date.
4642: # - both defined: printable if start <= now <= end
4643: #
1.487 foxr 4644:
4645: # Get the print open/close dates for the resource.
4646:
4647: my $start = $self->parmval("printstartdate", $part);
4648: my $end = $self->parmval("printenddate", $part);
4649:
4650: if (!$start) {
4651: $start = $self->parmval("opendate", $part);
4652: }
4653: if (!$start) {
4654: $start = $self->parmval("contentopen", $part);
4655: }
4656:
4657:
1.459 foxr 4658: my $now = time();
4659:
1.487 foxr 4660:
1.459 foxr 4661: my $startok = 1;
4662: my $endok = 1;
4663:
1.460 foxr 4664: if ((defined $start) && ($start ne '')) {
1.459 foxr 4665: $startok = $start <= $now;
4666: }
1.460 foxr 4667: if ((defined $end) && ($end != '')) {
1.459 foxr 4668: $endok = $end >= $now;
4669: }
4670: return $startok && $endok;
4671: }
4672:
4673: sub resprintable {
4674: my $self = shift;
4675:
4676: # get parts...or realize there are no parts.
4677:
1.460 foxr 4678: my $partsref = $self->parts();
4679: my @parts = @$partsref;
4680:
1.489 raeburn 4681: if (!@parts) {
1.459 foxr 4682: return $self->printable(0);
4683: } else {
1.460 foxr 4684: foreach my $part (@parts) {
4685: if (!$self->printable($part)) {
4686: return 0;
4687: }
1.459 foxr 4688: }
4689: return 1;
4690: }
4691: }
4692:
1.51 bowersj2 4693: sub acc {
4694: (my $self, my $part) = @_;
1.410 raeburn 4695: my $acc = $self->parmval("acc", $part);
4696: return $acc;
1.51 bowersj2 4697: }
4698: sub answerdate {
4699: (my $self, my $part) = @_;
4700: # Handle intervals
1.410 raeburn 4701: my $answerdatetype = $self->parmval("answerdate.type", $part);
4702: my $answerdate = $self->parmval("answerdate", $part);
4703: my $duedate = $self->parmval("duedate", $part);
4704: if ($answerdatetype eq 'date_interval') {
4705: $answerdate = $duedate + $answerdate;
1.51 bowersj2 4706: }
1.410 raeburn 4707: return $answerdate;
1.106 bowersj2 4708: }
1.211 bowersj2 4709: sub awarded {
4710: my $self = shift; my $part = shift;
1.221 bowersj2 4711: $self->{NAV_MAP}->get_user_data();
1.211 bowersj2 4712: if (!defined($part)) { $part = '0'; }
1.508 damieng 4713: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.awarded'};
1.211 bowersj2 4714: }
1.432 raeburn 4715: sub taskversion {
4716: my $self = shift; my $part = shift;
4717: $self->{NAV_MAP}->get_user_data();
4718: if (!defined($part)) { $part = '0'; }
1.508 damieng 4719: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.version'};
1.432 raeburn 4720: }
4721: sub taskstatus {
4722: my $self = shift; my $part = shift;
4723: $self->{NAV_MAP}->get_user_data();
4724: if (!defined($part)) { $part = '0'; }
1.508 damieng 4725: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'};
1.432 raeburn 4726: }
4727: sub solved {
4728: my $self = shift; my $part = shift;
4729: $self->{NAV_MAP}->get_user_data();
4730: if (!defined($part)) { $part = '0'; }
1.508 damieng 4731: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.solved'};
1.432 raeburn 4732: }
4733: sub checkedin {
4734: my $self = shift; my $part = shift;
4735: $self->{NAV_MAP}->get_user_data();
4736: if (!defined($part)) { $part = '0'; }
4737: if ($self->is_task()) {
4738: my $version = $self->taskversion($part);
1.508 damieng 4739: return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$version .'.'.$part.'.checkedin.slot'});
1.432 raeburn 4740: } else {
1.508 damieng 4741: return ($self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin'},$self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.checkedin.slot'});
1.432 raeburn 4742: }
4743: }
1.382 albertel 4744: # this should work exactly like the copy in lonhomework.pm
1.459 foxr 4745: # Why is there a copy in lonhomework? Why not centralized?
4746: #
4747: # TODO: Centralize duedate.
4748: #
4749:
1.51 bowersj2 4750: sub duedate {
4751: (my $self, my $part) = @_;
1.479 raeburn 4752: if (defined ($self->{DUEDATE_CACHE}->{$part})) {
4753: return $self->{DUEDATE_CACHE}->{$part};
4754: }
1.382 albertel 4755: my $date;
1.406 albertel 4756: my @interval=$self->parmval("interval", $part);
1.382 albertel 4757: my $due_date=$self->parmval("duedate", $part);
1.520 raeburn 4758: if ($interval[0] =~ /^(\d+)/) {
4759: my $timelimit = $1;
4760: my $first_access=&Apache::lonnet::get_first_access($interval[1],
4761: $self->{SYMB});
1.382 albertel 4762: if (defined($first_access)) {
1.520 raeburn 4763: my $interval = $first_access+$timelimit;
1.404 albertel 4764: $date = (!$due_date || $interval < $due_date) ? $interval
4765: : $due_date;
1.382 albertel 4766: } else {
4767: $date = $due_date;
4768: }
4769: } else {
4770: $date = $due_date;
1.260 albertel 4771: }
1.479 raeburn 4772: $self->{DUEDATE_CACHE}->{$part} = $date;
1.382 albertel 4773: return $date;
1.51 bowersj2 4774: }
1.334 albertel 4775: sub handgrade {
4776: (my $self, my $part) = @_;
1.399 albertel 4777: my @response_ids = $self->responseIds($part);
4778: if (@response_ids) {
4779: foreach my $response_id (@response_ids) {
1.410 raeburn 4780: my $handgrade = $self->parmval("handgrade",$part.'_'.$response_id);
4781: if (lc($handgrade) eq 'yes') {
1.399 albertel 4782: return 'yes';
4783: }
4784: }
4785: }
1.410 raeburn 4786: my $handgrade = $self->parmval("handgrade", $part);
4787: return $handgrade;
1.334 albertel 4788: }
1.51 bowersj2 4789: sub maxtries {
4790: (my $self, my $part) = @_;
1.410 raeburn 4791: my $maxtries = $self->parmval("maxtries", $part);
4792: return $maxtries;
1.51 bowersj2 4793: }
4794: sub opendate {
4795: (my $self, my $part) = @_;
1.410 raeburn 4796: my $opendatetype = $self->parmval("opendate.type", $part);
4797: my $opendate = $self->parmval("opendate", $part);
4798: if ($opendatetype eq 'date_interval') {
4799: my $duedate = $self->duedate($part);
4800: $opendate = $duedate - $opendate;
1.51 bowersj2 4801: }
1.410 raeburn 4802: return $opendate;
1.51 bowersj2 4803: }
1.185 bowersj2 4804: sub problemstatus {
4805: (my $self, my $part) = @_;
1.410 raeburn 4806: my $problemstatus = $self->parmval("problemstatus", $part);
4807: return lc($problemstatus);
1.185 bowersj2 4808: }
1.51 bowersj2 4809: sub sig {
4810: (my $self, my $part) = @_;
1.410 raeburn 4811: my $sig = $self->parmval("sig", $part);
4812: return $sig;
1.51 bowersj2 4813: }
4814: sub tol {
4815: (my $self, my $part) = @_;
1.410 raeburn 4816: my $tol = $self->parmval("tol", $part);
4817: return $tol;
1.51 bowersj2 4818: }
1.410 raeburn 4819: sub tries {
1.108 bowersj2 4820: my $self = shift;
4821: my $tries = $self->queryRestoreHash('tries', shift);
4822: if (!defined($tries)) { return '0';}
1.51 bowersj2 4823: return $tries;
4824: }
1.70 bowersj2 4825: sub type {
4826: (my $self, my $part) = @_;
1.410 raeburn 4827: my $type = $self->parmval("type", $part);
4828: return $type;
1.70 bowersj2 4829: }
1.109 bowersj2 4830: sub weight {
4831: my $self = shift; my $part = shift;
1.211 bowersj2 4832: if (!defined($part)) { $part = '0'; }
1.409 raeburn 4833: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1.508 damieng 4834: $self->{SYMB}, $self->{DOMAIN},
1.453 www 4835: $self->{USERNAME},
1.409 raeburn 4836: $env{'request.course.sec'});
4837: return $weight;
1.274 matthew 4838: }
4839: sub part_display {
4840: my $self= shift(); my $partID = shift();
4841: if (! defined($partID)) { $partID = '0'; }
4842: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
1.514 raeburn 4843: $self->{SYMB});
1.274 matthew 4844: if (! defined($display) || $display eq '') {
4845: $display = $partID;
4846: }
4847: return $display;
1.70 bowersj2 4848: }
1.432 raeburn 4849: sub slot_control {
4850: my $self=shift(); my $part = shift();
4851: if (!defined($part)) { $part = '0'; }
4852: my $useslots = $self->parmval("useslots", $part);
4853: my $availablestudent = $self->parmval("availablestudent", $part);
4854: my $available = $self->parmval("available", $part);
4855: return ($useslots,$availablestudent,$available);
4856: }
1.51 bowersj2 4857:
4858: # Multiple things need this
4859: sub getReturnHash {
4860: my $self = shift;
4861:
4862: if (!defined($self->{RETURN_HASH})) {
1.524 damieng 4863: #my %tmpHash = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME});
4864: #$self->{RETURN_HASH} = \%tmpHash;
4865: # When info is retrieved for several resources (as when rendering a directory),
4866: # it is much faster to use the user profile dump and avoid repeated lonnet requests
4867: # (especially since lonnet::currentdump is using Lond directly whenever possible,
4868: # and lonnet::restore is not at this point).
4869: $self->{NAV_MAP}->get_user_data();
4870: $self->{RETURN_HASH} = $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}};
1.51 bowersj2 4871: }
4872: }
4873:
4874: ######
4875: # Status queries
4876: ######
4877:
4878: # These methods query the status of problems.
4879:
4880: # If we need to count parts, this function determines the number of
4881: # parts from the metadata. When called, it returns a reference to a list
4882: # of strings corresponding to the parts. (Thus, using it in a scalar context
4883: # tells you how many parts you have in the problem:
4884: # $partcount = scalar($resource->countParts());
4885: # Don't use $self->{PARTS} directly because you don't know if it's been
4886: # computed yet.
4887:
4888: =pod
4889:
4890: =head2 Resource misc
4891:
4892: Misc. functions for the resource.
4893:
4894: =over 4
4895:
1.174 albertel 4896: =item * B<hasDiscussion>:
1.59 bowersj2 4897:
1.174 albertel 4898: Returns a false value if there has been discussion since the user last
4899: logged in, true if there has. Always returns false if the discussion
4900: data was not extracted when the nav map was constructed.
4901:
1.366 albertel 4902: =item * B<last_post_time>:
4903:
4904: Returns a false value if there hasn't been discussion otherwise returns
4905: unix timestamp of last time a discussion posting (or edit) was made.
4906:
1.393 raeburn 4907: =item * B<discussion_info>:
1.366 albertel 4908:
1.393 raeburn 4909: optional argument is a filter (currently can be 'unread');
4910: returns in scalar context the count of the number of discussion postings.
1.366 albertel 4911:
4912: returns in list context both the count of postings and a hash ref
1.393 raeburn 4913: containing information about the postings (subject, id, timestamp) in a hash.
4914:
4915: Default is to return counts for all postings. However if called with a second argument set to 'unread', will return information about only unread postings.
1.366 albertel 4916:
1.174 albertel 4917: =item * B<getFeedback>:
4918:
4919: Gets the feedback for the resource and returns the raw feedback string
4920: for the resource, or the null string if there is no feedback or the
4921: email data was not extracted when the nav map was constructed. Usually
4922: used like this:
1.59 bowersj2 4923:
1.394 raeburn 4924: for my $url (split(/\,/, $res->getFeedback())) {
4925: my $link = &escape($url);
1.59 bowersj2 4926: ...
4927:
4928: and use the link as appropriate.
4929:
4930: =cut
4931:
4932: sub hasDiscussion {
4933: my $self = shift;
1.508 damieng 4934: return $self->{NAV_MAP}->hasDiscussion($self->{SYMB});
1.59 bowersj2 4935: }
4936:
1.366 albertel 4937: sub last_post_time {
4938: my $self = shift;
1.508 damieng 4939: return $self->{NAV_MAP}->last_post_time($self->{SYMB});
1.366 albertel 4940: }
4941:
1.393 raeburn 4942: sub discussion_info {
4943: my ($self,$filter) = @_;
1.508 damieng 4944: return $self->{NAV_MAP}->discussion_info($self->{SYMB},$filter);
1.366 albertel 4945: }
4946:
1.59 bowersj2 4947: sub getFeedback {
4948: my $self = shift;
1.124 bowersj2 4949: my $source = $self->src();
1.508 damieng 4950: my $symb = $self->{SYMB};
1.125 bowersj2 4951: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395 raeburn 4952: return $self->{NAV_MAP}->getFeedback($symb,$source);
1.124 bowersj2 4953: }
4954:
4955: sub getErrors {
4956: my $self = shift;
4957: my $source = $self->src();
1.508 damieng 4958: my $symb = $self->{SYMB};
1.124 bowersj2 4959: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395 raeburn 4960: return $self->{NAV_MAP}->getErrors($symb,$source);
1.59 bowersj2 4961: }
4962:
4963: =pod
4964:
1.174 albertel 4965: =item * B<parts>():
1.51 bowersj2 4966:
1.174 albertel 4967: Returns a list reference containing sorted strings corresponding to
1.193 bowersj2 4968: each part of the problem. Single part problems have only a part '0'.
4969: Multipart problems do not return their part '0', since they typically
4970: do not really matter.
1.174 albertel 4971:
4972: =item * B<countParts>():
4973:
4974: Returns the number of parts of the problem a student can answer. Thus,
4975: for single part problems, returns 1. For multipart, it returns the
1.193 bowersj2 4976: number of parts in the problem, not including psuedo-part 0.
1.51 bowersj2 4977:
1.290 matthew 4978: =item * B<countResponses>():
4979:
4980: Returns the total number of responses in the problem a student can answer.
4981:
4982: =item * B<responseTypes>():
4983:
4984: Returns a hash whose keys are the response types. The values are the number
4985: of times each response type is used. This is for the I<entire> problem, not
4986: just a single part.
4987:
1.192 bowersj2 4988: =item * B<multipart>():
4989:
1.193 bowersj2 4990: Returns true if the problem is multipart, false otherwise. Use this instead
4991: of countParts if all you want is multipart/not multipart.
1.192 bowersj2 4992:
1.187 bowersj2 4993: =item * B<responseType>($part):
4994:
4995: Returns the response type of the part, without the word "response" on the
4996: end. Example return values: 'string', 'essay', 'numeric', etc.
4997:
1.193 bowersj2 4998: =item * B<responseIds>($part):
1.187 bowersj2 4999:
1.193 bowersj2 5000: Retreives the response IDs for the given part as an array reference containing
5001: strings naming the response IDs. This may be empty.
1.187 bowersj2 5002:
1.51 bowersj2 5003: =back
5004:
5005: =cut
5006:
5007: sub parts {
5008: my $self = shift;
5009:
1.192 bowersj2 5010: if ($self->ext) { return []; }
1.67 bowersj2 5011:
1.51 bowersj2 5012: $self->extractParts();
5013: return $self->{PARTS};
5014: }
5015:
5016: sub countParts {
5017: my $self = shift;
5018:
5019: my $parts = $self->parts();
1.191 bowersj2 5020:
5021: # If I left this here, then it's not necessary.
5022: #my $delta = 0;
5023: #for my $part (@$parts) {
5024: # if ($part eq '0') { $delta--; }
5025: #}
1.66 bowersj2 5026:
5027: if ($self->{RESOURCE_ERROR}) {
5028: return 0;
5029: }
5030:
1.191 bowersj2 5031: return scalar(@{$parts}); # + $delta;
1.192 bowersj2 5032: }
5033:
1.290 matthew 5034: sub countResponses {
5035: my $self = shift;
5036: my $count;
1.293 matthew 5037: foreach my $part (@{$self->parts()}) {
5038: $count+= scalar($self->responseIds($part));
1.290 matthew 5039: }
5040: return $count;
5041: }
5042:
5043: sub responseTypes {
5044: my $self = shift;
1.291 albertel 5045: my %responses;
1.368 raeburn 5046: foreach my $part (@{$self->parts()}) {
1.290 matthew 5047: foreach my $responsetype ($self->responseType($part)) {
1.291 albertel 5048: $responses{$responsetype}++ if (defined($responsetype));
1.290 matthew 5049: }
5050: }
1.291 albertel 5051: return %responses;
1.290 matthew 5052: }
5053:
1.192 bowersj2 5054: sub multipart {
5055: my $self = shift;
5056: return $self->countParts() > 1;
1.51 bowersj2 5057: }
5058:
1.225 bowersj2 5059: sub singlepart {
5060: my $self = shift;
5061: return $self->countParts() == 1;
5062: }
5063:
1.187 bowersj2 5064: sub responseType {
1.184 bowersj2 5065: my $self = shift;
5066: my $part = shift;
5067:
5068: $self->extractParts();
1.235 albertel 5069: if (defined($self->{RESPONSE_TYPES}->{$part})) {
5070: return @{$self->{RESPONSE_TYPES}->{$part}};
5071: } else {
5072: return undef;
5073: }
1.187 bowersj2 5074: }
5075:
1.193 bowersj2 5076: sub responseIds {
1.187 bowersj2 5077: my $self = shift;
5078: my $part = shift;
5079:
5080: $self->extractParts();
1.235 albertel 5081: if (defined($self->{RESPONSE_IDS}->{$part})) {
5082: return @{$self->{RESPONSE_IDS}->{$part}};
5083: } else {
5084: return undef;
5085: }
1.184 bowersj2 5086: }
5087:
5088: # Private function: Extracts the parts information, both part names and
1.187 bowersj2 5089: # part types, and saves it.
1.51 bowersj2 5090: sub extractParts {
5091: my $self = shift;
5092:
1.153 bowersj2 5093: return if (defined($self->{PARTS}));
1.67 bowersj2 5094: return if ($self->ext);
1.51 bowersj2 5095:
5096: $self->{PARTS} = [];
5097:
1.181 bowersj2 5098: my %parts;
5099:
1.82 bowersj2 5100: # Retrieve part count, if this is a problem
5101: if ($self->is_problem()) {
1.240 albertel 5102: my $partorder = &Apache::lonnet::metadata($self->src(), 'partorder');
1.152 matthew 5103: my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
1.181 bowersj2 5104:
1.239 bowersj2 5105: if ($partorder) {
5106: my @parts;
5107: for my $part (split (/,/,$partorder)) {
1.508 damieng 5108: if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239 bowersj2 5109: push @parts, $part;
1.241 albertel 5110: $parts{$part} = 1;
1.239 bowersj2 5111: }
5112: }
5113: $self->{PARTS} = \@parts;
5114: } else {
5115: if (!$metadata) {
5116: $self->{RESOURCE_ERROR} = 1;
5117: $self->{PARTS} = [];
5118: $self->{PART_TYPE} = {};
5119: return;
5120: }
1.394 raeburn 5121: foreach my $entry (split(/\,/,$metadata)) {
5122: if ($entry =~ /^(?:part|Task)_(.*)$/) {
1.239 bowersj2 5123: my $part = $1;
5124: # This floods the logs if it blows up
5125: if (defined($parts{$part})) {
1.508 damieng 5126: &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->{SYMB});
1.241 albertel 5127: }
1.239 bowersj2 5128:
5129: # check to see if part is turned off.
5130:
1.508 damieng 5131: if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239 bowersj2 5132: $parts{$part} = 1;
5133: }
5134: }
5135: }
1.504 raeburn 5136: my @sortedParts = sort(keys(%parts));
1.239 bowersj2 5137: $self->{PARTS} = \@sortedParts;
1.51 bowersj2 5138: }
1.82 bowersj2 5139:
1.187 bowersj2 5140:
1.284 matthew 5141: # These hashes probably do not need names that end with "Hash"....
1.187 bowersj2 5142: my %responseIdHash;
5143: my %responseTypeHash;
5144:
1.189 bowersj2 5145:
5146: # Init the responseIdHash
1.394 raeburn 5147: foreach my $part (@{$self->{PARTS}}) {
5148: $responseIdHash{$part} = [];
1.189 bowersj2 5149: }
5150:
1.187 bowersj2 5151: # Now, the unfortunate thing about this is that parts, part name, and
1.239 bowersj2 5152: # response id are delimited by underscores, but both the part
1.187 bowersj2 5153: # name and response id can themselves have underscores in them.
5154: # So we have to use our knowlege of part names to figure out
5155: # where the part names begin and end, and even then, it is possible
5156: # to construct ambiguous situations.
1.504 raeburn 5157: foreach my $data (split(/,/, $metadata)) {
1.379 albertel 5158: if ($data =~ /^([a-zA-Z]+)response_(.*)/
5159: || $data =~ /^(Task)_(.*)/) {
1.187 bowersj2 5160: my $responseType = $1;
5161: my $partStuff = $2;
5162: my $partIdSoFar = '';
1.504 raeburn 5163: my @partChunks = split(/_/, $partStuff);
1.187 bowersj2 5164: my $i = 0;
5165: for ($i = 0; $i < scalar(@partChunks); $i++) {
5166: if ($partIdSoFar) { $partIdSoFar .= '_'; }
5167: $partIdSoFar .= $partChunks[$i];
5168: if ($parts{$partIdSoFar}) {
5169: my @otherChunks = @partChunks[$i+1..$#partChunks];
5170: my $responseId = join('_', @otherChunks);
1.379 albertel 5171: if ($self->is_task()) {
5172: push(@{$responseIdHash{$partIdSoFar}},
5173: $partIdSoFar);
5174: } else {
5175: push(@{$responseIdHash{$partIdSoFar}},
5176: $responseId);
5177: }
5178: push(@{$responseTypeHash{$partIdSoFar}},
5179: $responseType);
1.187 bowersj2 5180: }
5181: }
5182: }
5183: }
1.264 albertel 5184: my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
1.284 matthew 5185: #
5186: # Reorder the arrays in the %responseIdHash and %responseTypeHash
1.264 albertel 5187: if ($resorder) {
5188: my @resorder=split(/,/,$resorder);
5189: foreach my $part (keys(%responseIdHash)) {
1.286 albertel 5190: my $i=0;
5191: my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} };
1.264 albertel 5192: my @neworder;
5193: foreach my $possibleid (@resorder) {
5194: if (exists($resids{$possibleid})) {
1.286 albertel 5195: push(@neworder,$resids{$possibleid});
1.264 albertel 5196: }
5197: }
1.286 albertel 5198: my @ids;
5199: my @type;
5200: foreach my $element (@neworder) {
5201: push (@ids,$responseIdHash{$part}->[$element]);
5202: push (@type,$responseTypeHash{$part}->[$element]);
5203: }
5204: $responseIdHash{$part}=\@ids;
5205: $responseTypeHash{$part}=\@type;
1.264 albertel 5206: }
5207: }
1.187 bowersj2 5208: $self->{RESPONSE_IDS} = \%responseIdHash;
5209: $self->{RESPONSE_TYPES} = \%responseTypeHash;
1.154 bowersj2 5210: }
5211:
1.51 bowersj2 5212: return;
5213: }
5214:
5215: =pod
5216:
5217: =head2 Resource Status
5218:
1.174 albertel 5219: Problem resources have status information, reflecting their various
5220: dates and completion statuses.
1.51 bowersj2 5221:
1.174 albertel 5222: There are two aspects to the status: the date-related information and
5223: the completion information.
1.51 bowersj2 5224:
1.174 albertel 5225: Idiomatic usage of these two methods would probably look something
5226: like
1.51 bowersj2 5227:
1.394 raeburn 5228: foreach my $part ($resource->parts()) {
5229: my $dateStatus = $resource->getDateStatus($part);
5230: my $completionStatus = $resource->getCompletionStatus($part);
1.51 bowersj2 5231:
1.70 bowersj2 5232: or
5233:
1.394 raeburn 5234: my $status = $resource->status($part);
1.70 bowersj2 5235:
1.51 bowersj2 5236: ... use it here ...
5237: }
5238:
1.174 albertel 5239: Which you use depends on exactly what you are looking for. The
5240: status() function has been optimized for the nav maps display and may
5241: not precisely match what you need elsewhere.
1.101 bowersj2 5242:
1.174 albertel 5243: The symbolic constants shown below can be accessed through the
5244: resource object: C<$res->OPEN>.
1.101 bowersj2 5245:
1.51 bowersj2 5246: =over 4
5247:
1.174 albertel 5248: =item * B<getDateStatus>($part):
5249:
5250: ($part defaults to 0). A convenience function that returns a symbolic
5251: constant telling you about the date status of the part. The possible
5252: return values are:
1.51 bowersj2 5253:
5254: =back
5255:
5256: B<Date Codes>
5257:
5258: =over 4
5259:
1.174 albertel 5260: =item * B<OPEN_LATER>:
5261:
5262: The problem will be opened later.
5263:
5264: =item * B<OPEN>:
5265:
5266: Open and not yet due.
5267:
1.51 bowersj2 5268:
1.174 albertel 5269: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 5270:
1.174 albertel 5271: The due date has passed, but the answer date has not yet arrived.
1.59 bowersj2 5272:
1.174 albertel 5273: =item * B<PAST_DUE_NO_ANSWER>:
1.54 bowersj2 5274:
1.174 albertel 5275: The due date has passed and there is no answer opening date set.
1.51 bowersj2 5276:
1.174 albertel 5277: =item * B<ANSWER_OPEN>:
1.51 bowersj2 5278:
1.174 albertel 5279: The answer date is here.
5280:
5281: =item * B<NETWORK_FAILURE>:
5282:
5283: The information is unknown due to network failure.
1.51 bowersj2 5284:
5285: =back
5286:
5287: =cut
5288:
5289: # Apparently the compiler optimizes these into constants automatically
1.54 bowersj2 5290: sub OPEN_LATER { return 0; }
5291: sub OPEN { return 1; }
5292: sub PAST_DUE_NO_ANSWER { return 2; }
5293: sub PAST_DUE_ANSWER_LATER { return 3; }
5294: sub ANSWER_OPEN { return 4; }
1.432 raeburn 5295: sub NOTHING_SET { return 5; }
1.54 bowersj2 5296: sub NETWORK_FAILURE { return 100; }
5297:
5298: # getDateStatus gets the date status for a given problem part.
5299: # Because answer date, due date, and open date are fully independent
5300: # (i.e., it is perfectly possible to *only* have an answer date),
5301: # we have to completely cover the 3x3 maxtrix of (answer, due, open) x
5302: # (past, future, none given). This function handles this with a decision
5303: # tree. Read the comments to follow the decision tree.
1.51 bowersj2 5304:
5305: sub getDateStatus {
5306: my $self = shift;
5307: my $part = shift;
5308: $part = "0" if (!defined($part));
1.54 bowersj2 5309:
5310: # Always return network failure if there was one.
1.51 bowersj2 5311: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5312:
5313: my $now = time();
5314:
1.53 bowersj2 5315: my $open = $self->opendate($part);
5316: my $due = $self->duedate($part);
5317: my $answer = $self->answerdate($part);
5318:
5319: if (!$open && !$due && !$answer) {
5320: # no data on the problem at all
5321: # should this be the same as "open later"? think multipart.
5322: return $self->NOTHING_SET;
5323: }
1.59 bowersj2 5324: if (!$open || $now < $open) {return $self->OPEN_LATER}
5325: if (!$due || $now < $due) {return $self->OPEN}
5326: if ($answer && $now < $answer) {return $self->PAST_DUE_ANSWER_LATER}
5327: if ($answer) { return $self->ANSWER_OPEN; }
1.54 bowersj2 5328: return PAST_DUE_NO_ANSWER;
1.51 bowersj2 5329: }
5330:
5331: =pod
5332:
5333: B<>
5334:
5335: =over 4
5336:
1.174 albertel 5337: =item * B<getCompletionStatus>($part):
1.51 bowersj2 5338:
1.174 albertel 5339: ($part defaults to 0.) A convenience function that returns a symbolic
5340: constant telling you about the completion status of the part, with the
5341: following possible results:
5342:
5343: =back
1.51 bowersj2 5344:
5345: B<Completion Codes>
5346:
5347: =over 4
5348:
1.174 albertel 5349: =item * B<NOT_ATTEMPTED>:
5350:
5351: Has not been attempted at all.
5352:
5353: =item * B<INCORRECT>:
5354:
5355: Attempted, but wrong by student.
1.51 bowersj2 5356:
1.174 albertel 5357: =item * B<INCORRECT_BY_OVERRIDE>:
1.51 bowersj2 5358:
1.174 albertel 5359: Attempted, but wrong by instructor override.
1.51 bowersj2 5360:
1.174 albertel 5361: =item * B<CORRECT>:
1.51 bowersj2 5362:
1.174 albertel 5363: Correct or correct by instructor.
1.51 bowersj2 5364:
1.174 albertel 5365: =item * B<CORRECT_BY_OVERRIDE>:
1.51 bowersj2 5366:
1.174 albertel 5367: Correct by instructor override.
1.51 bowersj2 5368:
1.174 albertel 5369: =item * B<EXCUSED>:
5370:
5371: Excused. Not yet implemented.
5372:
5373: =item * B<NETWORK_FAILURE>:
5374:
5375: Information not available due to network failure.
5376:
5377: =item * B<ATTEMPTED>:
5378:
5379: Attempted, and not yet graded.
1.69 bowersj2 5380:
1.450 raeburn 5381: =item * B<CREDIT_ATTEMPTED>:
5382:
5383: Attempted, and credit received for attempt (survey and anonymous survey only).
5384:
1.51 bowersj2 5385: =back
5386:
5387: =cut
5388:
1.53 bowersj2 5389: sub NOT_ATTEMPTED { return 10; }
5390: sub INCORRECT { return 11; }
5391: sub INCORRECT_BY_OVERRIDE { return 12; }
5392: sub CORRECT { return 13; }
5393: sub CORRECT_BY_OVERRIDE { return 14; }
5394: sub EXCUSED { return 15; }
1.69 bowersj2 5395: sub ATTEMPTED { return 16; }
1.450 raeburn 5396: sub CREDIT_ATTEMPTED { return 17; }
1.51 bowersj2 5397:
5398: sub getCompletionStatus {
5399: my $self = shift;
1.332 albertel 5400: my $part = shift;
1.51 bowersj2 5401: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5402:
1.332 albertel 5403: my $status = $self->queryRestoreHash('solved', $part);
1.51 bowersj2 5404:
1.251 www 5405: # Left as separate if statements in case we ever do more with this
1.51 bowersj2 5406: if ($status eq 'correct_by_student') {return $self->CORRECT;}
1.288 albertel 5407: if ($status eq 'correct_by_scantron') {return $self->CORRECT;}
1.332 albertel 5408: if ($status eq 'correct_by_override') {
5409: return $self->CORRECT_BY_OVERRIDE;
5410: }
1.51 bowersj2 5411: if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
5412: if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
5413: if ($status eq 'excused') {return $self->EXCUSED; }
1.69 bowersj2 5414: if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
1.450 raeburn 5415: if ($status eq 'credit_attempted') {
5416: if ($self->is_anonsurvey($part) || $self->is_survey($part)) {
5417: return $self->CREDIT_ATTEMPTED;
5418: } else {
5419: return $self->ATTEMPTED;
5420: }
5421: }
1.51 bowersj2 5422: return $self->NOT_ATTEMPTED;
1.108 bowersj2 5423: }
5424:
5425: sub queryRestoreHash {
5426: my $self = shift;
5427: my $hashentry = shift;
5428: my $part = shift;
1.185 bowersj2 5429: $part = "0" if (!defined($part) || $part eq '');
1.108 bowersj2 5430: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5431:
5432: $self->getReturnHash();
5433:
5434: return $self->{RETURN_HASH}->{'resource.'.$part.'.'.$hashentry};
1.51 bowersj2 5435: }
5436:
5437: =pod
5438:
5439: B<Composite Status>
5440:
1.174 albertel 5441: Along with directly returning the date or completion status, the
5442: resource object includes a convenience function B<status>() that will
5443: combine the two status tidbits into one composite status that can
1.191 bowersj2 5444: represent the status of the resource as a whole. This method represents
5445: the concept of the thing we want to display to the user on the nav maps
5446: screen, which is a combination of completion and open status. The precise logic is
1.174 albertel 5447: documented in the comments of the status method. The following results
5448: may be returned, all available as methods on the resource object
1.185 bowersj2 5449: ($res->NETWORK_FAILURE): In addition to the return values that match
5450: the date or completion status, this function can return "ANSWER_SUBMITTED"
5451: if that problemstatus parameter value is set to No, suppressing the
5452: incorrect/correct feedback.
1.51 bowersj2 5453:
5454: =over 4
5455:
1.174 albertel 5456: =item * B<NETWORK_FAILURE>:
5457:
5458: The network has failed and the information is not available.
1.51 bowersj2 5459:
1.174 albertel 5460: =item * B<NOTHING_SET>:
1.53 bowersj2 5461:
1.174 albertel 5462: No dates have been set for this problem (part) at all. (Because only
5463: certain parts of a multi-part problem may be assigned, this can not be
5464: collapsed into "open later", as we do not know a given part will EVER
5465: be opened. For single part, this is the same as "OPEN_LATER".)
1.51 bowersj2 5466:
1.174 albertel 5467: =item * B<CORRECT>:
1.51 bowersj2 5468:
1.174 albertel 5469: For any reason at all, the part is considered correct.
1.54 bowersj2 5470:
1.174 albertel 5471: =item * B<EXCUSED>:
1.51 bowersj2 5472:
1.174 albertel 5473: For any reason at all, the problem is excused.
1.51 bowersj2 5474:
1.174 albertel 5475: =item * B<PAST_DUE_NO_ANSWER>:
1.51 bowersj2 5476:
1.174 albertel 5477: The problem is past due, not considered correct, and no answer date is
5478: set.
1.51 bowersj2 5479:
1.174 albertel 5480: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 5481:
1.174 albertel 5482: The problem is past due, not considered correct, and an answer date in
5483: the future is set.
1.51 bowersj2 5484:
1.174 albertel 5485: =item * B<ANSWER_OPEN>:
5486:
5487: The problem is past due, not correct, and the answer is now available.
5488:
5489: =item * B<OPEN_LATER>:
5490:
5491: The problem is not yet open.
5492:
5493: =item * B<TRIES_LEFT>:
5494:
5495: The problem is open, has been tried, is not correct, but there are
5496: tries left.
5497:
5498: =item * B<INCORRECT>:
5499:
5500: The problem is open, and all tries have been used without getting the
5501: correct answer.
5502:
5503: =item * B<OPEN>:
5504:
5505: The item is open and not yet tried.
5506:
5507: =item * B<ATTEMPTED>:
5508:
5509: The problem has been attempted.
1.69 bowersj2 5510:
1.450 raeburn 5511: =item * B<CREDIT_ATTEMPTED>:
5512:
5513: The problem has been attempted, and credit given for the attempt (survey and anonymous survey only).
5514:
1.185 bowersj2 5515: =item * B<ANSWER_SUBMITTED>:
5516:
5517: An answer has been submitted, but the student should not see it.
5518:
1.51 bowersj2 5519: =back
5520:
5521: =cut
5522:
1.432 raeburn 5523: sub TRIES_LEFT { return 20; }
5524: sub ANSWER_SUBMITTED { return 21; }
5525: sub PARTIALLY_CORRECT { return 22; }
5526:
5527: sub RESERVED_LATER { return 30; }
5528: sub RESERVED { return 31; }
5529: sub RESERVED_LOCATION { return 32; }
5530: sub RESERVABLE { return 33; }
5531: sub RESERVABLE_LATER { return 34; }
5532: sub NOTRESERVABLE { return 35; }
5533: sub NOT_IN_A_SLOT { return 36; }
5534: sub NEEDS_CHECKIN { return 37; }
5535: sub WAITING_FOR_GRADE { return 38; }
5536: sub UNKNOWN { return 39; }
1.51 bowersj2 5537:
5538: sub status {
5539: my $self = shift;
5540: my $part = shift;
5541: if (!defined($part)) { $part = "0"; }
5542: my $completionStatus = $self->getCompletionStatus($part);
5543: my $dateStatus = $self->getDateStatus($part);
5544:
5545: # What we have is a two-dimensional matrix with 4 entries on one
5546: # dimension and 5 entries on the other, which we want to colorize,
1.54 bowersj2 5547: # plus network failure and "no date data at all".
1.51 bowersj2 5548:
1.222 bowersj2 5549: #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }
1.53 bowersj2 5550: if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
1.51 bowersj2 5551:
1.408 raeburn 5552: my $suppressFeedback = 0;
5553: if (($self->problemstatus($part) eq 'no') ||
5554: ($self->problemstatus($part) eq 'no_feedback_ever')) {
5555: $suppressFeedback = 1;
5556: }
1.236 bowersj2 5557: # If there's an answer date and we're past it, don't
5558: # suppress the feedback; student should know
1.330 albertel 5559: if ($self->duedate($part) && $self->duedate($part) < time() &&
5560: $self->answerdate($part) && $self->answerdate($part) < time()) {
1.236 bowersj2 5561: $suppressFeedback = 0;
5562: }
1.185 bowersj2 5563:
1.51 bowersj2 5564: # There are a few whole rows we can dispose of:
1.53 bowersj2 5565: if ($completionStatus == CORRECT ||
5566: $completionStatus == CORRECT_BY_OVERRIDE ) {
1.332 albertel 5567: if ( $suppressFeedback ) { return ANSWER_SUBMITTED }
5568: my $awarded=$self->awarded($part);
5569: if ($awarded < 1 && $awarded > 0) {
5570: return PARTIALLY_CORRECT;
5571: } elsif ($awarded<1) {
5572: return INCORRECT;
5573: }
5574: return CORRECT;
1.69 bowersj2 5575: }
5576:
1.343 albertel 5577: # If it's WRONG... and not open
5578: if ( ($completionStatus == INCORRECT ||
5579: $completionStatus == INCORRECT_BY_OVERRIDE)
5580: && (!$self->opendate($part) || $self->opendate($part) > time()) ) {
5581: return INCORRECT;
5582: }
5583:
1.69 bowersj2 5584: if ($completionStatus == ATTEMPTED) {
5585: return ATTEMPTED;
1.53 bowersj2 5586: }
5587:
1.450 raeburn 5588: if ($completionStatus == CREDIT_ATTEMPTED) {
5589: return CREDIT_ATTEMPTED;
5590: }
5591:
1.53 bowersj2 5592: # If it's EXCUSED, then return that no matter what
5593: if ($completionStatus == EXCUSED) {
5594: return EXCUSED;
1.51 bowersj2 5595: }
5596:
1.53 bowersj2 5597: if ($dateStatus == NOTHING_SET) {
5598: return NOTHING_SET;
1.51 bowersj2 5599: }
5600:
1.69 bowersj2 5601: # Now we're down to a 4 (incorrect, incorrect_override, not_attempted)
5602: # by 4 matrix (date statuses).
1.51 bowersj2 5603:
1.54 bowersj2 5604: if ($dateStatus == PAST_DUE_ANSWER_LATER ||
1.59 bowersj2 5605: $dateStatus == PAST_DUE_NO_ANSWER ) {
1.272 albertel 5606: return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus;
1.51 bowersj2 5607: }
5608:
1.53 bowersj2 5609: if ($dateStatus == ANSWER_OPEN) {
5610: return ANSWER_OPEN;
1.51 bowersj2 5611: }
5612:
5613: # Now: (incorrect, incorrect_override, not_attempted) x
5614: # (open_later), (open)
5615:
1.53 bowersj2 5616: if ($dateStatus == OPEN_LATER) {
5617: return OPEN_LATER;
1.51 bowersj2 5618: }
5619:
5620: # If it's WRONG...
1.53 bowersj2 5621: if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE) {
1.51 bowersj2 5622: # and there are TRIES LEFT:
1.79 bowersj2 5623: if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
1.222 bowersj2 5624: return $suppressFeedback ? ANSWER_SUBMITTED : TRIES_LEFT;
1.51 bowersj2 5625: }
1.185 bowersj2 5626: return $suppressFeedback ? ANSWER_SUBMITTED : INCORRECT; # otherwise, return orange; student can't fix this
1.51 bowersj2 5627: }
5628:
5629: # Otherwise, it's untried and open
1.473 raeburn 5630: return OPEN;
1.224 bowersj2 5631: }
5632:
1.432 raeburn 5633: sub check_for_slot {
5634: my $self = shift;
5635: my $part = shift;
1.508 damieng 5636: my $symb = $self->{SYMB};
1.432 raeburn 5637: my ($use_slots,$available,$availablestudent) = $self->slot_control($part);
5638: if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) {
5639: my @slots = (split(/:/,$availablestudent),split(/:/,$available));
5640: my $cid=$env{'request.course.id'};
5641: my $cdom=$env{'course.'.$cid.'.domain'};
5642: my $cnum=$env{'course.'.$cid.'.num'};
5643: my $now = time;
1.473 raeburn 5644: my $num_usable_slots = 0;
1.522 raeburn 5645: my ($checkedin,$checkedinslot,%consumed_uniq,%slots);
1.432 raeburn 5646: if (@slots > 0) {
1.522 raeburn 5647: %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
1.432 raeburn 5648: if (&Apache::lonnet::error(%slots)) {
5649: return (UNKNOWN);
5650: }
1.473 raeburn 5651: my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
1.432 raeburn 5652: foreach my $slot_name (@sorted_slots) {
1.473 raeburn 5653: next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name}));
1.432 raeburn 5654: my $end = $slots{$slot_name}->{'endtime'};
5655: my $start = $slots{$slot_name}->{'starttime'};
5656: my $ip = $slots{$slot_name}->{'ip'};
5657: if ($self->simpleStatus() == OPEN) {
5658: if ($end > $now) {
1.473 raeburn 5659: if ($start > $now) {
5660: return (RESERVED_LATER,$start,$slot_name);
5661: } else {
5662: if ($ip ne '') {
5663: if (!&Apache::loncommon::check_ip_acc($ip)) {
1.503 raeburn 5664: return (RESERVED_LOCATION,$end,$slot_name);
1.432 raeburn 5665: }
5666: }
1.473 raeburn 5667: my @proctors;
5668: if ($slots{$slot_name}->{'proctor'} ne '') {
5669: @proctors = split(',',$slots{$slot_name}->{'proctor'});
5670: }
5671: if (@proctors > 0) {
5672: ($checkedin,$checkedinslot) = $self->checkedin();
5673: unless ((grep(/^\Q$checkedin\E/,@proctors)) &&
5674: ($checkedinslot eq $slot_name)) {
5675: return (NEEDS_CHECKIN,undef,$slot_name);
1.472 raeburn 5676: }
1.432 raeburn 5677: }
1.473 raeburn 5678: return (RESERVED,$end,$slot_name);
1.432 raeburn 5679: }
5680: }
1.473 raeburn 5681: } elsif ($end > $now) {
5682: $num_usable_slots ++;
1.432 raeburn 5683: }
5684: }
1.522 raeburn 5685: my ($is_correct,$wait_for_grade);
1.432 raeburn 5686: if ($self->is_task()) {
5687: my $taskstatus = $self->taskstatus();
5688: $is_correct = (($taskstatus eq 'pass') ||
5689: ($self->solved() =~ /^correct_/));
1.522 raeburn 5690: unless ($taskstatus =~ /^(?:pass|fail)$/) {
5691: $wait_for_grade = 1;
5692: }
1.432 raeburn 5693: } else {
1.522 raeburn 5694: unless ($self->completable()) {
5695: $wait_for_grade = 1;
5696: }
5697: unless (($self->problemstatus($part) eq 'no') ||
5698: ($self->problemstatus($part) eq 'no_feedback_ever')) {
5699: $is_correct = ($self->solved($part) =~ /^correct_/);
5700: $wait_for_grade = 0;
5701: }
1.432 raeburn 5702: }
5703: ($checkedin,$checkedinslot) = $self->checkedin();
5704: if ($checkedin) {
1.522 raeburn 5705: if (ref($slots{$checkedinslot}) eq 'HASH') {
5706: $consumed_uniq{$checkedinslot} = $slots{$checkedinslot}{'uniqueperiod'};
5707: }
5708: if ($wait_for_grade) {
1.432 raeburn 5709: return (WAITING_FOR_GRADE);
5710: } elsif ($is_correct) {
5711: return (CORRECT);
5712: }
5713: }
1.473 raeburn 5714: if ($num_usable_slots) {
5715: return(NOT_IN_A_SLOT);
5716: }
5717: }
5718: my $reservable = &Apache::lonnet::get_reservable_slots($cnum,$cdom,$env{'user.name'},
5719: $env{'user.domain'});
5720: if (ref($reservable) eq 'HASH') {
1.511 raeburn 5721: my ($map) = &Apache::lonnet::decode_symb($symb);
1.473 raeburn 5722: if ((ref($reservable->{'now_order'}) eq 'ARRAY') && (ref($reservable->{'now'}) eq 'HASH')) {
1.474 raeburn 5723: foreach my $slot (reverse (@{$reservable->{'now_order'}})) {
1.510 raeburn 5724: my $canuse;
5725: if ($reservable->{'now'}{$slot}{'symb'} eq '') {
5726: $canuse = 1;
5727: } else {
5728: my %oksymbs;
5729: my @slotsymbs = split(/\s*,\s*/,$reservable->{'now'}{$slot}{'symb'});
5730: map { $oksymbs{$_} = 1; } @slotsymbs;
5731: if ($oksymbs{$symb}) {
5732: $canuse = 1;
5733: } else {
5734: foreach my $item (@slotsymbs) {
5735: if ($item =~ /\.(page|sequence)$/) {
5736: (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item);
5737: if (($map ne '') && ($map eq $sloturl)) {
5738: $canuse = 1;
5739: last;
5740: }
5741: }
5742: }
5743: }
5744: }
5745: if ($canuse) {
1.522 raeburn 5746: if ($checkedin) {
5747: if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
5748: my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
5749: if ($reservable->{'now'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
5750: my ($new_uniq_start,$new_uniq_end) = ($1,$2);
5751: next if (!
5752: ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
5753: ($uniqstart > $new_uniq_end && $uniqend > $new_uniq_end ));
5754: }
5755: }
5756: }
1.473 raeburn 5757: return(RESERVABLE,$reservable->{'now'}{$slot}{'endreserve'});
5758: }
5759: }
1.432 raeburn 5760: }
1.473 raeburn 5761: if ((ref($reservable->{'future_order'}) eq 'ARRAY') && (ref($reservable->{'future'}) eq 'HASH')) {
1.474 raeburn 5762: foreach my $slot (@{$reservable->{'future_order'}}) {
1.510 raeburn 5763: my $canuse;
5764: if ($reservable->{'future'}{$slot}{'symb'} eq '') {
5765: $canuse = 1;
5766: } elsif ($reservable->{'future'}{$slot}{'symb'} =~ /,/) {
5767: my %oksymbs;
5768: my @slotsymbs = split(/\s*,\s*/,$reservable->{'future'}{$slot}{'symb'});
5769: map { $oksymbs{$_} = 1; } @slotsymbs;
5770: if ($oksymbs{$symb}) {
5771: $canuse = 1;
5772: } else {
5773: foreach my $item (@slotsymbs) {
5774: if ($item =~ /\.(page|sequence)$/) {
5775: (undef,undef, my $sloturl) = &Apache::lonnet::decode_symb($item);
5776: if (($map ne '') && ($map eq $sloturl)) {
5777: $canuse = 1;
5778: last;
5779: }
5780: }
5781: }
5782: }
5783: } elsif ($reservable->{'future'}{$slot}{'symb'} eq $symb) {
5784: $canuse = 1;
5785: }
5786: if ($canuse) {
1.522 raeburn 5787: if ($checkedin) {
5788: if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
5789: my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
5790: if ($reservable->{'future'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
5791: my ($new_uniq_start,$new_uniq_end) = ($1,$2);
5792: next if (!
5793: ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
5794: ($uniqstart > $new_uniq_end && $uniqend > $new_uniq_end ));
5795: }
5796: }
5797: }
1.473 raeburn 5798: return(RESERVABLE_LATER,$reservable->{'future'}{$slot}{'startreserve'});
5799: }
5800: }
1.432 raeburn 5801: }
5802: }
1.473 raeburn 5803: return(NOTRESERVABLE);
1.432 raeburn 5804: }
5805: return;
5806: }
5807:
1.224 bowersj2 5808: sub CLOSED { return 23; }
5809: sub ERROR { return 24; }
5810:
5811: =pod
5812:
5813: B<Simple Status>
5814:
5815: Convenience method B<simpleStatus> provides a "simple status" for the resource.
5816: "Simple status" corresponds to "which icon is shown on the
5817: Navmaps". There are six "simple" statuses:
5818:
5819: =over 4
5820:
5821: =item * B<CLOSED>: The problem is currently closed. (No icon shown.)
5822:
5823: =item * B<OPEN>: The problem is open and unattempted.
5824:
5825: =item * B<CORRECT>: The problem is correct for any reason.
5826:
5827: =item * B<INCORRECT>: The problem is incorrect and can still be
5828: completed successfully.
5829:
5830: =item * B<ATTEMPTED>: The problem has been attempted, but the student
5831: does not know if they are correct. (The ellipsis icon.)
5832:
5833: =item * B<ERROR>: There is an error retrieving information about this
5834: problem.
5835:
5836: =back
5837:
5838: =cut
5839:
5840: # This hash maps the composite status to this simple status, and
5841: # can be used directly, if you like
5842: my %compositeToSimple =
5843: (
5844: NETWORK_FAILURE() => ERROR,
5845: NOTHING_SET() => CLOSED,
5846: CORRECT() => CORRECT,
1.332 albertel 5847: PARTIALLY_CORRECT() => PARTIALLY_CORRECT,
1.224 bowersj2 5848: EXCUSED() => CORRECT,
5849: PAST_DUE_NO_ANSWER() => INCORRECT,
5850: PAST_DUE_ANSWER_LATER() => INCORRECT,
5851: ANSWER_OPEN() => INCORRECT,
5852: OPEN_LATER() => CLOSED,
5853: TRIES_LEFT() => OPEN,
5854: INCORRECT() => INCORRECT,
5855: OPEN() => OPEN,
5856: ATTEMPTED() => ATTEMPTED,
1.450 raeburn 5857: CREDIT_ATTEMPTED() => CORRECT,
1.224 bowersj2 5858: ANSWER_SUBMITTED() => ATTEMPTED
5859: );
5860:
5861: sub simpleStatus {
5862: my $self = shift;
5863: my $part = shift;
5864: my $status = $self->status($part);
5865: return $compositeToSimple{$status};
1.225 bowersj2 5866: }
5867:
5868: =pod
5869:
5870: B<simpleStatusCount> will return an array reference containing, in
5871: this order, the number of OPEN, CLOSED, CORRECT, INCORRECT, ATTEMPTED,
5872: and ERROR parts the given problem has.
5873:
5874: =cut
5875:
5876: # This maps the status to the slot we want to increment
5877: my %statusToSlotMap =
5878: (
5879: OPEN() => 0,
5880: CLOSED() => 1,
5881: CORRECT() => 2,
5882: INCORRECT() => 3,
5883: ATTEMPTED() => 4,
5884: ERROR() => 5
5885: );
5886:
5887: sub statusToSlot { return $statusToSlotMap{shift()}; }
5888:
5889: sub simpleStatusCount {
5890: my $self = shift;
5891:
5892: my @counts = (0, 0, 0, 0, 0, 0, 0);
5893: foreach my $part (@{$self->parts()}) {
5894: $counts[$statusToSlotMap{$self->simpleStatus($part)}]++;
5895: }
5896:
5897: return \@counts;
1.191 bowersj2 5898: }
5899:
5900: =pod
5901:
5902: B<Completable>
5903:
5904: The completable method represents the concept of I<whether the student can
5905: currently do the problem>. If the student can do the problem, which means
5906: that it is open, there are tries left, and if the problem is manually graded
5907: or the grade is suppressed via problemstatus, the student has not tried it
5908: yet, then the method returns 1. Otherwise, it returns 0, to indicate that
5909: either the student has tried it and there is no feedback, or that for
5910: some reason it is no longer completable (not open yet, successfully completed,
5911: out of tries, etc.). As an example, this is used as the filter for the
5912: "Uncompleted Homework" option for the nav maps.
5913:
5914: If this does not quite meet your needs, do not fiddle with it (unless you are
5915: fixing it to better match the student's conception of "completable" because
5916: it's broken somehow)... make a new method.
5917:
5918: =cut
5919:
5920: sub completable {
5921: my $self = shift;
5922: if (!$self->is_problem()) { return 0; }
5923: my $partCount = $self->countParts();
5924:
5925: foreach my $part (@{$self->parts()}) {
5926: if ($part eq '0' && $partCount != 1) { next; }
5927: my $status = $self->status($part);
5928: # "If any of the parts are open, or have tries left (implies open),
5929: # and it is not "attempted" (manually graded problem), it is
5930: # not "complete"
1.216 bowersj2 5931: if ($self->getCompletionStatus($part) == ATTEMPTED() ||
1.450 raeburn 5932: $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
1.216 bowersj2 5933: $status == ANSWER_SUBMITTED() ) {
5934: # did this part already, as well as we can
5935: next;
5936: }
5937: if ($status == OPEN() || $status == TRIES_LEFT()) {
5938: return 1;
5939: }
1.191 bowersj2 5940: }
5941:
5942: # If all the parts were complete, so was this problem.
1.216 bowersj2 5943: return 0;
1.51 bowersj2 5944: }
5945:
5946: =pod
5947:
1.507 raeburn 5948: B<Answerable>
5949:
5950: The answerable method differs from the completable method in its handling of problem parts
5951: for which feedback on correctness is suppressed, but the student still has tries left, and
5952: the problem part is not past due, (i.e., the student could submit a different answer if
5953: he/she so chose). For that case completable will return 0, whereas answerable will return 1.
5954:
5955: =cut
5956:
5957: sub answerable {
5958: my $self = shift;
5959: if (!$self->is_problem()) { return 0; }
5960: my $partCount = $self->countParts();
5961: foreach my $part (@{$self->parts()}) {
5962: if ($part eq '0' && $partCount != 1) { next; }
5963: my $status = $self->status($part);
5964: if ($self->getCompletionStatus($part) == ATTEMPTED() ||
5965: $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
5966: $status == ANSWER_SUBMITTED() ) {
5967: if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
5968: return 1;
5969: }
5970: }
5971: if ($status == OPEN() || $status == TRIES_LEFT() || $status == NETWORK_FAILURE()) {
5972: return 1;
5973: }
5974: }
5975: # None of the parts were answerable, so neither is this problem.
5976: return 0;
5977: }
5978:
5979: =pod
5980:
1.51 bowersj2 5981: =head2 Resource/Nav Map Navigation
5982:
5983: =over 4
5984:
1.174 albertel 5985: =item * B<getNext>():
5986:
5987: Retreive an array of the possible next resources after this
5988: one. Always returns an array, even in the one- or zero-element case.
5989:
5990: =item * B<getPrevious>():
1.85 bowersj2 5991:
1.174 albertel 5992: Retreive an array of the possible previous resources from this
5993: one. Always returns an array, even in the one- or zero-element case.
1.51 bowersj2 5994:
5995: =cut
5996:
5997: sub getNext {
5998: my $self = shift;
5999: my @branches;
6000: my $to = $self->to();
1.85 bowersj2 6001: foreach my $branch ( split(/,/, $to) ) {
1.51 bowersj2 6002: my $choice = $self->{NAV_MAP}->getById($branch);
1.342 albertel 6003: #if (!$choice->condition()) { next; }
1.51 bowersj2 6004: my $next = $choice->goesto();
6005: $next = $self->{NAV_MAP}->getById($next);
6006:
1.131 bowersj2 6007: push @branches, $next;
1.85 bowersj2 6008: }
6009: return \@branches;
6010: }
6011:
6012: sub getPrevious {
6013: my $self = shift;
6014: my @branches;
6015: my $from = $self->from();
1.504 raeburn 6016: foreach my $branch ( split(/,/, $from)) {
1.85 bowersj2 6017: my $choice = $self->{NAV_MAP}->getById($branch);
6018: my $prev = $choice->comesfrom();
6019: $prev = $self->{NAV_MAP}->getById($prev);
6020:
1.131 bowersj2 6021: push @branches, $prev;
1.51 bowersj2 6022: }
6023: return \@branches;
1.131 bowersj2 6024: }
6025:
6026: sub browsePriv {
6027: my $self = shift;
1.505 raeburn 6028: my $noblockcheck = shift;
1.131 bowersj2 6029: if (defined($self->{BROWSE_PRIV})) {
6030: return $self->{BROWSE_PRIV};
6031: }
6032:
1.311 albertel 6033: $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(),
1.508 damieng 6034: $self->{SYMB},undef,
1.505 raeburn 6035: undef,$noblockcheck);
1.51 bowersj2 6036: }
6037:
6038: =pod
1.2 www 6039:
1.51 bowersj2 6040: =back
1.2 www 6041:
1.51 bowersj2 6042: =cut
1.2 www 6043:
1.51 bowersj2 6044: 1;
1.2 www 6045:
1.51 bowersj2 6046: __END__
1.2 www 6047:
6048:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>