package LATMOS::Accounts::Bases::Sql::Site;

use 5.010000;
use strict;
use warnings;

use base qw(LATMOS::Accounts::Bases::Sql::objects);

our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];

=head1 NAME

LATMOS::Accounts::Bases::Sql::Site - Common Location/Address object

=head1 DESCRIPTION

Store common to many people office address (typically building location).

=cut

sub _object_table { 'site' }

sub _key_field { 'name' }

sub _has_extended_attributes { 1 }

sub _get_attr_schema {
    my ($class, $base) = @_;

    $class->SUPER::_get_attr_schema($base,
        {
            name   => { ro => 1, inline => 1, },
            cn     => { ro => 1, inline => 1, iname => 'name' },
            date   => { ro => 1, inline => 1, },
            create => { ro => 1, inline => 1, },
            streetAddress => { formtype => 'TEXTAREA' },
            postalAddress => {
                ro => 1,
                get => sub {
                    my $self = $_[0]->object;
                    my $bp = $self->_get_c_field('postOfficeBox');
                    return join("\n", grep { $_ } (
                            $self->_get_c_field('o'),
                            $self->_get_c_field('streetAddress'),
                            ($bp ? 'BP ' . $bp : ''),
                            join(' ', grep { $_ } (
                                    $self->_get_c_field('postalCode'),
                                    $self->_get_c_field('l'),)),
                            join(' ', grep { $_ } (
                                    $self->_get_c_field('st'),
                                    $self->_get_c_field('co'),),
                            )
                        )
                    );
                },
            },
            siteNick => { uniq => 1 },
            st => { },
            postalCode => { },
            postOfficeBox => { },
            o => { },
            l => { },
            facsimileTelephoneNumber => { },
            description => { },
            co => { },
        }
    )
}

1;

__END__

=head1 SEE ALSO

L<LATMOS::Accounts::Bases::Sql>

=head1 AUTHOR

Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.


=cut
