source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Groupofnames.pm @ 2453

Last change on this file since 2453 was 2453, checked in by nanardon, 3 years ago

Fix: Groupofnames listing

File size: 3.3 KB
Line 
1package LATMOS::Accounts::Bases::Sql::Groupofnames;
2
3use 5.010000;
4use strict;
5use warnings;
6use overload '""' => 'stringify';
7
8use base qw(LATMOS::Accounts::Bases::Sql::Group);
9use LATMOS::Accounts::Log;
10use LATMOS::Accounts::I18N;
11
12our $VERSION = (q$Rev: 1920 $ =~ /^Rev: (\d+) /)[0];
13
14=head1 NAME
15
16LATMOS::Accounts::Bases::Sql::Group - Groups objects support
17
18=cut
19
20sub stringify {
21    my ($self) = @_;
22
23    $self->get_field('label')
24    || $self->id;
25}
26
27sub _object_table { 'group' }
28
29sub _key_field { 'name' }
30
31sub _has_extended_attributes { 1 }
32
33sub listReal {
34    my ($class, $base) = @_;
35
36    my $sth = $base->db->prepare_cached(
37        sprintf(
38            q{select name as k from "group" where oalias IS NULL and internobject = false %s
39              and ikey in (
40                SELECT okey from group_attributes
41                join "user" on group_attributes.value = "user".name
42                where attr = 'memberUID' %s
43                )
44              order by name
45            },
46            ($base->{wexported} ? '' : 'and exported = true'),
47            ($base->{wexported} ? '' : 'and "user".exported = true'),
48        )
49    );
50    $sth->execute;
51    my @keys;
52    while(my $res = $sth->fetchrow_hashref) {
53        push(@keys, $res->{k});
54    }
55    @keys
56}
57
58sub list {
59    my ($class, $base) = @_;
60
61    my $sth = $base->db->prepare_cached(
62        sprintf(
63            q{select name as k from "group" where internobject = false %s
64              and ikey in (
65                SELECT okey from group_attributes
66                join "user" on group_attributes.value = "user".name
67                where attr = 'memberUID' %s
68                )
69              order by name
70            },
71            ($base->{wexported} ? '' : 'and exported = true'),
72            ($base->{wexported} ? '' : 'and "user".exported = true'),
73        )
74    );
75    $sth->execute;
76    my @keys;
77    while(my $res = $sth->fetchrow_hashref) {
78        push(@keys, $res->{k});
79    }
80    @keys
81}
82
83sub list_from_rev {
84    my ($class, $base, $rev) = @_;
85    my $sth = $base->db->prepare_cached(
86        sprintf(
87            q{select name as k from "group" where internobject = false %s
88              and rev > ? and oalias IS NULL
89              and ikey in (
90                SELECT okey from group_attributes
91                join "user" on group_attributes.value = "user".name
92                where attr = 'memberUID' %s
93                )
94              order by name
95            },
96            ($base->{wexported} ? '' : 'and exported = true'),
97            ($base->{wexported} ? '' : 'and "user".exported = true'),
98        )
99    );
100    $sth->execute($rev);
101    my @keys;
102    while(my $res = $sth->fetchrow_hashref) {
103        push(@keys, $res->{k});
104    }
105    @keys
106}
107
108sub _get_attr_schema {
109    my ($class, $base) = @_;
110
111    my $Attrs = $class->SUPER::_get_attr_schema( $base );
112    foreach (keys %$Attrs) {
113        $Attrs->{$_}->{ro} = 1;
114    }
115
116    return $Attrs;
117}
118
1191;
120
121__END__
122
123=head1 SEE ALSO
124
125L<LATMOS::Accounts::Bases::Sql>
126
127=head1 AUTHOR
128
129Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
130
131=head1 COPYRIGHT AND LICENSE
132
133Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS
134
135This library is free software; you can redistribute it and/or modify
136it under the same terms as Perl itself, either Perl version 5.10.0 or,
137at your option, any later version of Perl 5 you may have available.
138
139=cut
Note: See TracBrowser for help on using the repository browser.