Fixing some bugs in the nav system.

This commit is contained in:
Martin Kamerbeek 2004-07-14 12:08:19 +00:00
parent 497b85bbc0
commit ab676117f8

View file

@ -609,19 +609,22 @@ daughter of. Defaults to the current page.
=cut =cut
sub getFirstDaughter { sub getFirstDaughter {
my ($self, $pageId, $daughterId); my ($self, $pageId, $daughterId, @daughters);
($self, $pageId) = @_; ($self, $pageId) = @_;
unless (ref($self)) { unless (ref($self)) {
$self = WebGUI::Page->new($pageId || $session{page}{pageId}); $self = WebGUI::Page->new($pageId || $session{page}{pageId});
} }
$daughterId = ($self->daughters)[0]->{pageId}; @daughters = $self->daughters;
return undef unless (scalar(@daughters));
$daughterId = $daughters[0]->{pageId};
return WebGUI::Page->new($daughterId); return WebGUI::Page->new($daughterId);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getGrandMother( pageId ) =head2 getGrandmother( pageId )
Returns the grandmother of the current node, or, when called in class context, the garndmother Returns the grandmother of the current node, or, when called in class context, the garndmother
of 'pageId'. of 'pageId'.
@ -637,14 +640,14 @@ grandmother of. Defaults to the current page.
=cut =cut
sub getGrandMother { sub getGrandmother {
my ($self, $pageId, $grannyId); my ($self, $pageId, $grannyId);
($self, $pageId) = @_; ($self, $pageId) = @_;
unless (ref($self)) { unless (ref($self)) {
$self = WebGUI::Page->new($pageId || $session{page}{pageId}); $self = WebGUI::Page->new($pageId || $session{page}{pageId});
} }
return undef if ($self->get('depth') < 2); return undef if ($self->get('depth') < 1);
# We use self and ancestors here because ancestors strips on the wrong side. # We use self and ancestors here because ancestors strips on the wrong side.
$grannyId = (reverse $self->self_and_ancestors)[2]->{pageId}; $grannyId = (reverse $self->self_and_ancestors)[2]->{pageId};
@ -706,7 +709,7 @@ sub getMother {
$self = WebGUI::Page->new($pageId || $session{page}{pageId}); $self = WebGUI::Page->new($pageId || $session{page}{pageId});
} }
return undef if ($self->get('depth') < 1); return undef if ($self->get('depth') < 0);
# We use self and ancestors here because ancestors strips on the wrong side. # We use self and ancestors here because ancestors strips on the wrong side.
$mommyId = (reverse $self->self_and_ancestors)[1]->{pageId}; $mommyId = (reverse $self->self_and_ancestors)[1]->{pageId};
@ -786,21 +789,19 @@ top page of. Defaults to the current page.
sub getTop { sub getTop {
my ($self, $pageId, $topId, @descendants); my ($self, $pageId, $topId);
($self, $pageId) = shift; ($self, $pageId) = shift;
unless (ref($self)) { unless (ref($self)) {
$self= WebGUI::Page->new($pageId || $session{page}{pageId}); $self= WebGUI::Page->new($pageId || $session{page}{pageId});
} }
@descendants = $self->descendants; if ($self->get('depth') == 1) {
if (scalar(@descendants) == 2) { $topId = $self->get('pageId'); #The current page is a top level page
$topId = $self->get('pageId'); #The current page is a top level page } elsif ($self->get('depth') > 1) {
} elsif (scalar(@descendants) > 2) { $topId = ($self->self_and_ancestors)[2]->{pageId};
$topId = $descendants[2]->{pageId}; } else {
} else { #Either the current page is a root page or there's no top level page.
$topId = ($self->daughters)[0]->{pageId}; $topId = ($self->daughters)[0]->{pageId};
} }
return WebGUI::Page->new($topId); return WebGUI::Page->new($topId);
} }
@ -881,17 +882,16 @@ WebGUI root of. Defaults to the current page.
=cut =cut
sub getWebGUIRoot { sub getWebGUIRoot {
my ($self, $pageId, $node, $rootId, @descendants); my ($self, $pageId, $rootId);
($self, $pageId) = shift; ($self, $pageId) = shift;
unless (ref($self)) { unless (ref($self)) {
$self= WebGUI::Page->new($pageId || $session{page}{pageId}); $self= WebGUI::Page->new($pageId || $session{page}{pageId});
} }
@descendants = $self->descendants; if ($self->get('depth') == 0) { #The current page is a WebGUI root
if (scalar(@descendants) == 1) { #The current page is a WebGUI root
$rootId = $self->get('pageId'); $rootId = $self->get('pageId');
} elsif (scalar(@descendants) > 1) { } elsif ($self->get('depth') > 0) {
$rootId = $descendants[1]->{pageId}; $rootId = ($self->ancestors)[1]->{pageId};
} else { #There's no root, your tree is broken } else { #There's no root, your tree is broken
return undef; return undef;
} }