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

Last change on this file since 1520 was 1520, checked in by nanardon, 8 years ago

Add virtual obejct Userstatus

File size: 3.3 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) = @_;
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
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            ($base->{wexported} ? '' : 'and "user".exported = true'),
39            ($base->{wexported} ? '' : 'and ' .
40                $base->db->quote_identifier($class->_object_table) . '.exported = true'),
41            $base->db->quote_identifier($class->_object_table),
42            $base->db->quote_identifier($class->_key_field),
43        )
44    );
45    $sth->execute;
46    my @keys;
47    while(my $res = $sth->fetchrow_hashref) {
48        push(@keys, $res->{k});
49    }
50    @keys
51}
52
53sub list_from_rev {
54    my ($class, $base, $rev) = @_;
55
56    my $sth = $base->db->prepare_cached(
57        sprintf(
58            q{select %s.%s as k from %s
59              join "user" on %s."user" = "user".name
60              where (%s.lastday is null or %s.lastday >= now() - '1 days'::interval)
61              and rev > ?
62              %s %s
63              order by %s.%s
64            },
65            $base->db->quote_identifier($class->_object_table),
66            $base->db->quote_identifier($class->_key_field),
67            $base->db->quote_identifier($class->_object_table),
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->{wexported} ? '' : 'and "user".exported = true'),
72            ($base->{wexported} ? '' : 'and ' .
73                $base->db->quote_identifier($class->_object_table) . '.exported = true'),
74            $base->db->quote_identifier($class->_object_table),
75            $base->db->quote_identifier($class->_key_field),
76        )
77    );
78    $sth->execute($rev);
79    my @keys;
80    while(my $res = $sth->fetchrow_hashref) {
81        push(@keys, $res->{k});
82    }
83    @keys
84}
85
861;
87
88__END__
89
90=head1 SEE ALSO
91
92L<LATMOS::Accounts::Bases::Sql>
93
94L<LATMOS::Accounts::Bases::Sql::Address>
95
96=head1 AUTHOR
97
98Thauvin Olivier, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
99
100=head1 COPYRIGHT AND LICENSE
101
102Copyright (C) 2009, 2010, 2011, 2012 by Thauvin Olivier
103
104This library is free software; you can redistribute it and/or modify
105it under the same terms as Perl itself, either Perl version 5.10.0 or,
106at your option, any later version of Perl 5 you may have available.
107
108=cut
Note: See TracBrowser for help on using the repository browser.