1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2018 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::Record::Role::Lifecycle;
54 use Scalar::Util qw(blessed);
58 RT::Record::Role::Lifecycle - Common methods for records which have a Lifecycle column
62 =head2 L<RT::Record::Role>
66 Used as a role parameter. Must return a string of the type of lifecycles the
67 record consumes, i.e. I<ticket> for L<RT::Queue>.
71 A Lifecycle method which returns a lifecycle name is required. Currently
72 unenforced at compile-time due to poor interactions with
73 L<DBIx::SearchBuilder::Record/AUTOLOAD>. You'll hit run-time errors if this
74 method isn't available in consuming classes, however.
78 with 'RT::Record::Role';
79 requires 'LifecycleType';
81 # XXX: can't require column methods due to DBIx::SB::Record's AUTOLOAD
82 #requires 'Lifecycle';
88 Returns an L<RT::Lifecycle> object for this record's C<Lifecycle>. If called
89 as a class method, returns an L<RT::Lifecycle> object which is an aggregation
90 of all lifecycles of the appropriate type.
96 my $type = $self->LifecycleType;
97 my $fallback = $self->_Accessible( Lifecycle => "default" );
99 unless (blessed($self) and $self->id) {
100 return RT::Lifecycle->Load( Type => $type );
103 my $name = $self->Lifecycle || $fallback;
104 my $res = RT::Lifecycle->Load( Name => $name, Type => $type );
107 sprintf "Lifecycle '%s' of type %s for %s #%d doesn't exist",
108 $name, $type, ref($self), $self->id);
109 return RT::Lifecycle->Load( Name => $fallback, Type => $type );
116 Validates that the specified lifecycle exists before updating the record.
118 Takes a lifecycle name.
124 my $value = shift || $self->_Accessible( Lifecycle => "default" );
126 return (0, $self->loc('[_1] is not a valid lifecycle', $value))
127 unless $self->ValidateLifecycle($value);
129 return $self->_Set( Field => 'Lifecycle', Value => $value, @_ );
132 =head2 ValidateLifecycle
134 Takes a lifecycle name. Returns true if it's an OK name and such lifecycle is
135 configured. Returns false otherwise.
139 sub ValidateLifecycle {
142 return unless $value;
143 return unless RT::Lifecycle->Load( Name => $value, Type => $self->LifecycleType );
147 =head2 ActiveStatusArray
149 Returns an array of all ActiveStatuses for the lifecycle
153 sub ActiveStatusArray {
155 return $self->LifecycleObj->Valid('initial', 'active');
158 =head2 InactiveStatusArray
160 Returns an array of all InactiveStatuses for the lifecycle
164 sub InactiveStatusArray {
166 return $self->LifecycleObj->Inactive;
171 Returns an array of all statuses for the lifecycle
177 return $self->LifecycleObj->Valid( @_ );
184 Returns true if STATUS is a valid status. Otherwise, returns 0.
190 return $self->LifecycleObj->IsValid( shift );
193 =head2 IsActiveStatus
197 Returns true if STATUS is a Active status. Otherwise, returns 0
203 return $self->LifecycleObj->IsValid( shift, 'initial', 'active');
206 =head2 IsInactiveStatus
210 Returns true if STATUS is a Inactive status. Otherwise, returns 0
214 sub IsInactiveStatus {
216 return $self->LifecycleObj->IsInactive( shift );