1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/copyleft/gpl.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
48 package RT::ObjectCustomFieldValue;
51 no warnings qw(redefine);
64 ContentEncoding => '',
69 if( $args{'Content'} && length($args{'Content'}) > 255 && !$args{'LargeContent'} ) {
71 $args{'LargeContent'} = $args{'Content'};
72 $args{'Content'} = '';
73 $args{'ContentType'} = 'text/plain';
76 ( $args{'ContentEncoding'}, $args{'LargeContent'} ) =
77 $self->_EncodeLOB( $args{'LargeContent'}, $args{'ContentType'} )
78 if ( $args{'LargeContent'} );
81 CustomField => $args{'CustomField'},
82 ObjectType => $args{'ObjectType'},
83 ObjectId => $args{'ObjectId'},
84 Disabled => $args{'Disabled'},
85 Content => $args{'Content'},
86 LargeContent => $args{'LargeContent'},
87 ContentType => $args{'ContentType'},
88 ContentEncoding => $args{'ContentEncoding'},
98 $self->_DecodeLOB( $self->ContentType, $self->ContentEncoding,
99 $self->_Value( 'LargeContent', decode_utf8 => 0 ) );
106 =head2 LoadByTicketContentAndCustomField { Ticket => TICKET, CustomField => CUSTOMFIELD, Content => CONTENT }
108 Loads a custom field value by Ticket, Content and which CustomField it's tied to
113 sub LoadByTicketContentAndCustomField {
115 my %args = ( Ticket => undef,
116 CustomField => undef,
122 $self->LoadByCols( Content => $args{'Content'},
123 CustomField => $args{'CustomField'},
124 ObjectType => 'RT::Ticket',
125 ObjectId => $args{'Ticket'},
132 sub LoadByObjectContentAndCustomField {
134 my %args = ( Object => undef,
135 CustomField => undef,
140 my $obj = $args{'Object'} or return;
142 $self->LoadByCols( Content => $args{'Content'},
143 CustomField => $args{'CustomField'},
144 ObjectType => ref($obj),
145 ObjectId => $obj->Id,
154 Return this custom field's content. If there's no "regular"
155 content, try "LargeContent"
162 my $content = $self->SUPER::Content;
163 if (!$content && $self->ContentType eq 'text/plain') {
164 return $self->LargeContent();
173 Returns the object this value applies to
179 my $Object = $self->__Value('ObjectType')->new($self->CurrentUser);
180 $Object->Load($self->__Value('ObjectId'));
187 Disable this value. Used to remove "current" values from records while leaving them in the history.
194 $self->SetDisabled(1);
197 =head2 _FillInTemplateURL URL
199 Takes a URL containing placeholders and returns the URL as filled in for this
200 ObjectCustomFieldValue.
202 Available placeholders:
208 The id of the object in question.
210 =item __CustomField__
212 The value of this custom field for the object in question.
218 sub _FillInTemplateURL {
224 $url =~ s/__id__/@{[$self->ObjectId]}/g;
225 $url =~ s/__CustomField__/@{[$self->Content]}/g;
233 Returns a filled in URL template for this ObjectCustomFieldValue, suitable for
234 constructing a hyperlink in RT's webui. Returns undef if this custom field doesn't have
241 return $self->_FillInTemplateURL($self->CustomFieldObj->LinkValueTo);
246 =head2 ValueIncludeURL
248 Returns a filled in URL template for this ObjectCustomFieldValue, suitable for
249 constructing a hyperlink in RT's webui. Returns undef if this custom field doesn't have
250 a IncludeContentForValue
254 sub IncludeContentForValue {
256 return $self->_FillInTemplateURL($self->CustomFieldObj->IncludeContentForValue);