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