Projekt

Allgemein

Profil

Herunterladen (1,9 KB) Statistiken
| Zweig: | Markierung: | Revision:
a5ba22d2 Moritz Bunkus
package SL::DB::AuthUser;

use strict;

23b83d0e Moritz Bunkus
use List::Util qw(first);

a5ba22d2 Moritz Bunkus
use SL::DB::MetaSetup::AuthUser;
d8ac0828 Moritz Bunkus
use SL::DB::Manager::AuthUser;
3568f2f8 Moritz Bunkus
use SL::DB::Helper::Util;
a5ba22d2 Moritz Bunkus
3a476fcc Thomas Heck
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
numberformat show_form_details signature stylesheet taxincluded_checked tel
516e618b Tamino Steinert
template_format focus_position form_cvars_nr_cols item_multiselect
follow_up_notify_by_email
);
6f398b35 Moritz Bunkus
a5ba22d2 Moritz Bunkus
__PACKAGE__->meta->add_relationship(
groups => {
type => 'many to many',
map_class => 'SL::DB::AuthUserGroup',
map_from => 'user',
map_to => 'group',
},
configs => {
type => 'one to many',
class => 'SL::DB::AuthUserConfig',
column_map => { id => 'user_id' },
},
3ced230d Moritz Bunkus
clients => {
type => 'many to many',
d5fc4d8a Moritz Bunkus
map_class => 'SL::DB::AuthClientUser',
3ced230d Moritz Bunkus
map_from => 'user',
map_to => 'client',
},
a5ba22d2 Moritz Bunkus
);

__PACKAGE__->meta->initialize;

3568f2f8 Moritz Bunkus
sub validate {
my ($self) = @_;

my @errors;
288111da Moritz Bunkus
push @errors, $::locale->text('The login is missing.') if !$self->login;
push @errors, $::locale->text('The login is not unique.') if !SL::DB::Helper::Util::is_unique($self, 'login');
3568f2f8 Moritz Bunkus
return @errors;
}

23b83d0e Moritz Bunkus
sub get_config_value {
my ($self, $key) = @_;

288111da Moritz Bunkus
my $cfg = first { $_->cfg_key eq $key } @{ $self->configs || [] };
23b83d0e Moritz Bunkus
return $cfg ? $cfg->cfg_value : undef;
}

d8ac0828 Moritz Bunkus
sub config_values {
my $self = shift;

if (0 != scalar(@_)) {
my %settings = (ref($_[0]) || '') eq 'HASH' ? %{ $_[0] } : @_;
$self->configs([ map { SL::DB::AuthUserConfig->new(cfg_key => $_, cfg_value => $settings{$_}) } keys %settings ]);
}

288111da Moritz Bunkus
return { map { ($_->cfg_key => $_->cfg_value) } @{ $self->configs || [] } };
d8ac0828 Moritz Bunkus
}

a5ba22d2 Moritz Bunkus
1;