I've created a simple function which allows me to determine which status options a change can have. For example a status of 'Pending' can only be changed to 'Active', 'Rejected' and 'Removed'.
In my class I store these as constants which reference the necessary record in a status column for purposes of comparison throughout the site.
My 'transition' array has the following:-
protected static $allowedTransitions=array(
Booking::STATUS_ACTIVE=>array(Booking::STATUS_REVOKED),
Booking::STATUS_PENDING=>array(Booking::STATUS_ACTIVE, Booking::STATUS_REJECTED, Booking::STATUS_REVOKED),
Booking::STATUS_REJECTED=>array(Booking::STATUS_ACTIVE, Booking::STATUS_REVOKED),
Booking::STATUS_REVOKED=>array()
);
What are the opinions on this approach? It doesn't seem like a very good idea to add constants in an array.
In order to check if a status request can be fulfilled, I pass the current status type Id to statusTransitions() which allows me to determine if the change is valid.
public static function statusTransitions($statusTypeId) {
return self::$allowedTransitions[$statusTypeId];
}