summaryrefslogtreecommitdiff
path: root/rt/lib/RT/Watchers.pm
blob: c55adda3f505b15b85242603c6ff93a3f553e1f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Attic/Watchers.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
# (c) 1996-2000 Jesse Vincent <jesse@fsck.com>
# This software is redistributable under the terms of the GNU GPL

=head1 NAME

  RT::Watchers - Collection of RT Watcher objects

=head1 SYNOPSIS

  use RT::Watchers;
  my $watchers = new RT::Watchers($CurrentUser);
  while (my $watcher = $watchers->Next()) {
    print $watcher->Id . "is a watcher";
  }  

=head1 DESCRIPTION

This module should never be called directly by client code. it's an internal module which
should only be accessed through exported APIs in Ticket, Queue and other similar objects.


=head1 METHODS

=begin testing

ok(require RT::TestHarness);
ok(require RT::Watchers);

=end testing

=cut

package RT::Watchers;

use strict;
use vars qw( @ISA );


require RT::EasySearch;
require RT::Watcher;
@ISA= qw(RT::EasySearch);


# {{{ sub _Init
sub _Init  {
  my $self = shift;
  
  $self->{'table'} = "Watchers";
  $self->{'primary_key'} = "id";
  return($self->SUPER::_Init(@_));
}
# }}}

# {{{ sub Limit 

=head2 Limit

  A wrapper around RT::EasySearch::Limit which sets
the default entry aggregator to 'AND'

=cut

sub Limit  {
  my $self = shift;
  my %args = ( ENTRYAGGREGATOR => 'AND',
	       @_);

  $self->SUPER::Limit(%args);
}
# }}}

# {{{ sub LimitToTicket

=head2 LimitToTicket

Takes a single arg which is a ticket id
Limits to watchers of that ticket

=cut

sub LimitToTicket { 
  my $self = shift;
  my $ticket = shift;
  $self->Limit( ENTRYAGGREGATOR => 'OR',
		FIELD => 'Value',
		VALUE => $ticket);
  $self->Limit (ENTRYAGGREGATOR => 'AND',
		FIELD => 'Scope',
		VALUE => 'Ticket');
}
# }}}

# {{{ sub LimitToQueue 

=head2 LimitToQueue

Takes a single arg, which is a queue id
Limits to watchers of that queue.

=cut

sub LimitToQueue  {
  my $self = shift;
  my $queue = shift;
  $self->Limit (ENTRYAGGREGATOR => 'OR',
		FIELD => 'Value',
		VALUE => $queue);
  $self->Limit (ENTRYAGGREGATOR => 'AND',
		FIELD => 'Scope',
		VALUE => 'Queue');
}
# }}}

# {{{ sub LimitToType 

=head2 LimitToType

Takes a single string as its argument. That string is a watcher type
which is one of 'Requestor', 'Cc' or 'AdminCc'
Limits to watchers of that type

=cut


sub LimitToType  {
  my $self = shift;
  my $type = shift;
  $self->Limit(FIELD => 'Type',
	       VALUE => "$type");
}
# }}}

# {{{ sub LimitToRequestors 

=head2 LimitToRequestors

Limits to watchers of type 'Requestor'

=cut

sub LimitToRequestors  {
  my $self = shift;
  $self->LimitToType("Requestor");
}
# }}}

# {{{ sub LimitToCc 

=head2 LimitToCc

Limits to watchers of type 'Cc'

=cut

sub LimitToCc  {
    my $self = shift;
    $self->LimitToType("Cc");
}
# }}}

# {{{ sub LimitToAdminCc 

=head2 LimitToAdminCc

Limits to watchers of type AdminCc

=cut

sub LimitToAdminCc  {
    my $self = shift;
    $self->LimitToType("AdminCc");
}
# }}}

# {{{ sub Emails 

=head2 Emails

# Return a (reference to a) list of emails

=cut

sub Emails  {
    my $self = shift;
    my @list;    # List is a list of watcher email addresses

    # $watcher is an RT::Watcher object
    while (my $watcher=$self->Next()) {
	push(@list, $watcher->Email);
    }
    return \@list;
}
# }}}

# {{{ sub EmailsAsString

=head2 EmailsAsString

# Returns the RT::Watchers->Emails as a comma seperated string

=cut

sub EmailsAsString {
    my $self = shift;
    return(join(", ",@{$self->Emails}));
}
# }}}

# {{{ sub NewItem 



sub NewItem  {
    my $self = shift;
    
    use RT::Watcher;
    my  $item = new RT::Watcher($self->CurrentUser);
    return($item);
}
# }}}
1;