1 | package LATMOS::Accounts::Bases::Sql::Onlyaddress; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use base qw(LATMOS::Accounts::Bases::Sql::Address); |
---|
7 | |
---|
8 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
9 | |
---|
10 | =head1 NAME |
---|
11 | |
---|
12 | LATMOS::Accounts::Bases::Sql::Onlyaddress - Secondary office Address support SQL base |
---|
13 | |
---|
14 | =head1 DESCRIPTION |
---|
15 | |
---|
16 | This module handle object for office address, allowing to support multiple |
---|
17 | address per people. |
---|
18 | |
---|
19 | =cut |
---|
20 | |
---|
21 | sub 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 | |
---|
52 | sub 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 | |
---|
74 | sub 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 | |
---|
90 | 1; |
---|
91 | |
---|
92 | __END__ |
---|
93 | |
---|
94 | =head1 SEE ALSO |
---|
95 | |
---|
96 | L<LATMOS::Accounts::Bases::Sql> |
---|
97 | |
---|
98 | L<LATMOS::Accounts::Bases::Sql::Address> |
---|
99 | |
---|
100 | =head1 AUTHOR |
---|
101 | |
---|
102 | Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
103 | |
---|
104 | =head1 COPYRIGHT AND LICENSE |
---|
105 | |
---|
106 | Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier |
---|
107 | |
---|
108 | This library is free software; you can redistribute it and/or modify |
---|
109 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
110 | at your option, any later version of Perl 5 you may have available. |
---|
111 | |
---|
112 | =cut |
---|