Hey I am trying to change a state of an object in PHP based on its previews state. the state itself is a string and the state can be 4 states: published, published assigned, displayed, displayed assigned. if the state is published it cant go back to displayed but it can go between assigned and not assigned.
Ill show you the code I am checking first if its published, and if not Ill put displayed in the state. the assigned work as expected but for some reason it will always make the state displayed even when it was published.
<code>
$state = strtolower($suboutcome->state);
$is_assigned = $suboutcome->outcome != -1;
if (str_contains($state, 'published') && !$is_assigned) {
return 'published';
} elseif (str_contains($state, 'published') && $is_assigned) {
return 'published assigned';
} elseif ($is_assigned) {
return 'displayed assigned';
} else {
return 'displayed ';
}
</code>
<code>
$state = strtolower($suboutcome->state);
$is_assigned = $suboutcome->outcome != -1;
if (str_contains($state, 'published') && !$is_assigned) {
return 'published';
} elseif (str_contains($state, 'published') && $is_assigned) {
return 'published assigned';
} elseif ($is_assigned) {
return 'displayed assigned';
} else {
return 'displayed ';
}
</code>
$state = strtolower($suboutcome->state);
$is_assigned = $suboutcome->outcome != -1;
if (str_contains($state, 'published') && !$is_assigned) {
return 'published';
} elseif (str_contains($state, 'published') && $is_assigned) {
return 'published assigned';
} elseif ($is_assigned) {
return 'displayed assigned';
} else {
return 'displayed ';
}
1