summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-17 23:16:35 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-10-17 23:16:35 +0000
commit9af6ae6be1019ea656a101dfe7b66709f82f68ca (patch)
tree524b0cb9de85fe3dc7adfdfa5c8c460d08f32731 /LedgerSMB
parentb31d6b0e52b43fd0a3a1b6bdc8d5579d8cc22b58 (diff)
Serious updates to the Admin controller;
Creation of a User controller/object - I would like to use this to save/load roles, as well. Creation of Person stored procs, Entity stored procs. Serious updates to the employee stored procs. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1778 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rw-r--r--LedgerSMB/DBObject/Admin.pm53
-rw-r--r--LedgerSMB/DBObject/User.pm52
-rw-r--r--LedgerSMB/Employee.pm21
3 files changed, 118 insertions, 8 deletions
diff --git a/LedgerSMB/DBObject/Admin.pm b/LedgerSMB/DBObject/Admin.pm
index e09e1214..51620c47 100644
--- a/LedgerSMB/DBObject/Admin.pm
+++ b/LedgerSMB/DBObject/Admin.pm
@@ -6,24 +6,39 @@ use LedgerSMB::Location;
use LedgerSMB::DBObject::Employee;
use LedgerSMB::Contact;
-sub save_user {
+#[18:00:31] <aurynn> I'd like to split them employee/user and roles/prefs
+#[18:00:44] <aurynn> edit/create employee and add user features if needed.
+
+sub save {
+
+ $self->error("Cannot save an Adminstrator object.");
+}
+
+sub save_employee {
my $self = shift @_;
my $entity_id = shift @{ $self->exec_method( procname => "save_user" ) };
$self->merge($entity_id);
- my $employee = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'list',
+ my $person = LedgerSMB::DBObject::Person->new(base=>$self, copy=>'list',
merge=>[
'salutation',
'first_name',
'last_name',
+ ]
+ );
+ my $employee = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'list',
+ merge=>[
+ '',
+ 'first_name',
+ 'last_name',
'employeenumber',
]
);
$employee->{entity_id} = $entity_id->{id};
- $employee->save_employee();
+ $employee->save();
my $loc = LedgerSMB::DBObject::Location->new(base=>$self, copy=>'list',
merge=>[
@@ -36,10 +51,11 @@ sub save_user {
'companyname',
]
);
- $loc->save_location();
- $loc->join_to_person(person=>$employee);
-
+ $loc->save();
+ $employee->set_location($loc->{id});
+ $loc->(person=>$employee);
+
my $workphone = LedgerSMB::Contact->new(base=>$self);
my $homephone = LedgerSMB::Contact->new(base=>$self);
my $email = LedgerSMB::Contact->new(base=>$self);
@@ -51,8 +67,28 @@ sub save_user {
$homephone->save();
$email->save();
- my $roles = $self->exec_method( procname => "all_roles" );
- my $user_roles = $self->exec_method(procname => "get_user_roles", args=>[ $self->{ modifying_user } ] );
+ # now, check for user-specific stuff. Is this person a user or not?
+
+ my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'list',
+ merge=>[
+ 'username',
+ 'password',
+ 'is_a_user'
+ ]
+ );
+
+ $user->get();
+ $user->save();
+}
+
+sub save_roles {
+
+ my $self = shift @_;
+
+ my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'all');
+
+ my $roles = $self->exec_method( procname => "admin_all_roles" );
+ my $user_roles = $self->exec_method(procname => "admin_get_user_roles", args=>[ $self->{ username } ] );
my %active_roles;
for my $role (@{$user_roles}) {
@@ -86,6 +122,7 @@ sub save_user {
);
}
}
+
}
sub save_group {
diff --git a/LedgerSMB/DBObject/User.pm b/LedgerSMB/DBObject/User.pm
new file mode 100644
index 00000000..62ae4e0b
--- /dev/null
+++ b/LedgerSMB/DBObject/User.pm
@@ -0,0 +1,52 @@
+package LedgerSMB::DBObject::User;
+
+use base qw/LedgerSMB::DBObject/;
+
+sub save {
+
+ my $self = shift @_;
+
+ my $user = $self->get();
+
+ if ($user->{id} && $self->{is_a_user}) {
+
+ # doesn't check for the password - that's done in the sproc.
+ $self->{id} = @{ $self->exec_method(procname=>'admin_save_user',
+ args=>[$user->{id}, $self->{username}, $self->{password}] ) }[0];
+ else {
+
+ return 0;
+ }
+ }
+ elsif ($user && !$self->{is_a_user}) {
+
+ # there WAS a user, and we've decided we want that user to go away now.
+
+ $self->{id} = $user->{id};
+ return $self->remove();
+
+ }
+ return 1;
+}
+
+sub get {
+
+ my $self = shift @_;
+
+ my ($user_id, $username) = @{ $self->exec_method(procname=>'admin_get_user',
+ args=>[$self->{id}])};
+
+ return {id=>$user_id, username=>$username};
+}
+
+sub remove {
+
+ my $self = shift;
+
+ my $code = $self->exec_method(procname=>"admin_delete_user", args=>[$self->{id}, $self->{username}]);
+ $self->{id} = undef; # never existed..
+
+ return $code->[0];
+}
+
+1; \ No newline at end of file
diff --git a/LedgerSMB/Employee.pm b/LedgerSMB/Employee.pm
index d0b09829..59a550f2 100644
--- a/LedgerSMB/Employee.pm
+++ b/LedgerSMB/Employee.pm
@@ -48,6 +48,10 @@ our $VERSION = '1.0.0';
sub save {
my $self = shift;
+
+ my $person = shift @{ $self->exec_method (procname => 'person_save',
+ args => [] )};
+
my $hashref = shift @{ $self->exec_method( procname => "employee_save" ) };
$self->merge( $hashref, 'id' );
}
@@ -70,4 +74,21 @@ sub search {
$self->exec_method( procname => "employee_search" );
}
+sub set_location {
+
+ my $self = shift @_;
+ my $location = shift @_;
+
+ my $code = $self->exec_method ( procname => 'employee_set_location',
+ args=>[ $self->{id}, $location->{id} ] );
+
+ if ($code) {
+
+ # good, it worked.
+
+ return 1;
+ }
+ return 0;
+}
+
1;