From a498349aa91f645793b8ce2905ca38ef3bef4469 Mon Sep 17 00:00:00 2001 From: aurynn_cmd Date: Thu, 13 Sep 2007 22:05:20 +0000 Subject: Updates to admin.pm to correct for multiple Contact objects, instead of a single contact object. DBObject has ->set() added, which allows setting 1..n args in the object. Contact stub beginning to be expanded, ->get, ->save and ->search implemented. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1588 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Contact.pm | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ LedgerSMB/DBObject.pm | 11 +++++++++++ 2 files changed, 63 insertions(+) diff --git a/LedgerSMB/Contact.pm b/LedgerSMB/Contact.pm index 473e50c5..b98a6298 100644 --- a/LedgerSMB/Contact.pm +++ b/LedgerSMB/Contact.pm @@ -34,3 +34,55 @@ your software. =cut +package LedgerSMB::Contact; + +use base LedgerSMB::DBObject; +use LedgerSMB::Error; + + +sub save { + + my $self = shift @_; + + # check for the various fields being appropriately set.. + + if ($self->{person_id} && $self->{contact} && $self->{contact_class}) { + + my $id = shift @ {$self->exec_method( procname => "save_contact" ) }; + $self->merge($id); + return $self->{id}; + } + else { + + # raise an exception + my $err = LedgerSMB::Error->new(); + $err->text("Unable to save contact information"); + $err->throw(); + } +} + +sub get { + + my $self=shift @_; + my $id = shift @_; + + my $result = shift @{ $self->exec_method( + procname => 'get', + args=>[$id] + ); +} + +sub search { + + my $self = shift @_; + my ($pattern, $offset, $limit) = @_; + + my $results = $self->exec_method( + procname => 'search', + args=>[$pattern, $offset, $limit] + ); + + return $results; +} + +1; \ No newline at end of file diff --git a/LedgerSMB/DBObject.pm b/LedgerSMB/DBObject.pm index e712c934..f83ab3ea 100644 --- a/LedgerSMB/DBObject.pm +++ b/LedgerSMB/DBObject.pm @@ -266,4 +266,15 @@ sub _parse_array { return @return_array; } +sub set { + + my $self = shift @_; + my %args = @_; + + for my $arg (keys(%args)) { + $self->{$arg} = $args{$arg}; + } + return 1; +} + 1; -- cgit v1.2.3