summaryrefslogtreecommitdiff
path: root/rt/lib/RT/ObjectKeyword.pm
blob: 287d41fab898aca467579b7ebc962b52de58d846 (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
#$Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Attic/ObjectKeyword.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
# Released under the terms of the GNU Public License

=head1 NAME

  RT::ObjectKeyword -- a keyword tied to an object in the database

=head1 SYNOPSIS

  use RT::ObjectKeyword;


=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.


=begin testing

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

=end testing

=head1 METHODS

=cut

package RT::ObjectKeyword;

use strict;
use vars qw(@ISA);
use RT::Record;

@ISA = qw(RT::Record);

sub _Init {
    my $self = shift;
    $self->{'table'} = "ObjectKeywords";
    $self->SUPER::_Init(@_);
}

sub _Accessible {
    my $self = shift;
    
    my %cols = (
		Keyword       => 'read/write', #link to the B<RT::Keyword>
		KeywordSelect => 'read/write', #link to the B<RT::KeywordSelect>
		ObjectType    => 'read/write', #currently only C<Ticket>
		ObjectId      => 'read/write', #link to the object specified in I<ObjectType>
	       );
    return ($self->SUPER::_Accessible( @_, %cols));
}



# TODO - post 2.0. add in _Set and _Value, so we can ACL them.  protected at another API level


=head1 NAME

 RT::ObjectKeyword - Manipulate an RT::ObjectKeyword record

=head1 SYNOPSIS

  use RT::ObjectKeyword;

  my $keyword = RT::ObjectKeyword->new($CurrentUser);
  $keyword->Create;

=head1 DESCRIPTION

An B<RT::ObjectKeyword> object associates an B<RT::Keyword> with another
object (currently only B<RT::Ticket>.

This module should B<NEVER> be called directly by client code. its API is entirely through RT ticket or other objects which can have keywords assigned.


=head1 METHODS

=over 4

=item new CURRENT_USER

Takes a single argument, an RT::CurrentUser object.  Instantiates a new
(uncreated) RT::ObjectKeyword object.

=cut

# {{{ sub Create

=item Create KEY => VALUE, ...

Takes a list of key/value pairs and creates a the object.  Returns the id of
the newly created record, or false if there was an error.

Keys are:

Keyword - link to the B<RT::Keyword>
ObjectType - currently only C<Ticket>
ObjectId - link to the object specified in I<ObjectType>

=cut


sub Create {
    my $self = shift;
    my %args = (Keyword => undef,
		KeywordSelect => undef,
		ObjectType => undef,
		ObjectId => undef,
		@_);
    
    #TODO post 2.0 ACL check
    
    return ($self->SUPER::Create( Keyword => $args{'Keyword'}, 
				  KeywordSelect => $args{'KeywordSelect'},
				  ObjectType => $args{'ObjectType'}, 
				  ObjectId => $args{'ObjectId'}))
}
# }}}

# {{{ sub KeywordObj

=item KeywordObj 

Returns an B<RT::Keyword> object of the Keyword associated with this ObjectKeyword.

=cut

sub KeywordObj {
    my $self = shift;
    my $keyword = new RT::Keyword($self->CurrentUser);
    $keyword->Load($self->Keyword);
    return ($keyword);
}
# }}}

# {{{ sub KeywordSelectObj

=item KeywordSelectObj 

Returns an B<RT::KeywordSelect> object of the KeywordSelect associated with this ObjectKeyword.

=cut

sub KeywordSelectObj {
    my $self = shift;
    my $keyword_sel = new RT::KeywordSelect($self->CurrentUser);
    $keyword_sel->Load($self->KeywordSelect);
    return ($keyword_sel);
}
# }}}

# {{{ sub KeywordRelativePath

=item KeywordRelativePath

Returns a string of the Keyword's path relative to this ObjectKeyword's KeywordSelect



=cut

sub KeywordRelativePath {
    my $self = shift;
    return($self->KeywordObj->RelativePath(
              $self->KeywordSelectObj->KeywordObj->Path));
    
}
# }}}

=back

=head1 AUTHOR

Ivan Kohler <ivan-rt@420.am>

=head1 BUGS

Yes.

=head1 SEE ALSO

L<RT::ObjectKeywords>, L<RT::Keyword>, L<RT::Keywords>, L<RT::Ticket>,
L<RT::Record>

=cut

1;