Bugfix für 2275 Verkäuferinformationen im Druck kommen aus der Authdatenbank
[kivitendo-erp.git] / SL / DB / Manager / Employee.pm
1 package SL::DB::Manager::Employee;
2
3 use strict;
4
5 use SL::DB::Helper::Manager;
6 use base qw(SL::DB::Helper::Manager);
7
8 sub object_class { 'SL::DB::Employee' }
9
10 __PACKAGE__->make_manager_methods;
11
12 sub current {
13   return undef unless $::form && $::form->{login};
14   return shift->find_by(login => $::form->{login});
15 }
16
17 sub update_entries_for_authorized_users {
18   my ($class) = @_;
19
20   my %employees_by_login = map { ($_->login => $_) } @{ $class->get_all };
21
22   require SL::DB::AuthClient;
23   foreach my $user (@{ SL::DB::AuthClient->new(id => $::auth->client->{id})->load->users || [] }) {
24     my $user_config = $user->config_values;
25     my $employee    = $employees_by_login{$user->login} || SL::DB::Employee->new(login => $user->login);
26
27     $employee->update_attributes(
28       name      => $user_config->{name},
29       deleted   => 0,
30     );
31   }
32 }
33
34 1;
35 __END__
36
37 =pod
38
39 =encoding utf8
40
41 =head1 NAME
42
43 SL::DB::Manager::Employee - RDBO manager for the C<employee> table
44
45 =head1 SYNOPSIS
46
47   my $logged_in_employee = SL::DB::Manager::Employee->current;
48
49 =head1 FUNCTIONS
50
51 =over 4
52
53 =item C<current>
54
55 Returns an RDBO instance corresponding to the currently logged-in user.
56
57 =item C<update_entries_for_authorized_users>
58
59 For each user created by the administrator in the admin section an
60 entry only exists in the authentication table, but not in the employee
61 table. This is where this function comes in: It iterates over all
62 authentication users that have access to the current client and ensure
63 than an entry for them exists in the table C<employee>. The matching
64 is done via the login name which must be the same in both tables.
65
66 The only other properties that will be copied from the authentication
67 table into the C<employee> row are C<name> and C<workphone>. In
68 addition C<deleted> is always set to 0.
69
70 The intention is that this function is called automatically during the
71 login process.
72
73 =back
74
75 =head1 BUGS
76
77 Nothing here yet.
78
79 =head1 AUTHOR
80
81 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
82
83 =cut