import of rt 3.0.4
[freeside.git] / rt / lib / RT / GroupMembers_Overlay.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 =head1 NAME
25
26   RT::GroupMembers - a collection of RT::GroupMember objects
27
28 =head1 SYNOPSIS
29
30   use RT::GroupMembers;
31
32 =head1 DESCRIPTION
33
34
35 =head1 METHODS
36
37
38 =begin testing
39
40 ok (require RT::GroupMembers);
41
42 =end testing
43
44 =cut
45
46 use strict;
47 no warnings qw(redefine);
48
49 # {{{ LimitToUsers
50
51 =head2 LimitToUsers
52
53 Limits this search object to users who are members of this group.
54 This is really useful when you want to haave your UI seperate out
55 groups from users for display purposes
56
57 =cut
58
59 sub LimitToUsers {
60     my $self = shift;
61
62     my $principals = $self->NewAlias('Principals');
63     $self->Join( ALIAS1 => 'main', FIELD1 => 'MemberId',
64                  ALIAS2 => $principals, FIELD2 =>'id');
65
66     $self->Limit(       ALIAS => $principals,
67                          FIELD => 'PrincipalType',
68                          VALUE => 'User',
69                          ENTRYAGGREGATOR => 'OR',
70                          );
71 }
72
73 # }}}
74
75
76 # {{{ LimitToGroups
77
78 =head2 LimitToGroups
79
80 Limits this search object to Groups who are members of this group.
81 This is really useful when you want to haave your UI seperate out
82 groups from users for display purposes
83
84 =cut
85
86 sub LimitToGroups {
87     my $self = shift;
88
89     my $principals = $self->NewAlias('Principals');
90     $self->Join( ALIAS1 => 'main', FIELD1 => 'MemberId',
91                  ALIAS2 => $principals, FIELD2 =>'id');
92
93     $self->Limit(       ALIAS => $principals,
94                          FIELD => 'PrincipalType',
95                          VALUE => 'Group',
96                          ENTRYAGGREGATOR => 'OR',
97                          );
98 }
99
100 # }}}
101
102 # {{{ sub LimitToMembersOfGroup
103
104 =head2 LimitToMembersOfGroup PRINCIPAL_ID
105
106 Takes a Principal Id as its only argument. 
107 Limits the current search principals which are _directly_ members
108 of the group which has PRINCIPAL_ID as its principal id.
109
110 =cut
111
112 sub LimitToMembersOfGroup {
113     my $self = shift;
114     my $group = shift;
115
116     return ($self->Limit( 
117                          VALUE => $group,
118                          FIELD => 'GroupId',
119                          ENTRYAGGREGATOR => 'OR',
120                                      QUOTEVALUE => 0
121                          ));
122
123 }
124 # }}}
125
126 1;