summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject/User.pm
blob: af02e7ff6f2180b78c8d14ba4ba892a87a33a677 (plain)
  1. package LedgerSMB::DBObject::User;
  2. use base qw/LedgerSMB::DBObject/;
  3. use Data::Dumper;
  4. sub save {
  5. my $self = shift @_;
  6. my $user = $self->get();
  7. if ( $user->{id} && $self->{is_a_user} ) {
  8. # doesn't check for the password - that's done in the sproc.
  9. $self->{id} = shift @{ $self->exec_method(funcname=>'admin__save_user',
  10. args=>[$user->{id}, $self->{username}, $self->{password}] ) };
  11. if (!$self->{id}) {
  12. return 0;
  13. }
  14. }
  15. elsif ($user && !$self->{is_a_user}) {
  16. # there WAS a user, and we've decided we want that user to go away now.
  17. $self->{id} = $user->{id};
  18. return $self->remove();
  19. }
  20. elsif ($self->{is_a_user}) {
  21. # No user ID, meaning, creating a new one.
  22. $self->{id} = shift @{ $self->exec_method(funcname=>'admin__save_user',
  23. args=>[undef, $self->{username}, $self->{password}] ) };
  24. }
  25. return 1;
  26. }
  27. sub get {
  28. my $self = shift @_;
  29. my $id = shift;
  30. $self->{user} = @{ $self->exec_method(
  31. funcname=>'admin__get_user',
  32. args=>[$id]
  33. )
  34. }[0];
  35. $self->{pref} = @{ $self->exec_method(
  36. funcname=>'admin__user_preferences',
  37. args=>[$id]
  38. )
  39. }[0];
  40. $self->{person} = @{ $self->exec_method(
  41. funcname=>'admin__user_preferences',
  42. args=>[$self->{user}->{entity_id}]
  43. )
  44. }[0];
  45. $self->{employee} = @{ $self->exec_method(
  46. funcname=>'employee__get',
  47. args=>[$id]
  48. )
  49. }[0];
  50. $self->{entity} = @{ $self->exec_method(
  51. funcname=>'entity__get_entity',
  52. args=>[ $self->{user}->{entity_id} ]
  53. )
  54. }[0];
  55. $self->{roles} = $self->exec_method(
  56. funcname=>'admin__get_roles_for_user',
  57. args=>[$id]
  58. );
  59. #$user->{user} = $u->get($id);
  60. #$user->{pref} = $u->preferences($id);
  61. #$user->{employee} = $u->employee($user->{user}->{entity_id});
  62. #$user->{person} = $u->person($user->{user}->{entity_id});
  63. #$user->{entity} = $u->entity($id);
  64. #$user->{roles} = $u->roles($id);
  65. }
  66. sub remove {
  67. my $self = shift;
  68. my $code = $self->exec_method(funcname=>"admin__delete_user", args=>[$self->{id}, $self->{username}]);
  69. $self->{id} = undef; # never existed..
  70. return $code->[0];
  71. }
  72. sub save_prefs {
  73. my $self = shift @_;
  74. my $pref_id = $self->exec_method(funcname=>"admin__save_preferences",
  75. args=>[
  76. 'language',
  77. 'stylesheet',
  78. 'printer',
  79. 'dateformat',
  80. 'numberformat'
  81. ]
  82. );
  83. }
  84. sub get_all_users {
  85. my $self = shift @_;
  86. my @ret = $self->exec_method( funcname=>"user__get_all_users" );
  87. $self->{users} = \@ret;
  88. }
  89. sub roles {
  90. my $self = shift @_;
  91. my $id = shift @_;
  92. }
  93. 1;