Admin: Teile von admin.pl in neuen Controller Admin verschoben; Mandanten anzeigen
[kivitendo-erp.git] / SL / DB / AuthUser.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::AuthUser;
5
6 use strict;
7
8 use List::Util qw(first);
9
10 use SL::DB::MetaSetup::AuthUser;
11 use SL::DB::Manager::AuthUser;
12 use SL::DB::AuthUserGroup;
13
14 __PACKAGE__->meta->schema('auth');
15
16 __PACKAGE__->meta->add_relationship(
17   groups => {
18     type      => 'many to many',
19     map_class => 'SL::DB::AuthUserGroup',
20     map_from  => 'user',
21     map_to    => 'group',
22   },
23   configs => {
24     type       => 'one to many',
25     class      => 'SL::DB::AuthUserConfig',
26     column_map => { id => 'user_id' },
27   },
28   clients => {
29     type      => 'many to many',
30     map_class => 'SL::DB::AuthClient',
31     map_from  => 'user',
32     map_to    => 'client',
33   },
34 );
35
36 __PACKAGE__->meta->initialize;
37
38 sub get_config_value {
39   my ($self, $key) = @_;
40
41   my $cfg = first { $_->cfg_key eq $key } @{ $self->configs };
42   return $cfg ? $cfg->cfg_value : undef;
43 }
44
45 sub config_values {
46   my $self = shift;
47
48   if (0 != scalar(@_)) {
49     my %settings = (ref($_[0]) || '') eq 'HASH' ? %{ $_[0] } : @_;
50     $self->configs([ map { SL::DB::AuthUserConfig->new(cfg_key => $_, cfg_value => $settings{$_}) } keys %settings ]);
51   }
52
53   return { map { ($_->cfg_key => $_->cfg_value) } @{ $self->configs } };
54 }
55
56 1;