[LON-CAPA-dev] Extracting problems from page or sequence

Jerf lon-capa-dev@mail.lon-capa.org
Wed, 26 Feb 2003 15:32:02 -0500


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

H. K. Ng wrote:

First, go ahead and add the "getResourceByUrl" I wrote to
Apache::lonnavsmaps::navmap, so I can use it. I'll leave in the quote
marks so you can see what I changed. Also, I assume the symb of the map
~ is in $mapSymb; correct as necessary.

Note that the parts array is sorted lexigraphically, because the order
information is not preserved by the system. Generally, that gives the
correct order, but it may differ on occasion.

| Here is what I want to do.
|
|     my $navmap = Apache::lonnavmaps::navmap-> new(
|                                       $ENV{'request.course.fn'}.'.db',
|
| $ENV{'request.course.fn'}.'_parms.db',1, 1);
|
| # Below is the sym name of the page I am interested in. How do I extract
| the mapId from the sym? I had tried a few things but none of them works.
|
|
/fsu/ng/2053c_winter2003/CollegePhysicsA_Spring_2003.sequence___8___fsu/ng/2053c_winter2003/Assignment01.page

|
|

~      my ($mapUrl, $id, $resourceUrl) = split(/___/, $mapSymb);
~      my $map = $navmap->getResourceByUrl($mapUrl); # add to navmaps

|
|     my $iterator = $navmap->getIterator($map->map_start(),
|                               $map->map_finish());
|
|
|     my $depth = 1;
|     $iterator->next(); # skip the first BEGIN_MAP
|     my $curRes = $iterator->next(); # for "current resource"
|
|     while ($depth > 0) {
|         if($curRes == $iterator->BEGIN_MAP) { $depth++; }
|         if($curRes == $iterator->END_MAP) { $depth++; }
|
|         if (ref($curRes) && $curRes->is_problem()) {
| # What I want to do here is
| #(1) to get the sym name for each problem that is enclosed in the above
| #sequence/page,

~              my $symb = $curRes->symb();

| #(2) the title of the problem, and

~              my $title = $curRes->compTitle();

| #(3) the parts in order.

~              my $parts = $curRes->parts();

| # I got it to work extracting the title for each sequence/page in a
| # course but not the problems within a sequence/page.
|
|        }
|         $curRes = $iterator->next();
|     }
|
|
|
|
|
| At 03:24 PM 2/21/03 -0500, you wrote:
|
|> H. K. Ng wrote:
|>
|>> Presumably you are referring to the ID that is embedded in the
|>> symbolic name. I was able to get the page from which the problem
|>> comes from but could not get the symbolic names for other problems
|>> from the same page.
|>
|>
|> I just committed a new lonnavmaps that includes a "getResourceByUrl"
|> method on the lonnavmaps object, so you can ask the $navmap for the
|> map directly if you know the URL. (It turns out to be useful in many
|> contexts, not surprisingly.)
|>
|> Of course if you want this before the next release that doesn't help
|> much, but you can look at the code as an example if you want, as the
|> "getResourceByUrl" code should work in the .6.2 release, if you want
|> to implement it somewhere else or include it in your local copy.
|>
|> Here's how it's coded (and documented) in the latest lonnavmaps,
|> package Apache::lonnavmaps::navmap :
|>
|> =pod
|>
|> =item * B<getResourceByUrl>(url): Retrieves a resource object by URL
|> of the resource. If passed a resource object, it will simply return
|> it, so it is safe to use this method in code like "$res =
|> $navmap->getResourceByUrl($res)", if you're not sure if $res is
|> already an object, or just a URL. If the resource appears multiple
|> times in the course, only the first instance will be returned. As a
|> result, this is probably useful only for maps.
|>
|> =cut
|>
|> sub getResourceByUrl {
|>     my $self = shift;
|>     my $resUrl = shift;
|>
|>     if (ref($resUrl)) { return $resUrl; }
|>
|>     $resUrl = &Apache::lonnet::clutter($resUrl);
|>     my $resId = $self->{NAV_HASH}->{'ids_' . $resUrl};
|>     if ($resId =~ /,/) {
|>         $resId = (split (/,/, $resId))[0];
|>     }
|>     if (!$resId) { return ''; }
|>     return $self->getById($resId);
|> }
|>
|> _______________________________________________
|> LON-CAPA-dev mailing list
|> LON-CAPA-dev@mail.lon-capa.org
|> http://mail.lon-capa.org/mailman/listinfo/lon-capa-dev
|
|
|
| _______________________________________________
| LON-CAPA-dev mailing list
| LON-CAPA-dev@mail.lon-capa.org
| http://mail.lon-capa.org/mailman/listinfo/lon-capa-dev
|

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+XSRBPaYWE58at8cRAtbcAJ4+wLajs3pQWmo5sYd6bWIv9QSPBgCgnIXW
yieo/f+JXrxseigseSJWi3E=
=k6II
-----END PGP SIGNATURE-----