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

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



Revision: 861
          http://svn.sourceforge.net/ledger-smb/?rev=861&view=rev
Author:   einhverfr
Date:     2007-03-07 19:22:22 -0800 (Wed, 07 Mar 2007)

Log Message:
-----------
More ORM changes and HR rewrite

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/Form.pm
    trunk/LedgerSMB.pm

Added Paths:
-----------
    trunk/LedgerSMB/Employee.pm

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2007-03-08 02:26:39 UTC (rev 860)
+++ trunk/LedgerSMB/DBObject.pm	2007-03-08 03:22:22 UTC (rev 861)
@@ -8,25 +8,28 @@
 
 =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
 
+package LedgerSMB::DBObject;
 use LedgerSMB;
-package LedgerSMB::DBObject;
 use strict;
 no strict 'refs';
 use warnings;
 
-sub AUTOLOAD {
-	my ($ref) = shift @_;
..hidden.. = (LedgerSMB);
+
+sub exec_method {
+	my ($self) = shift @_;
 	my ($funcname) = shift @_;
 
 	my $query = 
@@ -36,6 +39,11 @@
 	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 @@
 			@proc_args = @_;
 		}
 	}
-	LedgerSMB::callproc($funcname, @proc_args);
+	$self->callproc($funcname, @proc_args);
 }

Added: trunk/LedgerSMB/Employee.pm
===================================================================
--- trunk/LedgerSMB/Employee.pm	                        (rev 0)
+++ trunk/LedgerSMB/Employee.pm	2007-03-08 03:22:22 UTC (rev 861)
@@ -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;
..hidden.. = (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");
+}

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2007-03-08 02:26:39 UTC (rev 860)
+++ trunk/LedgerSMB/Form.pm	2007-03-08 03:22:22 UTC (rev 861)
@@ -532,7 +532,7 @@
 		$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)){

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2007-03-08 02:26:39 UTC (rev 860)
+++ trunk/LedgerSMB.pm	2007-03-08 03:22:22 UTC (rev 861)
@@ -532,7 +532,7 @@
 		$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)){


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