source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Onlyaddress.pm @ 1904

Last change on this file since 1904 was 1023, checked in by nanardon, 12 years ago
  • complete POD

This patch a basic documentation to all functions.
It also add two test to ensure all POD syntax are correct and coverage is full.

  • Property svn:keywords set to Id Rev
File size: 3.4 KB
Line 
1package LATMOS::Accounts::Bases::Sql::Onlyaddress;
2
3use strict;
4use warnings;
5
6use base qw(LATMOS::Accounts::Bases::Sql::Address);
7
8our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
9
10=head1 NAME
11
12LATMOS::Accounts::Bases::Sql::Onlyaddress - Secondary office Address support SQL base
13
14=head1 DESCRIPTION
15
16This module handle object for office address, allowing to support multiple
17address per people.
18
19=cut
20
21sub list {
22    my ($class, $base) = @_;
23
24    my $sth = $base->db->prepare_cached(
25        sprintf(
26            q{select %s.%s as k from %s
27              join "user" on %s."user" = "user".name %s
28              where %s.ikey not in (select okey from %s where attr = 'isMainAddress') %s
29              order by %s.%s
30            },
31            $base->db->quote_identifier($class->_object_table),
32            $base->db->quote_identifier($class->_key_field),
33            $base->db->quote_identifier($class->_object_table),
34            $base->db->quote_identifier($class->_object_table),
35            ($base->{wexported} ? '' : 'and "user".exported = true'),
36            $base->db->quote_identifier($class->_object_table),
37            $base->db->quote_identifier($class->_object_table. '_attributes'), # attr
38            ($base->{wexported} ? '' : 'and ' .
39                $base->db->quote_identifier($class->_object_table) . '.exported = true'),
40            $base->db->quote_identifier($class->_object_table),
41            $base->db->quote_identifier($class->_key_field),
42        )
43    );
44    $sth->execute;
45    my @keys;
46    while(my $res = $sth->fetchrow_hashref) {
47        push(@keys, $res->{k});
48    }
49    @keys
50}
51
52sub list_from_rev {
53    my ($class, $base, $rev) = @_;
54
55    my $sth = $base->db->prepare_cached(
56        sprintf(
57            q{select %s as k from %s where ikey not in (select okey from %s
58            where attr = 'isMainAddress') and rev > ? %s order by %s},
59            $base->db->quote_identifier($class->_key_field),
60            $base->db->quote_identifier($class->_object_table),
61            $base->db->quote_identifier($class->_object_table. '_attributes'), # attr
62            ($base->{wexported} ? '' : 'and exported = true'),
63            $base->db->quote_identifier($class->_key_field),
64        )
65    );
66    $sth->execute($rev);
67    my @keys;
68    while(my $res = $sth->fetchrow_hashref) {
69        push(@keys, $res->{k});
70    }
71    @keys
72}
73
74sub new {
75    my ($class, $base, $id) = @_;
76    my $sth = $base->db->prepare_cached(
77        sprintf(q{select 1 from %s where %s = ? %s and ikey not in (select okey from %s where attr = 'isMainAddress')},
78            $base->db->quote_identifier($class->_object_table),
79            $base->db->quote_identifier($class->_key_field),
80            ($base->{wexported} ? '' : 'and exported = true'),
81            $base->db->quote_identifier($class->_object_table. '_attributes'),
82        ),
83    );
84    my $count = $sth->execute($id);
85    $sth->finish;
86    $count == 1 or return;
87    $class->SUPER::new($base, $id);
88}
89
901;
91
92__END__
93
94=head1 SEE ALSO
95
96L<LATMOS::Accounts::Bases::Sql>
97
98L<LATMOS::Accounts::Bases::Sql::Address>
99
100=head1 AUTHOR
101
102Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
103
104=head1 COPYRIGHT AND LICENSE
105
106Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
107
108This library is free software; you can redistribute it and/or modify
109it under the same terms as Perl itself, either Perl version 5.10.0 or,
110at your option, any later version of Perl 5 you may have available.
111
112=cut
Note: See TracBrowser for help on using the repository browser.