This commit was generated by cvs2svn to compensate for changes in r2523,
[freeside.git] / rt / lib / RT / Scrips.pm
1 # Copyright 1999-2001 Jesse Vincent <jesse@fsck.com>
2 # Released under the terms of the GNU Public License
3 # $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Scrips.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
4
5 =head1 NAME
6
7   RT::Scrips - a collection of RT Scrip objects
8
9 =head1 SYNOPSIS
10
11   use RT::Scrips;
12
13 =head1 DESCRIPTION
14
15
16 =head1 METHODS
17
18
19 =begin testing
20
21 ok (require RT::TestHarness);
22 ok (require RT::Scrips);
23
24 =end testing
25
26 =cut
27
28 package RT::Scrips;
29 use RT::EasySearch;
30 use RT::Scrip;
31 @ISA= qw(RT::EasySearch);
32
33
34 # {{{ sub _Init
35 sub _Init { 
36   my $self = shift;
37   $self->{'table'} = "Scrips";
38   $self->{'primary_key'} = "id";
39   return ( $self->SUPER::_Init(@_));
40 }
41 # }}}
42
43 # {{{ sub LimitToQueue 
44
45 =head2 LimitToQueue
46
47 Takes a queue id (numerical) as its only argument. Makes sure that 
48 Scopes it pulls out apply to this queue (or another that you've selected with
49 another call to this method
50
51 =cut
52
53 sub LimitToQueue  {
54    my $self = shift;
55   my $queue = shift;
56  
57   $self->Limit (ENTRYAGGREGATOR => 'OR',
58                 FIELD => 'Queue',
59                 VALUE => "$queue")
60       if defined $queue;
61   
62 }
63 # }}}
64
65 # {{{ sub LimitToGlobal
66
67 =head2 LimitToGlobal
68
69 Makes sure that 
70 Scopes it pulls out apply to all queues (or another that you've selected with
71 another call to this method or LimitToQueue
72
73 =cut
74
75
76 sub LimitToGlobal  {
77    my $self = shift;
78  
79   $self->Limit (ENTRYAGGREGATOR => 'OR',
80                 FIELD => 'Queue',
81                 VALUE => 0);
82   
83 }
84 # }}}
85
86 # {{{ sub NewItem 
87 sub NewItem  {
88   my $self = shift;
89   
90   return(new RT::Scrip($self->CurrentUser));
91 }
92 # }}}
93
94 # {{{ sub Next 
95
96 =head2 Next
97
98 Returns the next scrip that this user can see.
99
100 =cut
101   
102 sub Next {
103     my $self = shift;
104     
105     
106     my $Scrip = $self->SUPER::Next();
107     if ((defined($Scrip)) and (ref($Scrip))) {
108
109         if ($Scrip->CurrentUserHasRight('ShowScrips')) {
110             return($Scrip);
111         }
112         
113         #If the user doesn't have the right to show this scrip
114         else {  
115             return($self->Next());
116         }
117     }
118     #if there never was any scrip
119     else {
120         return(undef);
121     }   
122     
123 }
124 # }}}
125
126 1;
127