summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-03-08 03:22:22 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-03-08 03:22:22 +0000
commit3f116c01b5fdce5770258e5a35b82f5d05e8c99a (patch)
tree89c73ba47772d1871899c4836d86fdcfec1f59b5 /LedgerSMB
parente3938391654168316f393f55a688df29a9a38c48 (diff)
More ORM changes and HR rewrite
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@861 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rw-r--r--LedgerSMB/DBObject.pm24
-rw-r--r--LedgerSMB/Employee.pm84
-rwxr-xr-xLedgerSMB/Form.pm2
3 files changed, 101 insertions, 9 deletions
diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm
index 77869f7f..e2441beb 100644
--- a/LedgerSMB/DBObject.pm
+++ b/LedgerSMB/DBObject.pm
@@ -8,25 +8,28 @@ This module creates object instances based on LedgerSMB's in-database ORM.
=head1 METHODS
-Most methods are dynamically created. The following methods are static, however.
+=item find_method ($hashref, $function_name, @args)
-=item make_object hashref, string,
-This creates a new data object instance based on information in the PostgreSQL
-catalogs.
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+This file is licensed under the Gnu General Public License version 2, or at your
+option any later version. A copy of the license should have been included with
+your software.
=back
=cut
-use LedgerSMB;
package LedgerSMB::DBObject;
+use LedgerSMB;
use strict;
no strict 'refs';
use warnings;
-sub AUTOLOAD {
- my ($ref) = shift @_;
+@ISA = (LedgerSMB);
+
+sub exec_method {
+ my ($self) = shift @_;
my ($funcname) = shift @_;
my $query =
@@ -36,6 +39,11 @@ sub AUTOLOAD {
my $ref;
$ref = $sth->fetchrow_hashref(NAME_lc);
+
+ if (!$ref){ # no such function
+ $self->error($locale->text("No such function: ") .$funcname;
+ die;
+ }
my $m_name = $ref->{proname};
my $args = $ref->{proargnames};
my @proc_args;
@@ -53,5 +61,5 @@ sub AUTOLOAD {
@proc_args = @_;
}
}
- LedgerSMB::callproc($funcname, @proc_args);
+ $self->callproc($funcname, @proc_args);
}
diff --git a/LedgerSMB/Employee.pm b/LedgerSMB/Employee.pm
new file mode 100644
index 00000000..007b44d5
--- /dev/null
+++ b/LedgerSMB/Employee.pm
@@ -0,0 +1,84 @@
+=head1 NAME
+
+LedgerSMB::Employee - LedgerSMB class for managing Employees
+
+=head1 SYOPSIS
+
+This module creates object instances based on LedgerSMB's in-database ORM.
+
+=head1 METHODS
+
+The following method is static:
+=item new ($LedgerSMB object);
+
+=item merge ($hashref, @attrs)
+copies @attrs from $hashref to $self.
+
+The following methods are passed through to stored procedures via Autoload.
+=item save
+=item get
+=item search
+=item list_managers
+
+The above list may grow over time, and may depend on other installed modules.
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+This file is licensed under the Gnu General Public License version 2, or at your
+option any later version. A copy of the license should have been included with
+your software.
+
+=back
+
+=cut
+
+package LedgerSMB::Employee;
+use LedgerSMB;
+use LedgerSMB::DBObject;
+@ISA = (LedgerSMB, LedgerSMB::DBObject);
+
+sub AUTOLOAD {
+ my $procname = "employee_$LedgerSMB::Employee::Autoload";
+ $self->exec_method($procname);
+}
+
+sub new {
+ my $lsmb = shift @_;
+ if (! $lsmb->isa(LedgerSMB)){
+ $self->error("Employee called without LedgerSMB object arg");
+ my $self = {};
+ for $attr (keys $lsmb){
+ $self->{$attr} = $lsmb->{$attr};
+ }
+ bless $self;
+}
+
+
+sub merge {
+ my $self = shift @_;
+ my $src = shift @_;
+ for $arg (@_){
+ $self->{$arg} = $src->{$arg};
+ }
+}
+
+sub save {
+ my $hashref = shift ($self->exec_method("employee_save"));
+ $self->merge($hashref, 'id');
+}
+
+sub get {
+ my $hashref = shift ($self->exec_method("employee_get"));
+ $self->merge($hashref, keys $hashref);
+}
+
+sub delete {
+ $self->exec_method("employee_delete");
+}
+
+sub list_managers {
+ $self->{manager_list} = $self->exec_method("employee_list_managers");
+}
+
+sub search {
+ $self->{search_results} = $self->exec_method("employee_search");
+}
diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm
index d728f428..8f51c2ff 100755
--- a/LedgerSMB/Form.pm
+++ b/LedgerSMB/Form.pm
@@ -532,7 +532,7 @@ sub callproc {
$argstr .= "?, ";
}
$argstr =~ s/\, $//;
- $query = "SELECT $procname";
+ $query = "SELECT * FROM $procname";
$query =~ s/\(\)/$argstr/;
my $sth = $self->{dbh}->prepare($query);
while (my $ref = $sth->fetchrow_hashref(NAME_lc)){