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