src/Utilities/Repository.php
public static function replenishPositions(array &$items, $asLast = true, $force = false)
    {
        $position = self::getExtremePosition($items, $asLast);

        /*
         * Extreme position is unknown, but it's required?
         * Use 0 as default/start value
         */
        if (null === $position && $force) {
            $position = 0;
        }

        /*
         * Extreme position is unknown or there are no items to sort?
         * Nothing to do
         */
        if (null === $position || empty($items)) {
            return;
        }

        foreach ($items as &$item) {
            // Not sortable?
            if (!self::isSortable($item)) {
                continue;
            }

            // Sorted already (position has been set)?
            if (self::isSorted($item)) {
                continue;
            }

            // Calculate position
            if ($asLast) {
                ++$position;
            } else {
                --$position;
            }

            /*
             * It's an object?
             * Use proper method to set position
             */
            if (is_object($item)) {
                $item->setPosition($position);

                continue;
            }

            /*
             * It's an array
             * Use proper key to set position
             */
            $item[static::POSITION_KEY] = $position;
        }
    }
public static function replenishPositions(array &$items, $asLast = true, $force = false)
    {
        $position = self::getExtremePosition($items, $asLast);

        /*
         * Extreme position is unknown, but it's required?
         * Use 0 as default/start value
         */
        if (null === $position && $force) {
            $position = 0;
        }

        /*
         * Extreme position is unknown or there are no items to sort?
         * Nothing to do
         */
        if (null === $position || empty($items)) {
            return;
        }

        foreach ($items as &$item) {
            // Not sortable?
            if (!self::isSortable($item)) {
                continue;
            }

            // Sorted already (position has been set)?
            if (self::isSorted($item)) {
                continue;
            }

            // Calculate position
            if ($asLast) {
                ++$position;
            } else {
                --$position;
            }

            /*
             * It's an object?
             * Use proper method to set position
             */
            if (is_object($item)) {
                $item->setPosition($position);

                continue;
            }

            /*
             * It's an array
             * Use proper key to set position
             */
            $item[static::POSITION_KEY] = $position;
        }
    }
public static function replenishPositions ( array & $ items , $ asLast = true , $ force = false ) { $ position = self :: getExtremePosition ( $ items , $ asLast ) ; /*
         * Extreme position is unknown, but it's required?
         * Use 0 as default/start value
         */ if ( null === $ position && $ force ) { $ position = 0 ; } /*
         * Extreme position is unknown or there are no items to sort?
         * Nothing to do
         */ if ( null === $ position || empty ( $ items ) ) { return ; } foreach ( $ items as & $ item ) { // Not sortable? if ( ! self :: isSortable ( $ item ) ) { continue ; } // Sorted already (position has been set)? if ( self :: isSorted ( $ item ) ) { continue ; } // Calculate position if ( $ asLast ) { ++ $ position ; } else { -- $ position ; } /*
             * It's an object?
             * Use proper method to set position
             */ if ( is_object ( $ item ) ) { $ item -> setPosition ( $ position ) ; continue ; } /*
             * It's an array
             * Use proper key to set position
             */ $ item [ static :: POSITION_KEY ] = $ position ; } }
Replenishes positions of given items

@param array $items  Objects who have "getPosition()" and "setPosition()" methods or arrays
@param bool  $asLast (optional) If is set to true, items are placed at the end (default behaviour). Otherwise -
at top.
@param bool  $force  (optional) If is set to true, positions are set even there is no extreme position.
Otherwise - if extreme position is unknown (is null) replenishment is stopped / skipped
(default behaviour).
Replenishes positions of given items