package DTA::Schema::Result::Account;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

use strict;
use warnings;

use Moose;
use MooseX::NonMoose;
use namespace::autoclean;
extends 'DBIx::Class::Core';

__PACKAGE__->load_components("InflateColumn::DateTime");

=head1 NAME

DTAQ::Schema::Result::Account

=cut

__PACKAGE__->table("account");

=head1 ACCESSORS

=head2 id

  data_type: 'integer'
  is_auto_increment: 1
  is_nullable: 0
  sequence: 'account_id_seq'

=head2 username

  data_type: 'text'
  is_nullable: 1

=head2 realname

  data_type: 'text'
  is_nullable: 1

=head2 email

  data_type: 'text'
  is_nullable: 1

=head2 password

  data_type: 'text'
  is_nullable: 1

=head2 status

  data_type: 'text'
  is_nullable: 1

=head2 lastlogin

  data_type: 'timestamp'
  is_nullable: 1

=head2 created

  data_type: 'timestamp'
  is_nullable: 1

=cut

__PACKAGE__->add_columns(
  "id",
  {
    data_type         => "integer",
    is_auto_increment => 1,
    is_nullable       => 0,
    sequence          => "account_id_seq",
  },
  "username",
  { data_type => "text", is_nullable => 1 },
  "realname",
  { data_type => "text", is_nullable => 1 },
  "email",
  { data_type => "text", is_nullable => 1 },
  "password",
  { data_type => "text", is_nullable => 1 },
  "status",
  { data_type => "text", is_nullable => 1 },
  "lastlogin",
  { data_type => "timestamp", is_nullable => 1 },
  "created",
  { data_type => "timestamp", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");

=head1 RELATIONS


=head2 roles

Type: might_have

Related object: L<DTAQ::Schema::Result::Role>

=cut

__PACKAGE__->might_have(
    "roles",
    "DTAQ::Schema::Result::Role",
    { "foreign.id" => "self.id" },
    { cascade_copy => 0, cascade_delete => 0 },
);

=head2 account_expertises

Type: has_many

Related object: L<DTAQ::Schema::Result::AccountExpertise>

=cut

__PACKAGE__->has_many(
  "account_expertises",
  "DTAQ::Schema::Result::AccountExpertise",
  { "foreign.account" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 clips

Type: has_many

Related object: L<DTAQ::Schema::Result::Clip>

=cut

__PACKAGE__->has_many(
  "clips",
  "DTAQ::Schema::Result::Clip",
  { "foreign.account" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 events

Type: has_many

Related object: L<DTAQ::Schema::Result::Event>

=cut

__PACKAGE__->has_many(
  "events",
  "DTAQ::Schema::Result::Event",
  { "foreign.author" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 formulas

Type: has_many

Related object: L<DTAQ::Schema::Result::Formula>

=cut

__PACKAGE__->has_many(
  "formulas",
  "DTAQ::Schema::Result::Formula",
  { "foreign.account" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 news_authors

Type: has_many

Related object: L<DTAQ::Schema::Result::News>

=cut

__PACKAGE__->has_many(
  "news_authors",
  "DTAQ::Schema::Result::News",
  { "foreign.author" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 news_editors

Type: has_many

Related object: L<DTAQ::Schema::Result::News>

=cut

__PACKAGE__->has_many(
  "news_editors",
  "DTAQ::Schema::Result::News",
  { "foreign.editor" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 prefs

Type: has_many

Related object: L<DTAQ::Schema::Result::Pref>

=cut

__PACKAGE__->has_many(
  "prefs",
  "DTAQ::Schema::Result::Pref",
  { "foreign.account" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 roles

Type: has_many

Related object: L<DTAQ::Schema::Result::Role>

=cut

__PACKAGE__->has_many(
  "roles",
  "DTAQ::Schema::Result::Role",
  { "foreign.account" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);


# Created by DBIx::Class::Schema::Loader v0.07008 @ 2012-06-05 15:48:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:IKQi0hhUP33h82GtkP8d7Q

sub has_pref {
    my ( $self, $field, $value ) = @_;
    return $self->prefs->search({ field => $field, value => $value })->count;
}



=head2

return groups which are roles, but ...

=cut

sub groups {
    my $self = shift;

    my @groups;
    foreach my $role( $self->roles ){
       push @groups, $role->role;
    }
    return @groups;
}


# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;

__END__

=head1 AUTHORS

Frank Wiegand

Markus Raulf <markus.raulf@bbaw.de>

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut
