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