Zeitformat einstellbar machen
[kivitendo-erp.git] / SL / DB / AuthUser.pm
1 package SL::DB::AuthUser;
2
3 use strict;
4
5 use List::Util qw(first);
6
7 use SL::DB::MetaSetup::AuthUser;
8 use SL::DB::Manager::AuthUser;
9 use SL::DB::Helper::Util;
10
11 use constant CONFIG_VARS => qw(copies countrycode dateformat timeformat default_media default_printer_id email favorites fax hide_cvar_search_options mandatory_departments menustyle name
12                                numberformat show_form_details signature stylesheet taxincluded_checked tel template_format vclimit);
13
14 __PACKAGE__->meta->add_relationship(
15   groups => {
16     type      => 'many to many',
17     map_class => 'SL::DB::AuthUserGroup',
18     map_from  => 'user',
19     map_to    => 'group',
20   },
21   configs => {
22     type       => 'one to many',
23     class      => 'SL::DB::AuthUserConfig',
24     column_map => { id => 'user_id' },
25   },
26   clients => {
27     type      => 'many to many',
28     map_class => 'SL::DB::AuthClientUser',
29     map_from  => 'user',
30     map_to    => 'client',
31   },
32 );
33
34 __PACKAGE__->meta->initialize;
35
36 sub validate {
37   my ($self) = @_;
38
39   my @errors;
40   push @errors, $::locale->text('The login is missing.')    if !$self->login;
41   push @errors, $::locale->text('The login is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'login');
42
43   return @errors;
44 }
45
46 sub get_config_value {
47   my ($self, $key) = @_;
48
49   my $cfg = first { $_->cfg_key eq $key } @{ $self->configs || [] };
50   return $cfg ? $cfg->cfg_value : undef;
51 }
52
53 sub config_values {
54   my $self = shift;
55
56   if (0 != scalar(@_)) {
57     my %settings = (ref($_[0]) || '') eq 'HASH' ? %{ $_[0] } : @_;
58     $self->configs([ map { SL::DB::AuthUserConfig->new(cfg_key => $_, cfg_value => $settings{$_}) } keys %settings ]);
59   }
60
61   return { map { ($_->cfg_key => $_->cfg_value) } @{ $self->configs || [] } };
62 }
63
64 1;