1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2015 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/;
57 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];
106 my $cf_id = $self->CustomField;
108 my $cf = RT::CustomField->new( $self->CurrentUser );
112 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
115 unless ($cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues')) {
116 return (0, $self->loc('Permission Denied'));
119 return $self->SUPER::_Set( @_ );
125 Returns the current value of id.
126 (In the database, id is stored as int(11).)
134 Returns the current value of CustomField.
135 (In the database, CustomField is stored as int(11).)
139 =head2 SetCustomField VALUE
142 Set CustomField to VALUE.
143 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
144 (In the database, CustomField will be stored as a int(11).)
147 =head2 SetCustomFieldObj
149 Store the CustomField object which loaded this CustomFieldValue.
150 Passed down from the CustomFieldValues collection in AddRecord.
152 This object will be transparently returned from CustomFieldObj rather
153 than loading from the database.
157 sub SetCustomFieldObj {
159 return $self->{'custom_field'} = shift;
162 =head2 CustomFieldObj
164 If a CustomField object was stored using SetCustomFieldObj and it is
165 the same CustomField stored in the CustomField column, then the stored
166 CustomField object (likely passed down from CustomField->Values) will be returned.
168 Otherwise returns the CustomField Object which has the id returned by CustomField
175 return $self->{custom_field} if $self->{custom_field}
176 and $self->{custom_field}->id == $self->__Value('CustomField');
178 my $CustomField = RT::CustomField->new($self->CurrentUser);
179 $CustomField->Load($self->__Value('CustomField'));
180 return($CustomField);
185 Returns the current value of Name.
186 (In the database, Name is stored as varchar(200).)
194 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
195 (In the database, Name will be stored as a varchar(200).)
203 Returns the current value of Description.
204 (In the database, Description is stored as varchar(255).)
208 =head2 SetDescription VALUE
211 Set Description to VALUE.
212 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
213 (In the database, Description will be stored as a varchar(255).)
221 Returns the current value of SortOrder.
222 (In the database, SortOrder is stored as int(11).)
226 =head2 SetSortOrder VALUE
229 Set SortOrder to VALUE.
230 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
231 (In the database, SortOrder will be stored as a int(11).)
239 Returns the current value of Category.
240 (In the database, Category is stored as varchar(255).)
244 =head2 SetCategory VALUE
247 Set Category to VALUE.
248 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
249 (In the database, Category will be stored as a varchar(255).)
257 Returns the current value of Creator.
258 (In the database, Creator is stored as int(11).)
266 Returns the current value of Created.
267 (In the database, Created is stored as datetime.)
275 Returns the current value of LastUpdatedBy.
276 (In the database, LastUpdatedBy is stored as int(11).)
284 Returns the current value of LastUpdated.
285 (In the database, LastUpdated is stored as datetime.)
292 sub _CoreAccessible {
296 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
298 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
300 {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''},
302 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
304 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
306 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
308 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
310 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
312 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
314 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
320 sub FindDependencies {
322 my ($walker, $deps) = @_;
324 $self->SUPER::FindDependencies($walker, $deps);
326 $deps->Add( out => $self->CustomFieldObj );
329 RT::Base->_ImportOverlays();