source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Userstatus.pm @ 2449

Last change on this file since 2449 was 2449, checked in by nanardon, 4 years ago

Fix: column reference oalias is ambiguous

File size: 3.4 KB
Line 
1package LATMOS::Accounts::Bases::Sql::Userstatus;
2
3use strict;
4use warnings;
5
6use base qw(LATMOS::Accounts::Bases::Sql::Employment);
7
8our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
9
10=head1 NAME
11
12LATMOS::Accounts::Bases::Sql::Userstatus - Virtual object about only futur employment
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, $Real) = @_;
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
28              where (%s.lastday is null or %s.lastday >= now() - '1 days'::interval)
29              %s %s %s
30              order by %s.%s
31            },
32            $base->db->quote_identifier($class->_object_table),
33            $base->db->quote_identifier($class->_key_field),
34            $base->db->quote_identifier($class->_object_table),
35            $base->db->quote_identifier($class->_object_table),
36            $base->db->quote_identifier($class->_object_table),
37            $base->db->quote_identifier($class->_object_table),
38            ($Real ? 'and ' . $base->db->quote_identifier($class->_object_table) . '.oalias IS NULL' : ''),
39            ($base->{wexported} ? '' : 'and "user".exported = true'),
40            ($base->{wexported} ? '' : 'and ' .
41                $base->db->quote_identifier($class->_object_table) . '.exported = true'),
42            $base->db->quote_identifier($class->_object_table),
43            $base->db->quote_identifier($class->_key_field),
44        )
45    );
46    $sth->execute;
47    my @keys;
48    while(my $res = $sth->fetchrow_hashref) {
49        push(@keys, $res->{k});
50    }
51    @keys
52}
53
54sub list_from_rev {
55    my ($class, $base, $rev) = @_;
56
57    my $sth = $base->db->prepare_cached(
58        sprintf(
59            q{select %s.%s as k from %s
60              join "user" on %s."user" = "user".name
61              where (%s.lastday is null or %s.lastday >= now() - '1 days'::interval)
62              and rev > ?
63              %s %s
64              order by %s.%s
65            },
66            $base->db->quote_identifier($class->_object_table),
67            $base->db->quote_identifier($class->_key_field),
68            $base->db->quote_identifier($class->_object_table),
69            $base->db->quote_identifier($class->_object_table),
70            $base->db->quote_identifier($class->_object_table),
71            $base->db->quote_identifier($class->_object_table),
72            ($base->{wexported} ? '' : 'and "user".exported = true'),
73            ($base->{wexported} ? '' : 'and ' .
74                $base->db->quote_identifier($class->_object_table) . '.exported = true'),
75            $base->db->quote_identifier($class->_object_table),
76            $base->db->quote_identifier($class->_key_field),
77        )
78    );
79    $sth->execute($rev);
80    my @keys;
81    while(my $res = $sth->fetchrow_hashref) {
82        push(@keys, $res->{k});
83    }
84    @keys
85}
86
871;
88
89__END__
90
91=head1 SEE ALSO
92
93L<LATMOS::Accounts::Bases::Sql>
94
95L<LATMOS::Accounts::Bases::Sql::Address>
96
97=head1 AUTHOR
98
99Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
100
101=head1 COPYRIGHT AND LICENSE
102
103Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
104
105This library is free software; you can redistribute it and/or modify
106it under the same terms as Perl itself, either Perl version 5.10.0 or,
107at your option, any later version of Perl 5 you may have available.
108
109=cut
Note: See TracBrowser for help on using the repository browser.