Ejemplo n.º 1
0
 /**
  * Rebuilds the tree: update descendants and their order
  * @param type $categories
  * @return type
  */
 public static function rebuildTree($categories)
 {
     if (is_array($categories)) {
         foreach ($categories as $cat) {
             $node = Category::find($cat['id']);
             //$node->descendants->linknodes();
             //loop recursively through the children
             if (isset($cat['children']) && is_array($cat['children']) && count($cat['children'])) {
                 foreach ($cat['children'] as $child) {
                     //append the children to their (old/new)parents
                     $descendant = Category::find($child['id']);
                     $node->appendNode($descendant);
                     //shift the descendants to the bottom to get the right order at the end
                     $shift = count($descendant->getSiblings());
                     $descendant->down($shift);
                     Category::rebuildTree($cat['children']);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Reorder nestable
  *
  * @param ShopCategoryReorderRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function setReorder(ShopCategoryReorderRequest $request)
 {
     //@TODO Reorder need fix
     $categories = json_decode($request->get('data'), true);
     Category::updateTreeRoots($categories);
     Category::rebuildTree($categories);
     Category::fixTree();
     // Category::update($categories);
     return response()->json(['status' => 'ok']);
 }