diff options
-rw-r--r-- | LedgerSMB/DBObject/Menu.pm | 33 | ||||
-rw-r--r-- | scripts/menu.pl | 4 | ||||
-rw-r--r-- | sql/Pg-database.sql | 29 |
3 files changed, 60 insertions, 6 deletions
diff --git a/LedgerSMB/DBObject/Menu.pm b/LedgerSMB/DBObject/Menu.pm index 733d8f91..f92c02cb 100644 --- a/LedgerSMB/DBObject/Menu.pm +++ b/LedgerSMB/DBObject/Menu.pm @@ -40,11 +40,39 @@ th result set, This function does not return an entry for the top-level menu. sub generate { my ($self) = shift @_; - my @args; @{$self->{menu_items}} = $self->exec_method(funcname => 'menu_generate'); + $self->__generate; + + return @{$self->{menu_items}}; +} + +=over + +=item Menu::generate_secton($object) + +This class acts like Menu::Generate except it returns only a cross-section of +the menu. Basically it returns all nodes which are direct children below +$object->{parent_id}. + +=cut + +sub generate_section { + my ($self) = shift @_; + + @{$self->{menu_items}} = $self->exec_method(funcname => 'menu_children'); + $self->__generate; + + return @{$self->{menu_items}}; +} + +# Private method which contains logic common to the full menu and section logic + +sub __generate { + my ($self) = @_; $self->debug({file => '/tmp/menu'}); + my @args; shift @{$self->{menu_items}}; @@ -61,6 +89,3 @@ sub generate { } } } - return @{$self->{menu_items}}; -} - diff --git a/scripts/menu.pl b/scripts/menu.pl index 878e2fe1..51ec1551 100644 --- a/scripts/menu.pl +++ b/scripts/menu.pl @@ -8,7 +8,7 @@ package LedgerSMB::Scripts::menu; our $VERSION = '0.1'; $menufile = "menu.ini"; -use LedgerSMB::Menu; +use LedgerSMB::DBObject::Menu; use LedgerSMB::Template; use strict; @@ -37,7 +37,7 @@ sub root_doc { sub expanding_menu { my ($request) = @_; - my $menu = LedgerSMB::Menu->new({base => $request}); + my $menu = LedgerSMB::DBObject::Menu->new({base => $request}); $menu->generate(); my $template = LedgerSMB::Template->new( user => $request->{_user}, diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql index 8d22a0cb..e0010afb 100644 --- a/sql/Pg-database.sql +++ b/sql/Pg-database.sql @@ -2543,6 +2543,35 @@ BEGIN END LOOP; END; $$ language plpgsql; + +CREATE OR REPLACE FUNCTION menu_children(in_parent_id int) RETURNS SETOF menu_item +AS $$ +declare + item menu_item; + arg menu_attribute%ROWTYPE; +begin + FOR item IN + SELECT n.position, n.id, c.level, n.label, c.path, '{}' + FROM connectby('menu_node', 'id', 'parent', 'position', + in_parent_id, 1, ',') + c(id integer, parent integer, "level" integer, + path text, list_order integer) + JOIN menu_node n USING(id) + LOOP + FOR arg IN + SELECT * + FROM menu_attribute + WHERE node_id = item.id + LOOP + item.args := item.args || + (arg.attribute || '=' || arg.value)::varchar; + END LOOP; + return next item; + end loop; +end; +$$ language plpgsql; + +COMMENT ON FUNCTION menu_children(int) IS $$ This function returns all menu items which are children of in_parent_id (the only input parameter. $$; -- -- PostgreSQL database dump -- |