1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
6 # <sales@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/licenses/old-licenses/gpl-2.0.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 }}}
52 package RT::CustomFieldValue;
54 no warnings qw/redefine/;
59 Override the default ValidateName method that stops custom field values
75 my $cf_id = ref $args{'CustomField'}? $args{'CustomField'}->id: $args{'CustomField'};
77 my $cf = RT::CustomField->new( $self->CurrentUser );
80 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
82 unless ( $cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues') ) {
83 return (0, $self->loc('Permission Denied'));
86 my ($id, $msg) = $self->SUPER::Create(
87 CustomField => $cf_id,
88 map { $_ => $args{$_} } qw(Name Description SortOrder)
90 return ($id, $msg) unless $id;
92 if ( defined $args{'Category'} && length $args{'Category'} ) {
93 # $self would be loaded at this stage
94 my ($status, $msg) = $self->SetCategory( $args{'Category'} );
96 $RT::Logger->error("Couldn't set category: $msg");
105 Returns the Category assigned to this Value
106 Returns udef if there is no Category
112 my $attr = $self->FirstAttribute('Category') or return undef;
113 return $attr->Content;
116 =head2 SetCategory Category
118 Takes a string Category and stores it as an attribute of this CustomFieldValue
124 my $category = shift;
125 if ( defined $category && length $category ) {
126 return $self->SetAttribute(
128 Content => $category,
132 my ($status, $msg) = $self->DeleteAttribute( 'Category' );
134 $RT::Logger->warning("Couldn't delete atribute: $msg");
136 # return true even if there was no category
137 return (1, $self->loc('Category unset'));
142 return defined $_[1] && length $_[1];
145 =head2 DeleteCategory
147 Deletes the category associated with this value
148 Returns -1 if there is no Category
154 my $attr = $self->FirstAttribute('Category') or return (-1,'No Category Set');
155 return $attr->Delete;
160 Make sure we delete our Category when we're deleted
167 my ($result, $msg) = $self->DeleteCategory;
170 return ($result, $msg);
173 return $self->SUPER::Delete(@_);
179 my $cf_id = $self->CustomField;
181 my $cf = RT::CustomField->new( $self->CurrentUser );
185 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
188 unless ($cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues')) {
189 return (0, $self->loc('Permission Denied'));
192 return $self->SUPER::_Set( @_ );