]> git.uio.no Git - usit-rt.git/blame - lib/RT/ObjectCustomField.pm
Upgrade to 4.2.8
[usit-rt.git] / lib / RT / ObjectCustomField.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
3ffc5f4f 5# This software is Copyright (c) 1996-2014 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
84fb5b46
MKG
49use strict;
50use warnings;
51
3ffc5f4f
MKG
52package RT::ObjectCustomField;
53use base 'RT::Record::AddAndSort';
84fb5b46
MKG
54
55use RT::CustomField;
3ffc5f4f 56use RT::ObjectCustomFields;
84fb5b46
MKG
57
58sub Table {'ObjectCustomFields'}
59
3ffc5f4f 60sub ObjectCollectionClass {
84fb5b46 61 my $self = shift;
3ffc5f4f
MKG
62 my %args = (@_);
63 return $args{'CustomField'}->CollectionClassFromLookupType;
84fb5b46
MKG
64}
65
3ffc5f4f 66# XXX: Where is ACL check when we create a record?
84fb5b46
MKG
67
68=head2 CustomFieldObj
69
70Returns the CustomField Object which has the id returned by CustomField
71
84fb5b46
MKG
72=cut
73
74sub CustomFieldObj {
75 my $self = shift;
76 my $id = shift || $self->CustomField;
77
78 # To find out the proper context object to load the CF with, we need
79 # data from the CF -- namely, the record class. Go find that as the
80 # system user first.
81 my $system_CF = RT::CustomField->new( RT->SystemUser );
82 $system_CF->Load( $id );
83 my $class = $system_CF->RecordClassFromLookupType;
84
85 my $obj = $class->new( $self->CurrentUser );
86 $obj->Load( $self->ObjectId );
87
88 my $CF = RT::CustomField->new( $self->CurrentUser );
89 $CF->SetContextObject( $obj );
90 $CF->Load( $id );
91 return $CF;
92}
93
3ffc5f4f 94sub Neighbors {
84fb5b46 95 my $self = shift;
3ffc5f4f 96 my %args = @_;
84fb5b46 97
3ffc5f4f
MKG
98 my $res = $self->CollectionClass->new( $self->CurrentUser );
99 $res->LimitToLookupType(
100 ($args{'CustomField'} || $self->CustomFieldObj)->LookupType
101 );
102 return $res;
84fb5b46
MKG
103}
104
84fb5b46
MKG
105=head2 id
106
107Returns the current value of id.
108(In the database, id is stored as int(11).)
109
110
111=cut
112
113
114=head2 CustomField
115
116Returns the current value of CustomField.
117(In the database, CustomField is stored as int(11).)
118
119
120
121=head2 SetCustomField VALUE
122
123
124Set CustomField to VALUE.
125Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
126(In the database, CustomField will be stored as a int(11).)
127
128
129=cut
130
131
132=head2 ObjectId
133
134Returns the current value of ObjectId.
135(In the database, ObjectId is stored as int(11).)
136
137
138
139=head2 SetObjectId VALUE
140
141
142Set ObjectId to VALUE.
143Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
144(In the database, ObjectId will be stored as a int(11).)
145
146
147=cut
148
149
150=head2 SortOrder
151
152Returns the current value of SortOrder.
153(In the database, SortOrder is stored as int(11).)
154
155
156
157=head2 SetSortOrder VALUE
158
159
160Set SortOrder to VALUE.
161Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
162(In the database, SortOrder will be stored as a int(11).)
163
164
165=cut
166
167
168=head2 Creator
169
170Returns the current value of Creator.
171(In the database, Creator is stored as int(11).)
172
173
174=cut
175
176
177=head2 Created
178
179Returns the current value of Created.
180(In the database, Created is stored as datetime.)
181
182
183=cut
184
185
186=head2 LastUpdatedBy
187
188Returns the current value of LastUpdatedBy.
189(In the database, LastUpdatedBy is stored as int(11).)
190
191
192=cut
193
194
195=head2 LastUpdated
196
197Returns the current value of LastUpdated.
198(In the database, LastUpdated is stored as datetime.)
199
200
201=cut
202
203
204
205sub _CoreAccessible {
206 {
207
208 id =>
3ffc5f4f 209 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
84fb5b46 210 CustomField =>
3ffc5f4f 211 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
84fb5b46 212 ObjectId =>
3ffc5f4f 213 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
84fb5b46 214 SortOrder =>
3ffc5f4f 215 {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
84fb5b46 216 Creator =>
3ffc5f4f 217 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
84fb5b46 218 Created =>
3ffc5f4f 219 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
84fb5b46 220 LastUpdatedBy =>
3ffc5f4f 221 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
84fb5b46 222 LastUpdated =>
3ffc5f4f 223 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
84fb5b46
MKG
224
225 }
226};
227
3ffc5f4f
MKG
228sub FindDependencies {
229 my $self = shift;
230 my ($walker, $deps) = @_;
231
232 $self->SUPER::FindDependencies($walker, $deps);
233
234 $deps->Add( out => $self->CustomFieldObj );
235
236 if ($self->ObjectId) {
237 my $class = $self->CustomFieldObj->RecordClassFromLookupType;
238 my $obj = $class->new( $self->CurrentUser );
239 $obj->Load( $self->ObjectId );
240 $deps->Add( out => $obj );
241 }
242}
243
244sub Serialize {
245 my $self = shift;
246 my %args = (@_);
247 my %store = $self->SUPER::Serialize(@_);
248
249 if ($store{ObjectId}) {
250 my $class = $self->CustomFieldObj->RecordClassFromLookupType;
251 my $obj = $class->new( RT->SystemUser );
252 $obj->Load( $store{ObjectId} );
253 $store{ObjectId} = \($obj->UID);
254 }
255 return %store;
256}
257
258
84fb5b46
MKG
259RT::Base->_ImportOverlays();
260
2611;