rt 4.2.15
[freeside.git] / rt / lib / RT / ObjectCustomField.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2 #
3 # COPYRIGHT:
4 #
5 # This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
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
49 use strict;
50 use warnings;
51
52 package RT::ObjectCustomField;
53 use base 'RT::Record::AddAndSort';
54
55 use RT::CustomField;
56 use RT::ObjectCustomFields;
57
58 sub Table {'ObjectCustomFields'}
59
60 sub ObjectCollectionClass {
61     my $self = shift;
62     my %args = (@_);
63     return $args{'CustomField'}->CollectionClassFromLookupType;
64 }
65
66 # XXX: Where is ACL check when we create a record?
67
68 =head2 CustomFieldObj
69
70 Returns the CustomField Object which has the id returned by CustomField
71
72 =cut
73
74 sub 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
94 sub Neighbors {
95     my $self = shift;
96     my %args = @_;
97
98     my $res = $self->CollectionClass->new( $self->CurrentUser );
99     $res->LimitToLookupType(
100         ($args{'CustomField'} || $self->CustomFieldObj)->LookupType
101     );
102     return $res;
103 }
104
105 =head2 id
106
107 Returns 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
116 Returns the current value of CustomField.
117 (In the database, CustomField is stored as int(11).)
118
119
120
121 =head2 SetCustomField VALUE
122
123
124 Set CustomField to VALUE.
125 Returns (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
134 Returns the current value of ObjectId.
135 (In the database, ObjectId is stored as int(11).)
136
137
138
139 =head2 SetObjectId VALUE
140
141
142 Set ObjectId to VALUE.
143 Returns (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
152 Returns the current value of SortOrder.
153 (In the database, SortOrder is stored as int(11).)
154
155
156
157 =head2 SetSortOrder VALUE
158
159
160 Set SortOrder to VALUE.
161 Returns (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
170 Returns 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
179 Returns the current value of Created.
180 (In the database, Created is stored as datetime.)
181
182
183 =cut
184
185
186 =head2 LastUpdatedBy
187
188 Returns 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
197 Returns the current value of LastUpdated.
198 (In the database, LastUpdated is stored as datetime.)
199
200
201 =cut
202
203
204
205 sub _CoreAccessible {
206     {
207
208         id =>
209                 {read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
210         CustomField =>
211                 {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
212         ObjectId =>
213                 {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
214         SortOrder =>
215                 {read => 1, write => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
216         Creator =>
217                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
218         Created =>
219                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
220         LastUpdatedBy =>
221                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
222         LastUpdated =>
223                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
224
225  }
226 };
227
228 sub 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
244 sub 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
259 RT::Base->_ImportOverlays();
260
261 1;