PMA\libraries\navigation\nodes\Node::hasSiblings PHP Method

hasSiblings() public method

The only exception is for nodes on the third level of the tree (columns and indexes), for which the function always returns true. This is because we want to render the containers for these nodes
public hasSiblings ( ) : boolean
return boolean
    public function hasSiblings()
    {
        $retval = false;
        $paths = $this->getPaths();
        if (count($paths['aPath_clean']) > 3) {
            $retval = true;
            return $retval;
        }
        foreach ($this->parent->children as $child) {
            if ($child !== $this && ($child->type == Node::OBJECT || $child->hasChildren(false))) {
                $retval = true;
                break;
            }
        }
        return $retval;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Renders a single node or a branch of the tree
  *
  * @param Node   $node      The node to render
  * @param bool   $recursive Bool: Whether to render a single node or a branch
  * @param string $class     An additional class for the list item
  *
  * @return string HTML code for the tree node or branch
  */
 private function _renderNode($node, $recursive, $class = '')
 {
     $retval = '';
     $paths = $node->getPaths();
     if ($node->hasSiblings() || $node->realParent() === false) {
         if ($node->type == Node::CONTAINER && count($node->children) == 0 && $GLOBALS['is_ajax_request'] != true) {
             return '';
         }
         $retval .= '<li class="' . trim($class . ' ' . $node->classes) . '">';
         $sterile = array('events', 'triggers', 'functions', 'procedures', 'views', 'columns', 'indexes');
         $parentName = '';
         $parents = $node->parents(false, true);
         if (count($parents)) {
             $parentName = $parents[0]->real_name;
         }
         // if node name itself is in sterile, then allow
         if ($node->is_group || !in_array($parentName, $sterile) && !$node->isNew || in_array($node->real_name, $sterile)) {
             $retval .= "<div class='block'>";
             $iClass = '';
             if ($class == 'first') {
                 $iClass = " class='first'";
             }
             $retval .= "<i{$iClass}></i>";
             if (strpos($class, 'last') === false) {
                 $retval .= "<b></b>";
             }
             $match = $this->_findTreeMatch($this->_vPath, $paths['vPath_clean']);
             $retval .= '<a class="' . $node->getCssClasses($match) . '"';
             $retval .= " href='#'>";
             $retval .= "<span class='hide aPath'>";
             $retval .= $paths['aPath'];
             $retval .= "</span>";
             $retval .= "<span class='hide vPath'>";
             $retval .= $paths['vPath'];
             $retval .= "</span>";
             $retval .= "<span class='hide pos'>";
             $retval .= $this->_pos;
             $retval .= "</span>";
             $retval .= $this->_getPaginationParamsHtml($node);
             if ($GLOBALS['cfg']['ShowDatabasesNavigationAsTree'] || $parentName != 'root') {
                 $retval .= $node->getIcon($match);
             }
             $retval .= "</a>";
             $retval .= "</div>";
         } else {
             $retval .= "<div class='block'>";
             $iClass = '';
             if ($class == 'first') {
                 $iClass = " class='first'";
             }
             $retval .= "<i{$iClass}></i>";
             $retval .= $this->_getPaginationParamsHtml($node);
             $retval .= "</div>";
         }
         $linkClass = '';
         $haveAjax = array('functions', 'procedures', 'events', 'triggers', 'indexes');
         $parent = $node->parents(false, true);
         $isNewView = $parent[0]->real_name == 'views' && $node->isNew === true;
         if ($parent[0]->type == Node::CONTAINER && (in_array($parent[0]->real_name, $haveAjax) || $isNewView)) {
             $linkClass = ' ajax';
         }
         if ($node->type == Node::CONTAINER) {
             $retval .= "<i>";
         }
         $divClass = '';
         if (isset($node->links['icon']) && !empty($node->links['icon'])) {
             $iconLinks = $node->links['icon'];
             $icons = $node->icon;
             if (!is_array($iconLinks)) {
                 $iconLinks = array($iconLinks);
                 $icons = array($icons);
             }
             if (count($icons) > 1) {
                 $divClass = 'double';
             }
         }
         $retval .= "<div class='block " . $divClass . "'>";
         if (isset($node->links['icon']) && !empty($node->links['icon'])) {
             $args = array();
             foreach ($node->parents(true) as $parent) {
                 $args[] = urlencode($parent->real_name);
             }
             foreach ($icons as $key => $icon) {
                 $link = vsprintf($iconLinks[$key], $args);
                 if ($linkClass != '') {
                     $retval .= "<a class='{$linkClass}' href='{$link}'>";
                     $retval .= "{$icon}</a>";
                 } else {
                     $retval .= "<a href='{$link}'>{$icon}</a>";
                 }
             }
         } else {
             $retval .= "<u>{$node->icon}</u>";
         }
         $retval .= "</div>";
         if (isset($node->links['text'])) {
             $args = array();
             foreach ($node->parents(true) as $parent) {
                 $args[] = urlencode($parent->real_name);
             }
             $link = vsprintf($node->links['text'], $args);
             $title = empty($node->links['title']) ? '' : $node->links['title'];
             if ($node->type == Node::CONTAINER) {
                 $retval .= "&nbsp;<a class='hover_show_full' href='{$link}'>";
                 $retval .= htmlspecialchars($node->name);
                 $retval .= "</a>";
             } else {
                 $retval .= "<a class='hover_show_full{$linkClass}' href='{$link}'";
                 $retval .= " title='{$title}'>";
                 $retval .= htmlspecialchars($node->real_name);
                 $retval .= "</a>";
             }
         } else {
             $retval .= "&nbsp;{$node->name}";
         }
         $retval .= $node->getHtmlForControlButtons();
         if ($node->type == Node::CONTAINER) {
             $retval .= "</i>";
         }
         $retval .= '<div class="clearfloat"></div>';
         $wrap = true;
     } else {
         $node->visible = true;
         $wrap = false;
         $retval .= $this->_getPaginationParamsHtml($node);
     }
     if ($recursive) {
         $hide = '';
         if (!$node->visible) {
             $hide = " style='display: none;'";
         }
         $children = $node->children;
         usort($children, array('PMA\\libraries\\navigation\\NavigationTree', 'sortNode'));
         $buffer = '';
         $extra_class = '';
         for ($i = 0, $nbChildren = count($children); $i < $nbChildren; $i++) {
             if ($i + 1 == $nbChildren) {
                 $extra_class = ' last';
             }
             $buffer .= $this->_renderNode($children[$i], true, $children[$i]->classes . $extra_class);
         }
         if (!empty($buffer)) {
             if ($wrap) {
                 $retval .= "<div{$hide} class='list_container'><ul>";
             }
             $retval .= $this->_fastFilterHtml($node);
             $retval .= $this->_getPageSelector($node);
             $retval .= $buffer;
             if ($wrap) {
                 $retval .= "</ul></div>";
             }
         }
     }
     if ($node->hasSiblings()) {
         $retval .= "</li>";
     }
     return $retval;
 }