1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2012 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/;
58 use base 'RT::Record';
60 sub Table {'CustomFieldValues'}
65 Override the default ValidateName method that stops custom field values
81 my $cf_id = ref $args{'CustomField'}? $args{'CustomField'}->id: $args{'CustomField'};
83 my $cf = RT::CustomField->new( $self->CurrentUser );
86 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
88 unless ( $cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues') ) {
89 return (0, $self->loc('Permission Denied'));
92 my ($id, $msg) = $self->SUPER::Create(
93 CustomField => $cf_id,
94 map { $_ => $args{$_} } qw(Name Description SortOrder Category)
100 return defined $_[1] && length $_[1];
103 =head2 DeleteCategory
105 Deletes the category associated with this value
106 Returns -1 if there is no Category
112 my $attr = $self->FirstAttribute('Category') or return (-1,'No Category Set');
113 return $attr->Delete;
118 Make sure we delete our Category when we're deleted
125 my ($result, $msg) = $self->DeleteCategory;
128 return ($result, $msg);
131 return $self->SUPER::Delete(@_);
137 my $cf_id = $self->CustomField;
139 my $cf = RT::CustomField->new( $self->CurrentUser );
143 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
146 unless ($cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues')) {
147 return (0, $self->loc('Permission Denied'));
150 return $self->SUPER::_Set( @_ );
156 Returns the current value of id.
157 (In the database, id is stored as int(11).)
165 Returns the current value of CustomField.
166 (In the database, CustomField is stored as int(11).)
170 =head2 SetCustomField VALUE
173 Set CustomField to VALUE.
174 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
175 (In the database, CustomField will be stored as a int(11).)
181 =head2 CustomFieldObj
183 Returns the CustomField Object which has the id returned by CustomField
190 my $CustomField = RT::CustomField->new($self->CurrentUser);
191 $CustomField->Load($self->__Value('CustomField'));
192 return($CustomField);
197 Returns the current value of Name.
198 (In the database, Name is stored as varchar(200).)
206 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
207 (In the database, Name will be stored as a varchar(200).)
215 Returns the current value of Description.
216 (In the database, Description is stored as varchar(255).)
220 =head2 SetDescription VALUE
223 Set Description to VALUE.
224 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
225 (In the database, Description will be stored as a varchar(255).)
233 Returns the current value of SortOrder.
234 (In the database, SortOrder is stored as int(11).)
238 =head2 SetSortOrder VALUE
241 Set SortOrder to VALUE.
242 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
243 (In the database, SortOrder will be stored as a int(11).)
251 Returns the current value of Category.
252 (In the database, Category is stored as varchar(255).)
256 =head2 SetCategory VALUE
259 Set Category to VALUE.
260 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
261 (In the database, Category will be stored as a varchar(255).)
269 Returns the current value of Creator.
270 (In the database, Creator is stored as int(11).)
278 Returns the current value of Created.
279 (In the database, Created is stored as datetime.)
287 Returns the current value of LastUpdatedBy.
288 (In the database, LastUpdatedBy is stored as int(11).)
296 Returns the current value of LastUpdated.
297 (In the database, LastUpdated is stored as datetime.)
304 sub _CoreAccessible {
308 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
310 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
312 {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''},
314 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
316 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
318 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
320 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
322 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
324 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
326 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
334 RT::Base->_ImportOverlays();