Reorders items with values of sortAttribute begin from zero.
@param bool $middle
@return integer
@throws \Exception
6014
public function reorder($middle = true)
    {
        $result = 0;
        \Yii::$app->getDb()->transaction(function () use (&$result, $middle) {
            $list = $this->getQueryInternal()
                ->select($this->owner->primaryKey())
                ->orderBy([$this->sortAttribute => SORT_ASC])
                ->asArray()
                ->all();
            $from = $middle ? count($list) >> 1 : 0;
            foreach ($list as $i => $item) {
                $result += $this->owner->updateAll([$this->sortAttribute => ($i - $from) * $this->step], $item);
            }
        });

        return $result;
    }
442730
private function sortAttributeModel(AttributeModel $a, AttributeModel $b)
    {
        return strlen($b->isWrite()) <=> strlen($a->isWrite());
    }
418895
protected static function sortByOrder($a, $b) {
        if(!isset($a['link_order']) && isset($b['link_order'])){$a['link_order'] = ($b['link_order'] + 1);}
        if(!isset($b['link_order']) && isset($a['link_order'])){$b['link_order'] = ($a['link_order'] + 1);}
        if(isset($a['link_order']) && isset($b['link_order']) && is_numeric($a['link_order']) && is_numeric($b['link_order'])){
            return intval($a['link_order']) - intval($b['link_order']);
        }
        return 0;
    }
1235253
function reverseOrder(array $attributes = null)
    {
        if ($attributes !== null) {
            $attributes = array_map('strval', $attributes);

            $orders = array_filter($this->getNodes()->orders, function($o) use ($attributes) {
                $expr = $o->getExpression();
                $name = (string) $expr;

                return in_array($name, $attributes);
            });
        } else {
            $orders = $this->getNodes()->orders;
        }

        foreach ($orders as $order) {
            $order->reverse();
        }

        return $this;
    }
948264
public function orderBy($attribute, bool $desc = false)
    {
        $this->orders[] = [$attribute, $desc ? 'desc' : 'asc'];

        return $this;
    }
315417
def _sortAttributeValue(self, offset):
        
        if self._currentResults:
            pageStart = (self._currentResults[offset][
                self.currentSortColumn.attributeID],
                         self._currentResults[offset][
                    '__item__'].storeID)
        else:
            pageStart = None
        return pageStart
702611
public function rewind()
    {
        usort(
            $this->entries, function ($a, $b) {
            return $a['priority'] - $b['priority'];
        }
        );
        $this->position = 0;
        $this->sorted = true;
    }
211902
public function sort( bool $desc = false )
	{
		$items = $this->items;
		asort($items);
		if($desc)
		{
			$items = array_reverse($items, true);
		}
		return new static($items);
	}
871391
public function reorder($lang = false)
	{
		// if reorder_table_permission is false, abort
		if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
			abort(403, 'Not allowed.');
		}

		if ($lang == false)
		{
			$lang = \Lang::locale();
		}

		// get all results for that entity
		$model = $this->crud['model'];
		if (property_exists($model, 'translatable'))
		{
			$this->data['entries'] = $model::where('translation_lang', $lang)->get();
			$this->data['languages'] = \Dick\TranslationManager\Models\Language::all();
			$this->data['active_language'] = $lang;
		}
		else
		{
			$this->data['entries'] = $model::all();
		}
		$this->data['crud'] = $this->crud;

		// load the view from /resources/views/vendor/dick/crud/ if it exists, otherwise load the one in the package
		return $this->firstViewThatExists('vendor.dick.crud.reorder', 'crud::reorder', $this->data);
	}
1133018
protected function get(ServerRequestInterface $request, bool $next = false): ?MiddlewareInterface
    {
        $index = $next ? ++$this->index : $this->index;

        if (!isset($this->middleware[$index])) {
            return null;
        }

        $middleware = $this->middleware[$index];

        if (\is_array($middleware)) {
            $conditions = $middleware;
            $middleware = \array_pop($conditions);

            if (!Matcher\Factory::matches($conditions, $request)) {
                return $this->get($request, true);
            }
        }

        if (\is_callable($middleware)) {
            return new Middleware\CallableWrapper($middleware);
        }

        if (\is_string($middleware)) {
            if ($this->container === null) {
                throw new \RuntimeException("No valid middleware provided: $middleware");
            }

            $middleware = $this->container->get($middleware);
        }

        if (!$middleware instanceof MiddlewareInterface) {
            throw new \RuntimeException('The middleware must be an instance of MiddlewareInterface');
        }

        return $middleware;
    }
