[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1477] trunk



Revision: 1477
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1477&view=rev
Author:   einhverfr
Date:     2007-08-31 18:37:57 -0700 (Fri, 31 Aug 2007)

Log Message:
-----------
Menu cross sections, used for example in handhelds, now work from an API point of view

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Menu.pm
    trunk/scripts/menu.pl
    trunk/sql/Pg-database.sql

Modified: trunk/LedgerSMB/DBObject/Menu.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Menu.pm	2007-08-30 19:25:09 UTC (rev 1476)
+++ trunk/LedgerSMB/DBObject/Menu.pm	2007-09-01 01:37:57 UTC (rev 1477)
@@ -40,11 +40,39 @@
 
 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 @@
             }
         }
     }
-    return @{$self->{menu_items}};
-}
-

Modified: trunk/scripts/menu.pl
===================================================================
--- trunk/scripts/menu.pl	2007-08-30 19:25:09 UTC (rev 1476)
+++ trunk/scripts/menu.pl	2007-09-01 01:37:57 UTC (rev 1477)
@@ -8,7 +8,7 @@
 our $VERSION = '0.1';
 
 $menufile = "menu.ini";
-use LedgerSMB::Menu;
+use LedgerSMB::DBObject::Menu;
 use LedgerSMB::Template;
 use strict;
 
@@ -37,7 +37,7 @@
 
 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}, 

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2007-08-30 19:25:09 UTC (rev 1476)
+++ trunk/sql/Pg-database.sql	2007-09-01 01:37:57 UTC (rev 1477)
@@ -2543,6 +2543,35 @@
 	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
 --


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.