namespace Application; use Application\Categories; use Bluz\Proxy\Messages; return function ($tree, $treeParent) use($view) { /** * @var Bootstrap $this */ try { $categories = json_decode($tree); if (!$categories) { throw new Exception('Categories tree is broken'); } foreach ($categories as $node) { if (isset($node->item_id)) { $dbNode = Categories\Table::findRow($node->item_id); if (!$node->parent_id) { $node->parent_id = $treeParent; } if ($dbNode->parentId != $node->parent_id && $node->parent_id) { $dbNode->parentId = $node->parent_id; $dbNode->save(); } if ($dbNode->order != $node->order && $node->order) { $dbNode->order = $node->order; $dbNode->save(); } } } Messages::addSuccess('Tree has been saved'); } catch (\Exception $e) {
*/ /** * @namespace */ namespace Application; use Application\Categories; use Bluz\Proxy\Layout; use Bluz\Proxy\Messages; return function ($id = null) use($view) { /** * @var Bootstrap $this * @var \Bluz\View\View $view */ Layout::setTemplate('dashboard.phtml'); Layout::headStyle($view->baseUrl('css/categories.css')); Layout::breadCrumbs([$view->ahref('Dashboard', ['dashboard', 'grid']), __('Categories')]); $categoriesTable = Categories\Table::getInstance(); $rootTree = $categoriesTable->getAllRootCategory(); if (count($rootTree) == 0) { Messages::addNotice('There are no categories'); return $view; } $view->rootTree = $rootTree; if (!$id) { $id = $rootTree[0]->id; } $view->branch = $id; $view->tree = $categoriesTable->buildTree($id); return $view; };