rt 4.2.15
[freeside.git] / rt / lib / RT / ObjectClass.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::ObjectClass;
53 use base 'RT::Record';
54
55 sub Table {'ObjectClasses'}
56
57
58
59 sub Create {
60     my $self = shift;
61     my %args = ( 
62         Class => '0',
63         ObjectType => '',
64         ObjectId => '0',
65
66         @_);
67
68     unless ( $self->CurrentUser->HasRight( Right  => 'AdminClass', 
69             Object => $RT::System ) ) {
70         return ( 0, $self->loc('Permission Denied') );
71     }
72
73     $self->SUPER::Create(
74                          Class => $args{'Class'},
75                          ObjectType => $args{'ObjectType'},
76                          ObjectId => $args{'ObjectId'},
77     );
78
79 }
80
81
82 =head2 id
83
84 Returns the current value of id. 
85 (In the database, id is stored as int(11).)
86
87
88 =cut
89
90
91 =head2 Class
92
93 Returns the current value of Class. 
94 (In the database, Class is stored as int(11).)
95
96
97
98 =head2 SetClass VALUE
99
100
101 Set Class to VALUE. 
102 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
103 (In the database, Class will be stored as a int(11).)
104
105
106 =cut
107
108
109 =head2 ClassObj
110
111 Returns the Class Object which has the id returned by Class
112
113
114 =cut
115
116 sub ClassObj {
117     my $self = shift;
118     my $Class =  RT::Class->new($self->CurrentUser);
119     $Class->Load($self->Class());
120     return($Class);
121 }
122
123 =head2 ObjectType
124
125 Returns the current value of ObjectType. 
126 (In the database, ObjectType is stored as varchar(255).)
127
128
129
130 =head2 SetObjectType VALUE
131
132
133 Set ObjectType to VALUE. 
134 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
135 (In the database, ObjectType will be stored as a varchar(255).)
136
137
138 =cut
139
140
141 =head2 ObjectId
142
143 Returns the current value of ObjectId. 
144 (In the database, ObjectId is stored as int(11).)
145
146
147
148 =head2 SetObjectId VALUE
149
150
151 Set ObjectId to VALUE. 
152 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
153 (In the database, ObjectId will be stored as a int(11).)
154
155
156 =cut
157
158
159 =head2 Creator
160
161 Returns the current value of Creator. 
162 (In the database, Creator is stored as int(11).)
163
164
165 =cut
166
167
168 =head2 Created
169
170 Returns the current value of Created. 
171 (In the database, Created is stored as datetime.)
172
173
174 =cut
175
176
177 =head2 LastUpdatedBy
178
179 Returns the current value of LastUpdatedBy. 
180 (In the database, LastUpdatedBy is stored as int(11).)
181
182
183 =cut
184
185
186 =head2 LastUpdated
187
188 Returns the current value of LastUpdated. 
189 (In the database, LastUpdated is stored as datetime.)
190
191
192 =cut
193
194
195
196 sub _CoreAccessible {
197     {
198      
199         id =>
200                 {read => 1, type => 'int(11)', default => ''},
201         Class => 
202                 {read => 1, write => 1, type => 'int(11)', default => '0'},
203         ObjectType => 
204                 {read => 1, write => 1, type => 'varchar(255)', default => ''},
205         ObjectId => 
206                 {read => 1, write => 1, type => 'int(11)', default => '0'},
207         Creator => 
208                 {read => 1, auto => 1, type => 'int(11)', default => '0'},
209         Created => 
210                 {read => 1, auto => 1, type => 'datetime', default => ''},
211         LastUpdatedBy => 
212                 {read => 1, auto => 1, type => 'int(11)', default => '0'},
213         LastUpdated => 
214                 {read => 1, auto => 1, type => 'datetime', default => ''},
215
216  }
217 };
218
219 sub FindDependencies {
220     my $self = shift;
221     my ($walker, $deps) = @_;
222
223     $self->SUPER::FindDependencies($walker, $deps);
224
225     $deps->Add( out => $self->ClassObj );
226
227     my $obj = $self->ObjectType->new( $self->CurrentUser );
228     $obj->Load( $self->ObjectId );
229     $deps->Add( out => $obj );
230 }
231
232 sub Serialize {
233     my $self = shift;
234     my %args = (@_);
235     my %store = $self->SUPER::Serialize(@_);
236
237     if ($store{ObjectId}) {
238         my $obj = $self->ObjectType->new( RT->SystemUser );
239         $obj->Load( $store{ObjectId} );
240         $store{ObjectId} = \($obj->UID);
241     }
242     return %store;
243 }
244
245 RT::Base->_ImportOverlays();
246
247 1;