[LON-CAPA-dev] Extracting problems from page or sequence
Jeremy Bowers
lon-capa-dev@mail.lon-capa.org
Fri, 21 Feb 2003 15:24:04 -0500
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);
}