version 1.533, 2017/08/21 21:29:56
|
version 1.535, 2017/09/10 00:11:27
|
Line 501 use Apache::lonlocal;
|
Line 501 use Apache::lonlocal;
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::lonmap; |
use Apache::lonmap; |
|
|
use POSIX qw (floor strftime); |
use POSIX qw (ceil floor strftime); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use LONCAPA; |
use LONCAPA; |
use DateTime(); |
use DateTime(); |
Line 2882 sub recurseup_maps {
|
Line 2882 sub recurseup_maps {
|
} |
} |
|
|
sub recursed_crumbs { |
sub recursed_crumbs { |
my ($self,$mapurl) = @_; |
my ($self,$mapurl,$restitle) = @_; |
my (@revmapinfo,@revmapres); |
my (@revmapinfo,@revmapres); |
my $mapres = $self->getResourceByUrl($mapurl); |
my $mapres = $self->getResourceByUrl($mapurl); |
if (ref($mapres)) { |
if (ref($mapres)) { |
@revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_hierarchy()); |
@revmapres = map { $self->getByMapPc($_); } split(/,/,$mapres->map_breadcrumbs()); |
shift(@revmapres); |
shift(@revmapres); |
push(@revmapres,$mapres); |
|
} |
} |
my %toplevel; |
my $allowedlength = 60; |
|
my $minlength = 5; |
|
my $allowedtitle = 30; |
|
if (($env{'environment.icons'} eq 'iconsonly') && (!$env{'browser.mobile'})) { |
|
$allowedlength = 100; |
|
$allowedtitle = 70; |
|
} |
|
if (length($restitle) > $allowedtitle) { |
|
$restitle = &truncate_crumb_text($restitle,$allowedtitle); |
|
} |
|
my $totallength = length($restitle); |
|
my @links; |
|
|
foreach my $map (@revmapres) { |
foreach my $map (@revmapres) { |
my $pc = $map->map_pc(); |
my $pc = $map->map_pc(); |
next if ((!$pc) || ($pc == 1)); |
next if ((!$pc) || ($pc == 1)); |
my $func = sub { return ($_[0]->src() ne $map->src); }; |
push(@links,$map); |
my @resources = $self->retrieveResources($map->src,$func,0); |
push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,}); |
my $count = 0; |
$totallength += length($map->title()); |
my $notmap = 0; |
} |
foreach my $res (@resources) { |
my $numlinks = scalar(@links); |
next unless (ref($res)); |
if ($numlinks) { |
my $symb = $res->symb(); |
if ($totallength - $allowedlength > 0) { |
unless ($toplevel{$symb}) { |
my $available = $allowedlength - length($restitle); |
$toplevel{$symb} = $res->src; |
my $avg = POSIX::ceil($available/$numlinks); |
$count ++; |
if ($avg < $minlength) { |
unless ($res->is_map()) { |
$avg = $minlength; |
$notmap ++; |
} |
|
@revmapinfo = (); |
|
foreach my $map (@links) { |
|
my $showntitle = &truncate_crumb_text($map->title(),$avg); |
|
if ($showntitle ne '') { |
|
push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $showntitle,'no_mt' => 1,}); |
} |
} |
} |
} |
} |
} |
if (($count > 1) || ($count && $notmap)) { |
} |
push(@revmapinfo,{'href' => $map->link().'?navmap=1','text' => $map->title(),'no_mt' => 1,}); |
if ($restitle ne '') { |
} |
push(@revmapinfo,{'text' => $restitle, 'no_mt' => 1}); |
} |
} |
return @revmapinfo; |
return @revmapinfo; |
} |
} |
|
|
|
sub truncate_crumb_text { |
|
my ($title,$limit) = @_; |
|
my $showntitle = ''; |
|
if (length($title) > $limit) { |
|
my @words = split(/\b\s*/,$title); |
|
if (@words == 1) { |
|
$showntitle = substr($title,0,$limit).' ...'; |
|
} else { |
|
my $linklength = 0; |
|
my $num = 0; |
|
foreach my $word (@words) { |
|
$linklength += 1+length($word); |
|
if ($word eq '-') { |
|
$showntitle =~ s/ $//; |
|
$showntitle .= $word; |
|
} elsif ($linklength > $limit) { |
|
if ($num < @words) { |
|
$showntitle .= $word.' ...'; |
|
last; |
|
} else { |
|
$showntitle .= $word; |
|
} |
|
} else { |
|
$showntitle .= $word.' '; |
|
} |
|
} |
|
$showntitle =~ s/ $//; |
|
} |
|
return $showntitle; |
|
} else { |
|
return $title; |
|
} |
|
} |
|
|
# |
# |
# Determines the open/close dates for printing a map that |
# Determines the open/close dates for printing a map that |
Line 4564 Returns a string with a comma-separated
|
Line 4613 Returns a string with a comma-separated
|
for the hierarchy of maps containing a map, with the top level |
for the hierarchy of maps containing a map, with the top level |
map first, then descending to deeper levels, with the enclosing map last. |
map first, then descending to deeper levels, with the enclosing map last. |
|
|
|
=item * B<map_breadcrumbs>: |
|
|
|
Same as map_hierarchy, except maps containing only a single itemm if |
|
it's a map, or containing no items are omitted, unless it's the top |
|
level map (map_pc = 1), which is always included. |
|
|
=back |
=back |
|
|
=cut |
=cut |
Line 4599 sub map_hierarchy {
|
Line 4654 sub map_hierarchy {
|
my $pc = $self->map_pc(); |
my $pc = $self->map_pc(); |
return $self->navHash("map_hierarchy_$pc", 0); |
return $self->navHash("map_hierarchy_$pc", 0); |
} |
} |
|
sub map_breadcrumbs { |
|
my $self = shift; |
|
my $pc = $self->map_pc(); |
|
return $self->navHash("map_breadcrumbs_$pc", 0); |
|
} |
|
|
##### |
##### |
# Property queries |
# Property queries |