1 | package LATMOS::Accounts::Bases::Sql::Groupofnames; |
---|
2 | |
---|
3 | use 5.010000; |
---|
4 | use strict; |
---|
5 | use warnings; |
---|
6 | use overload '""' => 'stringify'; |
---|
7 | |
---|
8 | use base qw(LATMOS::Accounts::Bases::Sql::Group); |
---|
9 | use LATMOS::Accounts::Log; |
---|
10 | use LATMOS::Accounts::I18N; |
---|
11 | |
---|
12 | our $VERSION = (q$Rev: 1920 $ =~ /^Rev: (\d+) /)[0]; |
---|
13 | |
---|
14 | =head1 NAME |
---|
15 | |
---|
16 | LATMOS::Accounts::Bases::Sql::Group - Groups objects support |
---|
17 | |
---|
18 | =cut |
---|
19 | |
---|
20 | sub stringify { |
---|
21 | my ($self) = @_; |
---|
22 | |
---|
23 | $self->get_field('label') |
---|
24 | || $self->id; |
---|
25 | } |
---|
26 | |
---|
27 | sub _object_table { 'group' } |
---|
28 | |
---|
29 | sub _key_field { 'name' } |
---|
30 | |
---|
31 | sub _has_extended_attributes { 1 } |
---|
32 | |
---|
33 | sub 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 | |
---|
58 | sub 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 | |
---|
83 | sub 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_users |
---|
91 | join "user" on group_attributes_users.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 | |
---|
108 | sub _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 | |
---|
119 | 1; |
---|
120 | |
---|
121 | __END__ |
---|
122 | |
---|
123 | =head1 SEE ALSO |
---|
124 | |
---|
125 | L<LATMOS::Accounts::Bases::Sql> |
---|
126 | |
---|
127 | =head1 AUTHOR |
---|
128 | |
---|
129 | Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt> |
---|
130 | |
---|
131 | =head1 COPYRIGHT AND LICENSE |
---|
132 | |
---|
133 | Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS |
---|
134 | |
---|
135 | This library is free software; you can redistribute it and/or modify |
---|
136 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
137 | at your option, any later version of Perl 5 you may have available. |
---|
138 | |
---|
139 | =cut |
---|