summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-09 02:21:21 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-07-09 02:21:21 +0000
commitbdff0866f37cded4d1aaabd214ee22209864b0f6 (patch)
tree41a7e40fd585a8fd7bc044226d551c55348ce303 /LedgerSMB
parentae39575800beeff17d7b4ef5a188df850939cd82 (diff)
Moving menu over to new template and stored proc model. THe menu expansion/contraction doesn't quite work yet and there needs to be some additional help on the CSS/Javascript side of this.
Also, this makes a few changes to the lower-level Perl API. Classes calling LedgerSMB::call_procedure() directly may need some editing but I believe I got them all. These changes were necessary to accomodate zero-argument stored procedures. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1355 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rw-r--r--LedgerSMB/DBObject.pm70
-rw-r--r--LedgerSMB/Menu.pm65
-rw-r--r--LedgerSMB/Reconciliation.pm2
3 files changed, 88 insertions, 49 deletions
diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm
index f3094dff..d50c300c 100644
--- a/LedgerSMB/DBObject.pm
+++ b/LedgerSMB/DBObject.pm
@@ -50,17 +50,24 @@ sub AUTOLOAD {
my $type = Scalar::Util::blessed $self;
$type =~ m/::(.*?)$/;
$type = lc $1;
- print "Type: $type\n";
$self->exec_method( procname => "$type" . "_" . $AUTOLOAD, args => \@_);
}
sub new {
my $class = shift @_;
- my %args = @_;
- my $base = $args{base};
- my $mode = $args{copy};
- my @mergelist = @{$args{merge}};
+ my $args = shift @_;
+ my $base = $args->{base};
+ my $mode = $args->{copy};
my $self = bless {}, $class;
+ my @mergelist;
+ if (defined $args->{merge}){
+ @mergelist = @{$args->{merge}};
+ } elsif (defined $mode && ( $mode eq 'list')) {
+ $self->error('Mergelist not set');
+ }
+ else {
+ @mergelist = [];
+ }
if ( !$base->isa('LedgerSMB') ) {
$self->error("Constructor called without LedgerSMB object arg");
}
@@ -93,19 +100,23 @@ sub exec_method {
my $self = shift @_;
my %args = @_;
my $funcname = $args{funcname};
- my @in_args = @{ $args{args} };
+ my @in_args;
+ @in_args = @{ $args{args}} if $args{args};
my @call_args;
- my $query = "SELECT proname, proargnames FROM pg_proc WHERE proname = ?";
+ my $query = "SELECT proname, pronargs, proargnames FROM pg_proc WHERE proname = ?";
my $sth = $self->{dbh}->prepare($query);
$sth->execute($funcname);
my $ref;
$ref = $sth->fetchrow_hashref('NAME_lc');
my $args = $ref->{proargnames};
- $args =~ s/\{(.*)\}/$1/;
- my @proc_args = split /,/, $args;
-
+ my @proc_args;
+ $ref->{pronargs} = 0 unless defined $ref->{pronargs};
+ if ($ref->{pronargs}){
+ $args =~ s/\{(.*)\}/$1/;
+ @proc_args = split /,/, $args if $args;
+ }
if ( !$ref ) { # no such function
$self->error( "No such function: ", $funcname );
die;
@@ -119,10 +130,10 @@ sub exec_method {
}
}
}
- else {
- @call_args = @_;
- }
- $self->call_procedure( procname => $funcname, args => \@call_args );
+ for (@in_args) { push @call_args, $_ } ;
+ $self->{call_args} = \@call_args;
+ $self->debug({file => '/tmp/dbobject'});
+ $self->call_procedure( procname => $funcname, args => @call_args );
}
sub run_custom_queries {
@@ -224,4 +235,35 @@ sub run_custom_queries {
@rc;
}
+sub _parse_array {
+ my ($self, $value) = @_;
+ my $next;
+ my $separator;
+ my @return_array;
+
+ while ($value ne '{}') {
+ my $next = "";
+ my $separator = "";
+ if ($value =~ /^\{"/){
+ while ($next eq "" or ($next =~ /\\".$/)){
+ $value =~ s/^\{("[^"]*".)/\{/;
+ $next .= $1;
+ $next =~ /(.)$/;
+ $separator = $1;
+ }
+ $next =~ s/"(.*)"$separator$/$1/;
+
+ } else {
+ $value =~ s/^\{([^,]*)(,|\})/\{/;
+ $next = $1;
+ $separator = $2;
+ }
+ $value .= '}' if $separator eq '}';
+ $next =~ s/\\\\/\\/g;
+ $next =~ s/\\"/"/g;
+ push @return_array, $next;
+ }
+ return @return_array;
+}
+
1;
diff --git a/LedgerSMB/Menu.pm b/LedgerSMB/Menu.pm
index 5c017a7c..b95b7a6a 100644
--- a/LedgerSMB/Menu.pm
+++ b/LedgerSMB/Menu.pm
@@ -18,7 +18,7 @@ included COPYRIGHT and LICENSE files for more information.
package LedgerSMB::Menu;
use Config::Std;
-use base(qw(LedgerSMB));
+use base(qw(LedgerSMB::DBObject));
1;
@@ -26,45 +26,42 @@ use base(qw(LedgerSMB));
=over
-=item new({files => ['path/to/file/glob' ... ], user = $user_ref})
+=item LedgerSMB::Menu->new()
-Creates a new Menu data structure with the files listed and the files in the
-paths.
+Inherited from LedgerSMB::DBObject. Please see that documnetation for details.
+
+=item $menu->generate()
+
+This function returns a list of menu items. Each list item is a hashref:
+keys %menu_item would return the equivalent of qw(position id level label path
+args). Returns the complete list and sets $menu->{menu_items} to a referene to
+th result set, This function does not return an entry for the top-level menu.
=cut
+sub generate {
+ my ($self) = shift @_;
+ my @args;
+
+ @{$self->{menu_items}} = $self->exec_method(funcname => 'menu_generate');
+
+ $self->debug({file => '/tmp/menu'});
-sub new {
- my ($class, $args) = @_;
- my $self = {};
- bless ($self, $class);
- my $index = 1;
- for $file_glob (@{$args->{files}}){
- for $file (glob($file_glob)){
- my %config;
- read_config($file => %config );
- for $key (keys %config){
- next if $args->{user}->{acs} =~ /$key/;
- my $orig_key = $key;
- my $ref = $self;
- while ($key =~ s/^([^-]*)--//){
- $ref->{subs} ||= {};
- $ref->{subs}->{$1} ||= {};
- $ref = $ref->{subs}->{$1};
- }
- $ref->{subs} ||= {};
- $ref->{subs}->{key} ||= {};
- $ref = $ref->{subs}->{$key};
- for (keys %{$config{$orig_key}}){
- $ref->{$_} = ${$config{$orig_key}}{$_};
- }
- $ref->{id} = $index;
- $ref->{label} = $key;
- ++$index;
+ shift @{$self->{menu_items}};
+
+ for my $attribute (@{$self->{menu_items}}){
+
+ @args = $self->_parse_array($attribute->{args});
+ delete $attribute->{args};
+ @{$attribute->{args}} = @args;
+ for (@{$attribute->{args}}){
+ if ($_ =~ /(module|menu|action)=/){
+ @elems = split(/=/, $_);
+ print STDERR join(','. @elems) . "\n";
+ $attribute->{$elems[0]} = $elems[1];
}
}
}
- return $self;
+ return @{$self->{menu_items}};
}
-1;
-=back
+
diff --git a/LedgerSMB/Reconciliation.pm b/LedgerSMB/Reconciliation.pm
index 6dca96d2..e1096f63 100644
--- a/LedgerSMB/Reconciliation.pm
+++ b/LedgerSMB/Reconciliation.pm
@@ -179,4 +179,4 @@ sub entry {
return $self->single_entry($self->{report_id},$self->{entry_id});
}
-1; \ No newline at end of file
+1;