public function setPriority($stateId, $priority)
{
$objectState = $this->load($stateId);
$groupObjectStates = $this->loadObjectStates($objectState->groupId);
$priorityList = array();
foreach ($groupObjectStates as $index => $groupObjectState) {
// Update given state and push all other states with same or higher priority down
if ($objectState->id === $groupObjectState->id) {
$priorityList[$groupObjectState->id] = (int) $priority;
} else {
$priorityList[$groupObjectState->id] = $index < $priority ? $index : $index + 1;
}
}
asort($priorityList, SORT_NUMERIC);
foreach (array_keys($priorityList) as $objectStatePriority => $objectStateId) {
$this->objectStateGateway->updateObjectStatePriority($objectStateId, $objectStatePriority);
}
}