Annotation of loncom/interface/lonnavmaps.pm, revision 1.509.2.15
1.481 foxr 1: # The LearningOnline Network with CAPA
1.2 www 2: # Navigate Maps Handler
1.1 www 3: #
1.509.2.15! raeburn 4: # $Id: lonnavmaps.pm,v 1.509.2.14 2021/12/31 23:14:04 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.509.2.15! raeburn 345: =item * B<suppressNavmap>: 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;
1.509.2.15! raeburn 1418: my $here_is_navmaps = 0;
! 1419: if ($here =~ m{___\d+___adm/navmaps$}) {
! 1420: $here_is_navmaps = 1;
! 1421: }
1.140 bowersj2 1422:
1423: # We only need to do this if we need to open the maps to show the
1424: # current position. This will change the counter so we can't count
1425: # for the jump marker with this loop.
1.509.2.15! raeburn 1426: while ($here && ($curRes = $mapIterator->next()) && !$found && !$here_is_navmaps) {
1.158 bowersj2 1427: if (ref($curRes) && $curRes->symb() eq $here) {
1.140 bowersj2 1428: my $mapStack = $mapIterator->getStack();
1429:
1430: # Ensure the parent maps are open
1431: for my $map (@{$mapStack}) {
1432: if ($condition) {
1433: undef $filterHash->{$map->map_pc()};
1434: } else {
1435: $filterHash->{$map->map_pc()} = 1;
1436: }
1437: }
1438: $found = 1;
1439: }
1440: }
1.159 bowersj2 1441: }
1.140 bowersj2 1442:
1.320 albertel 1443: if ( !defined($args->{'iterator'}) && $env{'form.folderManip'} ) { # we came from a user's manipulation of the nav page
1.140 bowersj2 1444: # If this is a click on a folder or something, we want to preserve the "here"
1445: # from the querystring, and get the new "jump" marker
1.320 albertel 1446: $here = $env{'form.here'};
1447: $jump = $env{'form.jump'};
1.140 bowersj2 1448: }
1449:
1.132 bowersj2 1450: my $it = $args->{'iterator'};
1451: if (!defined($it)) {
1.320 albertel 1452: # Construct a default iterator based on $env{'form.'} information
1.140 bowersj2 1453:
1454: # Step 1: Check to see if we have a navmap
1455: if (!defined($navmap)) {
1.221 bowersj2 1456: $navmap = Apache::lonnavmaps::navmap->new();
1.423 raeburn 1457: if (!defined($navmap)) {
1458: # no longer in course
1459: return '<span class="LC_error">'.&mt('No course selected').'</span><br />
1460: <a href="/adm/roles">'.&mt('Select a course').'</a><br />';
1461: }
1.140 bowersj2 1462: }
1463:
1.144 bowersj2 1464: # See if we're being passed a specific map
1465: if ($args->{'iterator_map'}) {
1466: my $map = $args->{'iterator_map'};
1.145 bowersj2 1467: $map = $navmap->getResourceByUrl($map);
1.509.2.9 raeburn 1468: if (ref($map)) {
1469: my $firstResource = $map->map_start();
1470: my $finishResource = $map->map_finish();
1471: $args->{'iterator'} = $it = $navmap->getIterator($firstResource, $finishResource, $filterHash, $condition);
1472: } else {
1473: return;
1474: }
1.144 bowersj2 1475: } else {
1.401 albertel 1476: $args->{'iterator'} = $it = $navmap->getIterator(undef, undef, $filterHash, $condition,undef,$args->{'include_top_level_map'});
1.144 bowersj2 1477: }
1.132 bowersj2 1478: }
1.256 albertel 1479:
1.159 bowersj2 1480: # (re-)Locate the jump point, if any
1.191 bowersj2 1481: # Note this does not take filtering or hidden into account... need
1482: # to be fixed?
1.159 bowersj2 1483: my $mapIterator = $navmap->getIterator(undef, undef, $filterHash, 0);
1.222 bowersj2 1484: my $curRes;
1.159 bowersj2 1485: my $foundJump = 0;
1486: my $counter = 0;
1487:
1.222 bowersj2 1488: while (($curRes = $mapIterator->next()) && !$foundJump) {
1.159 bowersj2 1489: if (ref($curRes)) { $counter++; }
1490:
1491: if (ref($curRes) && $jump eq $curRes->symb()) {
1492:
1493: # This is why we have to use the main iterator instead of the
1494: # potentially faster DFS: The count has to be the same, so
1495: # the order has to be the same, which DFS won't give us.
1496: $args->{'currentJumpIndex'} = $counter;
1497: $foundJump = 1;
1498: }
1499: }
1500:
1.132 bowersj2 1501: my $showParts = setDefault($args->{'showParts'}, 1);
1502: my $condenseParts = setDefault($args->{'condenseParts'}, 1);
1.139 bowersj2 1503: # keeps track of when the current resource is found,
1504: # so we can back up a few and put the anchor above the
1505: # current resource
1.140 bowersj2 1506: my $printKey = $args->{'printKey'};
1507: my $printCloseAll = $args->{'printCloseAll'};
1508: if (!defined($printCloseAll)) { $printCloseAll = 1; }
1.425 schulted 1509:
1.140 bowersj2 1510: # Print key?
1511: if ($printKey) {
1512: $result .= '<table border="0" cellpadding="2" cellspacing="0">';
1513: $result.='<tr><td align="right" valign="bottom">Key: </td>';
1.298 albertel 1514: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonMisc");
1.140 bowersj2 1515: if ($navmap->{LAST_CHECK}) {
1516: $result .=
1.434 bisitz 1517: '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('New discussion since').' '.
1.140 bowersj2 1518: strftime("%A, %b %e at %I:%M %P", localtime($navmap->{LAST_CHECK})).
1519: '</td><td align="center" valign="bottom"> '.
1.434 bisitz 1520: '<img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').'<p>'.
1.140 bowersj2 1521: '</td>';
1522: } else {
1523: $result .= '<td align="center" valign="bottom"> '.
1.434 bisitz 1524: '<img src="'.$location.'/chat.gif" alt="" /> '.&mt('Discussions').'</td><td align="center" valign="bottom">'.
1525: ' <img src="'.$location.'/feedback.gif" alt="" /> '.&mt('New message (click to open)').
1.140 bowersj2 1526: '</td>';
1527: }
1528:
1529: $result .= '</tr></table>';
1530: }
1531:
1.172 bowersj2 1532: if ($printCloseAll && !$args->{'resource_no_folder_link'}) {
1.281 albertel 1533: my ($link,$text);
1.140 bowersj2 1534: if ($condition) {
1.446 raeburn 1535: $link='navmaps?condition=0&filter=&'.$queryString.
1.449 bisitz 1536: '&here='.&escape($here);
1.377 www 1537: $text='Close all folders';
1.140 bowersj2 1538: } else {
1.446 raeburn 1539: $link='navmaps?condition=1&filter=&'.$queryString.
1.449 bisitz 1540: '&here='.&escape($here);
1.377 www 1541: $text='Open all folders';
1.281 albertel 1542: }
1543: if ($args->{'caller'} eq 'navmapsdisplay') {
1.478 raeburn 1544: unless ($args->{'notools'}) {
1545: &add_linkitem($args->{'linkitems'},'changefolder',
1546: "location.href='$link'",$text);
1547: }
1.281 albertel 1548: } else {
1.446 raeburn 1549: $result.= '<a href="'.$link.'">'.&mt($text).'</a>';
1.281 albertel 1550: }
1.266 raeburn 1551: $result .= "\n";
1552: }
1.140 bowersj2 1553:
1.266 raeburn 1554: # Check for any unread discussions in all resources.
1.478 raeburn 1555: if (($args->{'caller'} eq 'navmapsdisplay') && (!$args->{'notools'})) {
1.296 albertel 1556: &add_linkitem($args->{'linkitems'},'clearbubbles',
1557: 'document.clearbubbles.submit()',
1558: 'Mark all posts read');
1.297 albertel 1559: my $time=time;
1.486 raeburn 1560: my $querystr = &HTML::Entities::encode($ENV{'QUERY_STRING'},'<>&"');
1.296 albertel 1561: $result .= (<<END);
1562: <form name="clearbubbles" method="post" action="/adm/feedback">
1.486 raeburn 1563: <input type="hidden" name="navurl" value="$querystr" />
1.297 albertel 1564: <input type="hidden" name="navtime" value="$time" />
1.296 albertel 1565: END
1566: if ($args->{'sort'} eq 'discussion') {
1567: my $totdisc = 0;
1568: my $haveDisc = '';
1569: my @allres=$navmap->retrieveResources();
1570: foreach my $resource (@allres) {
1571: if ($resource->hasDiscussion()) {
1.323 albertel 1572: $haveDisc .= $resource->wrap_symb().':';
1.296 albertel 1573: $totdisc ++;
1.267 albertel 1574: }
1575: }
1.296 albertel 1576: if ($totdisc > 0) {
1577: $haveDisc =~ s/:$//;
1578: $result .= (<<END);
1579: <input type="hidden" name="navmaps" value="$haveDisc" />
1580: </form>
1581: END
1582: }
1.297 albertel 1583: }
1584: $result.='</form>';
1.478 raeburn 1585: }
1586: if (($args->{'caller'} eq 'navmapsdisplay') &&
1.509.2.5 raeburn 1587: ((&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) ||
1588: (&Apache::lonnet::allowed('cev',$env{'request.course.id'})))) {
1.478 raeburn 1589: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1590: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1591: if ($env{'course.'.$env{'request.course.id'}.'.url'} eq
1592: "uploaded/$cdom/$cnum/default.sequence") {
1593: &add_linkitem($args->{'linkitems'},'edittoplevel',
1594: "javascript:gocmd('/adm/coursedocs','editdocs');",
1595: 'Content Editor');
1.475 raeburn 1596: }
1.266 raeburn 1597: }
1.276 albertel 1598:
1.281 albertel 1599: if ($args->{'caller'} eq 'navmapsdisplay') {
1.476 raeburn 1600: $result .= &show_linkitems_toolbar($args,$condition);
1.281 albertel 1601: } elsif ($args->{'sort_html'}) {
1602: $result.=$args->{'sort_html'};
1603: }
1.276 albertel 1604:
1.425 schulted 1605: #$result .= "<br />\n";
1.140 bowersj2 1606: if ($r) {
1607: $r->print($result);
1608: $r->rflush();
1609: $result = "";
1610: }
1.132 bowersj2 1611: # End parameter setting
1.425 schulted 1612:
1613: $result .= "<br />\n";
1614:
1.132 bowersj2 1615: # Data
1.431 schulted 1616: $result.=&Apache::loncommon::start_data_table("LC_tableOfContent");
1.426 droeschl 1617:
1.132 bowersj2 1618: my $res = "Apache::lonnavmaps::resource";
1619: my %condenseStatuses =
1620: ( $res->NETWORK_FAILURE => 1,
1621: $res->NOTHING_SET => 1,
1622: $res->CORRECT => 1 );
1.133 bowersj2 1623:
1624: # Shared variables
1625: $args->{'counter'} = 0; # counts the rows
1626: $args->{'indentLevel'} = 0;
1627: $args->{'isNewBranch'} = 0;
1.426 droeschl 1628: $args->{'condensed'} = 0;
1629:
1.428 droeschl 1630: my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons/whitespace_21.gif");
1.426 droeschl 1631: $args->{'indentString'} = setDefault($args->{'indentString'}, "<img src='$location' alt='' />");
1.133 bowersj2 1632: $args->{'displayedHereMarker'} = 0;
1.132 bowersj2 1633:
1.509.2.3 raeburn 1634: # If we're suppressing empty sequences, look for them here.
1635: # We also do this even if $args->{'suppressEmptySequences'}
1636: # is not true, so we can hide empty sequences for which the
1637: # hiddenresource parameter is set to yes (at map level), or
1638: # mark as hidden for users who have $userCanSeeHidden.
1639: # Use DFS for speed, since structure actually doesn't matter,
1640: # except what map has what resources.
1641:
1642: my $dfsit = Apache::lonnavmaps::DFSiterator->new($navmap,
1643: $it->{FIRST_RESOURCE},
1644: $it->{FINISH_RESOURCE},
1645: {}, undef, 1);
1646:
1647: my $depth = 0;
1648: $dfsit->next();
1649: my $curRes = $dfsit->next();
1650: while ($depth > -1) {
1651: if ($curRes == $dfsit->BEGIN_MAP()) { $depth++; }
1652: if ($curRes == $dfsit->END_MAP()) { $depth--; }
1653:
1654: if (ref($curRes)) {
1655: # Parallel pre-processing: Do sequences have non-filtered-out children?
1656: if ($curRes->is_map()) {
1657: $curRes->{DATA}->{HAS_VISIBLE_CHILDREN} = 0;
1658: # Sequences themselves do not count as visible children,
1659: # unless those sequences also have visible children.
1660: # This means if a sequence appears, there's a "promise"
1661: # that there's something under it if you open it, somewhere.
1662: } elsif ($curRes->src()) {
1663: # Not a sequence: if it's filtered, ignore it, otherwise
1664: # rise up the stack and mark the sequences as having children
1665: if (&$filterFunc($curRes)) {
1666: for my $sequence (@{$dfsit->getStack()}) {
1667: $sequence->{DATA}->{HAS_VISIBLE_CHILDREN} = 1;
1.190 bowersj2 1668: }
1669: }
1670: }
1671: }
1.509.2.3 raeburn 1672: } continue {
1673: $curRes = $dfsit->next();
1.190 bowersj2 1674: }
1675:
1.133 bowersj2 1676: my $displayedJumpMarker = 0;
1.132 bowersj2 1677: # Set up iteration.
1678: my $now = time();
1679: my $in24Hours = $now + 24 * 60 * 60;
1680: my $rownum = 0;
1681:
1.141 bowersj2 1682: # export "here" marker information
1683: $args->{'here'} = $here;
1684:
1.222 bowersj2 1685: $args->{'indentLevel'} = -1; # first BEGIN_MAP takes this to 0
1.270 albertel 1686: my @resources;
1687: my $code='';# sub { !(shift->is_map();) };
1688: if ($args->{'sort'} eq 'title') {
1.276 albertel 1689: my $oldFilterFunc = $filterFunc;
1690: my $filterFunc=
1691: sub {
1692: my ($res)=@_;
1693: if ($res->is_map()) { return 0;}
1694: return &$oldFilterFunc($res);
1695: };
1696: @resources=$navmap->retrieveResources(undef,$filterFunc);
1.296 albertel 1697: @resources= sort { &cmp_title($a,$b) } @resources;
1698: } elsif ($args->{'sort'} eq 'duedate') {
1699: my $oldFilterFunc = $filterFunc;
1700: my $filterFunc=
1701: sub {
1702: my ($res)=@_;
1703: if (!$res->is_problem()) { return 0;}
1704: return &$oldFilterFunc($res);
1705: };
1706: @resources=$navmap->retrieveResources(undef,$filterFunc);
1.289 raeburn 1707: @resources= sort {
1.270 albertel 1708: if ($a->duedate ne $b->duedate) {
1709: return $a->duedate cmp $b->duedate;
1710: }
1.296 albertel 1711: my $value=&cmp_title($a,$b);
1712: return $value;
1.270 albertel 1713: } @resources;
1.296 albertel 1714: } elsif ($args->{'sort'} eq 'discussion') {
1715: my $oldFilterFunc = $filterFunc;
1716: my $filterFunc=
1717: sub {
1718: my ($res)=@_;
1719: if (!$res->hasDiscussion() &&
1720: !$res->getFeedback() &&
1721: !$res->getErrors()) { return 0;}
1722: return &$oldFilterFunc($res);
1723: };
1724: @resources=$navmap->retrieveResources(undef,$filterFunc);
1725: @resources= sort { &cmp_title($a,$b) } @resources;
1.276 albertel 1726: } else {
1727: #unknow sort mechanism or default
1728: undef($args->{'sort'});
1.270 albertel 1729: }
1730:
1.509.2.11 raeburn 1731: # Determine if page will be served with https in case
1732: # it contains a syllabus which uses an external URL
1733: # which points at an http site.
1734:
1735: my ($is_ssl,$cdom,$cnum,$hostname);
1736: if ($ENV{'SERVER_PORT'} == 443) {
1737: $is_ssl = 1;
1738: if ($r) {
1739: $hostname = $r->hostname();
1740: } else {
1741: $hostname = $ENV{'SERVER_NAME'};
1742: }
1743: }
1744: if ($env{'request.course.id'}) {
1745: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1746: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1747: }
1.276 albertel 1748:
1.509.2.7 raeburn 1749: my $inhibitmenu;
1750: if ($args->{'modalLink'}) {
1751: $inhibitmenu = '&inhibitmenu=yes';
1752: }
1753:
1.270 albertel 1754: while (1) {
1755: if ($args->{'sort'}) {
1756: $curRes = shift(@resources);
1757: } else {
1758: $curRes = $it->next($closeAllPages);
1759: }
1760: if (!$curRes) { last; }
1761:
1.132 bowersj2 1762: # Maintain indentation level.
1763: if ($curRes == $it->BEGIN_MAP() ||
1764: $curRes == $it->BEGIN_BRANCH() ) {
1.133 bowersj2 1765: $args->{'indentLevel'}++;
1.132 bowersj2 1766: }
1767: if ($curRes == $it->END_MAP() ||
1768: $curRes == $it->END_BRANCH() ) {
1.133 bowersj2 1769: $args->{'indentLevel'}--;
1.132 bowersj2 1770: }
1771: # Notice new branches
1772: if ($curRes == $it->BEGIN_BRANCH()) {
1.133 bowersj2 1773: $args->{'isNewBranch'} = 1;
1774: }
1775:
1776: # If this isn't an actual resource, continue on
1777: if (!ref($curRes)) {
1778: next;
1.132 bowersj2 1779: }
1.133 bowersj2 1780:
1.143 bowersj2 1781: # If this has been filtered out, continue on
1782: if (!(&$filterFunc($curRes))) {
1783: $args->{'isNewBranch'} = 0; # Don't falsely remember this
1784: next;
1785: }
1.132 bowersj2 1786:
1.190 bowersj2 1787: # If this is an empty sequence and we're filtering them, continue on
1.509.2.3 raeburn 1788: $args->{'mapHidden'} = 0;
1789: if (($curRes->is_map()) && (!$curRes->{DATA}->{HAS_VISIBLE_CHILDREN})) {
1790: if ($args->{'suppressEmptySequences'}) {
1791: next;
1792: } else {
1793: my $mapname = &Apache::lonnet::declutter($curRes->src());
1794: $mapname = &Apache::lonnet::deversion($mapname);
1795: if (lc($navmap->get_mapparam(undef,$mapname,"0.hiddenresource")) eq 'yes') {
1796: if ($userCanSeeHidden) {
1797: $args->{'mapHidden'} = 1;
1798: } else {
1799: next;
1800: }
1801: }
1802: }
1.190 bowersj2 1803: }
1804:
1.153 bowersj2 1805: # If we're suppressing navmaps and this is a navmap, continue on
1806: if ($suppressNavmap && $curRes->src() =~ /^\/adm\/navmaps/) {
1807: next;
1808: }
1809:
1.191 bowersj2 1810: $args->{'counter'}++;
1811:
1.132 bowersj2 1812: # Does it have multiple parts?
1.133 bowersj2 1813: $args->{'multipart'} = 0;
1814: $args->{'condensed'} = 0;
1.132 bowersj2 1815: my @parts;
1816:
1817: # Decide what parts to show.
1.133 bowersj2 1818: if ($curRes->is_problem() && $showParts) {
1.132 bowersj2 1819: @parts = @{$curRes->parts()};
1.192 bowersj2 1820: $args->{'multipart'} = $curRes->multipart();
1.132 bowersj2 1821:
1822: if ($condenseParts) { # do the condensation
1.133 bowersj2 1823: if (!$args->{'condensed'}) {
1.132 bowersj2 1824: # Decide whether to condense based on similarity
1.192 bowersj2 1825: my $status = $curRes->status($parts[0]);
1826: my $due = $curRes->duedate($parts[0]);
1827: my $open = $curRes->opendate($parts[0]);
1.132 bowersj2 1828: my $statusAllSame = 1;
1829: my $dueAllSame = 1;
1830: my $openAllSame = 1;
1.192 bowersj2 1831: for (my $i = 1; $i < scalar(@parts); $i++) {
1.132 bowersj2 1832: if ($curRes->status($parts[$i]) != $status){
1833: $statusAllSame = 0;
1834: }
1835: if ($curRes->duedate($parts[$i]) != $due ) {
1836: $dueAllSame = 0;
1837: }
1838: if ($curRes->opendate($parts[$i]) != $open) {
1839: $openAllSame = 0;
1840: }
1841: }
1842: # $*allSame is true if all the statuses were
1843: # the same. Now, if they are all the same and
1844: # match one of the statuses to condense, or they
1845: # are all open with the same due date, or they are
1846: # all OPEN_LATER with the same open date, display the
1847: # status of the first non-zero part (to get the 'correct'
1848: # status right, since 0 is never 'correct' or 'open').
1849: if (($statusAllSame && defined($condenseStatuses{$status})) ||
1850: ($dueAllSame && $status == $curRes->OPEN && $statusAllSame)||
1851: ($openAllSame && $status == $curRes->OPEN_LATER && $statusAllSame) ){
1.192 bowersj2 1852: @parts = ($parts[0]);
1.133 bowersj2 1853: $args->{'condensed'} = 1;
1.132 bowersj2 1854: }
1855: }
1.198 bowersj2 1856: # Multipart problem with one part: always "condense" (happens
1857: # to match the desirable behavior)
1858: if ($curRes->countParts() == 1) {
1859: @parts = ($parts[0]);
1860: $args->{'condensed'} = 1;
1861: }
1.132 bowersj2 1862: }
1.157 bowersj2 1863: }
1.132 bowersj2 1864:
1865: # If the multipart problem was condensed, "forget" it was multipart
1866: if (scalar(@parts) == 1) {
1.133 bowersj2 1867: $args->{'multipart'} = 0;
1.192 bowersj2 1868: } else {
1869: # Add part 0 so we display it correctly.
1870: unshift @parts, '0';
1.132 bowersj2 1871: }
1.310 albertel 1872:
1873: {
1874: my ($src,$symb,$anchor,$stack);
1875: if ($args->{'sort'}) {
1876: my $it = $navmap->getIterator(undef, undef, undef, 1);
1877: while ( my $res=$it->next()) {
1878: if (ref($res) &&
1879: $res->symb() eq $curRes->symb()) { last; }
1880: }
1881: $stack=$it->getStack();
1882: } else {
1883: $stack=$it->getStack();
1884: }
1885: ($src,$symb,$anchor)=getLinkForResource($stack);
1.509.2.11 raeburn 1886: my $srcHasQuestion = $src =~ /\?/;
1887: if ($env{'request.course.id'}) {
1888: if (($is_ssl) && ($src =~ m{^\Q/public/$cdom/$cnum/syllabus\E($|\?)}) &&
1889: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
1.509.2.14 raeburn 1890: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.509.2.11 raeburn 1891: if ($hostname ne '') {
1892: $src = 'http://'.$hostname.$src;
1893: }
1894: $src .= ($srcHasQuestion? '&' : '?') . 'usehttp=1';
1895: $srcHasQuestion = 1;
1896: }
1897: } elsif (($is_ssl) && ($src =~ m{^\Q/adm/wrapper/ext/\E(?!https:)})) {
1.509.2.14 raeburn 1898: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
1.509.2.11 raeburn 1899: if ($hostname ne '') {
1900: $src = 'http://'.$hostname.$src;
1901: }
1902: $src .= ($srcHasQuestion? '&' : '?') . 'usehttp=1';
1903: $srcHasQuestion = 1;
1904: }
1905: }
1906: }
1.509.2.10 raeburn 1907: if (defined($anchor)) { $anchor='#'.$anchor; }
1908: if (($args->{'caller'} eq 'sequence') && ($curRes->is_map())) {
1909: $args->{"resourceLink"} = $src.($srcHasQuestion?'&':'?') .'navmap=1';
1910: } else {
1911: $args->{"resourceLink"} = $src.
1912: ($srcHasQuestion?'&':'?') .
1913: 'symb=' . &escape($symb).$inhibitmenu.$anchor;
1914: }
1.310 albertel 1915: }
1.132 bowersj2 1916: # Now, we've decided what parts to show. Loop through them and
1917: # show them.
1.192 bowersj2 1918: foreach my $part (@parts) {
1.132 bowersj2 1919: $rownum ++;
1920:
1.431 schulted 1921: $result .= &Apache::loncommon::start_data_table_row();
1.134 bowersj2 1922:
1923: # Set up some data about the parts that the cols might want
1924: my $filter = $it->{FILTER};
1.270 albertel 1925:
1.132 bowersj2 1926: # Now, display each column.
1927: foreach my $col (@$cols) {
1.139 bowersj2 1928: my $colHTML = '';
1929: if (ref($col)) {
1930: $colHTML .= &$col($curRes, $part, $args);
1931: } else {
1932: $colHTML .= &{$preparedColumns[$col]}($curRes, $part, $args);
1933: }
1.132 bowersj2 1934:
1.133 bowersj2 1935: # If this is the first column and it's time to print
1936: # the anchor, do so
1937: if ($col == $cols->[0] &&
1938: $args->{'counter'} == $args->{'currentJumpIndex'} -
1.139 bowersj2 1939: $currentJumpDelta) {
1940: # Jam the anchor after the <td> tag;
1941: # necessary for valid HTML (which Mozilla requires)
1.509.2.12 raeburn 1942: $colHTML =~ s/\>/\>\<a name="curloc" \>\<\/a\>/;
1.133 bowersj2 1943: $displayedJumpMarker = 1;
1944: }
1.139 bowersj2 1945: $result .= $colHTML . "\n";
1.132 bowersj2 1946: }
1.431 schulted 1947: $result .= &Apache::loncommon::end_data_table_row();
1.140 bowersj2 1948: $args->{'isNewBranch'} = 0;
1.139 bowersj2 1949: }
1.153 bowersj2 1950:
1.139 bowersj2 1951: if ($r && $rownum % 20 == 0) {
1952: $r->print($result);
1953: $result = "";
1954: $r->rflush();
1.132 bowersj2 1955: }
1.156 bowersj2 1956: } continue {
1.208 bowersj2 1957: if ($r) {
1958: # If we have the connection, make sure the user is still connected
1959: my $c = $r->connection;
1960: if ($c->aborted()) {
1961: # Who cares what we do, nobody will see it anyhow.
1962: return '';
1963: }
1964: }
1.132 bowersj2 1965: }
1.486 raeburn 1966:
1967: $result.=&Apache::loncommon::end_data_table();
1.132 bowersj2 1968:
1.134 bowersj2 1969: # Print out the part that jumps to #curloc if it exists
1.159 bowersj2 1970: # delay needed because the browser is processing the jump before
1971: # it finishes rendering, so it goes to the wrong place!
1972: # onload might be better, but this routine has no access to that.
1973: # On mozilla, the 0-millisecond timeout seems to prevent this;
1974: # it's quite likely this might fix other browsers, too, and
1975: # certainly won't hurt anything.
1.139 bowersj2 1976: if ($displayedJumpMarker) {
1.449 bisitz 1977: $result .= &Apache::lonhtmlcommon::scripttag("
1.247 albertel 1978: if (location.href.indexOf('#curloc')==-1) {
1979: setTimeout(\"location += '#curloc';\", 0)
1980: }
1.449 bisitz 1981: ");
1.134 bowersj2 1982: }
1983:
1.140 bowersj2 1984: if ($r) {
1985: $r->print($result);
1986: $result = "";
1987: $r->rflush();
1988: }
1989:
1.132 bowersj2 1990: return $result;
1991: }
1992:
1.281 albertel 1993: sub add_linkitem {
1994: my ($linkitems,$name,$cmd,$text)=@_;
1995: $$linkitems{$name}{'cmd'}=$cmd;
1996: $$linkitems{$name}{'text'}=&mt($text);
1997: }
1998:
1.430 schulted 1999: sub show_linkitems_toolbar {
1.476 raeburn 2000: my ($args,$condition) = @_;
1.478 raeburn 2001: my $result;
1.476 raeburn 2002: if (ref($args) eq 'HASH') {
2003: if (ref($args->{'linkitems'}) eq 'HASH') {
1.478 raeburn 2004: my $numlinks = scalar(keys(%{$args->{'linkitems'}}));
2005: if ($numlinks > 1) {
2006: $result = '<td>'.
2007: &Apache::loncommon::help_open_menu('Navigation Screen','Navigation_Screen',
2008: undef,'RAT').
2009: '</td>'.
2010: '<td> </td>'.
2011: '<td class="LC_middle">'.&mt('Tools:').'</td>';
2012: }
2013: $result .= '<td align="left">'."\n".
2014: '<ul id="LC_toolbar">';
1.476 raeburn 2015: my @linkorder = ('firsthomework','everything','uncompleted',
2016: 'changefolder','clearbubbles','edittoplevel');
2017: foreach my $link (@linkorder) {
2018: if (ref($args->{'linkitems'}{$link}) eq 'HASH') {
2019: if ($args->{'linkitems'}{$link}{'text'} ne '') {
2020: $args->{'linkitems'}{$link}{'cmd'}=~s/"/'/g;
2021: if ($args->{'linkitems'}{$link}{'cmd'}) {
1.478 raeburn 2022: my $link_id = 'LC_content_toolbar_'.$link;
1.476 raeburn 2023: if ($link eq 'changefolder') {
2024: if ($condition) {
2025: $link_id='LC_content_toolbar_changefolder_toggled';
2026: } else {
2027: $link_id='LC_content_toolbar_changefolder';
2028: }
2029: }
2030: $result .= '<li><a href="#" '.
2031: 'onclick="'.$args->{'linkitems'}{$link}{'cmd'}.'" '.
2032: 'id="'.$link_id.'" '.
2033: 'class="LC_toolbarItem" '.
2034: 'title="'.$args->{'linkitems'}{$link}{'text'}.'">'.
2035: '</a></li>'."\n";
1.446 raeburn 2036: }
2037: }
2038: }
2039: }
1.476 raeburn 2040: $result .= '</ul>'.
1.486 raeburn 2041: '</td>';
1.478 raeburn 2042: if (($numlinks==1) && (exists($args->{'linkitems'}{'edittoplevel'}))) {
2043: $result .= '<td><a href="'.$args->{'linkitems'}{'edittoplevel'}{'cmd'}.'">'.
2044: &mt('Content Editor').'</a></td>';
2045: }
1.476 raeburn 2046: }
2047: if ($args->{'sort_html'}) {
2048: $result .= '<td> </td><td> </td><td> </td>'.
2049: '<td align="right">'.$args->{'sort_html'}.'</td>';
1.446 raeburn 2050: }
1.430 schulted 2051: }
1.478 raeburn 2052: if ($result) {
2053: $result = "<table><tr>$result</tr></table>";
2054: }
1.430 schulted 2055: return $result;
2056: }
2057:
1.133 bowersj2 2058: 1;
2059:
1.418 jms 2060:
2061:
2062:
2063:
2064:
2065:
2066:
2067:
1.133 bowersj2 2068: package Apache::lonnavmaps::navmap;
2069:
2070: =pod
2071:
1.216 bowersj2 2072: =head1 Object: Apache::lonnavmaps::navmap
1.133 bowersj2 2073:
1.217 bowersj2 2074: =head2 Overview
1.133 bowersj2 2075:
1.217 bowersj2 2076: The navmap object's job is to provide access to the resources
2077: in the course as Apache::lonnavmaps::resource objects, and to
2078: query and manage the relationship between those resource objects.
2079:
2080: Generally, you'll use the navmap object in one of three basic ways.
2081: In order of increasing complexity and power:
2082:
2083: =over 4
2084:
1.358 albertel 2085: =item * C<$navmap-E<gt>getByX>, where X is B<Id>, B<Symb> or B<MapPc> and getResourceByUrl. This provides
1.217 bowersj2 2086: various ways to obtain resource objects, based on various identifiers.
2087: Use this when you want to request information about one object or
2088: a handful of resources you already know the identities of, from some
2089: other source. For more about Ids, Symbs, and MapPcs, see the
2090: Resource documentation. Note that Url should be a B<last resort>,
1.358 albertel 2091: not your first choice; it only really works when there is only one
1.217 bowersj2 2092: instance of the resource in the course, which only applies to
1.358 albertel 2093: maps, and even that may change in the future (see the B<getResourceByUrl>
2094: documentation for more details.)
1.217 bowersj2 2095:
2096: =item * C<my @resources = $navmap-E<gt>retrieveResources(args)>. This
2097: retrieves resources matching some criterion and returns them
2098: in a flat array, with no structure information. Use this when
2099: you are manipulating a series of resources, based on what map
2100: the are in, but do not care about branching, or exactly how
2101: the maps and resources are related. This is the most common case.
2102:
2103: =item * C<$it = $navmap-E<gt>getIterator(args)>. This allows you traverse
2104: the course's navmap in various ways without writing the traversal
2105: code yourself. See iterator documentation below. Use this when
2106: you need to know absolutely everything about the course, including
2107: branches and the precise relationship between maps and resources.
2108:
2109: =back
2110:
2111: =head2 Creation And Destruction
2112:
2113: To create a navmap object, use the following function:
1.133 bowersj2 2114:
2115: =over 4
2116:
1.221 bowersj2 2117: =item * B<Apache::lonnavmaps::navmap-E<gt>new>():
1.133 bowersj2 2118:
1.221 bowersj2 2119: Creates a new navmap object. Returns the navmap object if this is
2120: successful, or B<undef> if not.
1.174 albertel 2121:
1.216 bowersj2 2122: =back
2123:
2124: =head2 Methods
2125:
2126: =over 4
2127:
1.174 albertel 2128: =item * B<getIterator>(first, finish, filter, condition):
2129:
2130: See iterator documentation below.
1.133 bowersj2 2131:
2132: =cut
2133:
2134: use strict;
2135: use GDBM_File;
1.320 albertel 2136: use Apache::lonnet;
1.397 albertel 2137: use LONCAPA;
1.133 bowersj2 2138:
2139: sub new {
2140: # magic invocation to create a class instance
2141: my $proto = shift;
2142: my $class = ref($proto) || $proto;
2143: my $self = {};
1.501 raeburn 2144: bless($self); # So we can call change_user if necessary
1.133 bowersj2 2145:
1.453 www 2146: $self->{USERNAME} = shift || $env{'user.name'};
2147: $self->{DOMAIN} = shift || $env{'user.domain'};
1.491 raeburn 2148: $self->{CODE} = shift;
1.496 raeburn 2149: $self->{NOHIDE} = shift;
1.453 www 2150:
1.465 foxr 2151:
2152:
1.133 bowersj2 2153: # Resource cache stores navmap resources as we reference them. We generate
2154: # them on-demand so we don't pay for creating resources unless we use them.
2155: $self->{RESOURCE_CACHE} = {};
2156:
2157: # Network failure flag, if we accessed the course or user opt and
2158: # failed
2159: $self->{NETWORK_FAILURE} = 0;
2160:
1.465 foxr 2161: # We can only tie the nav hash as done below if the username/domain
2162: # match the env one. Otherwise change_user does everything we need...since we can't
1.501 raeburn 2163: # assume there are course hashes for the specific requested user:domain
2164: # Note: change_user is also called if we need the nav hash when printing CODEd
2165: # assignments or printing an exam, in which the enclosing folder for the items in
2166: # the exam has hidden set.
1.465 foxr 2167: #
1.133 bowersj2 2168:
1.501 raeburn 2169: if (($self->{USERNAME} eq $env{'user.name'}) && ($self->{DOMAIN} eq $env{'user.domain'}) &&
2170: !$self->{CODE} && !$self->{NOHIDE}) {
1.465 foxr 2171:
2172: # tie the nav hash
2173:
2174: my %navmaphash;
2175: my %parmhash;
2176: my $courseFn = $env{"request.course.fn"};
2177: if (!(tie(%navmaphash, 'GDBM_File', "${courseFn}.db",
2178: &GDBM_READER(), 0640))) {
2179: return undef;
2180: }
2181:
2182: if (!(tie(%parmhash, 'GDBM_File', "${courseFn}_parms.db",
2183: &GDBM_READER(), 0640)))
2184: {
2185: untie %{$self->{PARM_HASH}};
2186: return undef;
2187: }
2188:
2189: $self->{NAV_HASH} = \%navmaphash;
2190: $self->{PARM_HASH} = \%parmhash;
2191: $self->{PARM_CACHE} = {};
2192: } else {
1.496 raeburn 2193: $self->change_user($self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE});
1.133 bowersj2 2194: }
1.470 foxr 2195:
1.465 foxr 2196: return $self;
2197: }
2198:
2199: #
2200: # In some instances it is useful to be able to dynamically change the
2201: # username/domain associated with a navmap (e.g. to navigate for someone
2202: # else besides the current user...if sufficiently privileged.
2203: # Parameters:
2204: # user - New user.
2205: # domain- Domain the user belongs to.
1.491 raeburn 2206: # code - Anonymous CODE in use.
1.465 foxr 2207: # Implicit inputs:
2208: #
2209: sub change_user {
2210: my $self = shift;
2211: $self->{USERNAME} = shift;
2212: $self->{DOMAIN} = shift;
1.491 raeburn 2213: $self->{CODE} = shift;
1.496 raeburn 2214: $self->{NOHIDE} = shift;
1.465 foxr 2215:
2216: # If the hashes are already tied make sure to break that bond:
2217:
2218: untie %{$self->{NAV_HASH}};
2219: untie %{$self->{PARM_HASH}};
2220:
2221: # The assumption is that we have to
2222: # use lonmap here to re-read the hash and from it reconstruct
2223: # new big and parameter hashes. An implicit assumption at this time
2224: # is that the course file is probably not created locally yet
2225: # an that we will therefore just read without tying.
2226:
2227: my ($cdom, $cnum) = split(/\_/, $env{'request.course.id'});
2228:
2229: my %big_hash;
1.496 raeburn 2230: &Apache::lonmap::loadmap($cnum, $cdom, $self->{USERNAME}, $self->{DOMAIN}, $self->{CODE}, $self->{NOHIDE}, \%big_hash);
1.465 foxr 2231: $self->{NAV_HASH} = \%big_hash;
2232:
1.470 foxr 2233:
2234:
1.465 foxr 2235: # Now clear the parm cache and reconstruct the parm hash fromt he big_hash
2236: # param.xxxx keys.
2237:
2238: $self->{PARM_CACHE} = {};
1.133 bowersj2 2239:
1.465 foxr 2240: my %parm_hash = {};
1.504 raeburn 2241: foreach my $key (keys(%big_hash)) {
1.465 foxr 2242: if ($key =~ /^param\./) {
2243: my $param_key = $key;
2244: $param_key =~ s/^param\.//;
2245: $parm_hash{$param_key} = $big_hash{$key};
2246: }
1.133 bowersj2 2247: }
2248:
1.465 foxr 2249: $self->{PARM_HASH} = \%parm_hash;
2250:
1.500 raeburn 2251: }
1.133 bowersj2 2252:
1.221 bowersj2 2253: sub generate_course_user_opt {
1.133 bowersj2 2254: my $self = shift;
1.221 bowersj2 2255: if ($self->{COURSE_USER_OPT_GENERATED}) { return; }
1.133 bowersj2 2256:
1.453 www 2257: my $uname=$self->{USERNAME};
2258: my $udom=$self->{DOMAIN};
2259:
1.320 albertel 2260: my $cid=$env{'request.course.id'};
1.326 albertel 2261: my $cdom=$env{'course.'.$cid.'.domain'};
2262: my $cnum=$env{'course.'.$cid.'.num'};
1.221 bowersj2 2263:
1.133 bowersj2 2264: # ------------------------------------------------- Get coursedata (if present)
1.326 albertel 2265: my $courseopt=&Apache::lonnet::get_courseresdata($cnum,$cdom);
2266: # Check for network failure
2267: if (!ref($courseopt)) {
2268: if ( $courseopt =~ /no.such.host/i || $courseopt =~ /con_lost/i) {
1.324 albertel 2269: $self->{NETWORK_FAILURE} = 1;
1.221 bowersj2 2270: }
1.326 albertel 2271: undef($courseopt);
2272: }
1.325 albertel 2273:
1.133 bowersj2 2274: # --------------------------------------------------- Get userdata (if present)
1.325 albertel 2275:
1.326 albertel 2276: my $useropt=&Apache::lonnet::get_userresdata($uname,$udom);
2277: # Check for network failure
2278: if (!ref($useropt)) {
2279: if ( $useropt =~ /no.such.host/i || $useropt =~ /con_lost/i) {
1.324 albertel 2280: $self->{NETWORK_FAILURE} = 1;
1.221 bowersj2 2281: }
1.326 albertel 2282: undef($useropt);
1.221 bowersj2 2283: }
2284:
1.326 albertel 2285: $self->{COURSE_OPT} = $courseopt;
2286: $self->{USER_OPT} = $useropt;
2287:
1.221 bowersj2 2288: $self->{COURSE_USER_OPT_GENERATED} = 1;
2289:
2290: return;
2291: }
2292:
1.485 foxr 2293:
2294:
1.221 bowersj2 2295: sub generate_email_discuss_status {
2296: my $self = shift;
1.259 raeburn 2297: my $symb = shift;
1.221 bowersj2 2298: if ($self->{EMAIL_DISCUSS_GENERATED}) { return; }
1.133 bowersj2 2299:
1.320 albertel 2300: my $cid=$env{'request.course.id'};
1.326 albertel 2301: my $cdom=$env{'course.'.$cid.'.domain'};
2302: my $cnum=$env{'course.'.$cid.'.num'};
1.221 bowersj2 2303:
1.454 www 2304: my %emailstatus = &Apache::lonnet::dump('email_status',$self->{DOMAIN},$self->{USERNAME});
1.221 bowersj2 2305: my $logoutTime = $emailstatus{'logout'};
1.320 albertel 2306: my $courseLeaveTime = $emailstatus{'logout_'.$env{'request.course.id'}};
1.221 bowersj2 2307: $self->{LAST_CHECK} = (($courseLeaveTime > $logoutTime) ?
2308: $courseLeaveTime : $logoutTime);
2309: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
2310: $cdom, $cnum);
1.259 raeburn 2311: my %lastread = &Apache::lonnet::dump('nohist_'.$cid.'_discuss',
1.453 www 2312: $self->{DOMAIN},$self->{USERNAME},'lastread');
1.259 raeburn 2313: my %lastreadtime = ();
1.504 raeburn 2314: foreach my $key (keys(%lastread)) {
1.394 raeburn 2315: my $shortkey = $key;
2316: $shortkey =~ s/_lastread$//;
2317: $lastreadtime{$shortkey} = $lastread{$key};
1.259 raeburn 2318: }
2319:
1.221 bowersj2 2320: my %feedback=();
2321: my %error=();
1.453 www 2322: my @keys = &Apache::lonnet::getkeys('nohist_email',$self->{DOMAIN},
2323: $self->{USERNAME});
1.221 bowersj2 2324:
1.325 albertel 2325: foreach my $msgid (@keys) {
1.295 albertel 2326: if ((!$emailstatus{$msgid}) || ($emailstatus{$msgid} eq 'new')) {
1.395 raeburn 2327: my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid,
1.509.2.8 raeburn 2328: $symb,$error) = &Apache::lonmsg::unpackmsgid(&LONCAPA::escape($msgid));
1.396 raeburn 2329: &Apache::lonenc::check_decrypt(\$symb);
2330: if (($fromcid ne '') && ($fromcid ne $cid)) {
2331: next;
2332: }
1.395 raeburn 2333: if (defined($symb)) {
2334: if (defined($error) && $error == 1) {
2335: $error{$symb}.=','.$msgid;
2336: } else {
2337: $feedback{$symb}.=','.$msgid;
2338: }
2339: } else {
2340: my $plain=
2341: &LONCAPA::unescape(&LONCAPA::unescape($msgid));
2342: if ($plain=~/ \[([^\]]+)\]\:/) {
2343: my $url=$1;
2344: if ($plain=~/\:Error \[/) {
2345: $error{$url}.=','.$msgid;
2346: } else {
2347: $feedback{$url}.=','.$msgid;
2348: }
2349: }
2350: }
1.221 bowersj2 2351: }
1.211 bowersj2 2352: }
1.221 bowersj2 2353:
1.395 raeburn 2354: #symbs of resources that have feedbacks (will be urls pre-2.3)
1.221 bowersj2 2355: $self->{FEEDBACK} = \%feedback;
1.395 raeburn 2356: #or errors (will be urls pre 2.3)
1.295 albertel 2357: $self->{ERROR_MSG} = \%error;
1.221 bowersj2 2358: $self->{DISCUSSION_TIME} = \%discussiontime;
2359: $self->{EMAIL_STATUS} = \%emailstatus;
1.259 raeburn 2360: $self->{LAST_READ} = \%lastreadtime;
1.221 bowersj2 2361:
2362: $self->{EMAIL_DISCUSS_GENERATED} = 1;
2363: }
2364:
2365: sub get_user_data {
2366: my $self = shift;
2367: if ($self->{RETRIEVED_USER_DATA}) { return; }
1.211 bowersj2 2368:
1.221 bowersj2 2369: # Retrieve performance data on problems
1.320 albertel 2370: my %student_data = Apache::lonnet::currentdump($env{'request.course.id'},
1.453 www 2371: $self->{DOMAIN},
2372: $self->{USERNAME});
1.221 bowersj2 2373: $self->{STUDENT_DATA} = \%student_data;
1.133 bowersj2 2374:
1.221 bowersj2 2375: $self->{RETRIEVED_USER_DATA} = 1;
1.133 bowersj2 2376: }
2377:
1.354 raeburn 2378: sub get_discussion_data {
2379: my $self = shift;
2380: if ($self->{RETRIEVED_DISCUSSION_DATA}) {
1.366 albertel 2381: return $self->{DISCUSSION_DATA};
1.354 raeburn 2382: }
1.366 albertel 2383:
2384: $self->generate_email_discuss_status();
2385:
1.354 raeburn 2386: my $cid=$env{'request.course.id'};
2387: my $cdom=$env{'course.'.$cid.'.domain'};
2388: my $cnum=$env{'course.'.$cid.'.num'};
2389: # Retrieve discussion data for resources in course
1.367 albertel 2390: my %discussion_data = &Apache::lonnet::dumpstore($cid,$cdom,$cnum);
1.366 albertel 2391:
2392:
1.354 raeburn 2393: $self->{DISCUSSION_DATA} = \%discussion_data;
2394: $self->{RETRIEVED_DISCUSSION_DATA} = 1;
2395: return $self->{DISCUSSION_DATA};
2396: }
2397:
2398:
1.133 bowersj2 2399: # Internal function: Takes a key to look up in the nav hash and implements internal
2400: # memory caching of that key.
2401: sub navhash {
2402: my $self = shift; my $key = shift;
2403: return $self->{NAV_HASH}->{$key};
2404: }
2405:
1.217 bowersj2 2406: =pod
2407:
2408: =item * B<courseMapDefined>(): Returns true if the course map is defined,
2409: false otherwise. Undefined course maps indicate an error somewhere in
2410: LON-CAPA, and you will not be able to proceed with using the navmap.
2411: See the B<NAV> screen for an example of using this.
2412:
2413: =cut
2414:
1.133 bowersj2 2415: # Checks to see if coursemap is defined, matching test in old lonnavmaps
2416: sub courseMapDefined {
2417: my $self = shift;
1.320 albertel 2418: my $uri = &Apache::lonnet::clutter($env{'request.course.uri'});
1.133 bowersj2 2419:
2420: my $firstres = $self->navhash("map_start_$uri");
2421: my $lastres = $self->navhash("map_finish_$uri");
2422: return $firstres && $lastres;
2423: }
2424:
2425: sub getIterator {
2426: my $self = shift;
2427: my $iterator = Apache::lonnavmaps::iterator->new($self, shift, shift,
1.314 albertel 2428: shift, undef, shift,
2429: shift, shift);
1.133 bowersj2 2430: return $iterator;
2431: }
2432:
2433: # Private method: Does the given resource (as a symb string) have
2434: # current discussion? Returns 0 if chat/mail data not extracted.
2435: sub hasDiscussion {
2436: my $self = shift;
2437: my $symb = shift;
1.221 bowersj2 2438: $self->generate_email_discuss_status();
2439:
1.133 bowersj2 2440: if (!defined($self->{DISCUSSION_TIME})) { return 0; }
2441:
2442: #return defined($self->{DISCUSSION_TIME}->{$symb});
1.259 raeburn 2443:
1.323 albertel 2444: # backward compatibility (bulletin boards used to be 'wrapped')
2445: my $ressymb = $self->wrap_symb($symb);
1.259 raeburn 2446: if ( defined ( $self->{LAST_READ}->{$ressymb} ) ) {
2447: return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_READ}->{$ressymb};
2448: } else {
1.266 raeburn 2449: # return $self->{DISCUSSION_TIME}->{$ressymb} > $self->{LAST_CHECK}; # v.1.1 behavior
2450: 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 2451: }
1.133 bowersj2 2452: }
2453:
1.366 albertel 2454: sub last_post_time {
2455: my $self = shift;
2456: my $symb = shift;
2457: my $ressymb = $self->wrap_symb($symb);
2458: return $self->{DISCUSSION_TIME}->{$ressymb};
2459: }
2460:
1.393 raeburn 2461: sub discussion_info {
1.366 albertel 2462: my $self = shift;
2463: my $symb = shift;
1.393 raeburn 2464: my $filter = shift;
1.366 albertel 2465:
2466: $self->get_discussion_data();
1.372 raeburn 2467:
1.366 albertel 2468: my $ressymb = $self->wrap_symb($symb);
1.372 raeburn 2469: # keys used to store bulletinboard postings use 'unwrapped' symb.
1.397 albertel 2470: my $discsymb = &escape($self->unwrap_symb($ressymb));
1.372 raeburn 2471: my $version = $self->{DISCUSSION_DATA}{'version:'.$discsymb};
1.366 albertel 2472: if (!$version) { return; }
2473:
2474: my $prevread = $self->{LAST_READ}{$ressymb};
2475:
1.393 raeburn 2476: my $count = 0;
1.366 albertel 2477: my $hiddenflag = 0;
2478: my $deletedflag = 0;
1.393 raeburn 2479: my ($hidden,$deleted,%info);
1.366 albertel 2480:
2481: for (my $id=$version; $id>0; $id--) {
1.372 raeburn 2482: my $vkeys=$self->{DISCUSSION_DATA}{$id.':keys:'.$discsymb};
1.366 albertel 2483: my @keys=split(/:/,$vkeys);
2484: if (grep(/^hidden$/ ,@keys)) {
2485: if (!$hiddenflag) {
1.372 raeburn 2486: $hidden = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':hidden'};
1.366 albertel 2487: $hiddenflag = 1;
2488: }
2489: } elsif (grep(/^deleted$/,@keys)) {
2490: if (!$deletedflag) {
1.372 raeburn 2491: $deleted = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':deleted'};
1.366 albertel 2492: $deletedflag = 1;
2493: }
2494: } else {
1.393 raeburn 2495: if (($hidden !~/\.$id\./) && ($deleted !~/\.$id\./)) {
2496: if ($filter eq 'unread') {
2497: if ($prevread >= $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'}) {
2498: next;
2499: }
2500: }
2501: $count++;
2502: $info{$count}{'subject'} =
2503: $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':subject'};
2504: $info{$count}{'id'} = $id;
2505: $info{$count}{'timestamp'} = $self->{DISCUSSION_DATA}{$id.':'.$discsymb.':timestamp'};
2506: }
1.366 albertel 2507: }
2508: }
2509: if (wantarray) {
1.393 raeburn 2510: return ($count,%info);
1.366 albertel 2511: }
1.393 raeburn 2512: return $count;
1.366 albertel 2513: }
2514:
1.321 raeburn 2515: sub wrap_symb {
1.322 albertel 2516: my $self = shift;
1.321 raeburn 2517: my $symb = shift;
1.373 albertel 2518: if ($symb =~ m-___(adm/[^/]+/[^/]+/)(\d+)(/bulletinboard)$-) {
1.322 albertel 2519: unless ($symb =~ m|adm/wrapper/adm|) {
2520: $symb = 'bulletin___'.$2.'___adm/wrapper/'.$1.$2.$3;
1.321 raeburn 2521: }
2522: }
1.322 albertel 2523: return $symb;
1.321 raeburn 2524: }
2525:
1.372 raeburn 2526: sub unwrap_symb {
2527: my $self = shift;
2528: my $ressymb = shift;
2529: my $discsymb = $ressymb;
1.373 albertel 2530: if ($ressymb =~ m-^(bulletin___\d+___)adm/wrapper/(adm/[^/]+/[^/]+/\d+/bulletinboard)$-) {
1.372 raeburn 2531: $discsymb = $1.$2;
2532: }
2533: return $discsymb;
2534: }
2535:
1.322 albertel 2536: # Private method: Does the given resource (as a symb string) have
2537: # current feedback? Returns the string in the feedback hash, which
2538: # will be false if it does not exist.
2539:
1.133 bowersj2 2540: sub getFeedback {
2541: my $self = shift;
2542: my $symb = shift;
1.395 raeburn 2543: my $source = shift;
1.133 bowersj2 2544:
1.221 bowersj2 2545: $self->generate_email_discuss_status();
2546:
1.133 bowersj2 2547: if (!defined($self->{FEEDBACK})) { return ""; }
2548:
1.395 raeburn 2549: my $feedback;
2550: if ($self->{FEEDBACK}->{$symb}) {
2551: $feedback = $self->{FEEDBACK}->{$symb};
2552: if ($self->{FEEDBACK}->{$source}) {
2553: $feedback .= ','.$self->{FEEDBACK}->{$source};
2554: }
2555: } else {
2556: if ($self->{FEEDBACK}->{$source}) {
2557: $feedback = $self->{FEEDBACK}->{$source};
2558: }
2559: }
2560: return $feedback;
1.133 bowersj2 2561: }
2562:
2563: # Private method: Get the errors for that resource (by source).
2564: sub getErrors {
2565: my $self = shift;
1.395 raeburn 2566: my $symb = shift;
1.133 bowersj2 2567: my $src = shift;
1.221 bowersj2 2568:
2569: $self->generate_email_discuss_status();
2570:
1.133 bowersj2 2571: if (!defined($self->{ERROR_MSG})) { return ""; }
1.395 raeburn 2572:
2573: my $errors;
2574: if ($self->{ERROR_MSG}->{$symb}) {
2575: $errors = $self->{ERROR_MSG}->{$symb};
2576: if ($self->{ERROR_MSG}->{$src}) {
2577: $errors .= ','.$self->{ERROR_MSG}->{$src};
2578: }
2579: } else {
2580: if ($self->{ERROR_MSG}->{$src}) {
2581: $errors = $self->{ERROR_MSG}->{$src};
2582: }
2583: }
2584: return $errors;
1.133 bowersj2 2585: }
2586:
2587: =pod
2588:
1.174 albertel 2589: =item * B<getById>(id):
2590:
2591: Based on the ID of the resource (1.1, 3.2, etc.), get a resource
2592: object for that resource. This method, or other methods that use it
2593: (as in the resource object) is the only proper way to obtain a
2594: resource object.
1.133 bowersj2 2595:
1.194 bowersj2 2596: =item * B<getBySymb>(symb):
2597:
2598: Based on the symb of the resource, get a resource object for that
2599: resource. This is one of the proper ways to get a resource object.
2600:
1.448 raeburn 2601: =item * B<getByMapPc>(map_pc):
1.194 bowersj2 2602:
2603: Based on the map_pc of the resource, get a resource object for
2604: the given map. This is one of the proper ways to get a resource object.
2605:
1.133 bowersj2 2606: =cut
2607:
2608: # The strategy here is to cache the resource objects, and only construct them
2609: # as we use them. The real point is to prevent reading any more from the tied
1.398 banghart 2610: # hash than we have to, which should hopefully alleviate speed problems.
1.133 bowersj2 2611:
2612: sub getById {
2613: my $self = shift;
2614: my $id = shift;
2615:
2616: if (defined ($self->{RESOURCE_CACHE}->{$id}))
2617: {
2618: return $self->{RESOURCE_CACHE}->{$id};
2619: }
2620:
2621: # resource handles inserting itself into cache.
2622: # Not clear why the quotes are necessary, but as of this
2623: # writing it doesn't work without them.
2624: return "Apache::lonnavmaps::resource"->new($self, $id);
1.132 bowersj2 2625: }
1.133 bowersj2 2626:
1.172 bowersj2 2627: sub getBySymb {
2628: my $self = shift;
2629: my $symb = shift;
1.277 matthew 2630:
1.228 albertel 2631: my ($mapUrl, $id, $filename) = &Apache::lonnet::decode_symb($symb);
1.172 bowersj2 2632: my $map = $self->getResourceByUrl($mapUrl);
1.277 matthew 2633: my $returnvalue = undef;
2634: if (ref($map)) {
2635: $returnvalue = $self->getById($map->map_pc() .'.'.$id);
2636: }
2637: return $returnvalue;
1.194 bowersj2 2638: }
2639:
2640: sub getByMapPc {
2641: my $self = shift;
2642: my $map_pc = shift;
2643: my $map_id = $self->{NAV_HASH}->{'map_id_' . $map_pc};
2644: $map_id = $self->{NAV_HASH}->{'ids_' . $map_id};
2645: return $self->getById($map_id);
1.172 bowersj2 2646: }
2647:
1.133 bowersj2 2648: =pod
2649:
1.174 albertel 2650: =item * B<firstResource>():
2651:
2652: Returns a resource object reference corresponding to the first
2653: resource in the navmap.
1.133 bowersj2 2654:
2655: =cut
2656:
2657: sub firstResource {
2658: my $self = shift;
2659: my $firstResource = $self->navhash('map_start_' .
1.320 albertel 2660: &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133 bowersj2 2661: return $self->getById($firstResource);
1.132 bowersj2 2662: }
1.133 bowersj2 2663:
2664: =pod
2665:
1.174 albertel 2666: =item * B<finishResource>():
2667:
2668: Returns a resource object reference corresponding to the last resource
2669: in the navmap.
1.133 bowersj2 2670:
2671: =cut
2672:
2673: sub finishResource {
2674: my $self = shift;
2675: my $firstResource = $self->navhash('map_finish_' .
1.320 albertel 2676: &Apache::lonnet::clutter($env{'request.course.uri'}));
1.133 bowersj2 2677: return $self->getById($firstResource);
1.132 bowersj2 2678: }
1.133 bowersj2 2679:
2680: # Parmval reads the parm hash and cascades the lookups. parmval_real does
2681: # the actual lookup; parmval caches the results.
2682: sub parmval {
2683: my $self = shift;
1.399 albertel 2684: my ($what,$symb,$recurse)=@_;
1.133 bowersj2 2685: my $hashkey = $what."|||".$symb;
1.459 foxr 2686: my $cache = $self->{PARM_CACHE};
1.133 bowersj2 2687: if (defined($self->{PARM_CACHE}->{$hashkey})) {
1.411 raeburn 2688: if (ref($self->{PARM_CACHE}->{$hashkey}) eq 'ARRAY') {
2689: if (defined($self->{PARM_CACHE}->{$hashkey}->[0])) {
2690: if (wantarray) {
2691: return @{$self->{PARM_CACHE}->{$hashkey}};
2692: } else {
2693: return $self->{PARM_CACHE}->{$hashkey}->[0];
2694: }
2695: }
2696: } else {
2697: return $self->{PARM_CACHE}->{$hashkey};
2698: }
1.133 bowersj2 2699: }
1.399 albertel 2700: my $result = $self->parmval_real($what, $symb, $recurse);
1.133 bowersj2 2701: $self->{PARM_CACHE}->{$hashkey} = $result;
1.405 albertel 2702: if (wantarray) {
1.411 raeburn 2703: return @{$result};
1.405 albertel 2704: }
2705: return $result->[0];
1.132 bowersj2 2706: }
2707:
1.485 foxr 2708:
1.133 bowersj2 2709: sub parmval_real {
2710: my $self = shift;
1.219 albertel 2711: my ($what,$symb,$recurse) = @_;
1.133 bowersj2 2712:
1.485 foxr 2713:
1.221 bowersj2 2714: # Make sure the {USER_OPT} and {COURSE_OPT} hashes are populated
2715: $self->generate_course_user_opt();
2716:
1.320 albertel 2717: my $cid=$env{'request.course.id'};
2718: my $csec=$env{'request.course.sec'};
1.350 raeburn 2719: my $cgroup='';
2720: my @cgrps=split(/:/,$env{'request.course.groups'});
2721: if (@cgrps > 0) {
2722: @cgrps = sort(@cgrps);
2723: $cgroup = $cgrps[0];
2724: }
1.453 www 2725: my $uname=$self->{USERNAME};
2726: my $udom=$self->{DOMAIN};
1.133 bowersj2 2727:
1.405 albertel 2728: unless ($symb) { return ['']; }
1.133 bowersj2 2729: my $result='';
2730:
1.226 www 2731: my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
1.383 albertel 2732: $mapname = &Apache::lonnet::deversion($mapname);
1.133 bowersj2 2733: # ----------------------------------------------------- Cascading lookup scheme
2734: my $rwhat=$what;
2735: $what=~s/^parameter\_//;
2736: $what=~s/\_/\./;
2737:
2738: my $symbparm=$symb.'.'.$what;
2739: my $mapparm=$mapname.'___(all).'.$what;
1.325 albertel 2740: my $usercourseprefix=$cid;
1.133 bowersj2 2741:
1.485 foxr 2742:
2743:
1.350 raeburn 2744: my $grplevel=$usercourseprefix.'.['.$cgroup.'].'.$what;
2745: my $grplevelr=$usercourseprefix.'.['.$cgroup.'].'.$symbparm;
2746: my $grplevelm=$usercourseprefix.'.['.$cgroup.'].'.$mapparm;
2747:
1.485 foxr 2748:
1.133 bowersj2 2749: my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
2750: my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
2751: my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
2752:
1.485 foxr 2753:
1.133 bowersj2 2754: my $courselevel= $usercourseprefix.'.'.$what;
2755: my $courselevelr=$usercourseprefix.'.'.$symbparm;
2756: my $courselevelm=$usercourseprefix.'.'.$mapparm;
2757:
1.485 foxr 2758:
1.133 bowersj2 2759: my $useropt = $self->{USER_OPT};
2760: my $courseopt = $self->{COURSE_OPT};
2761: my $parmhash = $self->{PARM_HASH};
2762:
2763: # ---------------------------------------------------------- first, check user
2764: if ($uname and defined($useropt)) {
1.405 albertel 2765: if (defined($$useropt{$courselevelr})) { return [$$useropt{$courselevelr},'resource']; }
2766: if (defined($$useropt{$courselevelm})) { return [$$useropt{$courselevelm},'map']; }
2767: if (defined($$useropt{$courselevel})) { return [$$useropt{$courselevel},'course']; }
1.133 bowersj2 2768: }
2769:
2770: # ------------------------------------------------------- second, check course
1.350 raeburn 2771: if ($cgroup ne '' and defined($courseopt)) {
1.405 albertel 2772: if (defined($$courseopt{$grplevelr})) { return [$$courseopt{$grplevelr},'resource']; }
2773: if (defined($$courseopt{$grplevelm})) { return [$$courseopt{$grplevelm},'map']; }
2774: if (defined($$courseopt{$grplevel})) { return [$$courseopt{$grplevel},'course']; }
1.350 raeburn 2775: }
2776:
1.133 bowersj2 2777: if ($csec and defined($courseopt)) {
1.405 albertel 2778: if (defined($$courseopt{$seclevelr})) { return [$$courseopt{$seclevelr},'resource']; }
2779: if (defined($$courseopt{$seclevelm})) { return [$$courseopt{$seclevelm},'map']; }
2780: if (defined($$courseopt{$seclevel})) { return [$$courseopt{$seclevel},'course']; }
1.133 bowersj2 2781: }
2782:
2783: if (defined($courseopt)) {
1.405 albertel 2784: if (defined($$courseopt{$courselevelr})) { return [$$courseopt{$courselevelr},'resource']; }
1.133 bowersj2 2785: }
2786:
2787: # ----------------------------------------------------- third, check map parms
2788:
2789: my $thisparm=$$parmhash{$symbparm};
1.405 albertel 2790: if (defined($thisparm)) { return [$thisparm,'map']; }
1.133 bowersj2 2791:
2792: # ----------------------------------------------------- fourth , check default
2793:
1.246 albertel 2794: my $meta_rwhat=$rwhat;
2795: $meta_rwhat=~s/\./_/g;
2796: my $default=&Apache::lonnet::metadata($fn,$meta_rwhat);
1.405 albertel 2797: if (defined($default)) { return [$default,'resource']}
1.246 albertel 2798: $default=&Apache::lonnet::metadata($fn,'parameter_'.$meta_rwhat);
1.405 albertel 2799: if (defined($default)) { return [$default,'resource']}
1.315 albertel 2800: # --------------------------------------------------- fifth, check more course
2801: if (defined($courseopt)) {
1.405 albertel 2802: if (defined($$courseopt{$courselevelm})) { return [$$courseopt{$courselevelm},'map']; }
2803: if (defined($$courseopt{$courselevel})) {
2804: my $ret = [$$courseopt{$courselevel},'course'];
2805: return $ret;
2806: }
1.315 albertel 2807: }
2808: # --------------------------------------------------- sixth , cascade up parts
1.133 bowersj2 2809:
2810: my ($space,@qualifier)=split(/\./,$rwhat);
2811: my $qualifier=join('.',@qualifier);
2812: unless ($space eq '0') {
1.160 albertel 2813: my @parts=split(/_/,$space);
2814: my $id=pop(@parts);
2815: my $part=join('_',@parts);
2816: if ($part eq '') { $part='0'; }
1.405 albertel 2817: my @partgeneral=$self->parmval($part.".$qualifier",$symb,1);
2818: if (defined($partgeneral[0])) { return \@partgeneral; }
1.133 bowersj2 2819: }
1.405 albertel 2820: if ($recurse) { return []; }
1.399 albertel 2821: my $pack_def=&Apache::lonnet::packages_tab_default($fn,'resource.'.$rwhat);
1.405 albertel 2822: if (defined($pack_def)) { return [$pack_def,'resource']; }
2823: return [''];
1.145 bowersj2 2824: }
1.509.2.5 raeburn 2825:
2826: sub recurseup_maps {
2827: my ($self,$mapname) = @_;
2828: my @recurseup;
2829: if ($mapname) {
2830: my $res = $self->getResourceByUrl($mapname);
2831: if (ref($res)) {
2832: my @pcs = split(/,/,$res->map_hierarchy());
2833: shift(@pcs);
2834: if (@pcs) {
2835: @recurseup = map { &Apache::lonnet::declutter($self->getByMapPc($_)->src()); } reverse(@pcs);
2836: }
2837: }
2838: }
2839: return @recurseup;
2840: }
2841:
1.509.2.10 raeburn 2842: sub recursed_crumbs {
2843: my ($self,$mapurl,$restitle) = @_;
2844: my (@revmapinfo,@revmapres);
2845: my $mapres = $self->getResourceByUrl($mapurl);
2846: if (ref($mapres)) {
2847: @revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs());
2848: shift(@revmapres);
2849: }
2850: my $allowedlength = 60;
2851: my $minlength = 5;
2852: my $allowedtitle = 30;
2853: if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) {
2854: $allowedlength = 100;
2855: $allowedtitle = 70;
2856: }
2857: if (length($restitle) > $allowedtitle) {
2858: $restitle = &truncate_crumb_text($restitle,$allowedtitle);
2859: }
2860: my $totallength = length($restitle);
2861: my @links;
2862:
2863: foreach my $map (@revmapres) {
2864: my $pc = $map->map_pc();
2865: next if ((!$pc) || ($pc == 1));
2866: push(@links,$map);
1.509.2.11 raeburn 2867: push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,});
1.509.2.10 raeburn 2868: $totallength += length($map->title());
2869: }
2870: my $numlinks = scalar(@links);
2871: if ($numlinks) {
2872: if ($totallength - $allowedlength > 0) {
2873: my $available = $allowedlength - length($restitle);
2874: my $avg = POSIX::ceil($available/$numlinks);
2875: if ($avg < $minlength) {
2876: $avg = $minlength;
2877: }
2878: @revmapinfo = ();
2879: foreach my $map (@links) {
2880: my $showntitle = &truncate_crumb_text($map->title(),$avg);
2881: if ($showntitle ne '') {
1.509.2.11 raeburn 2882: push(@revmapinfo,{'href' => $env{'request.use_absolute'}.$map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,});
1.509.2.10 raeburn 2883: }
2884: }
2885: }
2886: }
2887: if ($restitle ne '') {
2888: push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1});
2889: }
2890: return @revmapinfo;
2891: }
2892:
2893: sub truncate_crumb_text {
2894: my ($title,$limit) = @_;
2895: my $showntitle = '';
2896: if (length($title) > $limit) {
2897: my @words = split(/\b\s*/,$title);
2898: if (@words == 1) {
2899: $showntitle = substr($title,0,$limit).' ...';
2900: } else {
2901: my $linklength = 0;
2902: my $num = 0;
2903: foreach my $word (@words) {
2904: $linklength += 1+length($word);
2905: if ($word eq '-') {
2906: $showntitle =~ s/ $//;
2907: $showntitle .= $word;
2908: } elsif ($linklength > $limit) {
2909: if ($num < @words) {
2910: $showntitle .= $word.' ...';
2911: last;
2912: } else {
2913: $showntitle .= $word;
2914: }
2915: } else {
2916: $showntitle .= $word.' ';
2917: }
2918: }
2919: $showntitle =~ s/ $//;
2920: }
2921: return $showntitle;
2922: } else {
2923: return $title;
2924: }
2925: }
2926:
1.485 foxr 2927: #
2928: # Determines the open/close dates for printing a map that
2929: # encloses a resource.
2930: #
2931: sub map_printdates {
2932: my ($self, $res, $part) = @_;
2933:
2934:
2935:
2936:
2937:
1.509.2.3 raeburn 2938: my $opendate = $self->get_mapparam($res->symb(),'',"$part.printstartdate");
2939: my $closedate= $self->get_mapparam($res->symb(),'', "$part.printenddate");
1.485 foxr 2940:
2941:
2942: return ($opendate, $closedate);
2943: }
2944:
2945: sub get_mapparam {
1.509.2.3 raeburn 2946: my ($self, $symb, $mapname, $what) = @_;
1.485 foxr 2947:
2948: # Ensure the course option hash is populated:
2949:
2950: $self->generate_course_user_opt();
2951:
2952: # Get the course id and section if there is one.
2953:
2954: my $cid=$env{'request.course.id'};
2955: my $csec=$env{'request.course.sec'};
2956: my $cgroup='';
2957: my @cgrps=split(/:/,$env{'request.course.groups'});
2958: if (@cgrps > 0) {
2959: @cgrps = sort(@cgrps);
2960: $cgroup = $cgrps[0];
2961: }
2962: my $uname=$self->{USERNAME};
2963: my $udom=$self->{DOMAIN};
2964:
1.509.2.3 raeburn 2965: unless ($symb || $mapname) { return; }
1.485 foxr 2966: my $result='';
1.509.2.3 raeburn 2967: my ($recursed,@recurseup);
1.485 foxr 2968:
2969: # Figure out which map we are in.
2970:
1.509.2.3 raeburn 2971: if ($symb && !$mapname) {
2972: my ($id,$fn);
2973: ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
2974: $mapname = &Apache::lonnet::deversion($mapname);
2975: }
1.485 foxr 2976:
2977: my $rwhat=$what;
2978: $what=~s/^parameter\_//;
2979: $what=~s/\_/\./;
2980:
2981: # Build the hash keys for the lookup:
2982:
2983: my $symbparm=$symb.'.'.$what;
2984: my $mapparm=$mapname.'___(all).'.$what;
2985: my $usercourseprefix=$cid;
2986:
2987:
2988: my $grplevel = "$usercourseprefix.[$cgroup].$mapparm";
2989: my $seclevel = "$usercourseprefix.[$csec].$mapparm";
2990: my $courselevel = "$usercourseprefix.$mapparm";
2991:
2992:
2993: # Get handy references to the hashes we need in $self:
2994:
2995: my $useropt = $self->{USER_OPT};
2996: my $courseopt = $self->{COURSE_OPT};
2997: my $parmhash = $self->{PARM_HASH};
2998:
2999: # Check per user
3000:
3001:
3002:
3003: if ($uname and defined($useropt)) {
3004: if (defined($$useropt{$courselevel})) {
3005: return $$useropt{$courselevel};
3006: }
1.509.2.5 raeburn 3007: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3008: unless ($recursed) {
3009: @recurseup = $self->recurseup_maps($mapname);
3010: $recursed = 1;
3011: }
3012: foreach my $item (@recurseup) {
3013: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
3014: if (defined($$useropt{$norecursechk})) {
3015: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3016: return $$useropt{$norecursechk};
3017: }
3018: }
3019: }
3020: }
1.485 foxr 3021: }
3022:
3023: # Check course -- group
3024:
3025:
3026:
3027: if ($cgroup ne '' and defined ($courseopt)) {
3028: if (defined($$courseopt{$grplevel})) {
3029: return $$courseopt{$grplevel};
3030: }
1.509.2.5 raeburn 3031: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3032: unless ($recursed) {
3033: @recurseup = $self->recurseup_maps($mapname);
3034: $recursed = 1;
3035: }
3036: foreach my $item (@recurseup) {
3037: my $norecursechk=$usercourseprefix.'.['.$cgroup.'].'.$item.'___(all).'.$what;
3038: if (defined($$courseopt{$norecursechk})) {
3039: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3040: return $$courseopt{$norecursechk};
3041: }
3042: }
3043: }
3044: }
1.485 foxr 3045: }
3046:
3047: # Check course -- section
3048:
3049:
3050:
3051:
3052:
3053: if ($csec and defined($courseopt)) {
3054: if (defined($$courseopt{$seclevel})) {
3055: return $$courseopt{$seclevel};
3056: }
1.509.2.5 raeburn 3057: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3058: unless ($recursed) {
3059: @recurseup = $self->recurseup_maps($mapname);
3060: $recursed = 1;
3061: }
3062: foreach my $item (@recurseup) {
3063: my $norecursechk=$usercourseprefix.'.['.$csec.'].'.$item.'___(all).'.$what;
3064: if (defined($$courseopt{$norecursechk})) {
3065: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3066: return $$courseopt{$norecursechk};
3067: }
3068: }
3069: }
3070: }
1.485 foxr 3071: }
3072: # Check the map parameters themselves:
3073:
1.509.2.3 raeburn 3074: if ($symb) {
3075: my $symbparm=$symb.'.'.$what;
3076: my $thisparm = $$parmhash{$symbparm};
3077: if (defined($thisparm)) {
3078: return $thisparm;
3079: }
1.485 foxr 3080: }
3081:
3082:
3083: # Additional course parameters:
3084:
3085: if (defined($courseopt)) {
3086: if (defined($$courseopt{$courselevel})) {
3087: return $$courseopt{$courselevel};
3088: }
1.509.2.5 raeburn 3089: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3090: unless ($recursed) {
3091: @recurseup = $self->recurseup_maps($mapname);
3092: $recursed = 1;
3093: }
3094: foreach my $item (@recurseup) {
3095: my $norecursechk=$usercourseprefix.'.'.$item.'___(all).'.$what;
3096: if (defined($$courseopt{$norecursechk})) {
3097: if ($what =~ /\.(encrypturl|hiddenresource)$/) {
3098: return $$courseopt{$norecursechk};
3099: }
3100: }
3101: }
3102: }
1.485 foxr 3103: }
3104: return undef; # Unefined if we got here.
3105: }
3106:
3107: sub course_printdates {
3108: my ($self, $symb, $part) = @_;
3109:
3110:
3111: my $opendate = $self->getcourseparam($symb, $part . '.printstartdate');
3112: my $closedate = $self->getcourseparam($symb, $part . '.printenddate');
3113: return ($opendate, $closedate);
3114:
3115: }
3116:
3117: sub getcourseparam {
3118: my ($self, $symb, $what) = @_;
3119:
3120: $self->generate_course_user_opt(); # If necessary populate the hashes.
3121:
3122: my $uname = $self->{USERNAME};
3123: my $udom = $self->{DOMAIN};
3124:
3125: # Course, section, group ids come from the env:
3126:
3127: my $cid = $env{'request.course.id'};
3128: my $csec = $env{'request.course.sec'};
3129: my $cgroup = ''; # Assume no group
3130:
3131: my @cgroups = split(/:/, $env{'request.course.groups'});
3132: if(@cgroups > 0) {
3133: @cgroups = sort(@cgroups);
3134: $cgroup = $cgroups[0]; # There is a course group.
3135: }
3136: my ($mapname,$id,$fn)=&Apache::lonnet::decode_symb($symb);
3137: $mapname = &Apache::lonnet::deversion($mapname);
3138:
3139: #
3140: # Make the various lookup keys:
3141: #
3142:
3143: $what=~s/^parameter\_//;
3144: $what=~s/\_/\./;
3145:
3146:
3147: my $symbparm = $symb . '.' . $what;
3148: my $mapparm=$mapname.'___(all).'.$what;
3149:
3150: # Local refs to the hashes we're going to look at:
3151:
3152: my $useropt = $self->{USER_OPT};
3153: my $courseopt = $self->{COURSE_OPT};
3154:
3155: #
3156: # We want the course level stuff from the way
3157: # parmval_real operates
1.509.2.1 raeburn 3158: # TODO: Factor some of this stuff out of
1.485 foxr 3159: # both parmval_real and here
3160: #
3161: my $courselevel = $cid . '.' . $what;
3162: my $grplevel = $cid . '.[' . $cgroup . ']' . $what;
3163: my $seclevel = $cid . '.[' . $csec . ']' . $what;
3164:
3165:
3166: # Try for the user's course level option:
3167:
3168: if ($uname and defined($useropt)) {
3169: if (defined($$useropt{$courselevel})) {
3170: return $$useropt{$courselevel};
3171: }
3172: }
3173: # Try for the group's course level option:
3174:
1.509.2.1 raeburn 3175: if ($cgroup ne '' and defined($courseopt)) {
1.485 foxr 3176: if (defined($$courseopt{$grplevel})) {
3177: return $$courseopt{$grplevel};
3178: }
3179: }
3180:
3181: # Try for section level parameters:
3182:
1.509.2.1 raeburn 3183: if ($csec ne '' and defined($courseopt)) {
1.485 foxr 3184: if (defined($$courseopt{$seclevel})) {
3185: return $$courseopt{$seclevel};
3186: }
3187: }
1.509.2.1 raeburn 3188: # Try for 'additional' course parameters:
1.485 foxr 3189:
3190: if (defined($courseopt)) {
3191: if (defined($$courseopt{$courselevel})) {
3192: return $$courseopt{$courselevel};
3193: }
3194: }
3195: return undef;
3196:
3197: }
3198:
1.145 bowersj2 3199:
1.174 albertel 3200: =pod
1.145 bowersj2 3201:
1.352 raeburn 3202: =item * B<getResourceByUrl>(url,multiple):
1.145 bowersj2 3203:
1.352 raeburn 3204: Retrieves a resource object by URL of the resource, unless the optional
1.398 banghart 3205: multiple parameter is included in which case an array of resource
1.352 raeburn 3206: objects is returned. If passed a resource object, it will simply return
3207: it, so it is safe to use this method in code like
3208: "$res = $navmap->getResourceByUrl($res)"
3209: if you're not sure if $res is already an object, or just a URL. If the
3210: resource appears multiple times in the course, only the first instance
3211: will be returned (useful for maps), unless the multiple parameter has
3212: been included, in which case all instances are returned in an array.
1.174 albertel 3213:
1.505 raeburn 3214: =item * B<retrieveResources>(map, filterFunc, recursive, bailout, showall, noblockcheck):
1.174 albertel 3215:
3216: The map is a specification of a map to retreive the resources from,
3217: either as a url or as an object. The filterFunc is a reference to a
3218: function that takes a resource object as its one argument and returns
3219: true if the resource should be included, or false if it should not
3220: be. If recursive is true, the map will be recursively examined,
3221: otherwise it will not be. If bailout is true, the function will return
1.314 albertel 3222: as soon as it finds a resource, if false it will finish. If showall is
1.505 raeburn 3223: true it will not hide maps that contain nothing but one other map. The
3224: noblockcheck arg is propagated to become the sixth arg in the call to
3225: lonnet::allowed when checking a resource's availability during collection
3226: of resources using the iterator. noblockcheck needs to be true if
3227: retrieveResources() was called by a routine that itself was called by
3228: lonnet::allowed, in order to avoid recursion. By default the map
3229: is the top-level map of the course, filterFunc is a function that
3230: always returns 1, recursive is true, bailout is false, showall is
3231: false. The resources will be returned in a list containing the
3232: resource objects for the corresponding resources, with B<no structure
3233: information> in the list; regardless of branching, recursion, etc.,
3234: it will be a flat list.
1.174 albertel 3235:
3236: Thus, this is suitable for cases where you don't want the structure,
3237: just a list of all resources. It is also suitable for finding out how
3238: many resources match a given description; for this use, if all you
3239: want to know is if I<any> resources match the description, the bailout
3240: parameter will allow you to avoid potentially expensive enumeration of
3241: all matching resources.
1.145 bowersj2 3242:
1.318 albertel 3243: =item * B<hasResource>(map, filterFunc, recursive, showall):
1.145 bowersj2 3244:
1.398 banghart 3245: Convenience method for
1.146 bowersj2 3246:
1.318 albertel 3247: scalar(retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0
1.146 bowersj2 3248:
1.174 albertel 3249: which will tell whether the map has resources matching the description
3250: in the filter function.
1.146 bowersj2 3251:
1.352 raeburn 3252: =item * B<usedVersion>(url):
3253:
3254: Retrieves version infomation for a url. Returns the version (a number, or
3255: the string "mostrecent") for resources which have version information in
3256: the big hash.
1.448 raeburn 3257:
1.145 bowersj2 3258: =cut
3259:
1.277 matthew 3260:
1.145 bowersj2 3261: sub getResourceByUrl {
3262: my $self = shift;
3263: my $resUrl = shift;
1.352 raeburn 3264: my $multiple = shift;
1.145 bowersj2 3265:
3266: if (ref($resUrl)) { return $resUrl; }
3267:
3268: $resUrl = &Apache::lonnet::clutter($resUrl);
3269: my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
1.352 raeburn 3270: if (!$resId) { return ''; }
3271: if ($multiple) {
3272: my @resources = ();
3273: my @resIds = split (/,/, $resId);
3274: foreach my $id (@resIds) {
1.353 raeburn 3275: my $resourceId = $self->getById($id);
3276: if ($resourceId) {
3277: push(@resources,$resourceId);
1.352 raeburn 3278: }
3279: }
3280: return @resources;
3281: } else {
3282: if ($resId =~ /,/) {
3283: $resId = (split (/,/, $resId))[0];
3284: }
3285: return $self->getById($resId);
1.145 bowersj2 3286: }
3287: }
3288:
3289: sub retrieveResources {
3290: my $self = shift;
3291: my $map = shift;
3292: my $filterFunc = shift;
3293: if (!defined ($filterFunc)) {
3294: $filterFunc = sub {return 1;};
3295: }
3296: my $recursive = shift;
3297: if (!defined($recursive)) { $recursive = 1; }
3298: my $bailout = shift;
3299: if (!defined($bailout)) { $bailout = 0; }
1.314 albertel 3300: my $showall = shift;
1.506 raeburn 3301: my $noblockcheck = shift;
1.145 bowersj2 3302: # Create the necessary iterator.
3303: if (!ref($map)) { # assume it's a url of a map.
1.172 bowersj2 3304: $map = $self->getResourceByUrl($map);
1.145 bowersj2 3305: }
3306:
1.213 bowersj2 3307: # If nothing was passed, assume top-level map
3308: if (!$map) {
3309: $map = $self->getById('0.0');
3310: }
3311:
1.145 bowersj2 3312: # Check the map's validity.
1.213 bowersj2 3313: if (!$map->is_map()) {
1.145 bowersj2 3314: # Oh, to throw an exception.... how I'd love that!
3315: return ();
3316: }
3317:
1.146 bowersj2 3318: # Get an iterator.
3319: my $it = $self->getIterator($map->map_start(), $map->map_finish(),
1.314 albertel 3320: undef, $recursive, $showall);
1.146 bowersj2 3321:
3322: my @resources = ();
3323:
1.400 albertel 3324: if (&$filterFunc($map)) {
3325: push(@resources, $map);
3326: }
3327:
1.146 bowersj2 3328: # Run down the iterator and collect the resources.
1.222 bowersj2 3329: my $curRes;
3330:
1.505 raeburn 3331: while ($curRes = $it->next(undef,$noblockcheck)) {
1.146 bowersj2 3332: if (ref($curRes)) {
3333: if (!&$filterFunc($curRes)) {
3334: next;
3335: }
3336:
1.400 albertel 3337: push(@resources, $curRes);
1.146 bowersj2 3338:
3339: if ($bailout) {
3340: return @resources;
3341: }
3342: }
3343:
3344: }
3345:
3346: return @resources;
3347: }
3348:
3349: sub hasResource {
3350: my $self = shift;
3351: my $map = shift;
3352: my $filterFunc = shift;
3353: my $recursive = shift;
1.318 albertel 3354: my $showall = shift;
1.146 bowersj2 3355:
1.318 albertel 3356: return scalar($self->retrieveResources($map, $filterFunc, $recursive, 1, $showall)) > 0;
1.133 bowersj2 3357: }
1.51 bowersj2 3358:
1.352 raeburn 3359: sub usedVersion {
3360: my $self = shift;
3361: my $linkurl = shift;
3362: return $self->navhash("version_$linkurl");
3363: }
3364:
1.51 bowersj2 3365: 1;
3366:
3367: package Apache::lonnavmaps::iterator;
1.365 albertel 3368: use Scalar::Util qw(weaken);
1.320 albertel 3369: use Apache::lonnet;
3370:
1.51 bowersj2 3371: =pod
3372:
3373: =back
3374:
1.174 albertel 3375: =head1 Object: navmap Iterator
1.51 bowersj2 3376:
1.174 albertel 3377: An I<iterator> encapsulates the logic required to traverse a data
3378: structure. navmap uses an iterator to traverse the course map
3379: according to the criteria you wish to use.
3380:
3381: To obtain an iterator, call the B<getIterator>() function of a
3382: B<navmap> object. (Do not instantiate Apache::lonnavmaps::iterator
3383: directly.) This will return a reference to the iterator:
1.51 bowersj2 3384:
3385: C<my $resourceIterator = $navmap-E<gt>getIterator();>
3386:
3387: To get the next thing from the iterator, call B<next>:
3388:
3389: C<my $nextThing = $resourceIterator-E<gt>next()>
3390:
3391: getIterator behaves as follows:
3392:
3393: =over 4
3394:
1.174 albertel 3395: =item * B<getIterator>(firstResource, finishResource, filterHash, condition, forceTop, returnTopMap):
3396:
3397: All parameters are optional. firstResource is a resource reference
3398: corresponding to where the iterator should start. It defaults to
3399: navmap->firstResource() for the corresponding nav map. finishResource
3400: corresponds to where you want the iterator to end, defaulting to
3401: navmap->finishResource(). filterHash is a hash used as a set
3402: containing strings representing the resource IDs, defaulting to
3403: empty. Condition is a 1 or 0 that sets what to do with the filter
1.205 bowersj2 3404: hash: If a 0, then only resources that exist IN the filterHash will be
1.174 albertel 3405: recursed on. If it is a 1, only resources NOT in the filterHash will
3406: be recursed on. Defaults to 0. forceTop is a boolean value. If it is
3407: false (default), the iterator will only return the first level of map
3408: that is not just a single, 'redirecting' map. If true, the iterator
3409: will return all information, starting with the top-level map,
3410: regardless of content. returnTopMap, if true (default false), will
3411: cause the iterator to return the top-level map object (resource 0.0)
3412: before anything else.
3413:
3414: Thus, by default, only top-level resources will be shown. Change the
3415: condition to a 1 without changing the hash, and all resources will be
3416: shown. Changing the condition to 1 and including some values in the
3417: hash will allow you to selectively suppress parts of the navmap, while
3418: leaving it on 0 and adding things to the hash will allow you to
3419: selectively add parts of the nav map. See the handler code for
3420: examples.
3421:
3422: The iterator will return either a reference to a resource object, or a
3423: token representing something in the map, such as the beginning of a
3424: new branch. The possible tokens are:
3425:
3426: =over 4
1.51 bowersj2 3427:
1.222 bowersj2 3428: =item * B<END_ITERATOR>:
3429:
3430: The iterator has returned all that it's going to. Further calls to the
3431: iterator will just produce more of these. This is a "false" value, and
3432: is the only false value the iterator which will be returned, so it can
3433: be used as a loop sentinel.
3434:
1.217 bowersj2 3435: =item * B<BEGIN_MAP>:
1.51 bowersj2 3436:
1.174 albertel 3437: A new map is being recursed into. This is returned I<after> the map
3438: resource itself is returned.
1.51 bowersj2 3439:
1.217 bowersj2 3440: =item * B<END_MAP>:
1.174 albertel 3441:
3442: The map is now done.
1.51 bowersj2 3443:
1.217 bowersj2 3444: =item * B<BEGIN_BRANCH>:
1.70 bowersj2 3445:
1.174 albertel 3446: A branch is now starting. The next resource returned will be the first
3447: in that branch.
1.70 bowersj2 3448:
1.217 bowersj2 3449: =item * B<END_BRANCH>:
1.70 bowersj2 3450:
1.174 albertel 3451: The branch is now done.
1.51 bowersj2 3452:
3453: =back
3454:
1.174 albertel 3455: The tokens are retreivable via methods on the iterator object, i.e.,
3456: $iterator->END_MAP.
1.70 bowersj2 3457:
1.174 albertel 3458: Maps can contain empty resources. The iterator will automatically skip
3459: over such resources, but will still treat the structure
3460: correctly. Thus, a complicated map with several branches, but
3461: consisting entirely of empty resources except for one beginning or
3462: ending resource, will cause a lot of BRANCH_STARTs and BRANCH_ENDs,
3463: but only one resource will be returned.
1.116 bowersj2 3464:
1.242 matthew 3465: =back
3466:
1.222 bowersj2 3467: =head2 Normal Usage
3468:
3469: Normal usage of the iterator object is to do the following:
3470:
3471: my $it = $navmap->getIterator([your params here]);
3472: my $curRes;
3473: while ($curRes = $it->next()) {
3474: [your logic here]
3475: }
3476:
3477: Note that inside of the loop, it's frequently useful to check if
3478: "$curRes" is a reference or not with the reference function; only
3479: resource objects will be references, and any non-references will
3480: be the tokens described above.
3481:
1.505 raeburn 3482: The next() routine can take two (optional) arguments:
3483: closeAllPages - if true will not recurse down a .page
3484: noblockcheck - passed to browsePriv() for passing as sixth arg to
3485: call to lonnet::allowed. This needs to be set if retrieveResources
3486: was already called from another routine called within lonnet::allowed,
3487: so as to prevent recursion.
3488:
1.506 raeburn 3489: Also note there is some old code floating around that tries to track
1.222 bowersj2 3490: the depth of the iterator to see when it's done; do not copy that
1.398 banghart 3491: code. It is difficult to get right and harder to understand than
1.222 bowersj2 3492: this. They should be migrated to this new style.
1.51 bowersj2 3493:
3494: =cut
3495:
3496: # Here are the tokens for the iterator:
3497:
1.222 bowersj2 3498: sub END_ITERATOR { return 0; }
1.51 bowersj2 3499: sub BEGIN_MAP { return 1; } # begining of a new map
3500: sub END_MAP { return 2; } # end of the map
3501: sub BEGIN_BRANCH { return 3; } # beginning of a branch
3502: sub END_BRANCH { return 4; } # end of a branch
1.89 bowersj2 3503: sub FORWARD { return 1; } # go forward
3504: sub BACKWARD { return 2; }
1.51 bowersj2 3505:
1.96 bowersj2 3506: sub min {
3507: (my $a, my $b) = @_;
3508: if ($a < $b) { return $a; } else { return $b; }
3509: }
3510:
1.94 bowersj2 3511: sub new {
3512: # magic invocation to create a class instance
3513: my $proto = shift;
3514: my $class = ref($proto) || $proto;
3515: my $self = {};
3516:
1.300 albertel 3517: weaken($self->{NAV_MAP} = shift);
1.94 bowersj2 3518: return undef unless ($self->{NAV_MAP});
3519:
1.454 www 3520: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
3521: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
3522:
1.94 bowersj2 3523: # Handle the parameters
3524: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
3525: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
3526:
3527: # If the given resources are just the ID of the resource, get the
3528: # objects
3529: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
3530: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
3531: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
3532: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
3533:
3534: $self->{FILTER} = shift;
3535:
3536: # A hash, used as a set, of resource already seen
3537: $self->{ALREADY_SEEN} = shift;
3538: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
3539: $self->{CONDITION} = shift;
3540:
1.116 bowersj2 3541: # Do we want to automatically follow "redirection" maps?
3542: $self->{FORCE_TOP} = shift;
3543:
1.162 bowersj2 3544: # Do we want to return the top-level map object (resource 0.0)?
3545: $self->{RETURN_0} = shift;
3546: # have we done that yet?
3547: $self->{HAVE_RETURNED_0} = 0;
3548:
1.94 bowersj2 3549: # Now, we need to pre-process the map, by walking forward and backward
3550: # over the parts of the map we're going to look at.
1.96 bowersj2 3551:
1.97 bowersj2 3552: # The processing steps are exactly the same, except for a few small
3553: # changes, so I bundle those up in the following list of two elements:
3554: # (direction_to_iterate, VAL_name, next_resource_method_to_call,
3555: # first_resource).
3556: # This prevents writing nearly-identical code twice.
3557: my @iterations = ( [FORWARD(), 'TOP_DOWN_VAL', 'getNext',
3558: 'FIRST_RESOURCE'],
3559: [BACKWARD(), 'BOT_UP_VAL', 'getPrevious',
3560: 'FINISH_RESOURCE'] );
3561:
1.98 bowersj2 3562: my $maxDepth = 0; # tracks max depth
3563:
1.116 bowersj2 3564: # If there is only one resource in this map, and it's a map, we
3565: # want to remember that, so the user can ask for the first map
3566: # that isn't just a redirector.
3567: my $resource; my $resourceCount = 0;
3568:
1.209 bowersj2 3569: # Documentation on this algorithm can be found in the CVS repository at
3570: # /docs/lonnavdocs; these "**#**" markers correspond to documentation
3571: # in that file.
1.107 bowersj2 3572: # **1**
3573:
1.97 bowersj2 3574: foreach my $pass (@iterations) {
3575: my $direction = $pass->[0];
3576: my $valName = $pass->[1];
3577: my $nextResourceMethod = $pass->[2];
3578: my $firstResourceName = $pass->[3];
3579:
3580: my $iterator = Apache::lonnavmaps::DFSiterator->new($self->{NAV_MAP},
3581: $self->{FIRST_RESOURCE},
3582: $self->{FINISH_RESOURCE},
3583: {}, undef, 0, $direction);
1.96 bowersj2 3584:
1.97 bowersj2 3585: # prime the recursion
3586: $self->{$firstResourceName}->{DATA}->{$valName} = 0;
1.222 bowersj2 3587: $iterator->next();
1.97 bowersj2 3588: my $curRes = $iterator->next();
1.222 bowersj2 3589: my $depth = 1;
3590: while ($depth > 0) {
3591: if ($curRes == $iterator->BEGIN_MAP()) { $depth++; }
3592: if ($curRes == $iterator->END_MAP()) { $depth--; }
3593:
1.97 bowersj2 3594: if (ref($curRes)) {
1.116 bowersj2 3595: # If there's only one resource, this will save it
1.117 bowersj2 3596: # we have to filter empty resources from consideration here,
3597: # or even "empty", redirecting maps have two (start & finish)
3598: # or three (start, finish, plus redirector)
3599: if($direction == FORWARD && $curRes->src()) {
3600: $resource = $curRes; $resourceCount++;
3601: }
1.97 bowersj2 3602: my $resultingVal = $curRes->{DATA}->{$valName};
3603: my $nextResources = $curRes->$nextResourceMethod();
1.116 bowersj2 3604: my $nextCount = scalar(@{$nextResources});
1.104 bowersj2 3605:
1.116 bowersj2 3606: if ($nextCount == 1) { # **3**
1.97 bowersj2 3607: my $current = $nextResources->[0]->{DATA}->{$valName} || 999999999;
3608: $nextResources->[0]->{DATA}->{$valName} = min($resultingVal, $current);
3609: }
3610:
1.116 bowersj2 3611: if ($nextCount > 1) { # **4**
1.97 bowersj2 3612: foreach my $res (@{$nextResources}) {
3613: my $current = $res->{DATA}->{$valName} || 999999999;
3614: $res->{DATA}->{$valName} = min($current, $resultingVal + 1);
3615: }
3616: }
3617: }
1.96 bowersj2 3618:
1.107 bowersj2 3619: # Assign the final val (**2**)
1.97 bowersj2 3620: if (ref($curRes) && $direction == BACKWARD()) {
1.98 bowersj2 3621: my $finalDepth = min($curRes->{DATA}->{TOP_DOWN_VAL},
3622: $curRes->{DATA}->{BOT_UP_VAL});
3623:
3624: $curRes->{DATA}->{DISPLAY_DEPTH} = $finalDepth;
3625: if ($finalDepth > $maxDepth) {$maxDepth = $finalDepth;}
1.190 bowersj2 3626: }
1.222 bowersj2 3627:
3628: $curRes = $iterator->next();
1.96 bowersj2 3629: }
3630: }
1.94 bowersj2 3631:
1.116 bowersj2 3632: # Check: Was this only one resource, a map?
1.255 albertel 3633: if ($resourceCount == 1 && $resource->is_sequence() && !$self->{FORCE_TOP}) {
1.116 bowersj2 3634: my $firstResource = $resource->map_start();
3635: my $finishResource = $resource->map_finish();
1.500 raeburn 3636: return Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
3637: $finishResource, $self->{FILTER},
3638: $self->{ALREADY_SEEN},
3639: $self->{CONDITION},
3640: $self->{FORCE_TOP});
1.116 bowersj2 3641: }
3642:
1.98 bowersj2 3643: # Set up some bookkeeping information.
3644: $self->{CURRENT_DEPTH} = 0;
3645: $self->{MAX_DEPTH} = $maxDepth;
3646: $self->{STACK} = [];
3647: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
1.222 bowersj2 3648: $self->{FINISHED} = 0; # When true, the iterator has finished
1.98 bowersj2 3649:
3650: for (my $i = 0; $i <= $self->{MAX_DEPTH}; $i++) {
3651: push @{$self->{STACK}}, [];
3652: }
3653:
1.107 bowersj2 3654: # Prime the recursion w/ the first resource **5**
1.98 bowersj2 3655: push @{$self->{STACK}->[0]}, $self->{FIRST_RESOURCE};
3656: $self->{ALREADY_SEEN}->{$self->{FIRST_RESOURCE}->{ID}} = 1;
3657:
3658: bless ($self);
3659: return $self;
3660: }
3661:
3662: sub next {
3663: my $self = shift;
1.256 albertel 3664: my $closeAllPages=shift;
1.505 raeburn 3665: my $noblockcheck = shift;
1.222 bowersj2 3666: if ($self->{FINISHED}) {
3667: return END_ITERATOR();
3668: }
3669:
1.162 bowersj2 3670: # If we want to return the top-level map object, and haven't yet,
3671: # do so.
3672: if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0}) {
3673: $self->{HAVE_RETURNED_0} = 1;
1.470 foxr 3674: my $nextTopLevel = $self->{NAV_MAP}->getById('0.0');
1.162 bowersj2 3675: return $self->{NAV_MAP}->getById('0.0');
3676: }
1.401 albertel 3677: if ($self->{RETURN_0} && !$self->{HAVE_RETURNED_0_BEGIN_MAP}) {
3678: $self->{HAVE_RETURNED_0_BEGIN_MAP} = 1;
3679: return $self->BEGIN_MAP();
3680: }
1.98 bowersj2 3681:
3682: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3683: # grab the next from the recursive iterator
1.256 albertel 3684: my $next = $self->{RECURSIVE_ITERATOR}->next($closeAllPages);
1.98 bowersj2 3685:
3686: # is it a begin or end map? If so, update the depth
3687: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
3688: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
3689:
3690: # Are we back at depth 0? If so, stop recursing
3691: if ($self->{RECURSIVE_DEPTH} == 0) {
3692: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3693: }
3694: return $next;
3695: }
3696:
3697: if (defined($self->{FORCE_NEXT})) {
3698: my $tmp = $self->{FORCE_NEXT};
3699: $self->{FORCE_NEXT} = undef;
3700: return $tmp;
3701: }
3702:
3703: # Have we not yet begun? If not, return BEGIN_MAP and
3704: # remember we've started.
3705: if ( !$self->{STARTED} ) {
3706: $self->{STARTED} = 1;
3707: return $self->BEGIN_MAP();
3708: }
3709:
3710: # Here's the guts of the iterator.
3711:
3712: # Find the next resource, if any.
3713: my $found = 0;
3714: my $i = $self->{MAX_DEPTH};
3715: my $newDepth;
3716: my $here;
3717: while ( $i >= 0 && !$found ) {
1.107 bowersj2 3718: if ( scalar(@{$self->{STACK}->[$i]}) > 0 ) { # **6**
3719: $here = pop @{$self->{STACK}->[$i]}; # **7**
1.98 bowersj2 3720: $found = 1;
3721: $newDepth = $i;
3722: }
3723: $i--;
3724: }
3725:
3726: # If we still didn't find anything, we're done.
3727: if ( !$found ) {
3728: # We need to get back down to the correct branch depth
3729: if ( $self->{CURRENT_DEPTH} > 0 ) {
3730: $self->{CURRENT_DEPTH}--;
3731: return END_BRANCH();
3732: } else {
1.222 bowersj2 3733: $self->{FINISHED} = 1;
1.98 bowersj2 3734: return END_MAP();
3735: }
3736: }
3737:
1.104 bowersj2 3738: # If this is not a resource, it must be an END_BRANCH marker we want
3739: # to return directly.
1.107 bowersj2 3740: if (!ref($here)) { # **8**
1.104 bowersj2 3741: if ($here == END_BRANCH()) { # paranoia, in case of later extension
3742: $self->{CURRENT_DEPTH}--;
3743: return $here;
3744: }
3745: }
3746:
3747: # Otherwise, it is a resource and it's safe to store in $self->{HERE}
3748: $self->{HERE} = $here;
3749:
1.98 bowersj2 3750: # Get to the right level
3751: if ( $self->{CURRENT_DEPTH} > $newDepth ) {
3752: push @{$self->{STACK}->[$newDepth]}, $here;
3753: $self->{CURRENT_DEPTH}--;
3754: return END_BRANCH();
3755: }
3756: if ( $self->{CURRENT_DEPTH} < $newDepth) {
3757: push @{$self->{STACK}->[$newDepth]}, $here;
3758: $self->{CURRENT_DEPTH}++;
3759: return BEGIN_BRANCH();
3760: }
3761:
3762: # If we made it here, we have the next resource, and we're at the
3763: # right branch level. So let's examine the resource for where
3764: # we can get to from here.
3765:
3766: # So we need to look at all the resources we can get to from here,
3767: # categorize them if we haven't seen them, remember if we have a new
3768: my $nextUnfiltered = $here->getNext();
1.470 foxr 3769:
3770:
1.104 bowersj2 3771: my $maxDepthAdded = -1;
3772:
1.98 bowersj2 3773: for (@$nextUnfiltered) {
3774: if (!defined($self->{ALREADY_SEEN}->{$_->{ID}})) {
1.104 bowersj2 3775: my $depth = $_->{DATA}->{DISPLAY_DEPTH};
3776: push @{$self->{STACK}->[$depth]}, $_;
1.98 bowersj2 3777: $self->{ALREADY_SEEN}->{$_->{ID}} = 1;
1.104 bowersj2 3778: if ($maxDepthAdded < $depth) { $maxDepthAdded = $depth; }
1.98 bowersj2 3779: }
3780: }
1.104 bowersj2 3781:
3782: # Is this the end of a branch? If so, all of the resources examined above
1.398 banghart 3783: # led to lower levels than the one we are currently at, so we push a END_BRANCH
1.104 bowersj2 3784: # marker onto the stack so we don't forget.
3785: # Example: For the usual A(BC)(DE)F case, when the iterator goes down the
3786: # BC branch and gets to C, it will see F as the only next resource, but it's
3787: # one level lower. Thus, this is the end of the branch, since there are no
3788: # more resources added to this level or above.
1.111 bowersj2 3789: # We don't do this if the examined resource is the finish resource,
3790: # because the condition given above is true, but the "END_MAP" will
3791: # take care of things and we should already be at depth 0.
1.104 bowersj2 3792: my $isEndOfBranch = $maxDepthAdded < $self->{CURRENT_DEPTH};
1.111 bowersj2 3793: if ($isEndOfBranch && $here != $self->{FINISH_RESOURCE}) { # **9**
1.104 bowersj2 3794: push @{$self->{STACK}->[$self->{CURRENT_DEPTH}]}, END_BRANCH();
3795: }
3796:
1.98 bowersj2 3797: # That ends the main iterator logic. Now, do we want to recurse
3798: # down this map (if this resource is a map)?
1.256 albertel 3799: if ( ($self->{HERE}->is_sequence() || (!$closeAllPages && $self->{HERE}->is_page())) &&
1.509.2.13 raeburn 3800: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION}) &&
3801: ($env{'request.role.adv'} || !$self->{HERE}->randomout())) {
1.98 bowersj2 3802: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
3803: my $firstResource = $self->{HERE}->map_start();
3804: my $finishResource = $self->{HERE}->map_finish();
3805: $self->{RECURSIVE_ITERATOR} =
3806: Apache::lonnavmaps::iterator->new($self->{NAV_MAP}, $firstResource,
3807: $finishResource, $self->{FILTER},
1.314 albertel 3808: $self->{ALREADY_SEEN},
3809: $self->{CONDITION},
3810: $self->{FORCE_TOP});
1.98 bowersj2 3811: }
3812:
1.116 bowersj2 3813: # If this is a blank resource, don't actually return it.
1.117 bowersj2 3814: # Should you ever find you need it, make sure to add an option to the code
3815: # that you can use; other things depend on this behavior.
1.505 raeburn 3816: my $browsePriv = $self->{HERE}->browsePriv($noblockcheck);
1.138 bowersj2 3817: if (!$self->{HERE}->src() ||
3818: (!($browsePriv eq 'F') && !($browsePriv eq '2')) ) {
1.256 albertel 3819: return $self->next($closeAllPages);
1.116 bowersj2 3820: }
3821:
1.98 bowersj2 3822: return $self->{HERE};
3823:
3824: }
3825:
3826: =pod
3827:
1.174 albertel 3828: The other method available on the iterator is B<getStack>, which
3829: returns an array populated with the current 'stack' of maps, as
3830: references to the resource objects. Example: This is useful when
3831: making the navigation map, as we need to check whether we are under a
3832: page map to see if we need to link directly to the resource, or to the
3833: page. The first elements in the array will correspond to the top of
3834: the stack (most inclusive map).
1.98 bowersj2 3835:
3836: =cut
3837:
3838: sub getStack {
3839: my $self=shift;
3840:
3841: my @stack;
3842:
3843: $self->populateStack(\@stack);
3844:
3845: return \@stack;
3846: }
3847:
3848: # Private method: Calls the iterators recursively to populate the stack.
3849: sub populateStack {
3850: my $self=shift;
3851: my $stack = shift;
3852:
3853: push @$stack, $self->{HERE} if ($self->{HERE});
3854:
3855: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
3856: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
3857: }
1.94 bowersj2 3858: }
3859:
3860: 1;
3861:
3862: package Apache::lonnavmaps::DFSiterator;
1.365 albertel 3863: use Scalar::Util qw(weaken);
1.320 albertel 3864: use Apache::lonnet;
3865:
1.100 bowersj2 3866: # Not documented in the perldoc: This is a simple iterator that just walks
3867: # through the nav map and presents the resources in a depth-first search
3868: # fashion, ignorant of conditionals, randomized resources, etc. It presents
3869: # BEGIN_MAP and END_MAP, but does not understand branches at all. It is
3870: # useful for pre-processing of some kind, and is in fact used by the main
3871: # iterator that way, but that's about it.
3872: # One could imagine merging this into the init routine of the main iterator,
1.251 www 3873: # but this might as well be left separate, since it is possible some other
1.100 bowersj2 3874: # use might be found for it. - Jeremy
1.94 bowersj2 3875:
1.117 bowersj2 3876: # Unlike the main iterator, this DOES return all resources, even blank ones.
3877: # The main iterator needs them to correctly preprocess the map.
3878:
1.94 bowersj2 3879: sub BEGIN_MAP { return 1; } # begining of a new map
3880: sub END_MAP { return 2; } # end of the map
3881: sub FORWARD { return 1; } # go forward
3882: sub BACKWARD { return 2; }
3883:
1.100 bowersj2 3884: # Params: Nav map ref, first resource id/ref, finish resource id/ref,
3885: # filter hash ref (or undef), already seen hash or undef, condition
3886: # (as in main iterator), direction FORWARD or BACKWARD (undef->forward).
1.51 bowersj2 3887: sub new {
3888: # magic invocation to create a class instance
3889: my $proto = shift;
3890: my $class = ref($proto) || $proto;
3891: my $self = {};
3892:
1.300 albertel 3893: weaken($self->{NAV_MAP} = shift);
1.51 bowersj2 3894: return undef unless ($self->{NAV_MAP});
3895:
1.454 www 3896: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
3897: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
3898:
1.51 bowersj2 3899: $self->{FIRST_RESOURCE} = shift || $self->{NAV_MAP}->firstResource();
3900: $self->{FINISH_RESOURCE} = shift || $self->{NAV_MAP}->finishResource();
3901:
3902: # If the given resources are just the ID of the resource, get the
3903: # objects
3904: if (!ref($self->{FIRST_RESOURCE})) { $self->{FIRST_RESOURCE} =
3905: $self->{NAV_MAP}->getById($self->{FIRST_RESOURCE}); }
3906: if (!ref($self->{FINISH_RESOURCE})) { $self->{FINISH_RESOURCE} =
3907: $self->{NAV_MAP}->getById($self->{FINISH_RESOURCE}); }
3908:
3909: $self->{FILTER} = shift;
3910:
3911: # A hash, used as a set, of resource already seen
3912: $self->{ALREADY_SEEN} = shift;
1.140 bowersj2 3913: if (!defined($self->{ALREADY_SEEN})) { $self->{ALREADY_SEEN} = {} };
1.63 bowersj2 3914: $self->{CONDITION} = shift;
1.89 bowersj2 3915: $self->{DIRECTION} = shift || FORWARD();
1.51 bowersj2 3916:
1.100 bowersj2 3917: # Flag: Have we started yet?
1.51 bowersj2 3918: $self->{STARTED} = 0;
3919:
3920: # Should we continue calling the recursive iterator, if any?
3921: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3922: # The recursive iterator, if any
3923: $self->{RECURSIVE_ITERATOR} = undef;
3924: # Are we recursing on a map, or a branch?
3925: $self->{RECURSIVE_MAP} = 1; # we'll manually unset this when recursing on branches
3926: # And the count of how deep it is, so that this iterator can keep track of
3927: # when to pick back up again.
3928: $self->{RECURSIVE_DEPTH} = 0;
3929:
3930: # For keeping track of our branches, we maintain our own stack
1.100 bowersj2 3931: $self->{STACK} = [];
1.51 bowersj2 3932:
3933: # Start with the first resource
1.89 bowersj2 3934: if ($self->{DIRECTION} == FORWARD) {
1.100 bowersj2 3935: push @{$self->{STACK}}, $self->{FIRST_RESOURCE};
1.89 bowersj2 3936: } else {
1.100 bowersj2 3937: push @{$self->{STACK}}, $self->{FINISH_RESOURCE};
1.89 bowersj2 3938: }
1.51 bowersj2 3939:
3940: bless($self);
3941: return $self;
3942: }
3943:
3944: sub next {
3945: my $self = shift;
3946:
3947: # Are we using a recursive iterator? If so, pull from that and
3948: # watch the depth; we want to resume our level at the correct time.
1.98 bowersj2 3949: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
1.51 bowersj2 3950: # grab the next from the recursive iterator
3951: my $next = $self->{RECURSIVE_ITERATOR}->next();
3952:
3953: # is it a begin or end map? Update depth if so
3954: if ($next == BEGIN_MAP() ) { $self->{RECURSIVE_DEPTH}++; }
3955: if ($next == END_MAP() ) { $self->{RECURSIVE_DEPTH}--; }
3956:
3957: # Are we back at depth 0? If so, stop recursing.
3958: if ($self->{RECURSIVE_DEPTH} == 0) {
3959: $self->{RECURSIVE_ITERATOR_FLAG} = 0;
3960: }
3961:
3962: return $next;
3963: }
3964:
3965: # Is there a current resource to grab? If not, then return
1.100 bowersj2 3966: # END_MAP, which will end the iterator.
3967: if (scalar(@{$self->{STACK}}) == 0) {
3968: return $self->END_MAP();
1.51 bowersj2 3969: }
3970:
3971: # Have we not yet begun? If not, return BEGIN_MAP and
3972: # remember that we've started.
3973: if ( !$self->{STARTED} ) {
3974: $self->{STARTED} = 1;
3975: return $self->BEGIN_MAP;
3976: }
3977:
3978: # Get the next resource in the branch
1.100 bowersj2 3979: $self->{HERE} = pop @{$self->{STACK}};
1.52 bowersj2 3980:
1.100 bowersj2 3981: # remember that we've seen this, so we don't return it again later
1.51 bowersj2 3982: $self->{ALREADY_SEEN}->{$self->{HERE}->{ID}} = 1;
3983:
3984: # Get the next possible resources
1.90 bowersj2 3985: my $nextUnfiltered;
1.89 bowersj2 3986: if ($self->{DIRECTION} == FORWARD()) {
1.90 bowersj2 3987: $nextUnfiltered = $self->{HERE}->getNext();
1.89 bowersj2 3988: } else {
1.90 bowersj2 3989: $nextUnfiltered = $self->{HERE}->getPrevious();
1.89 bowersj2 3990: }
1.51 bowersj2 3991: my $next = [];
3992:
3993: # filter the next possibilities to remove things we've
1.100 bowersj2 3994: # already seen.
1.394 raeburn 3995: foreach my $item (@$nextUnfiltered) {
3996: if (!defined($self->{ALREADY_SEEN}->{$item->{ID}})) {
3997: push @$next, $item;
1.52 bowersj2 3998: }
1.51 bowersj2 3999: }
4000:
4001: while (@$next) {
1.100 bowersj2 4002: # copy the next possibilities over to the stack
4003: push @{$self->{STACK}}, shift @$next;
1.51 bowersj2 4004: }
4005:
4006: # If this is a map and we want to recurse down it... (not filtered out)
1.70 bowersj2 4007: if ($self->{HERE}->is_map() &&
1.63 bowersj2 4008: (defined($self->{FILTER}->{$self->{HERE}->map_pc()}) xor $self->{CONDITION})) {
1.51 bowersj2 4009: $self->{RECURSIVE_ITERATOR_FLAG} = 1;
4010: my $firstResource = $self->{HERE}->map_start();
4011: my $finishResource = $self->{HERE}->map_finish();
4012:
4013: $self->{RECURSIVE_ITERATOR} =
1.94 bowersj2 4014: Apache::lonnavmaps::DFSiterator->new ($self->{NAV_MAP}, $firstResource,
1.63 bowersj2 4015: $finishResource, $self->{FILTER}, $self->{ALREADY_SEEN},
1.91 bowersj2 4016: $self->{CONDITION}, $self->{DIRECTION});
1.51 bowersj2 4017: }
4018:
4019: return $self->{HERE};
1.190 bowersj2 4020: }
4021:
4022: # Identical to the full iterator methods of the same name. Hate to copy/paste
4023: # but I also hate to "inherit" either iterator from the other.
4024:
4025: sub getStack {
4026: my $self=shift;
4027:
4028: my @stack;
4029:
4030: $self->populateStack(\@stack);
4031:
4032: return \@stack;
4033: }
4034:
4035: # Private method: Calls the iterators recursively to populate the stack.
4036: sub populateStack {
4037: my $self=shift;
4038: my $stack = shift;
4039:
4040: push @$stack, $self->{HERE} if ($self->{HERE});
4041:
4042: if ($self->{RECURSIVE_ITERATOR_FLAG}) {
4043: $self->{RECURSIVE_ITERATOR}->populateStack($stack);
4044: }
1.51 bowersj2 4045: }
4046:
1.1 www 4047: 1;
1.2 www 4048:
1.51 bowersj2 4049: package Apache::lonnavmaps::resource;
1.365 albertel 4050: use Scalar::Util qw(weaken);
1.51 bowersj2 4051: use Apache::lonnet;
4052:
4053: =pod
4054:
1.217 bowersj2 4055: =head1 Object: resource
1.51 bowersj2 4056:
1.217 bowersj2 4057: X<resource, navmap object>
1.174 albertel 4058: A resource object encapsulates a resource in a resource map, allowing
4059: easy manipulation of the resource, querying the properties of the
4060: resource (including user properties), and represents a reference that
4061: can be used as the canonical representation of the resource by
4062: lonnavmap clients like renderers.
4063:
4064: A resource only makes sense in the context of a navmap, as some of the
4065: data is stored in the navmap object.
4066:
4067: You will probably never need to instantiate this object directly. Use
4068: Apache::lonnavmaps::navmap, and use the "start" method to obtain the
4069: starting resource.
1.51 bowersj2 4070:
1.188 bowersj2 4071: Resource objects respect the parameter_hiddenparts, which suppresses
4072: various parts according to the wishes of the map author. As of this
4073: writing, there is no way to override this parameter, and suppressed
4074: parts will never be returned, nor will their response types or ids be
4075: stored.
4076:
1.217 bowersj2 4077: =head2 Overview
1.51 bowersj2 4078:
1.217 bowersj2 4079: A B<Resource> is the most granular type of object in LON-CAPA that can
4080: be included in a course. It can either be a particular resource, like
4081: an HTML page, external resource, problem, etc., or it can be a
4082: container sequence, such as a "page" or a "map".
4083:
4084: To see a sequence from the user's point of view, please see the
4085: B<Creating a Course: Maps and Sequences> chapter of the Author's
4086: Manual.
4087:
4088: A Resource Object, once obtained from a navmap object via a B<getBy*>
4089: method of the navmap, or from an iterator, allows you to query
4090: information about that resource.
4091:
4092: Generally, you do not ever want to create a resource object yourself,
4093: so creation has been left undocumented. Always retrieve resources
4094: from navmap objects.
4095:
4096: =head3 Identifying Resources
4097:
4098: X<big hash>Every resource is identified by a Resource ID in the big hash that is
4099: unique to that resource for a given course. X<resource ID, in big hash>
4100: The Resource ID has the form #.#, where the first number is the same
4101: for every resource in a map, and the second is unique. For instance,
4102: for a course laid out like this:
4103:
4104: * Problem 1
4105: * Map
4106: * Resource 2
4107: * Resource 3
4108:
4109: C<Problem 1> and C<Map> will share a first number, and C<Resource 2>
4110: C<Resource 3> will share a first number. The second number may end up
4111: re-used between the two groups.
4112:
4113: The resource ID is only used in the big hash, but can be used in the
4114: context of a course to identify a resource easily. (For instance, the
4115: printing system uses it to record which resources from a sequence you
4116: wish to print.)
4117:
4118: X<symb> X<resource, symb>
4119: All resources also have B<symb>s, which uniquely identify a resource
4120: in a course. Many internal LON-CAPA functions expect a symb. A symb
4121: carries along with it the URL of the resource, and the map it appears
1.398 banghart 4122: in. Symbs are much larger than resource IDs.
1.51 bowersj2 4123:
4124: =cut
4125:
4126: sub new {
4127: # magic invocation to create a class instance
4128: my $proto = shift;
4129: my $class = ref($proto) || $proto;
4130: my $self = {};
4131:
1.300 albertel 4132: weaken($self->{NAV_MAP} = shift);
1.51 bowersj2 4133: $self->{ID} = shift;
4134:
1.454 www 4135: $self->{USERNAME} = $self->{NAV_MAP}->{USERNAME};
4136: $self->{DOMAIN} = $self->{NAV_MAP}->{DOMAIN};
4137:
1.51 bowersj2 4138: # Store this new resource in the parent nav map's cache.
4139: $self->{NAV_MAP}->{RESOURCE_CACHE}->{$self->{ID}} = $self;
1.66 bowersj2 4140: $self->{RESOURCE_ERROR} = 0;
1.51 bowersj2 4141:
1.479 raeburn 4142: $self->{DUEDATE_CACHE} = undef;
4143:
1.51 bowersj2 4144: # A hash that can be used by two-pass algorithms to store data
4145: # about this resource in. Not used by the resource object
4146: # directly.
4147: $self->{DATA} = {};
1.508 damieng 4148:
1.51 bowersj2 4149: bless($self);
4150:
1.508 damieng 4151: # This is a speed optimization, to avoid calling symb() too often.
4152: $self->{SYMB} = $self->symb();
4153:
1.51 bowersj2 4154: return $self;
4155: }
4156:
1.70 bowersj2 4157: # private function: simplify the NAV_HASH lookups we keep doing
4158: # pass the name, and to automatically append my ID, pass a true val on the
4159: # second param
4160: sub navHash {
4161: my $self = shift;
4162: my $param = shift;
4163: my $id = shift;
1.441 raeburn 4164: my $arg = $param . ($id?$self->{ID}:"");
1.451 raeburn 4165: if (ref($self) && ref($self->{NAV_MAP}) && defined($arg)) {
1.441 raeburn 4166: return $self->{NAV_MAP}->navhash($arg);
4167: }
4168: return;
1.70 bowersj2 4169: }
4170:
1.51 bowersj2 4171: =pod
4172:
1.217 bowersj2 4173: =head2 Methods
1.70 bowersj2 4174:
1.217 bowersj2 4175: Once you have a resource object, here's what you can do with it:
4176:
4177: =head3 Attribute Retrieval
4178:
4179: Every resource has certain attributes that can be retrieved and used:
1.70 bowersj2 4180:
4181: =over 4
4182:
1.217 bowersj2 4183: =item * B<ID>: Every resource has an ID that is unique for that
4184: resource in the course it is in. The ID is actually in the hash
4185: representing the resource, so for a resource object $res, obtain
4186: it via C<$res->{ID}).
4187:
1.174 albertel 4188: =item * B<compTitle>:
4189:
4190: Returns a "composite title", that is equal to $res->title() if the
4191: resource has a title, and is otherwise the last part of the URL (e.g.,
4192: "problem.problem").
4193:
4194: =item * B<ext>:
4195:
4196: Returns true if the resource is external.
4197:
4198: =item * B<kind>:
4199:
4200: Returns the kind of the resource from the compiled nav map.
4201:
4202: =item * B<randomout>:
1.106 bowersj2 4203:
1.174 albertel 4204: Returns true if this resource was chosen to NOT be shown to the user
4205: by the random map selection feature. In other words, this is usually
4206: false.
1.70 bowersj2 4207:
1.174 albertel 4208: =item * B<randompick>:
1.70 bowersj2 4209:
1.400 albertel 4210: Returns the number of randomly picked items for a map if the randompick
4211: feature is being used on the map.
4212:
4213: =item * B<randomorder>:
4214:
4215: Returns true for a map if the randomorder feature is being used on the
4216: map.
1.70 bowersj2 4217:
1.174 albertel 4218: =item * B<src>:
1.51 bowersj2 4219:
1.174 albertel 4220: Returns the source for the resource.
1.70 bowersj2 4221:
1.174 albertel 4222: =item * B<symb>:
1.70 bowersj2 4223:
1.174 albertel 4224: Returns the symb for the resource.
1.70 bowersj2 4225:
1.174 albertel 4226: =item * B<title>:
1.70 bowersj2 4227:
1.174 albertel 4228: Returns the title of the resource.
4229:
1.51 bowersj2 4230: =back
4231:
4232: =cut
4233:
4234: # These info functions can be used directly, as they don't return
4235: # resource information.
1.85 bowersj2 4236: sub comesfrom { my $self=shift; return $self->navHash("comesfrom_", 1); }
1.303 albertel 4237: sub encrypted { my $self=shift; return $self->navHash("encrypted_", 1); }
1.70 bowersj2 4238: sub ext { my $self=shift; return $self->navHash("ext_", 1) eq 'true:'; }
1.85 bowersj2 4239: sub from { my $self=shift; return $self->navHash("from_", 1); }
1.217 bowersj2 4240: # considered private and undocumented
1.51 bowersj2 4241: sub goesto { my $self=shift; return $self->navHash("goesto_", 1); }
4242: sub kind { my $self=shift; return $self->navHash("kind_", 1); }
1.68 bowersj2 4243: sub randomout { my $self=shift; return $self->navHash("randomout_", 1); }
4244: sub randompick {
4245: my $self = shift;
1.410 raeburn 4246: my $randompick = $self->parmval('randompick');
4247: return $randompick;
1.68 bowersj2 4248: }
1.400 albertel 4249: sub randomorder {
4250: my $self = shift;
1.410 raeburn 4251: my $randomorder = $self->parmval('randomorder');
4252: return ($randomorder =~ /^yes$/i);
1.400 albertel 4253: }
1.303 albertel 4254: sub link {
4255: my $self=shift;
4256: if ($self->encrypted()) { return &Apache::lonenc::encrypted($self->src); }
4257: return $self->src;
4258: }
1.51 bowersj2 4259: sub src {
4260: my $self=shift;
4261: return $self->navHash("src_", 1);
4262: }
1.303 albertel 4263: sub shown_symb {
4264: my $self=shift;
1.508 damieng 4265: if ($self->encrypted()) {return &Apache::lonenc::encrypted($self->{SYMB});}
4266: return $self->{SYMB};
1.303 albertel 4267: }
1.328 www 4268: sub id {
4269: my $self=shift;
4270: return $self->{ID};
4271: }
4272: sub enclosing_map_src {
4273: my $self=shift;
4274: (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
4275: return $self->navHash('map_id_'.$first);
4276: }
1.51 bowersj2 4277: sub symb {
4278: my $self=shift;
1.509.2.4 raeburn 4279: if (defined($self->{SYMB})) { return $self->{SYMB}; }
1.51 bowersj2 4280: (my $first, my $second) = $self->{ID} =~ /(\d+).(\d+)/;
4281: my $symbSrc = &Apache::lonnet::declutter($self->src());
1.223 albertel 4282: my $symb = &Apache::lonnet::declutter($self->navHash('map_id_'.$first))
1.51 bowersj2 4283: . '___' . $second . '___' . $symbSrc;
1.223 albertel 4284: return &Apache::lonnet::symbclean($symb);
1.51 bowersj2 4285: }
1.321 raeburn 4286: sub wrap_symb {
4287: my $self = shift;
1.508 damieng 4288: return $self->{NAV_MAP}->wrap_symb($self->{SYMB});
1.321 raeburn 4289: }
1.213 bowersj2 4290: sub title {
4291: my $self=shift;
4292: if ($self->{ID} eq '0.0') {
4293: # If this is the top-level map, return the title of the course
4294: # since this map can not be titled otherwise.
1.320 albertel 4295: return $env{'course.'.$env{'request.course.id'}.'.description'};
1.213 bowersj2 4296: }
4297: return $self->navHash("title_", 1); }
1.217 bowersj2 4298: # considered private and undocumented
1.70 bowersj2 4299: sub to { my $self=shift; return $self->navHash("to_", 1); }
1.301 albertel 4300: sub condition {
4301: my $self=shift;
4302: my $undercond=$self->navHash("undercond_", 1);
4303: if (!defined($undercond)) { return 1; };
4304: my $condid=$self->navHash("condid_$undercond");
4305: if (!defined($condid)) { return 1; };
4306: my $condition=&Apache::lonnet::directcondval($condid);
4307: return $condition;
4308: }
1.342 albertel 4309: sub condval {
4310: my $self=shift;
1.359 albertel 4311: my ($pathname,$filename) =
4312: &Apache::lonnet::split_uri_for_cond($self->src());
1.342 albertel 4313:
4314: my $match=($env{'acc.res.'.$env{'request.course.id'}.'.'.$pathname}=~
4315: /\&\Q$filename\E\:([\d\|]+)\&/);
4316: if ($match) {
4317: return &Apache::lonnet::condval($1);
4318: }
4319: return 0;
4320: }
1.106 bowersj2 4321: sub compTitle {
4322: my $self = shift;
4323: my $title = $self->title();
1.176 www 4324: $title=~s/\&colon\;/\:/gs;
1.106 bowersj2 4325: if (!$title) {
4326: $title = $self->src();
4327: $title = substr($title, rindex($title, '/') + 1);
4328: }
4329: return $title;
4330: }
1.399 albertel 4331:
1.70 bowersj2 4332: =pod
4333:
4334: B<Predicate Testing the Resource>
4335:
4336: These methods are shortcuts to deciding if a given resource has a given property.
4337:
4338: =over 4
4339:
1.174 albertel 4340: =item * B<is_map>:
4341:
4342: Returns true if the resource is a map type.
4343:
4344: =item * B<is_problem>:
1.70 bowersj2 4345:
1.174 albertel 4346: Returns true if the resource is a problem type, false
4347: otherwise. (Looks at the extension on the src field; might need more
4348: to work correctly.)
1.70 bowersj2 4349:
1.174 albertel 4350: =item * B<is_page>:
1.70 bowersj2 4351:
1.174 albertel 4352: Returns true if the resource is a page.
4353:
4354: =item * B<is_sequence>:
4355:
4356: Returns true if the resource is a sequence.
1.70 bowersj2 4357:
4358: =back
4359:
4360: =cut
4361:
1.256 albertel 4362: sub hasResource {
4363: my $self = shift;
4364: return $self->{NAV_MAP}->hasResource(@_);
4365: }
4366:
4367: sub retrieveResources {
4368: my $self = shift;
4369: return $self->{NAV_MAP}->retrieveResources(@_);
4370: }
1.70 bowersj2 4371:
1.369 albertel 4372: sub is_exam {
4373: my ($self,$part) = @_;
1.410 raeburn 4374: my $type = $self->parmval('type',$part);
4375: if ($type eq 'exam') {
1.369 albertel 4376: return 1;
4377: }
4378: if ($self->src() =~ /\.(exam)$/) {
4379: return 1;
4380: }
4381: return 0;
4382: }
1.70 bowersj2 4383: sub is_html {
1.51 bowersj2 4384: my $self=shift;
4385: my $src = $self->src();
1.70 bowersj2 4386: return ($src =~ /html$/);
1.51 bowersj2 4387: }
1.70 bowersj2 4388: sub is_map { my $self=shift; return defined($self->navHash("is_map_", 1)); }
4389: sub is_page {
1.51 bowersj2 4390: my $self=shift;
4391: my $src = $self->src();
1.205 bowersj2 4392: return $self->navHash("is_map_", 1) &&
4393: $self->navHash("map_type_" . $self->map_pc()) eq 'page';
1.51 bowersj2 4394: }
1.361 albertel 4395: sub is_practice {
4396: my $self=shift;
4397: my ($part) = @_;
1.410 raeburn 4398: my $type = $self->parmval('type',$part);
4399: if ($type eq 'practice') {
1.361 albertel 4400: return 1;
4401: }
4402: return 0;
4403: }
1.70 bowersj2 4404: sub is_problem {
1.51 bowersj2 4405: my $self=shift;
4406: my $src = $self->src();
1.466 www 4407: if ($src =~ /$LONCAPA::assess_re/) {
1.361 albertel 4408: return !($self->is_practice());
4409: }
4410: return 0;
1.256 albertel 4411: }
1.443 foxr 4412: #
4413: # The has below is the set of status that are considered 'incomplete'
4414: #
4415: my %incomplete_hash =
4416: (
4417: TRIES_LEFT() => 1,
4418: OPEN() => 1,
4419: ATTEMPTED() => 1
4420:
4421: );
4422: #
4423: # Return tru if a problem is incomplete... for now incomplete means that
4424: # any part of the problem is incomplete.
4425: # Note that if the resources is not a problem, 0 is returned.
4426: #
4427: sub is_incomplete {
4428: my $self = shift;
4429: if ($self->is_problem()) {
4430: foreach my $part (@{$self->parts()}) {
4431: if (exists($incomplete_hash{$self->status($part)})) {
4432: return 1;
4433: }
4434: }
4435: }
4436: return 0;
4437:
4438: }
1.413 www 4439: sub is_raw_problem {
4440: my $self=shift;
4441: my $src = $self->src();
1.466 www 4442: if ($src =~ /$LONCAPA::assess_re/) {
1.413 www 4443: return 1;
4444: }
4445: return 0;
4446: }
4447:
1.256 albertel 4448: sub contains_problem {
4449: my $self=shift;
4450: if ($self->is_page()) {
4451: my $hasProblem=$self->hasResource($self,sub { $_[0]->is_problem() },1);
4452: return $hasProblem;
4453: }
4454: return 0;
1.51 bowersj2 4455: }
1.401 albertel 4456: sub map_contains_problem {
4457: my $self=shift;
4458: if ($self->is_map()) {
4459: my $has_problem=
4460: $self->hasResource($self,sub { $_[0]->is_problem() },1);
4461: return $has_problem;
4462: }
4463: return 0;
4464: }
1.70 bowersj2 4465: sub is_sequence {
1.51 bowersj2 4466: my $self=shift;
1.205 bowersj2 4467: return $self->navHash("is_map_", 1) &&
1.426 droeschl 4468: $self->navHash("map_type_" . $self->map_pc()) eq 'sequence';
1.51 bowersj2 4469: }
1.261 matthew 4470: sub is_survey {
4471: my $self = shift();
4472: my $part = shift();
1.410 raeburn 4473: my $type = $self->parmval('type',$part);
1.444 raeburn 4474: if (($type eq 'survey') || ($type eq 'surveycred')) {
1.261 matthew 4475: return 1;
4476: }
1.263 albertel 4477: if ($self->src() =~ /\.(survey)$/) {
1.261 matthew 4478: return 1;
4479: }
4480: return 0;
4481: }
1.444 raeburn 4482: sub is_anonsurvey {
4483: my $self = shift();
4484: my $part = shift();
4485: my $type = $self->parmval('type',$part);
4486: if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
4487: return 1;
4488: }
4489: return 0;
4490: }
1.360 albertel 4491: sub is_task {
4492: my $self=shift;
4493: my $src = $self->src();
4494: return ($src =~ /\.(task)$/)
4495: }
1.51 bowersj2 4496:
1.266 raeburn 4497: sub is_empty_sequence {
4498: my $self=shift;
4499: my $src = $self->src();
4500: return !$self->is_page() && $self->navHash("is_map_", 1) && !$self->navHash("map_type_" . $self->map_pc());
4501: }
4502:
1.101 bowersj2 4503: # Private method: Shells out to the parmval in the nav map, handler parts.
1.51 bowersj2 4504: sub parmval {
4505: my $self = shift;
4506: my $what = shift;
1.185 bowersj2 4507: my $part = shift;
4508: if (!defined($part)) {
4509: $part = '0';
4510: }
1.508 damieng 4511: return $self->{NAV_MAP}->parmval($part.'.'.$what, $self->{SYMB});
1.51 bowersj2 4512: }
4513:
1.70 bowersj2 4514: =pod
4515:
4516: B<Map Methods>
4517:
1.174 albertel 4518: These methods are useful for getting information about the map
4519: properties of the resource, if the resource is a map (B<is_map>).
1.70 bowersj2 4520:
4521: =over 4
4522:
1.174 albertel 4523: =item * B<map_finish>:
4524:
4525: Returns a reference to a resource object corresponding to the finish
4526: resource of the map.
1.70 bowersj2 4527:
1.174 albertel 4528: =item * B<map_pc>:
1.70 bowersj2 4529:
1.174 albertel 4530: Returns the pc value of the map, which is the first number that
4531: appears in the resource ID of the resources in the map, and is the
4532: number that appears around the middle of the symbs of the resources in
4533: that map.
1.70 bowersj2 4534:
1.174 albertel 4535: =item * B<map_start>:
4536:
4537: Returns a reference to a resource object corresponding to the start
4538: resource of the map.
4539:
4540: =item * B<map_type>:
4541:
4542: Returns a string with the type of the map in it.
1.70 bowersj2 4543:
1.497 raeburn 4544: =item * B<map_hierarchy>:
1.448 raeburn 4545:
4546: Returns a string with a comma-separated ordered list of map_pc IDs
4547: for the hierarchy of maps containing a map, with the top level
4548: map first, then descending to deeper levels, with the enclosing map last.
4549:
1.509.2.10 raeburn 4550: =item * B<map_breadcrumbs>:
4551:
4552: Same as map_hierarchy, except maps containing only a single itemm if
4553: it's a map, or containing no items are omitted, unless it's the top
4554: level map (map_pc = 1), which is always included.
4555:
1.70 bowersj2 4556: =back
1.51 bowersj2 4557:
1.70 bowersj2 4558: =cut
1.51 bowersj2 4559:
4560: sub map_finish {
4561: my $self = shift;
4562: my $src = $self->src();
1.381 albertel 4563: $src = &Apache::lonnet::clutter($src);
1.51 bowersj2 4564: my $res = $self->navHash("map_finish_$src", 0);
4565: $res = $self->{NAV_MAP}->getById($res);
4566: return $res;
4567: }
1.70 bowersj2 4568: sub map_pc {
4569: my $self = shift;
1.381 albertel 4570: my $src = $self->src();
1.70 bowersj2 4571: return $self->navHash("map_pc_$src", 0);
4572: }
1.51 bowersj2 4573: sub map_start {
4574: my $self = shift;
4575: my $src = $self->src();
1.381 albertel 4576: $src = &Apache::lonnet::clutter($src);
1.51 bowersj2 4577: my $res = $self->navHash("map_start_$src", 0);
4578: $res = $self->{NAV_MAP}->getById($res);
4579: return $res;
4580: }
4581: sub map_type {
4582: my $self = shift;
4583: my $pc = $self->map_pc();
4584: return $self->navHash("map_type_$pc", 0);
4585: }
1.448 raeburn 4586: sub map_hierarchy {
4587: my $self = shift;
4588: my $pc = $self->map_pc();
4589: return $self->navHash("map_hierarchy_$pc", 0);
4590: }
1.509.2.10 raeburn 4591: sub map_breadcrumbs {
4592: my $self = shift;
4593: my $pc = $self->map_pc();
4594: return $self->navHash("map_breadcrumbs_$pc", 0);
4595: }
1.51 bowersj2 4596:
4597: #####
4598: # Property queries
4599: #####
4600:
4601: # These functions will be responsible for returning the CORRECT
4602: # VALUE for the parameter, no matter what. So while they may look
1.398 banghart 4603: # like direct calls to parmval, they can be more than that.
1.51 bowersj2 4604: # So, for instance, the duedate function should use the "duedatetype"
1.398 banghart 4605: # information, rather than the resource object user.
1.51 bowersj2 4606:
4607: =pod
4608:
4609: =head2 Resource Parameters
4610:
1.174 albertel 4611: In order to use the resource parameters correctly, the nav map must
4612: have been instantiated with genCourseAndUserOptions set to true, so
4613: the courseopt and useropt is read correctly. Then, you can call these
4614: functions to get the relevant parameters for the resource. Each
4615: function defaults to part "0", but can be directed to another part by
4616: passing the part as the parameter.
4617:
4618: These methods are responsible for getting the parameter correct, not
4619: merely reflecting the contents of the GDBM hashes. As we move towards
4620: dates relative to other dates, these methods should be updated to
4621: reflect that. (Then, anybody using these methods will not have to update
4622: their code.)
4623:
4624: =over 4
4625:
1.485 foxr 4626:
1.459 foxr 4627: =item * B<printable>
4628:
4629: returns true if the current date is such that the
4630: specified resource part is printable.
4631:
1.485 foxr 4632:
1.459 foxr 4633: =item * B<resprintable>
4634:
4635: Returns true if all parts in the resource are printable making the
4636: entire resource printable.
4637:
4638: =item * B<acc>
1.174 albertel 4639:
4640: Get the Client IP/Name Access Control information.
1.51 bowersj2 4641:
1.174 albertel 4642: =item * B<answerdate>:
1.51 bowersj2 4643:
1.174 albertel 4644: Get the answer-reveal date for the problem.
4645:
1.211 bowersj2 4646: =item * B<awarded>:
4647:
4648: Gets the awarded value for the problem part. Requires genUserData set to
4649: true when the navmap object was created.
4650:
1.174 albertel 4651: =item * B<duedate>:
4652:
4653: Get the due date for the problem.
4654:
4655: =item * B<tries>:
4656:
4657: Get the number of tries the student has used on the problem.
4658:
4659: =item * B<maxtries>:
4660:
4661: Get the number of max tries allowed.
4662:
4663: =item * B<opendate>:
1.51 bowersj2 4664:
1.174 albertel 4665: Get the open date for the problem.
1.51 bowersj2 4666:
1.174 albertel 4667: =item * B<sig>:
1.51 bowersj2 4668:
1.174 albertel 4669: Get the significant figures setting.
1.51 bowersj2 4670:
1.174 albertel 4671: =item * B<tol>:
1.51 bowersj2 4672:
1.174 albertel 4673: Get the tolerance for the problem.
1.51 bowersj2 4674:
1.174 albertel 4675: =item * B<tries>:
1.51 bowersj2 4676:
1.174 albertel 4677: Get the number of tries the user has already used on the problem.
1.51 bowersj2 4678:
1.174 albertel 4679: =item * B<type>:
1.51 bowersj2 4680:
1.174 albertel 4681: Get the question type for the problem.
1.70 bowersj2 4682:
1.174 albertel 4683: =item * B<weight>:
1.51 bowersj2 4684:
1.174 albertel 4685: Get the weight for the problem.
1.51 bowersj2 4686:
4687: =back
4688:
4689: =cut
4690:
1.485 foxr 4691:
4692:
4693:
1.459 foxr 4694: sub printable {
4695:
4696: my ($self, $part) = @_;
4697:
4698: # The following cases apply:
1.487 foxr 4699: # - If a start date is not set, it is replaced by the open date.
4700: # - Ditto for start/open replaced by content open.
4701: # - If neither start nor printdates are set the part is printable.
1.459 foxr 4702: # - Start date set but no end date: Printable if now >= start date.
4703: # - End date set but no start date: Printable if now <= end date.
4704: # - both defined: printable if start <= now <= end
4705: #
1.487 foxr 4706:
4707: # Get the print open/close dates for the resource.
4708:
4709: my $start = $self->parmval("printstartdate", $part);
4710: my $end = $self->parmval("printenddate", $part);
4711:
4712: if (!$start) {
4713: $start = $self->parmval("opendate", $part);
4714: }
4715: if (!$start) {
4716: $start = $self->parmval("contentopen", $part);
4717: }
4718:
4719:
1.459 foxr 4720: my $now = time();
4721:
1.487 foxr 4722:
1.459 foxr 4723: my $startok = 1;
4724: my $endok = 1;
4725:
1.460 foxr 4726: if ((defined $start) && ($start ne '')) {
1.459 foxr 4727: $startok = $start <= $now;
4728: }
1.460 foxr 4729: if ((defined $end) && ($end != '')) {
1.459 foxr 4730: $endok = $end >= $now;
4731: }
4732: return $startok && $endok;
4733: }
4734:
4735: sub resprintable {
4736: my $self = shift;
4737:
4738: # get parts...or realize there are no parts.
4739:
1.460 foxr 4740: my $partsref = $self->parts();
4741: my @parts = @$partsref;
4742:
1.489 raeburn 4743: if (!@parts) {
1.459 foxr 4744: return $self->printable(0);
4745: } else {
1.460 foxr 4746: foreach my $part (@parts) {
4747: if (!$self->printable($part)) {
4748: return 0;
4749: }
1.459 foxr 4750: }
4751: return 1;
4752: }
4753: }
4754:
1.51 bowersj2 4755: sub acc {
4756: (my $self, my $part) = @_;
1.410 raeburn 4757: my $acc = $self->parmval("acc", $part);
4758: return $acc;
1.51 bowersj2 4759: }
4760: sub answerdate {
4761: (my $self, my $part) = @_;
4762: # Handle intervals
1.410 raeburn 4763: my $answerdatetype = $self->parmval("answerdate.type", $part);
4764: my $answerdate = $self->parmval("answerdate", $part);
4765: my $duedate = $self->parmval("duedate", $part);
4766: if ($answerdatetype eq 'date_interval') {
4767: $answerdate = $duedate + $answerdate;
1.51 bowersj2 4768: }
1.410 raeburn 4769: return $answerdate;
1.106 bowersj2 4770: }
1.211 bowersj2 4771: sub awarded {
4772: my $self = shift; my $part = shift;
1.221 bowersj2 4773: $self->{NAV_MAP}->get_user_data();
1.211 bowersj2 4774: if (!defined($part)) { $part = '0'; }
1.508 damieng 4775: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.awarded'};
1.211 bowersj2 4776: }
1.432 raeburn 4777: sub taskversion {
4778: my $self = shift; my $part = shift;
4779: $self->{NAV_MAP}->get_user_data();
4780: if (!defined($part)) { $part = '0'; }
1.508 damieng 4781: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.version'};
1.432 raeburn 4782: }
4783: sub taskstatus {
4784: my $self = shift; my $part = shift;
4785: $self->{NAV_MAP}->get_user_data();
4786: if (!defined($part)) { $part = '0'; }
1.508 damieng 4787: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$self->taskversion($part).'.'.$part.'.status'};
1.432 raeburn 4788: }
4789: sub solved {
4790: my $self = shift; my $part = shift;
4791: $self->{NAV_MAP}->get_user_data();
4792: if (!defined($part)) { $part = '0'; }
1.508 damieng 4793: return $self->{NAV_MAP}->{STUDENT_DATA}->{$self->{SYMB}}->{'resource.'.$part.'.solved'};
1.432 raeburn 4794: }
4795: sub checkedin {
4796: my $self = shift; my $part = shift;
4797: $self->{NAV_MAP}->get_user_data();
4798: if (!defined($part)) { $part = '0'; }
4799: if ($self->is_task()) {
4800: my $version = $self->taskversion($part);
1.508 damieng 4801: 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 4802: } else {
1.508 damieng 4803: 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 4804: }
4805: }
1.382 albertel 4806: # this should work exactly like the copy in lonhomework.pm
1.459 foxr 4807: # Why is there a copy in lonhomework? Why not centralized?
4808: #
4809: # TODO: Centralize duedate.
4810: #
4811:
1.51 bowersj2 4812: sub duedate {
4813: (my $self, my $part) = @_;
1.479 raeburn 4814: if (defined ($self->{DUEDATE_CACHE}->{$part})) {
4815: return $self->{DUEDATE_CACHE}->{$part};
4816: }
1.382 albertel 4817: my $date;
1.406 albertel 4818: my @interval=$self->parmval("interval", $part);
1.382 albertel 4819: my $due_date=$self->parmval("duedate", $part);
1.406 albertel 4820: if ($interval[0] =~ /\d+/) {
4821: my $first_access=&Apache::lonnet::get_first_access($interval[1],
1.509.2.1 raeburn 4822: $self->{SYMB});
1.382 albertel 4823: if (defined($first_access)) {
1.406 albertel 4824: my $interval = $first_access+$interval[0];
1.404 albertel 4825: $date = (!$due_date || $interval < $due_date) ? $interval
4826: : $due_date;
1.382 albertel 4827: } else {
4828: $date = $due_date;
4829: }
4830: } else {
4831: $date = $due_date;
1.260 albertel 4832: }
1.479 raeburn 4833: $self->{DUEDATE_CACHE}->{$part} = $date;
1.382 albertel 4834: return $date;
1.51 bowersj2 4835: }
1.334 albertel 4836: sub handgrade {
4837: (my $self, my $part) = @_;
1.399 albertel 4838: my @response_ids = $self->responseIds($part);
4839: if (@response_ids) {
4840: foreach my $response_id (@response_ids) {
1.410 raeburn 4841: my $handgrade = $self->parmval("handgrade",$part.'_'.$response_id);
4842: if (lc($handgrade) eq 'yes') {
1.399 albertel 4843: return 'yes';
4844: }
4845: }
4846: }
1.410 raeburn 4847: my $handgrade = $self->parmval("handgrade", $part);
4848: return $handgrade;
1.334 albertel 4849: }
1.51 bowersj2 4850: sub maxtries {
4851: (my $self, my $part) = @_;
1.410 raeburn 4852: my $maxtries = $self->parmval("maxtries", $part);
4853: return $maxtries;
1.51 bowersj2 4854: }
4855: sub opendate {
4856: (my $self, my $part) = @_;
1.410 raeburn 4857: my $opendatetype = $self->parmval("opendate.type", $part);
4858: my $opendate = $self->parmval("opendate", $part);
4859: if ($opendatetype eq 'date_interval') {
4860: my $duedate = $self->duedate($part);
4861: $opendate = $duedate - $opendate;
1.51 bowersj2 4862: }
1.410 raeburn 4863: return $opendate;
1.51 bowersj2 4864: }
1.185 bowersj2 4865: sub problemstatus {
4866: (my $self, my $part) = @_;
1.410 raeburn 4867: my $problemstatus = $self->parmval("problemstatus", $part);
4868: return lc($problemstatus);
1.185 bowersj2 4869: }
1.51 bowersj2 4870: sub sig {
4871: (my $self, my $part) = @_;
1.410 raeburn 4872: my $sig = $self->parmval("sig", $part);
4873: return $sig;
1.51 bowersj2 4874: }
4875: sub tol {
4876: (my $self, my $part) = @_;
1.410 raeburn 4877: my $tol = $self->parmval("tol", $part);
4878: return $tol;
1.51 bowersj2 4879: }
1.410 raeburn 4880: sub tries {
1.108 bowersj2 4881: my $self = shift;
4882: my $tries = $self->queryRestoreHash('tries', shift);
4883: if (!defined($tries)) { return '0';}
1.51 bowersj2 4884: return $tries;
4885: }
1.70 bowersj2 4886: sub type {
4887: (my $self, my $part) = @_;
1.410 raeburn 4888: my $type = $self->parmval("type", $part);
4889: return $type;
1.70 bowersj2 4890: }
1.109 bowersj2 4891: sub weight {
4892: my $self = shift; my $part = shift;
1.211 bowersj2 4893: if (!defined($part)) { $part = '0'; }
1.409 raeburn 4894: my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
1.508 damieng 4895: $self->{SYMB}, $self->{DOMAIN},
1.453 www 4896: $self->{USERNAME},
1.409 raeburn 4897: $env{'request.course.sec'});
4898: return $weight;
1.274 matthew 4899: }
4900: sub part_display {
4901: my $self= shift(); my $partID = shift();
4902: if (! defined($partID)) { $partID = '0'; }
4903: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',
1.509.2.1 raeburn 4904: $self->{SYMB});
1.274 matthew 4905: if (! defined($display) || $display eq '') {
4906: $display = $partID;
4907: }
4908: return $display;
1.70 bowersj2 4909: }
1.432 raeburn 4910: sub slot_control {
4911: my $self=shift(); my $part = shift();
4912: if (!defined($part)) { $part = '0'; }
4913: my $useslots = $self->parmval("useslots", $part);
4914: my $availablestudent = $self->parmval("availablestudent", $part);
4915: my $available = $self->parmval("available", $part);
4916: return ($useslots,$availablestudent,$available);
4917: }
1.51 bowersj2 4918:
4919: # Multiple things need this
4920: sub getReturnHash {
4921: my $self = shift;
4922:
4923: if (!defined($self->{RETURN_HASH})) {
1.508 damieng 4924: my %tmpHash = &Apache::lonnet::restore($self->{SYMB},undef,$self->{DOMAIN},$self->{USERNAME});
1.51 bowersj2 4925: $self->{RETURN_HASH} = \%tmpHash;
4926: }
4927: }
4928:
4929: ######
4930: # Status queries
4931: ######
4932:
4933: # These methods query the status of problems.
4934:
4935: # If we need to count parts, this function determines the number of
4936: # parts from the metadata. When called, it returns a reference to a list
4937: # of strings corresponding to the parts. (Thus, using it in a scalar context
4938: # tells you how many parts you have in the problem:
4939: # $partcount = scalar($resource->countParts());
4940: # Don't use $self->{PARTS} directly because you don't know if it's been
4941: # computed yet.
4942:
4943: =pod
4944:
4945: =head2 Resource misc
4946:
4947: Misc. functions for the resource.
4948:
4949: =over 4
4950:
1.174 albertel 4951: =item * B<hasDiscussion>:
1.59 bowersj2 4952:
1.174 albertel 4953: Returns a false value if there has been discussion since the user last
4954: logged in, true if there has. Always returns false if the discussion
4955: data was not extracted when the nav map was constructed.
4956:
1.366 albertel 4957: =item * B<last_post_time>:
4958:
4959: Returns a false value if there hasn't been discussion otherwise returns
4960: unix timestamp of last time a discussion posting (or edit) was made.
4961:
1.393 raeburn 4962: =item * B<discussion_info>:
1.366 albertel 4963:
1.393 raeburn 4964: optional argument is a filter (currently can be 'unread');
4965: returns in scalar context the count of the number of discussion postings.
1.366 albertel 4966:
4967: returns in list context both the count of postings and a hash ref
1.393 raeburn 4968: containing information about the postings (subject, id, timestamp) in a hash.
4969:
4970: 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 4971:
1.174 albertel 4972: =item * B<getFeedback>:
4973:
4974: Gets the feedback for the resource and returns the raw feedback string
4975: for the resource, or the null string if there is no feedback or the
4976: email data was not extracted when the nav map was constructed. Usually
4977: used like this:
1.59 bowersj2 4978:
1.394 raeburn 4979: for my $url (split(/\,/, $res->getFeedback())) {
4980: my $link = &escape($url);
1.59 bowersj2 4981: ...
4982:
4983: and use the link as appropriate.
4984:
4985: =cut
4986:
4987: sub hasDiscussion {
4988: my $self = shift;
1.508 damieng 4989: return $self->{NAV_MAP}->hasDiscussion($self->{SYMB});
1.59 bowersj2 4990: }
4991:
1.366 albertel 4992: sub last_post_time {
4993: my $self = shift;
1.508 damieng 4994: return $self->{NAV_MAP}->last_post_time($self->{SYMB});
1.366 albertel 4995: }
4996:
1.393 raeburn 4997: sub discussion_info {
4998: my ($self,$filter) = @_;
1.508 damieng 4999: return $self->{NAV_MAP}->discussion_info($self->{SYMB},$filter);
1.366 albertel 5000: }
5001:
1.59 bowersj2 5002: sub getFeedback {
5003: my $self = shift;
1.124 bowersj2 5004: my $source = $self->src();
1.508 damieng 5005: my $symb = $self->{SYMB};
1.125 bowersj2 5006: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395 raeburn 5007: return $self->{NAV_MAP}->getFeedback($symb,$source);
1.124 bowersj2 5008: }
5009:
5010: sub getErrors {
5011: my $self = shift;
5012: my $source = $self->src();
1.508 damieng 5013: my $symb = $self->{SYMB};
1.124 bowersj2 5014: if ($source =~ /^\/res\//) { $source = substr $source, 5; }
1.395 raeburn 5015: return $self->{NAV_MAP}->getErrors($symb,$source);
1.59 bowersj2 5016: }
5017:
5018: =pod
5019:
1.174 albertel 5020: =item * B<parts>():
1.51 bowersj2 5021:
1.174 albertel 5022: Returns a list reference containing sorted strings corresponding to
1.193 bowersj2 5023: each part of the problem. Single part problems have only a part '0'.
5024: Multipart problems do not return their part '0', since they typically
5025: do not really matter.
1.174 albertel 5026:
5027: =item * B<countParts>():
5028:
5029: Returns the number of parts of the problem a student can answer. Thus,
5030: for single part problems, returns 1. For multipart, it returns the
1.193 bowersj2 5031: number of parts in the problem, not including psuedo-part 0.
1.51 bowersj2 5032:
1.290 matthew 5033: =item * B<countResponses>():
5034:
5035: Returns the total number of responses in the problem a student can answer.
5036:
5037: =item * B<responseTypes>():
5038:
5039: Returns a hash whose keys are the response types. The values are the number
5040: of times each response type is used. This is for the I<entire> problem, not
5041: just a single part.
5042:
1.192 bowersj2 5043: =item * B<multipart>():
5044:
1.193 bowersj2 5045: Returns true if the problem is multipart, false otherwise. Use this instead
5046: of countParts if all you want is multipart/not multipart.
1.192 bowersj2 5047:
1.187 bowersj2 5048: =item * B<responseType>($part):
5049:
5050: Returns the response type of the part, without the word "response" on the
5051: end. Example return values: 'string', 'essay', 'numeric', etc.
5052:
1.193 bowersj2 5053: =item * B<responseIds>($part):
1.187 bowersj2 5054:
1.193 bowersj2 5055: Retreives the response IDs for the given part as an array reference containing
5056: strings naming the response IDs. This may be empty.
1.187 bowersj2 5057:
1.51 bowersj2 5058: =back
5059:
5060: =cut
5061:
5062: sub parts {
5063: my $self = shift;
5064:
1.192 bowersj2 5065: if ($self->ext) { return []; }
1.67 bowersj2 5066:
1.51 bowersj2 5067: $self->extractParts();
5068: return $self->{PARTS};
5069: }
5070:
5071: sub countParts {
5072: my $self = shift;
5073:
5074: my $parts = $self->parts();
1.191 bowersj2 5075:
5076: # If I left this here, then it's not necessary.
5077: #my $delta = 0;
5078: #for my $part (@$parts) {
5079: # if ($part eq '0') { $delta--; }
5080: #}
1.66 bowersj2 5081:
5082: if ($self->{RESOURCE_ERROR}) {
5083: return 0;
5084: }
5085:
1.191 bowersj2 5086: return scalar(@{$parts}); # + $delta;
1.192 bowersj2 5087: }
5088:
1.290 matthew 5089: sub countResponses {
5090: my $self = shift;
5091: my $count;
1.293 matthew 5092: foreach my $part (@{$self->parts()}) {
5093: $count+= scalar($self->responseIds($part));
1.290 matthew 5094: }
5095: return $count;
5096: }
5097:
5098: sub responseTypes {
5099: my $self = shift;
1.291 albertel 5100: my %responses;
1.368 raeburn 5101: foreach my $part (@{$self->parts()}) {
1.290 matthew 5102: foreach my $responsetype ($self->responseType($part)) {
1.291 albertel 5103: $responses{$responsetype}++ if (defined($responsetype));
1.290 matthew 5104: }
5105: }
1.291 albertel 5106: return %responses;
1.290 matthew 5107: }
5108:
1.192 bowersj2 5109: sub multipart {
5110: my $self = shift;
5111: return $self->countParts() > 1;
1.51 bowersj2 5112: }
5113:
1.225 bowersj2 5114: sub singlepart {
5115: my $self = shift;
5116: return $self->countParts() == 1;
5117: }
5118:
1.187 bowersj2 5119: sub responseType {
1.184 bowersj2 5120: my $self = shift;
5121: my $part = shift;
5122:
5123: $self->extractParts();
1.235 albertel 5124: if (defined($self->{RESPONSE_TYPES}->{$part})) {
5125: return @{$self->{RESPONSE_TYPES}->{$part}};
5126: } else {
5127: return undef;
5128: }
1.187 bowersj2 5129: }
5130:
1.193 bowersj2 5131: sub responseIds {
1.187 bowersj2 5132: my $self = shift;
5133: my $part = shift;
5134:
5135: $self->extractParts();
1.235 albertel 5136: if (defined($self->{RESPONSE_IDS}->{$part})) {
5137: return @{$self->{RESPONSE_IDS}->{$part}};
5138: } else {
5139: return undef;
5140: }
1.184 bowersj2 5141: }
5142:
5143: # Private function: Extracts the parts information, both part names and
1.187 bowersj2 5144: # part types, and saves it.
1.51 bowersj2 5145: sub extractParts {
5146: my $self = shift;
5147:
1.153 bowersj2 5148: return if (defined($self->{PARTS}));
1.67 bowersj2 5149: return if ($self->ext);
1.51 bowersj2 5150:
5151: $self->{PARTS} = [];
5152:
1.181 bowersj2 5153: my %parts;
5154:
1.82 bowersj2 5155: # Retrieve part count, if this is a problem
5156: if ($self->is_problem()) {
1.240 albertel 5157: my $partorder = &Apache::lonnet::metadata($self->src(), 'partorder');
1.152 matthew 5158: my $metadata = &Apache::lonnet::metadata($self->src(), 'packages');
1.181 bowersj2 5159:
1.239 bowersj2 5160: if ($partorder) {
5161: my @parts;
5162: for my $part (split (/,/,$partorder)) {
1.508 damieng 5163: if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239 bowersj2 5164: push @parts, $part;
1.241 albertel 5165: $parts{$part} = 1;
1.239 bowersj2 5166: }
5167: }
5168: $self->{PARTS} = \@parts;
5169: } else {
5170: if (!$metadata) {
5171: $self->{RESOURCE_ERROR} = 1;
5172: $self->{PARTS} = [];
5173: $self->{PART_TYPE} = {};
5174: return;
5175: }
1.394 raeburn 5176: foreach my $entry (split(/\,/,$metadata)) {
5177: if ($entry =~ /^(?:part|Task)_(.*)$/) {
1.239 bowersj2 5178: my $part = $1;
5179: # This floods the logs if it blows up
5180: if (defined($parts{$part})) {
1.508 damieng 5181: &Apache::lonnet::logthis("$part multiply defined in metadata for " . $self->{SYMB});
1.241 albertel 5182: }
1.239 bowersj2 5183:
5184: # check to see if part is turned off.
5185:
1.508 damieng 5186: if (!Apache::loncommon::check_if_partid_hidden($part, $self->{SYMB})) {
1.239 bowersj2 5187: $parts{$part} = 1;
5188: }
5189: }
5190: }
1.504 raeburn 5191: my @sortedParts = sort(keys(%parts));
1.239 bowersj2 5192: $self->{PARTS} = \@sortedParts;
1.51 bowersj2 5193: }
1.82 bowersj2 5194:
1.187 bowersj2 5195:
1.284 matthew 5196: # These hashes probably do not need names that end with "Hash"....
1.187 bowersj2 5197: my %responseIdHash;
5198: my %responseTypeHash;
5199:
1.189 bowersj2 5200:
5201: # Init the responseIdHash
1.394 raeburn 5202: foreach my $part (@{$self->{PARTS}}) {
5203: $responseIdHash{$part} = [];
1.189 bowersj2 5204: }
5205:
1.187 bowersj2 5206: # Now, the unfortunate thing about this is that parts, part name, and
1.239 bowersj2 5207: # response id are delimited by underscores, but both the part
1.187 bowersj2 5208: # name and response id can themselves have underscores in them.
5209: # So we have to use our knowlege of part names to figure out
5210: # where the part names begin and end, and even then, it is possible
5211: # to construct ambiguous situations.
1.504 raeburn 5212: foreach my $data (split(/,/, $metadata)) {
1.379 albertel 5213: if ($data =~ /^([a-zA-Z]+)response_(.*)/
5214: || $data =~ /^(Task)_(.*)/) {
1.187 bowersj2 5215: my $responseType = $1;
5216: my $partStuff = $2;
5217: my $partIdSoFar = '';
1.504 raeburn 5218: my @partChunks = split(/_/, $partStuff);
1.187 bowersj2 5219: my $i = 0;
5220: for ($i = 0; $i < scalar(@partChunks); $i++) {
5221: if ($partIdSoFar) { $partIdSoFar .= '_'; }
5222: $partIdSoFar .= $partChunks[$i];
5223: if ($parts{$partIdSoFar}) {
5224: my @otherChunks = @partChunks[$i+1..$#partChunks];
5225: my $responseId = join('_', @otherChunks);
1.379 albertel 5226: if ($self->is_task()) {
5227: push(@{$responseIdHash{$partIdSoFar}},
5228: $partIdSoFar);
5229: } else {
5230: push(@{$responseIdHash{$partIdSoFar}},
5231: $responseId);
5232: }
5233: push(@{$responseTypeHash{$partIdSoFar}},
5234: $responseType);
1.187 bowersj2 5235: }
5236: }
5237: }
5238: }
1.264 albertel 5239: my $resorder = &Apache::lonnet::metadata($self->src(),'responseorder');
1.284 matthew 5240: #
5241: # Reorder the arrays in the %responseIdHash and %responseTypeHash
1.264 albertel 5242: if ($resorder) {
5243: my @resorder=split(/,/,$resorder);
5244: foreach my $part (keys(%responseIdHash)) {
1.286 albertel 5245: my $i=0;
5246: my %resids = map { ($_,$i++) } @{ $responseIdHash{$part} };
1.264 albertel 5247: my @neworder;
5248: foreach my $possibleid (@resorder) {
5249: if (exists($resids{$possibleid})) {
1.286 albertel 5250: push(@neworder,$resids{$possibleid});
1.264 albertel 5251: }
5252: }
1.286 albertel 5253: my @ids;
5254: my @type;
5255: foreach my $element (@neworder) {
5256: push (@ids,$responseIdHash{$part}->[$element]);
5257: push (@type,$responseTypeHash{$part}->[$element]);
5258: }
5259: $responseIdHash{$part}=\@ids;
5260: $responseTypeHash{$part}=\@type;
1.264 albertel 5261: }
5262: }
1.187 bowersj2 5263: $self->{RESPONSE_IDS} = \%responseIdHash;
5264: $self->{RESPONSE_TYPES} = \%responseTypeHash;
1.154 bowersj2 5265: }
5266:
1.51 bowersj2 5267: return;
5268: }
5269:
5270: =pod
5271:
5272: =head2 Resource Status
5273:
1.174 albertel 5274: Problem resources have status information, reflecting their various
5275: dates and completion statuses.
1.51 bowersj2 5276:
1.174 albertel 5277: There are two aspects to the status: the date-related information and
5278: the completion information.
1.51 bowersj2 5279:
1.174 albertel 5280: Idiomatic usage of these two methods would probably look something
5281: like
1.51 bowersj2 5282:
1.394 raeburn 5283: foreach my $part ($resource->parts()) {
5284: my $dateStatus = $resource->getDateStatus($part);
5285: my $completionStatus = $resource->getCompletionStatus($part);
1.51 bowersj2 5286:
1.70 bowersj2 5287: or
5288:
1.394 raeburn 5289: my $status = $resource->status($part);
1.70 bowersj2 5290:
1.51 bowersj2 5291: ... use it here ...
5292: }
5293:
1.174 albertel 5294: Which you use depends on exactly what you are looking for. The
5295: status() function has been optimized for the nav maps display and may
5296: not precisely match what you need elsewhere.
1.101 bowersj2 5297:
1.174 albertel 5298: The symbolic constants shown below can be accessed through the
5299: resource object: C<$res->OPEN>.
1.101 bowersj2 5300:
1.51 bowersj2 5301: =over 4
5302:
1.174 albertel 5303: =item * B<getDateStatus>($part):
5304:
5305: ($part defaults to 0). A convenience function that returns a symbolic
5306: constant telling you about the date status of the part. The possible
5307: return values are:
1.51 bowersj2 5308:
5309: =back
5310:
5311: B<Date Codes>
5312:
5313: =over 4
5314:
1.174 albertel 5315: =item * B<OPEN_LATER>:
5316:
5317: The problem will be opened later.
5318:
5319: =item * B<OPEN>:
5320:
5321: Open and not yet due.
5322:
1.51 bowersj2 5323:
1.174 albertel 5324: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 5325:
1.174 albertel 5326: The due date has passed, but the answer date has not yet arrived.
1.59 bowersj2 5327:
1.174 albertel 5328: =item * B<PAST_DUE_NO_ANSWER>:
1.54 bowersj2 5329:
1.174 albertel 5330: The due date has passed and there is no answer opening date set.
1.51 bowersj2 5331:
1.174 albertel 5332: =item * B<ANSWER_OPEN>:
1.51 bowersj2 5333:
1.174 albertel 5334: The answer date is here.
5335:
5336: =item * B<NETWORK_FAILURE>:
5337:
5338: The information is unknown due to network failure.
1.51 bowersj2 5339:
5340: =back
5341:
5342: =cut
5343:
5344: # Apparently the compiler optimizes these into constants automatically
1.54 bowersj2 5345: sub OPEN_LATER { return 0; }
5346: sub OPEN { return 1; }
5347: sub PAST_DUE_NO_ANSWER { return 2; }
5348: sub PAST_DUE_ANSWER_LATER { return 3; }
5349: sub ANSWER_OPEN { return 4; }
1.432 raeburn 5350: sub NOTHING_SET { return 5; }
1.54 bowersj2 5351: sub NETWORK_FAILURE { return 100; }
5352:
5353: # getDateStatus gets the date status for a given problem part.
5354: # Because answer date, due date, and open date are fully independent
5355: # (i.e., it is perfectly possible to *only* have an answer date),
5356: # we have to completely cover the 3x3 maxtrix of (answer, due, open) x
5357: # (past, future, none given). This function handles this with a decision
5358: # tree. Read the comments to follow the decision tree.
1.51 bowersj2 5359:
5360: sub getDateStatus {
5361: my $self = shift;
5362: my $part = shift;
5363: $part = "0" if (!defined($part));
1.54 bowersj2 5364:
5365: # Always return network failure if there was one.
1.51 bowersj2 5366: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5367:
5368: my $now = time();
5369:
1.53 bowersj2 5370: my $open = $self->opendate($part);
5371: my $due = $self->duedate($part);
5372: my $answer = $self->answerdate($part);
5373:
5374: if (!$open && !$due && !$answer) {
5375: # no data on the problem at all
5376: # should this be the same as "open later"? think multipart.
5377: return $self->NOTHING_SET;
5378: }
1.59 bowersj2 5379: if (!$open || $now < $open) {return $self->OPEN_LATER}
5380: if (!$due || $now < $due) {return $self->OPEN}
5381: if ($answer && $now < $answer) {return $self->PAST_DUE_ANSWER_LATER}
5382: if ($answer) { return $self->ANSWER_OPEN; }
1.54 bowersj2 5383: return PAST_DUE_NO_ANSWER;
1.51 bowersj2 5384: }
5385:
5386: =pod
5387:
5388: B<>
5389:
5390: =over 4
5391:
1.174 albertel 5392: =item * B<getCompletionStatus>($part):
1.51 bowersj2 5393:
1.174 albertel 5394: ($part defaults to 0.) A convenience function that returns a symbolic
5395: constant telling you about the completion status of the part, with the
5396: following possible results:
5397:
5398: =back
1.51 bowersj2 5399:
5400: B<Completion Codes>
5401:
5402: =over 4
5403:
1.174 albertel 5404: =item * B<NOT_ATTEMPTED>:
5405:
5406: Has not been attempted at all.
5407:
5408: =item * B<INCORRECT>:
5409:
5410: Attempted, but wrong by student.
1.51 bowersj2 5411:
1.174 albertel 5412: =item * B<INCORRECT_BY_OVERRIDE>:
1.51 bowersj2 5413:
1.174 albertel 5414: Attempted, but wrong by instructor override.
1.51 bowersj2 5415:
1.174 albertel 5416: =item * B<CORRECT>:
1.51 bowersj2 5417:
1.174 albertel 5418: Correct or correct by instructor.
1.51 bowersj2 5419:
1.174 albertel 5420: =item * B<CORRECT_BY_OVERRIDE>:
1.51 bowersj2 5421:
1.174 albertel 5422: Correct by instructor override.
1.51 bowersj2 5423:
1.174 albertel 5424: =item * B<EXCUSED>:
5425:
5426: Excused. Not yet implemented.
5427:
5428: =item * B<NETWORK_FAILURE>:
5429:
5430: Information not available due to network failure.
5431:
5432: =item * B<ATTEMPTED>:
5433:
5434: Attempted, and not yet graded.
1.69 bowersj2 5435:
1.450 raeburn 5436: =item * B<CREDIT_ATTEMPTED>:
5437:
5438: Attempted, and credit received for attempt (survey and anonymous survey only).
5439:
1.51 bowersj2 5440: =back
5441:
5442: =cut
5443:
1.53 bowersj2 5444: sub NOT_ATTEMPTED { return 10; }
5445: sub INCORRECT { return 11; }
5446: sub INCORRECT_BY_OVERRIDE { return 12; }
5447: sub CORRECT { return 13; }
5448: sub CORRECT_BY_OVERRIDE { return 14; }
5449: sub EXCUSED { return 15; }
1.69 bowersj2 5450: sub ATTEMPTED { return 16; }
1.450 raeburn 5451: sub CREDIT_ATTEMPTED { return 17; }
1.51 bowersj2 5452:
5453: sub getCompletionStatus {
5454: my $self = shift;
1.332 albertel 5455: my $part = shift;
1.51 bowersj2 5456: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5457:
1.332 albertel 5458: my $status = $self->queryRestoreHash('solved', $part);
1.51 bowersj2 5459:
1.251 www 5460: # Left as separate if statements in case we ever do more with this
1.51 bowersj2 5461: if ($status eq 'correct_by_student') {return $self->CORRECT;}
1.288 albertel 5462: if ($status eq 'correct_by_scantron') {return $self->CORRECT;}
1.332 albertel 5463: if ($status eq 'correct_by_override') {
5464: return $self->CORRECT_BY_OVERRIDE;
5465: }
1.51 bowersj2 5466: if ($status eq 'incorrect_attempted') {return $self->INCORRECT; }
5467: if ($status eq 'incorrect_by_override') {return $self->INCORRECT_BY_OVERRIDE; }
5468: if ($status eq 'excused') {return $self->EXCUSED; }
1.69 bowersj2 5469: if ($status eq 'ungraded_attempted') {return $self->ATTEMPTED; }
1.450 raeburn 5470: if ($status eq 'credit_attempted') {
5471: if ($self->is_anonsurvey($part) || $self->is_survey($part)) {
5472: return $self->CREDIT_ATTEMPTED;
5473: } else {
5474: return $self->ATTEMPTED;
5475: }
5476: }
1.51 bowersj2 5477: return $self->NOT_ATTEMPTED;
1.108 bowersj2 5478: }
5479:
5480: sub queryRestoreHash {
5481: my $self = shift;
5482: my $hashentry = shift;
5483: my $part = shift;
1.185 bowersj2 5484: $part = "0" if (!defined($part) || $part eq '');
1.108 bowersj2 5485: return $self->NETWORK_FAILURE if ($self->{NAV_MAP}->{NETWORK_FAILURE});
5486:
5487: $self->getReturnHash();
5488:
5489: return $self->{RETURN_HASH}->{'resource.'.$part.'.'.$hashentry};
1.51 bowersj2 5490: }
5491:
5492: =pod
5493:
5494: B<Composite Status>
5495:
1.174 albertel 5496: Along with directly returning the date or completion status, the
5497: resource object includes a convenience function B<status>() that will
5498: combine the two status tidbits into one composite status that can
1.191 bowersj2 5499: represent the status of the resource as a whole. This method represents
5500: the concept of the thing we want to display to the user on the nav maps
5501: screen, which is a combination of completion and open status. The precise logic is
1.174 albertel 5502: documented in the comments of the status method. The following results
5503: may be returned, all available as methods on the resource object
1.185 bowersj2 5504: ($res->NETWORK_FAILURE): In addition to the return values that match
5505: the date or completion status, this function can return "ANSWER_SUBMITTED"
5506: if that problemstatus parameter value is set to No, suppressing the
5507: incorrect/correct feedback.
1.51 bowersj2 5508:
5509: =over 4
5510:
1.174 albertel 5511: =item * B<NETWORK_FAILURE>:
5512:
5513: The network has failed and the information is not available.
1.51 bowersj2 5514:
1.174 albertel 5515: =item * B<NOTHING_SET>:
1.53 bowersj2 5516:
1.174 albertel 5517: No dates have been set for this problem (part) at all. (Because only
5518: certain parts of a multi-part problem may be assigned, this can not be
5519: collapsed into "open later", as we do not know a given part will EVER
5520: be opened. For single part, this is the same as "OPEN_LATER".)
1.51 bowersj2 5521:
1.174 albertel 5522: =item * B<CORRECT>:
1.51 bowersj2 5523:
1.174 albertel 5524: For any reason at all, the part is considered correct.
1.54 bowersj2 5525:
1.174 albertel 5526: =item * B<EXCUSED>:
1.51 bowersj2 5527:
1.174 albertel 5528: For any reason at all, the problem is excused.
1.51 bowersj2 5529:
1.174 albertel 5530: =item * B<PAST_DUE_NO_ANSWER>:
1.51 bowersj2 5531:
1.174 albertel 5532: The problem is past due, not considered correct, and no answer date is
5533: set.
1.51 bowersj2 5534:
1.174 albertel 5535: =item * B<PAST_DUE_ANSWER_LATER>:
1.51 bowersj2 5536:
1.174 albertel 5537: The problem is past due, not considered correct, and an answer date in
5538: the future is set.
1.51 bowersj2 5539:
1.174 albertel 5540: =item * B<ANSWER_OPEN>:
5541:
5542: The problem is past due, not correct, and the answer is now available.
5543:
5544: =item * B<OPEN_LATER>:
5545:
5546: The problem is not yet open.
5547:
5548: =item * B<TRIES_LEFT>:
5549:
5550: The problem is open, has been tried, is not correct, but there are
5551: tries left.
5552:
5553: =item * B<INCORRECT>:
5554:
5555: The problem is open, and all tries have been used without getting the
5556: correct answer.
5557:
5558: =item * B<OPEN>:
5559:
5560: The item is open and not yet tried.
5561:
5562: =item * B<ATTEMPTED>:
5563:
5564: The problem has been attempted.
1.69 bowersj2 5565:
1.450 raeburn 5566: =item * B<CREDIT_ATTEMPTED>:
5567:
5568: The problem has been attempted, and credit given for the attempt (survey and anonymous survey only).
5569:
1.185 bowersj2 5570: =item * B<ANSWER_SUBMITTED>:
5571:
5572: An answer has been submitted, but the student should not see it.
5573:
1.51 bowersj2 5574: =back
5575:
5576: =cut
5577:
1.432 raeburn 5578: sub TRIES_LEFT { return 20; }
5579: sub ANSWER_SUBMITTED { return 21; }
5580: sub PARTIALLY_CORRECT { return 22; }
5581:
5582: sub RESERVED_LATER { return 30; }
5583: sub RESERVED { return 31; }
5584: sub RESERVED_LOCATION { return 32; }
5585: sub RESERVABLE { return 33; }
5586: sub RESERVABLE_LATER { return 34; }
5587: sub NOTRESERVABLE { return 35; }
5588: sub NOT_IN_A_SLOT { return 36; }
5589: sub NEEDS_CHECKIN { return 37; }
5590: sub WAITING_FOR_GRADE { return 38; }
5591: sub UNKNOWN { return 39; }
1.51 bowersj2 5592:
5593: sub status {
5594: my $self = shift;
5595: my $part = shift;
5596: if (!defined($part)) { $part = "0"; }
5597: my $completionStatus = $self->getCompletionStatus($part);
5598: my $dateStatus = $self->getDateStatus($part);
5599:
5600: # What we have is a two-dimensional matrix with 4 entries on one
5601: # dimension and 5 entries on the other, which we want to colorize,
1.54 bowersj2 5602: # plus network failure and "no date data at all".
1.51 bowersj2 5603:
1.222 bowersj2 5604: #if ($self->{RESOURCE_ERROR}) { return NETWORK_FAILURE; }
1.53 bowersj2 5605: if ($completionStatus == NETWORK_FAILURE) { return NETWORK_FAILURE; }
1.51 bowersj2 5606:
1.408 raeburn 5607: my $suppressFeedback = 0;
5608: if (($self->problemstatus($part) eq 'no') ||
5609: ($self->problemstatus($part) eq 'no_feedback_ever')) {
5610: $suppressFeedback = 1;
5611: }
1.236 bowersj2 5612: # If there's an answer date and we're past it, don't
5613: # suppress the feedback; student should know
1.330 albertel 5614: if ($self->duedate($part) && $self->duedate($part) < time() &&
5615: $self->answerdate($part) && $self->answerdate($part) < time()) {
1.236 bowersj2 5616: $suppressFeedback = 0;
5617: }
1.185 bowersj2 5618:
1.51 bowersj2 5619: # There are a few whole rows we can dispose of:
1.53 bowersj2 5620: if ($completionStatus == CORRECT ||
5621: $completionStatus == CORRECT_BY_OVERRIDE ) {
1.332 albertel 5622: if ( $suppressFeedback ) { return ANSWER_SUBMITTED }
5623: my $awarded=$self->awarded($part);
5624: if ($awarded < 1 && $awarded > 0) {
5625: return PARTIALLY_CORRECT;
5626: } elsif ($awarded<1) {
5627: return INCORRECT;
5628: }
5629: return CORRECT;
1.69 bowersj2 5630: }
5631:
1.343 albertel 5632: # If it's WRONG... and not open
5633: if ( ($completionStatus == INCORRECT ||
5634: $completionStatus == INCORRECT_BY_OVERRIDE)
5635: && (!$self->opendate($part) || $self->opendate($part) > time()) ) {
5636: return INCORRECT;
5637: }
5638:
1.69 bowersj2 5639: if ($completionStatus == ATTEMPTED) {
5640: return ATTEMPTED;
1.53 bowersj2 5641: }
5642:
1.450 raeburn 5643: if ($completionStatus == CREDIT_ATTEMPTED) {
5644: return CREDIT_ATTEMPTED;
5645: }
5646:
1.53 bowersj2 5647: # If it's EXCUSED, then return that no matter what
5648: if ($completionStatus == EXCUSED) {
5649: return EXCUSED;
1.51 bowersj2 5650: }
5651:
1.53 bowersj2 5652: if ($dateStatus == NOTHING_SET) {
5653: return NOTHING_SET;
1.51 bowersj2 5654: }
5655:
1.69 bowersj2 5656: # Now we're down to a 4 (incorrect, incorrect_override, not_attempted)
5657: # by 4 matrix (date statuses).
1.51 bowersj2 5658:
1.54 bowersj2 5659: if ($dateStatus == PAST_DUE_ANSWER_LATER ||
1.59 bowersj2 5660: $dateStatus == PAST_DUE_NO_ANSWER ) {
1.272 albertel 5661: return $suppressFeedback ? ANSWER_SUBMITTED : $dateStatus;
1.51 bowersj2 5662: }
5663:
1.53 bowersj2 5664: if ($dateStatus == ANSWER_OPEN) {
5665: return ANSWER_OPEN;
1.51 bowersj2 5666: }
5667:
5668: # Now: (incorrect, incorrect_override, not_attempted) x
5669: # (open_later), (open)
5670:
1.53 bowersj2 5671: if ($dateStatus == OPEN_LATER) {
5672: return OPEN_LATER;
1.51 bowersj2 5673: }
5674:
5675: # If it's WRONG...
1.53 bowersj2 5676: if ($completionStatus == INCORRECT || $completionStatus == INCORRECT_BY_OVERRIDE) {
1.51 bowersj2 5677: # and there are TRIES LEFT:
1.79 bowersj2 5678: if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
1.222 bowersj2 5679: return $suppressFeedback ? ANSWER_SUBMITTED : TRIES_LEFT;
1.51 bowersj2 5680: }
1.185 bowersj2 5681: return $suppressFeedback ? ANSWER_SUBMITTED : INCORRECT; # otherwise, return orange; student can't fix this
1.51 bowersj2 5682: }
5683:
5684: # Otherwise, it's untried and open
1.473 raeburn 5685: return OPEN;
1.224 bowersj2 5686: }
5687:
1.432 raeburn 5688: sub check_for_slot {
5689: my $self = shift;
5690: my $part = shift;
1.508 damieng 5691: my $symb = $self->{SYMB};
1.432 raeburn 5692: my ($use_slots,$available,$availablestudent) = $self->slot_control($part);
5693: if (($use_slots ne '') && ($use_slots !~ /^\s*no\s*$/i)) {
5694: my @slots = (split(/:/,$availablestudent),split(/:/,$available));
5695: my $cid=$env{'request.course.id'};
5696: my $cdom=$env{'course.'.$cid.'.domain'};
5697: my $cnum=$env{'course.'.$cid.'.num'};
5698: my $now = time;
1.473 raeburn 5699: my $num_usable_slots = 0;
1.509.2.2 raeburn 5700: my ($checkedin,$checkedinslot,%consumed_uniq,%slots);
1.432 raeburn 5701: if (@slots > 0) {
1.509.2.2 raeburn 5702: %slots=&Apache::lonnet::get('slots',[@slots],$cdom,$cnum);
1.432 raeburn 5703: if (&Apache::lonnet::error(%slots)) {
5704: return (UNKNOWN);
5705: }
1.473 raeburn 5706: my @sorted_slots = &Apache::loncommon::sorted_slots(\@slots,\%slots,'starttime');
1.432 raeburn 5707: foreach my $slot_name (@sorted_slots) {
1.473 raeburn 5708: next if (!defined($slots{$slot_name}) || !ref($slots{$slot_name}));
1.432 raeburn 5709: my $end = $slots{$slot_name}->{'endtime'};
5710: my $start = $slots{$slot_name}->{'starttime'};
5711: my $ip = $slots{$slot_name}->{'ip'};
5712: if ($self->simpleStatus() == OPEN) {
5713: if ($end > $now) {
1.473 raeburn 5714: if ($start > $now) {
5715: return (RESERVED_LATER,$start,$slot_name);
5716: } else {
5717: if ($ip ne '') {
5718: if (!&Apache::loncommon::check_ip_acc($ip)) {
1.503 raeburn 5719: return (RESERVED_LOCATION,$end,$slot_name);
1.432 raeburn 5720: }
5721: }
1.473 raeburn 5722: my @proctors;
5723: if ($slots{$slot_name}->{'proctor'} ne '') {
5724: @proctors = split(',',$slots{$slot_name}->{'proctor'});
5725: }
5726: if (@proctors > 0) {
5727: ($checkedin,$checkedinslot) = $self->checkedin();
5728: unless ((grep(/^\Q$checkedin\E/,@proctors)) &&
5729: ($checkedinslot eq $slot_name)) {
1.509.2.6 raeburn 5730: return (NEEDS_CHECKIN,$end,$slot_name);
1.472 raeburn 5731: }
1.432 raeburn 5732: }
1.473 raeburn 5733: return (RESERVED,$end,$slot_name);
1.432 raeburn 5734: }
5735: }
1.473 raeburn 5736: } elsif ($end > $now) {
5737: $num_usable_slots ++;
1.432 raeburn 5738: }
5739: }
1.509.2.2 raeburn 5740: my ($is_correct,$wait_for_grade);
1.432 raeburn 5741: if ($self->is_task()) {
5742: my $taskstatus = $self->taskstatus();
5743: $is_correct = (($taskstatus eq 'pass') ||
5744: ($self->solved() =~ /^correct_/));
1.509.2.2 raeburn 5745: unless ($taskstatus =~ /^(?:pass|fail)$/) {
5746: $wait_for_grade = 1;
5747: }
1.432 raeburn 5748: } else {
1.509.2.2 raeburn 5749: unless ($self->completable()) {
5750: $wait_for_grade = 1;
5751: }
5752: unless (($self->problemstatus($part) eq 'no') ||
5753: ($self->problemstatus($part) eq 'no_feedback_ever')) {
5754: $is_correct = ($self->solved($part) =~ /^correct_/);
5755: $wait_for_grade = 0;
5756: }
1.432 raeburn 5757: }
5758: ($checkedin,$checkedinslot) = $self->checkedin();
5759: if ($checkedin) {
1.509.2.2 raeburn 5760: if (ref($slots{$checkedinslot}) eq 'HASH') {
5761: $consumed_uniq{$checkedinslot} = $slots{$checkedinslot}{'uniqueperiod'};
5762: }
5763: if ($wait_for_grade) {
1.432 raeburn 5764: return (WAITING_FOR_GRADE);
5765: } elsif ($is_correct) {
5766: return (CORRECT);
5767: }
5768: }
1.473 raeburn 5769: if ($num_usable_slots) {
5770: return(NOT_IN_A_SLOT);
5771: }
5772: }
5773: my $reservable = &Apache::lonnet::get_reservable_slots($cnum,$cdom,$env{'user.name'},
5774: $env{'user.domain'});
5775: if (ref($reservable) eq 'HASH') {
5776: if ((ref($reservable->{'now_order'}) eq 'ARRAY') && (ref($reservable->{'now'}) eq 'HASH')) {
1.474 raeburn 5777: foreach my $slot (reverse (@{$reservable->{'now_order'}})) {
1.509.2.2 raeburn 5778: my $canuse;
1.473 raeburn 5779: if (($reservable->{'now'}{$slot}{'symb'} eq '') ||
5780: ($reservable->{'now'}{$slot}{'symb'} eq $symb)) {
1.509.2.2 raeburn 5781: $canuse = 1;
5782: }
5783: if ($canuse) {
5784: if ($checkedin) {
5785: if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
5786: my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
5787: if ($reservable->{'now'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
5788: my ($new_uniq_start,$new_uniq_end) = ($1,$2);
5789: next if (!
5790: ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
5791: ($uniqstart > $new_uniq_end && $uniqend > $new_uniq_end ));
5792: }
5793: }
5794: }
1.473 raeburn 5795: return(RESERVABLE,$reservable->{'now'}{$slot}{'endreserve'});
5796: }
5797: }
1.432 raeburn 5798: }
1.473 raeburn 5799: if ((ref($reservable->{'future_order'}) eq 'ARRAY') && (ref($reservable->{'future'}) eq 'HASH')) {
1.474 raeburn 5800: foreach my $slot (@{$reservable->{'future_order'}}) {
1.509.2.2 raeburn 5801: my $canuse;
1.473 raeburn 5802: if (($reservable->{'future'}{$slot}{'symb'} eq '') ||
5803: ($reservable->{'future'}{$slot}{'symb'} eq $symb)) {
1.509.2.2 raeburn 5804: $canuse = 1;
5805: }
5806: if ($canuse) {
5807: if ($checkedin) {
5808: if (ref($consumed_uniq{$checkedinslot}) eq 'ARRAY') {
5809: my ($uniqstart,$uniqend)=@{$consumed_uniq{$checkedinslot}};
5810: if ($reservable->{'future'}{$slot}{'uniqueperiod'} =~ /^(\d+),(\d+)$/) {
5811: my ($new_uniq_start,$new_uniq_end) = ($1,$2);
5812: next if (!
5813: ($uniqstart < $new_uniq_start && $uniqend < $new_uniq_start) ||
5814: ($uniqstart > $new_uniq_end && $uniqend > $new_uniq_end ));
5815: }
5816: }
5817: }
1.473 raeburn 5818: return(RESERVABLE_LATER,$reservable->{'future'}{$slot}{'startreserve'});
5819: }
5820: }
1.432 raeburn 5821: }
5822: }
1.473 raeburn 5823: return(NOTRESERVABLE);
1.432 raeburn 5824: }
5825: return;
5826: }
5827:
1.224 bowersj2 5828: sub CLOSED { return 23; }
5829: sub ERROR { return 24; }
5830:
5831: =pod
5832:
5833: B<Simple Status>
5834:
5835: Convenience method B<simpleStatus> provides a "simple status" for the resource.
5836: "Simple status" corresponds to "which icon is shown on the
5837: Navmaps". There are six "simple" statuses:
5838:
5839: =over 4
5840:
5841: =item * B<CLOSED>: The problem is currently closed. (No icon shown.)
5842:
5843: =item * B<OPEN>: The problem is open and unattempted.
5844:
5845: =item * B<CORRECT>: The problem is correct for any reason.
5846:
5847: =item * B<INCORRECT>: The problem is incorrect and can still be
5848: completed successfully.
5849:
5850: =item * B<ATTEMPTED>: The problem has been attempted, but the student
5851: does not know if they are correct. (The ellipsis icon.)
5852:
5853: =item * B<ERROR>: There is an error retrieving information about this
5854: problem.
5855:
5856: =back
5857:
5858: =cut
5859:
5860: # This hash maps the composite status to this simple status, and
5861: # can be used directly, if you like
5862: my %compositeToSimple =
5863: (
5864: NETWORK_FAILURE() => ERROR,
5865: NOTHING_SET() => CLOSED,
5866: CORRECT() => CORRECT,
1.332 albertel 5867: PARTIALLY_CORRECT() => PARTIALLY_CORRECT,
1.224 bowersj2 5868: EXCUSED() => CORRECT,
5869: PAST_DUE_NO_ANSWER() => INCORRECT,
5870: PAST_DUE_ANSWER_LATER() => INCORRECT,
5871: ANSWER_OPEN() => INCORRECT,
5872: OPEN_LATER() => CLOSED,
5873: TRIES_LEFT() => OPEN,
5874: INCORRECT() => INCORRECT,
5875: OPEN() => OPEN,
5876: ATTEMPTED() => ATTEMPTED,
1.450 raeburn 5877: CREDIT_ATTEMPTED() => CORRECT,
1.224 bowersj2 5878: ANSWER_SUBMITTED() => ATTEMPTED
5879: );
5880:
5881: sub simpleStatus {
5882: my $self = shift;
5883: my $part = shift;
5884: my $status = $self->status($part);
5885: return $compositeToSimple{$status};
1.225 bowersj2 5886: }
5887:
5888: =pod
5889:
5890: B<simpleStatusCount> will return an array reference containing, in
5891: this order, the number of OPEN, CLOSED, CORRECT, INCORRECT, ATTEMPTED,
5892: and ERROR parts the given problem has.
5893:
5894: =cut
5895:
5896: # This maps the status to the slot we want to increment
5897: my %statusToSlotMap =
5898: (
5899: OPEN() => 0,
5900: CLOSED() => 1,
5901: CORRECT() => 2,
5902: INCORRECT() => 3,
5903: ATTEMPTED() => 4,
5904: ERROR() => 5
5905: );
5906:
5907: sub statusToSlot { return $statusToSlotMap{shift()}; }
5908:
5909: sub simpleStatusCount {
5910: my $self = shift;
5911:
5912: my @counts = (0, 0, 0, 0, 0, 0, 0);
5913: foreach my $part (@{$self->parts()}) {
5914: $counts[$statusToSlotMap{$self->simpleStatus($part)}]++;
5915: }
5916:
5917: return \@counts;
1.191 bowersj2 5918: }
5919:
5920: =pod
5921:
5922: B<Completable>
5923:
5924: The completable method represents the concept of I<whether the student can
5925: currently do the problem>. If the student can do the problem, which means
5926: that it is open, there are tries left, and if the problem is manually graded
5927: or the grade is suppressed via problemstatus, the student has not tried it
5928: yet, then the method returns 1. Otherwise, it returns 0, to indicate that
5929: either the student has tried it and there is no feedback, or that for
5930: some reason it is no longer completable (not open yet, successfully completed,
5931: out of tries, etc.). As an example, this is used as the filter for the
5932: "Uncompleted Homework" option for the nav maps.
5933:
5934: If this does not quite meet your needs, do not fiddle with it (unless you are
5935: fixing it to better match the student's conception of "completable" because
5936: it's broken somehow)... make a new method.
5937:
5938: =cut
5939:
5940: sub completable {
5941: my $self = shift;
5942: if (!$self->is_problem()) { return 0; }
5943: my $partCount = $self->countParts();
5944:
5945: foreach my $part (@{$self->parts()}) {
5946: if ($part eq '0' && $partCount != 1) { next; }
5947: my $status = $self->status($part);
5948: # "If any of the parts are open, or have tries left (implies open),
5949: # and it is not "attempted" (manually graded problem), it is
5950: # not "complete"
1.216 bowersj2 5951: if ($self->getCompletionStatus($part) == ATTEMPTED() ||
1.450 raeburn 5952: $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
1.216 bowersj2 5953: $status == ANSWER_SUBMITTED() ) {
5954: # did this part already, as well as we can
5955: next;
5956: }
5957: if ($status == OPEN() || $status == TRIES_LEFT()) {
5958: return 1;
5959: }
1.191 bowersj2 5960: }
5961:
5962: # If all the parts were complete, so was this problem.
1.216 bowersj2 5963: return 0;
1.51 bowersj2 5964: }
5965:
5966: =pod
5967:
1.507 raeburn 5968: B<Answerable>
5969:
5970: The answerable method differs from the completable method in its handling of problem parts
5971: for which feedback on correctness is suppressed, but the student still has tries left, and
5972: the problem part is not past due, (i.e., the student could submit a different answer if
5973: he/she so chose). For that case completable will return 0, whereas answerable will return 1.
5974:
5975: =cut
5976:
5977: sub answerable {
5978: my $self = shift;
5979: if (!$self->is_problem()) { return 0; }
5980: my $partCount = $self->countParts();
5981: foreach my $part (@{$self->parts()}) {
5982: if ($part eq '0' && $partCount != 1) { next; }
5983: my $status = $self->status($part);
5984: if ($self->getCompletionStatus($part) == ATTEMPTED() ||
5985: $self->getCompletionStatus($part) == CREDIT_ATTEMPTED() ||
5986: $status == ANSWER_SUBMITTED() ) {
5987: if ($self->tries($part) < $self->maxtries($part) || !$self->maxtries($part)) {
5988: return 1;
5989: }
5990: }
5991: if ($status == OPEN() || $status == TRIES_LEFT() || $status == NETWORK_FAILURE()) {
5992: return 1;
5993: }
5994: }
5995: # None of the parts were answerable, so neither is this problem.
5996: return 0;
5997: }
5998:
5999: =pod
6000:
1.51 bowersj2 6001: =head2 Resource/Nav Map Navigation
6002:
6003: =over 4
6004:
1.174 albertel 6005: =item * B<getNext>():
6006:
6007: Retreive an array of the possible next resources after this
6008: one. Always returns an array, even in the one- or zero-element case.
6009:
6010: =item * B<getPrevious>():
1.85 bowersj2 6011:
1.174 albertel 6012: Retreive an array of the possible previous resources from this
6013: one. Always returns an array, even in the one- or zero-element case.
1.51 bowersj2 6014:
6015: =cut
6016:
6017: sub getNext {
6018: my $self = shift;
6019: my @branches;
6020: my $to = $self->to();
1.85 bowersj2 6021: foreach my $branch ( split(/,/, $to) ) {
1.51 bowersj2 6022: my $choice = $self->{NAV_MAP}->getById($branch);
1.342 albertel 6023: #if (!$choice->condition()) { next; }
1.51 bowersj2 6024: my $next = $choice->goesto();
6025: $next = $self->{NAV_MAP}->getById($next);
6026:
1.131 bowersj2 6027: push @branches, $next;
1.85 bowersj2 6028: }
6029: return \@branches;
6030: }
6031:
6032: sub getPrevious {
6033: my $self = shift;
6034: my @branches;
6035: my $from = $self->from();
1.504 raeburn 6036: foreach my $branch ( split(/,/, $from)) {
1.85 bowersj2 6037: my $choice = $self->{NAV_MAP}->getById($branch);
6038: my $prev = $choice->comesfrom();
6039: $prev = $self->{NAV_MAP}->getById($prev);
6040:
1.131 bowersj2 6041: push @branches, $prev;
1.51 bowersj2 6042: }
6043: return \@branches;
1.131 bowersj2 6044: }
6045:
6046: sub browsePriv {
6047: my $self = shift;
1.505 raeburn 6048: my $noblockcheck = shift;
1.131 bowersj2 6049: if (defined($self->{BROWSE_PRIV})) {
6050: return $self->{BROWSE_PRIV};
6051: }
6052:
1.311 albertel 6053: $self->{BROWSE_PRIV} = &Apache::lonnet::allowed('bre',$self->src(),
1.508 damieng 6054: $self->{SYMB},undef,
1.505 raeburn 6055: undef,$noblockcheck);
1.51 bowersj2 6056: }
6057:
6058: =pod
1.2 www 6059:
1.51 bowersj2 6060: =back
1.2 www 6061:
1.51 bowersj2 6062: =cut
1.2 www 6063:
1.51 bowersj2 6064: 1;
1.2 www 6065:
1.51 bowersj2 6066: __END__
1.2 www 6067:
6068:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>