]> wagnertech.de Git - mfinanz.git/blob - SL/DB/AuthUser.pm
restart apache2 in postinst
[mfinanz.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
12                                email favorites fax hide_cvar_search_options mandatory_departments menustyle name
13                                numberformat show_form_details signature stylesheet taxincluded_checked tel
14                                template_format focus_position form_cvars_nr_cols item_multiselect
15                                follow_up_notify_by_email
16                                );
17
18 __PACKAGE__->meta->add_relationship(
19   groups => {
20     type      => 'many to many',
21     map_class => 'SL::DB::AuthUserGroup',
22     map_from  => 'user',
23     map_to    => 'group',
24   },
25   configs => {
26     type       => 'one to many',
27     class      => 'SL::DB::AuthUserConfig',
28     column_map => { id => 'user_id' },
29   },
30   clients => {
31     type      => 'many to many',
32     map_class => 'SL::DB::AuthClientUser',
33     map_from  => 'user',
34     map_to    => 'client',
35   },
36 );
37
38 __PACKAGE__->meta->initialize;
39
40 sub validate {
41   my ($self) = @_;
42
43   my @errors;
44   push @errors, $::locale->text('The login is missing.')    if !$self->login;
45   push @errors, $::locale->text('The login is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'login');
46
47   return @errors;
48 }
49
50 sub get_config_value {
51   my ($self, $key) = @_;
52
53   my $cfg = first { $_->cfg_key eq $key } @{ $self->configs || [] };
54   return $cfg ? $cfg->cfg_value : undef;
55 }
56
57 sub config_values {
58   my $self = shift;
59
60   if (0 != scalar(@_)) {
61     my %settings = (ref($_[0]) || '') eq 'HASH' ? %{ $_[0] } : @_;
62     $self->configs([ map { SL::DB::AuthUserConfig->new(cfg_key => $_, cfg_value => $settings{$_}) } keys %settings ]);
63   }
64
65   return { map { ($_->cfg_key => $_->cfg_value) } @{ $self->configs || [] } };
66 }
67
68 1;