public function applySorting ($sortMapping, array $where = []) : bool
    {
        if (!\is_array($sortMapping) || empty($sortMapping))
        {
            // if value is not in correct format or an empty array.
            return false;
        }

        $all = $this->getAllEntities($where);

        // check sort values
        $possibleSortValues = \range(0, \count($all) - 1);

        if (!$this->arraysAreIdentical($possibleSortValues, \array_values($sortMapping)))
        {
            // the given sort values are wrong
            return false;
        }

        // check item ids
        $allIds = \array_map(function (SortableEntityInterface $entity) { return $entity->getId(); }, $all);

        if (!$this->arraysAreIdentical($allIds, \array_keys($sortMapping)))
        {
            // the given item ids are wrong
            return false;
        }

        foreach ($all as $entity)
        {
            $entity->setSortOrder($sortMapping[$entity->getId()]);
        }

        return true;
    }