Elcodi\Admin\ProductBundle\Services\CategorySorter::sortCategoriesTree PHP Метод

sortCategoriesTree() защищенный Метод

Sort a category tree based on the received order recursively.
protected sortCategoriesTree ( array $categoriesOrder, Elcodi\Component\Product\Entity\Category | null $parentCategory = null ) : boolean
$categoriesOrder array The category order
$parentCategory Elcodi\Component\Product\Entity\Category | null The parent category in case is not a root category.
Результат boolean If the order process has finished right.
    protected function sortCategoriesTree(array $categoriesOrder, $parentCategory = null)
    {
        $counter = 0;
        foreach ($categoriesOrder as $categoryInfo) {
            $category = $this->categoryRepository->findOneBy(['id' => $categoryInfo['id']]);
            if (is_null($category)) {
                return false;
            }
            $category->setPosition($counter);
            if ($parentCategory) {
                $category->setPosition($counter);
                $category->setRoot(false);
                $category->setParent($parentCategory);
            } else {
                $category->setPosition($counter);
                $category->setRoot(true);
                $category->setParent(null);
            }
            ++$counter;
            if (isset($categoryInfo['subtree']) && !$this->sortCategoriesTree($categoryInfo['subtree'], $category)) {
                return false;
            }
        }
        return true;
    }