I have a class with two static properties.
$statuses
is an array with the status id and their string values for display.
$status_changes
is an array of the current status id and the value is an array of allowed status changes.
class Status {
public static $statuses = [
1 => 'Box Stock',
11 => 'Box Stock (Refurbished)',
2 => 'Transit',
3 => 'Active',
4 => 'Inactive',
12 => 'RMA Authorized',
5 => 'RMA',
6 => 'Scrap',
8 => 'Customer Spare',
9 => 'Consigned',
13 => 'Holding',
10 => 'Internal Use',
7 => 'Unknown'
];
public static $status_changes = [
1 => [2, 3, 10, 13],
11 => [2, 10, 13],
2 => [3, 10, 12, 13],
3 => [4],
4 => [3, 6, 7, 11, 12],
12 => [5, 6, 11],
5 => [6, 11],
6 => [7],
8 => [3],
9 => [3, 8],
13 => [3, 8],
10 => [3, 6, 11],
7 => [6, 11]
];
function echoAllowed($status) {
echo implode(', ', array_map(function ($s) {
return Status::$statuses[$s];
},
self::$status_changes[$status]));
}
}
$s = new Status();
$s->echoAllowed(1);
// Should print "Transit, Active, Internal Use, Holding".
What is the best way to implode the list of allowed status changes, given a status id? (As I've done in the echoAllowed()
method.)