/** * @return array Asynchronous result array */ public function __async_form($structureId = 0) { /** @var array $table Result of asynchronous controller * Represented as array of rendered table and pager objects */ $table = $this->__async_table($structureId); if ($structureId == 0) { // If parent structure is not set, store structure by itself instead $parent = isset($parent) ? $parent : CMSNav::fullTree(); /** @var SamsonTree $tree Tree structure object */ $tree = new SamsonTree('tree/template', 0, $this->id . '/getchild'); /** @var string $treeHTML Rendered tree */ $treeHTML = $tree->htmlTree($parent); $treeHide = false; } else { $treeHTML = ''; $treeHide = true; } // Return asynchronous result return array('status' => 1, 'html' => $this->view('form')->set($table)->set($treeHTML, 'tree')->set($treeHide, 'treeHide')->set($structureId, 'structureID')->output()); }
/** * @param CMSNav $parent * @param string $html * @param null $view * @param int $level * @param int $currentNavID * @return string */ public function htmlTree(CMSNav &$parent = null, &$html = '', $view = null, $level = 0, $currentNavID = 0, $recursion = 1) { /** Collection of visited structures to avoid recursion */ static $visited = array(); // If no parent structure is passed if (!isset($parent)) { // Use current object $parent =& $this; } // If we have not visited this structure yet if (!isset($visited[$parent->id])) { // Store it as visited $visited[$parent->id] = $parent->Name; // Get structure children // TODO: What is the difference? if ($parent->base) { $children = $parent->children(); } else { $children = $parent->baseChildren(); } // If we have children collection for this node if (sizeof($children)) { // Sort children usort($children, array(__CLASS__, 'strSorting')); // Start html list $html .= '<ul>'; // Iterate all children foreach ($children as $child) { // If external view is set if (isset($view)) { if (!$recursion && sizeof($child->children())) { // Start HTML list item and render this view $html .= '<li class="hasChildren">'; } else { $html .= '<li>'; } // Start HTML list item and render this view $html .= m()->view($view)->parentid($parent->id)->nav_id($currentNavID)->db_structure($child)->output(); } else { // Render just structure name $html .= '<li>' . $child->Name; } if ($recursion) { // Go deeper in recursion $parent->htmlTree($child, $html, $view, $level++, $currentNavID, $recursion); } // Close HTML list item $html .= '</li>'; } // Close HTML list $html .= '</ul>'; } } return $html; }
/** * Построение нового дерева. (Вызывается в цепи контроллеров) * @param null $currentMainNavID - указатель на родителя * * @return array */ public function __async_tree($currentMainNavID = null) { /** @var CMSNav $currentMainNav */ $currentMainNav = null; if (dbQuery('\\samson\\cms\\web\\navigation\\CMSNav')->StructureID($currentMainNavID)->first($currentMainNav)) { $currentMainNav->currentNavID = $currentMainNavID; } else { $currentMainNav = CMSNav::fullTree(); } $tree = new \samson\treeview\SamsonTree('tree/tree-template', 0, 'structure/addchildren'); $sub_menu = $this->view('sub_menu')->parentnav_id($currentMainNavID)->nav_id($currentMainNavID)->output(); // return Ajax response return array('status' => 1, 'tree' => $tree->htmlTree($currentMainNav), 'sub_menu' => $sub_menu); }