1371470
public function getSortOrder($newValue, $currentValue = null)
    {
        $sortOrder = $currentValue;

        if ($newValue !== null) {
            $sortOrder = $this->sortConverter->hash2SortOrder($newValue);
        }

        return $sortOrder;
    }
731978
public function sort($order = 'asc')
    {
        if ($order == 'desc') {
            rsort($this->_map);
        }else{
            sort($this->_map);
        }

        return $this;
    }
646465
final public function sort(array $attributes = array())
    {
        $productImage   = $this->find($attributes['movingId']);
        $positionEntity = $this->find($attributes['movedId']);

        if ($productImage instanceof ProductImage) {
            if ($this->fireEvent('sorting', array($productImage)) === false) {
                return false;
            }

            $productImage->setCaller($this);
            $productImage->{$attributes['type']}($positionEntity);

            $this->fireEvent('sorted', array($productImage));

            return $productImage;
        }

        throw new Exception(sprintf(Exception::CANT_UPDATE_MODEL,
            'Subbly\\Model\\Product',
            $this->name()
        ));
    }
98525
public function sort(callable $callback = null)
    {
        $items = $this->items;

        $callback = $callback ?: function ($a, $b) {
            return $a == $b ? 0 : (($a < $b) ? -1 : 1);

        };

        uasort($items, $callback);

        return new static($items);
    }
167083
protected function sortMiddleware($priorityMap, $middlewares)
    {
        $lastIndex = 0;

        foreach ($middlewares as $index => $middleware) {
            if (! is_string($middleware)) {
                continue;
            }

            $stripped = head(explode(':', $middleware));

            if (in_array($stripped, $priorityMap)) {
                $priorityIndex = array_search($stripped, $priorityMap);

                // This middleware is in the priority map. If we have encountered another middleware
                // that was also in the priority map and was at a lower priority than the current
                // middleware, we will move this middleware to be above the previous encounter.
                if (isset($lastPriorityIndex) && $priorityIndex < $lastPriorityIndex) {
                    return $this->sortMiddleware(
                        $priorityMap, array_values($this->moveMiddleware($middlewares, $index, $lastIndex))
                    );
                }

                // This middleware is in the priority map; but, this is the first middleware we have
                // encountered from the map thus far. We'll save its current index plus its index
                // from the priority map so we can compare against them on the next iterations.
                $lastIndex = $index;
                $lastPriorityIndex = $priorityIndex;
            }
        }

        return array_values(array_unique($middlewares, SORT_REGULAR));
    }
1074892
public function sort()
	{
		usort($this->allEvents, function ($event1, $event2) {
			if ($event1->getStartDate() == $event2->getStartDate()) {
				return $event1->getId() < $event2->getId() ? -1 : 1;
			}

			return $event1->getStartDate() < $event2->getStartDate() ? -1 : 1;
		});

		return $this;
	}
483662
public function reorderItems()
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        if (empty($this->request->data)) {
            throw new BadRequestException();
        }

        $this->request->data = Hash::map($this->request->data, '{n}', function($item) {
            if ($item['parent_id'] === 'null') {
                $item['parent_id'] = null;
            }
            return $item;
        });

        // save the new language positions
        $menuItems = $this->MenuItems->patchEntities(
            $this->MenuItems->find('threaded'),
            $this->request->data
        );
        $this->MenuItems->connection()->begin();
        foreach ($menuItems as $menuItem) {
            $this->MenuItems->behaviors()->unload('Tree');
            if (!$this->MenuItems->save($menuItem)) {
                $this->MenuItems->connection()->rollback();
                break;
            }
        }
        if ($this->MenuItems->connection()->inTransaction()) {
            $this->MenuItems->connection()->commit();
            $status = 'success';
            $flashMessage = __d('wasabi_core', 'The menu item positions have been updated.');
        } else {
            $status = 'error';
            $flashMessage = $this->dbErrorMessage;
        }

        $this->set([
            'status' => $status,
            'flashMessage' => $flashMessage,
            '_serialize' => ['status', 'flashMessage']
        ]);
    }