Upgrade to 4.0.10.
[usit-rt.git] / lib / RT / CustomFieldValue.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
403d7b0b 5# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
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
16# from www.gnu.org.
17#
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.
22#
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.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
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.)
37#
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.
46#
47# END BPS TAGGED BLOCK }}}
48
49use strict;
50use warnings;
51
52package RT::CustomFieldValue;
53
54no warnings qw/redefine/;
55
56
57use RT::CustomField;
58use base 'RT::Record';
59
60sub Table {'CustomFieldValues'}
61
62
63=head2 ValidateName
64
65Override the default ValidateName method that stops custom field values
66from being integers.
67
68=cut
69
70sub Create {
71 my $self = shift;
72 my %args = (
73 CustomField => 0,
74 Name => '',
75 Description => '',
76 SortOrder => 0,
77 Category => '',
78 @_,
79 );
80
81 my $cf_id = ref $args{'CustomField'}? $args{'CustomField'}->id: $args{'CustomField'};
82
83 my $cf = RT::CustomField->new( $self->CurrentUser );
84 $cf->Load( $cf_id );
85 unless ( $cf->id ) {
86 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
87 }
88 unless ( $cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues') ) {
89 return (0, $self->loc('Permission Denied'));
90 }
91
92 my ($id, $msg) = $self->SUPER::Create(
93 CustomField => $cf_id,
94 map { $_ => $args{$_} } qw(Name Description SortOrder Category)
95 );
96 return ($id, $msg);
97}
98
99sub ValidateName {
100 return defined $_[1] && length $_[1];
101};
102
103=head2 DeleteCategory
104
105Deletes the category associated with this value
106Returns -1 if there is no Category
107
108=cut
109
110sub DeleteCategory {
111 my $self = shift;
112 my $attr = $self->FirstAttribute('Category') or return (-1,'No Category Set');
113 return $attr->Delete;
114}
115
116=head2 Delete
117
118Make sure we delete our Category when we're deleted
119
120=cut
121
122sub Delete {
123 my $self = shift;
124
125 my ($result, $msg) = $self->DeleteCategory;
126
127 unless ($result) {
128 return ($result, $msg);
129 }
130
131 return $self->SUPER::Delete(@_);
132}
133
134sub _Set {
135 my $self = shift;
136
137 my $cf_id = $self->CustomField;
138
139 my $cf = RT::CustomField->new( $self->CurrentUser );
140 $cf->Load( $cf_id );
141
142 unless ( $cf->id ) {
143 return (0, $self->loc("Couldn't load Custom Field #[_1]", $cf_id));
144 }
145
146 unless ($cf->CurrentUserHasRight('AdminCustomField') || $cf->CurrentUserHasRight('AdminCustomFieldValues')) {
147 return (0, $self->loc('Permission Denied'));
148 }
149
150 return $self->SUPER::_Set( @_ );
151}
152
153
154=head2 id
155
156Returns the current value of id.
157(In the database, id is stored as int(11).)
158
159
160=cut
161
162
163=head2 CustomField
164
165Returns the current value of CustomField.
166(In the database, CustomField is stored as int(11).)
167
168
169
170=head2 SetCustomField VALUE
171
172
173Set CustomField to VALUE.
174Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
175(In the database, CustomField will be stored as a int(11).)
176
177
178=cut
179
180
181=head2 CustomFieldObj
182
183Returns the CustomField Object which has the id returned by CustomField
184
185
186=cut
187
188sub CustomFieldObj {
189 my $self = shift;
190 my $CustomField = RT::CustomField->new($self->CurrentUser);
191 $CustomField->Load($self->__Value('CustomField'));
192 return($CustomField);
193}
194
195=head2 Name
196
197Returns the current value of Name.
198(In the database, Name is stored as varchar(200).)
199
200
201
202=head2 SetName VALUE
203
204
205Set Name to VALUE.
206Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
207(In the database, Name will be stored as a varchar(200).)
208
209
210=cut
211
212
213=head2 Description
214
215Returns the current value of Description.
216(In the database, Description is stored as varchar(255).)
217
218
219
220=head2 SetDescription VALUE
221
222
223Set Description to VALUE.
224Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
225(In the database, Description will be stored as a varchar(255).)
226
227
228=cut
229
230
231=head2 SortOrder
232
233Returns the current value of SortOrder.
234(In the database, SortOrder is stored as int(11).)
235
236
237
238=head2 SetSortOrder VALUE
239
240
241Set SortOrder to VALUE.
242Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
243(In the database, SortOrder will be stored as a int(11).)
244
245
246=cut
247
248
249=head2 Category
250
251Returns the current value of Category.
252(In the database, Category is stored as varchar(255).)
253
254
255
256=head2 SetCategory VALUE
257
258
259Set Category to VALUE.
260Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
261(In the database, Category will be stored as a varchar(255).)
262
263
264=cut
265
266
267=head2 Creator
268
269Returns the current value of Creator.
270(In the database, Creator is stored as int(11).)
271
272
273=cut
274
275
276=head2 Created
277
278Returns the current value of Created.
279(In the database, Created is stored as datetime.)
280
281
282=cut
283
284
285=head2 LastUpdatedBy
286
287Returns the current value of LastUpdatedBy.
288(In the database, LastUpdatedBy is stored as int(11).)
289
290
291=cut
292
293
294=head2 LastUpdated
295
296Returns the current value of LastUpdated.
297(In the database, LastUpdated is stored as datetime.)
298
299
300=cut
301
302
303
304sub _CoreAccessible {
305 {
306
307 id =>
308 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
309 CustomField =>
310 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
311 Name =>
312 {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''},
313 Description =>
314 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
315 SortOrder =>
316 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
317 Category =>
318 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
319 Creator =>
320 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
321 Created =>
322 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
323 LastUpdatedBy =>
324 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
325 LastUpdated =>
326 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
327
328 }
329};
330
331
332
333
334RT::Base->_ImportOverlays();
335
3361;