eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Handler::setPriority PHP Method

setPriority() public method

Changes the priority of the state.
public setPriority ( mixed $stateId, integer $priority )
$stateId mixed
$priority integer
    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);
        }
    }