import of rt 3.0.4
[freeside.git] / rt / lib / RT / Links_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::Links - A collection of Link objects
27
28 =head1 SYNOPSIS
29
30   use RT::Links;
31   my $links = new RT::Links($CurrentUser);
32
33 =head1 DESCRIPTION
34
35
36 =head1 METHODS
37
38
39 =begin testing
40
41 ok (require RT::Links);
42
43 =end testing
44
45 =cut
46
47 use strict;
48 no warnings qw(redefine);
49 use RT::URI;
50
51 # {{{ sub Limit 
52 sub Limit  {
53     my $self = shift;
54     my %args = ( ENTRYAGGREGATOR => 'AND',
55                  OPERATOR => '=',
56                  @_);
57     
58     #if someone's trying to search for tickets, try to resolve the uris for searching.
59     
60     if (  ( $args{'OPERATOR'} eq '=') and
61           ( $args{'FIELD'}  eq 'Base') or ($args{'FIELD'} eq 'Target')
62        ) {
63           my $dummy = RT::URI->new($self->CurrentUser);
64            $dummy->FromURI($args{'VALUE'});
65            # $uri = $dummy->URI;
66     }
67
68
69     # If we're limiting by target, order by base
70     # (Order by the thing that's changing)
71
72     if ( ($args{'FIELD'} eq 'Target') or 
73          ($args{'FIELD'} eq 'LocalTarget') ) {
74         $self->OrderBy (ALIAS => 'main',
75                         FIELD => 'Base',
76                         ORDER => 'ASC');
77     }
78     elsif ( ($args{'FIELD'} eq 'Base') or 
79             ($args{'FIELD'} eq 'LocalBase') ) {
80         $self->OrderBy (ALIAS => 'main',
81                         FIELD => 'Target',
82                         ORDER => 'ASC');
83     }
84     
85
86     $self->SUPER::Limit(%args);
87 }
88 # }}}
89
90 # {{{ LimitRefersTo 
91
92 =head2 LimitRefersTo URI
93
94 find all things that refer to URI
95
96 =cut
97
98 sub LimitRefersTo {
99     my $self = shift;
100     my $URI = shift;
101
102     $self->Limit(FIELD => 'Type', VALUE => 'RefersTo');
103     $self->Limit(FIELD => 'Target', VALUE => $URI);
104 }
105
106 # }}}
107 # {{{ LimitReferredToBy
108
109 =head2 LimitReferredToBy URI
110
111 find all things that URI refers to
112
113 =cut
114
115 sub LimitReferredToBy {
116     my $self = shift;
117     my $URI = shift;
118
119     $self->Limit(FIELD => 'Type', VALUE => 'RefersTo');
120     $self->Limit(FIELD => 'Base', VALUE => $URI);
121 }
122
123 # }}}
124 1;
125