import rt 2.0.14
[freeside.git] / rt / lib / RT / Watchers.pm
1 # $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Attic/Watchers.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
2 # (c) 1996-2000 Jesse Vincent <jesse@fsck.com>
3 # This software is redistributable under the terms of the GNU GPL
4
5 =head1 NAME
6
7   RT::Watchers - Collection of RT Watcher objects
8
9 =head1 SYNOPSIS
10
11   use RT::Watchers;
12   my $watchers = new RT::Watchers($CurrentUser);
13   while (my $watcher = $watchers->Next()) {
14     print $watcher->Id . "is a watcher";
15   }  
16
17 =head1 DESCRIPTION
18
19 This module should never be called directly by client code. it's an internal module which
20 should only be accessed through exported APIs in Ticket, Queue and other similar objects.
21
22
23 =head1 METHODS
24
25 =begin testing
26
27 ok(require RT::TestHarness);
28 ok(require RT::Watchers);
29
30 =end testing
31
32 =cut
33
34 package RT::Watchers;
35
36 use strict;
37 use vars qw( @ISA );
38
39
40 require RT::EasySearch;
41 require RT::Watcher;
42 @ISA= qw(RT::EasySearch);
43
44
45 # {{{ sub _Init
46 sub _Init  {
47   my $self = shift;
48   
49   $self->{'table'} = "Watchers";
50   $self->{'primary_key'} = "id";
51   return($self->SUPER::_Init(@_));
52 }
53 # }}}
54
55 # {{{ sub Limit 
56
57 =head2 Limit
58
59   A wrapper around RT::EasySearch::Limit which sets
60 the default entry aggregator to 'AND'
61
62 =cut
63
64 sub Limit  {
65   my $self = shift;
66   my %args = ( ENTRYAGGREGATOR => 'AND',
67                @_);
68
69   $self->SUPER::Limit(%args);
70 }
71 # }}}
72
73 # {{{ sub LimitToTicket
74
75 =head2 LimitToTicket
76
77 Takes a single arg which is a ticket id
78 Limits to watchers of that ticket
79
80 =cut
81
82 sub LimitToTicket { 
83   my $self = shift;
84   my $ticket = shift;
85   $self->Limit( ENTRYAGGREGATOR => 'OR',
86                 FIELD => 'Value',
87                 VALUE => $ticket);
88   $self->Limit (ENTRYAGGREGATOR => 'AND',
89                 FIELD => 'Scope',
90                 VALUE => 'Ticket');
91 }
92 # }}}
93
94 # {{{ sub LimitToQueue 
95
96 =head2 LimitToQueue
97
98 Takes a single arg, which is a queue id
99 Limits to watchers of that queue.
100
101 =cut
102
103 sub LimitToQueue  {
104   my $self = shift;
105   my $queue = shift;
106   $self->Limit (ENTRYAGGREGATOR => 'OR',
107                 FIELD => 'Value',
108                 VALUE => $queue);
109   $self->Limit (ENTRYAGGREGATOR => 'AND',
110                 FIELD => 'Scope',
111                 VALUE => 'Queue');
112 }
113 # }}}
114
115 # {{{ sub LimitToType 
116
117 =head2 LimitToType
118
119 Takes a single string as its argument. That string is a watcher type
120 which is one of 'Requestor', 'Cc' or 'AdminCc'
121 Limits to watchers of that type
122
123 =cut
124
125
126 sub LimitToType  {
127   my $self = shift;
128   my $type = shift;
129   $self->Limit(FIELD => 'Type',
130                VALUE => "$type");
131 }
132 # }}}
133
134 # {{{ sub LimitToRequestors 
135
136 =head2 LimitToRequestors
137
138 Limits to watchers of type 'Requestor'
139
140 =cut
141
142 sub LimitToRequestors  {
143   my $self = shift;
144   $self->LimitToType("Requestor");
145 }
146 # }}}
147
148 # {{{ sub LimitToCc 
149
150 =head2 LimitToCc
151
152 Limits to watchers of type 'Cc'
153
154 =cut
155
156 sub LimitToCc  {
157     my $self = shift;
158     $self->LimitToType("Cc");
159 }
160 # }}}
161
162 # {{{ sub LimitToAdminCc 
163
164 =head2 LimitToAdminCc
165
166 Limits to watchers of type AdminCc
167
168 =cut
169
170 sub LimitToAdminCc  {
171     my $self = shift;
172     $self->LimitToType("AdminCc");
173 }
174 # }}}
175
176 # {{{ sub Emails 
177
178 =head2 Emails
179
180 # Return a (reference to a) list of emails
181
182 =cut
183
184 sub Emails  {
185     my $self = shift;
186     my @list;    # List is a list of watcher email addresses
187
188     # $watcher is an RT::Watcher object
189     while (my $watcher=$self->Next()) {
190         push(@list, $watcher->Email);
191     }
192     return \@list;
193 }
194 # }}}
195
196 # {{{ sub EmailsAsString
197
198 =head2 EmailsAsString
199
200 # Returns the RT::Watchers->Emails as a comma seperated string
201
202 =cut
203
204 sub EmailsAsString {
205     my $self = shift;
206     return(join(", ",@{$self->Emails}));
207 }
208 # }}}
209
210 # {{{ sub NewItem 
211
212
213
214 sub NewItem  {
215     my $self = shift;
216     
217     use RT::Watcher;
218     my  $item = new RT::Watcher($self->CurrentUser);
219     return($item);
220 }
221 # }}}
222 1;
223
224
225
226