PMA\libraries\navigation\NavigationTree::_buildPathPart PHP Method

_buildPathPart() private method

Builds a branch of the tree
private _buildPathPart ( array $path, string $type2, integer $pos2, string $type3, integer $pos3 ) : Node | false
$path array A paths pointing to the branch of the tree that needs to be built
$type2 string The type of item being paginated on the second level of the tree
$pos2 integer The position for the pagination of the branch at the second level of the tree
$type3 string The type of item being paginated on the third level of the tree
$pos3 integer The position for the pagination of the branch at the third level of the tree
return PMA\libraries\navigation\nodes\Node | false The active node or false in case of failure
    private function _buildPathPart($path, $type2, $pos2, $type3, $pos3)
    {
        if (empty($pos2)) {
            $pos2 = 0;
        }
        if (empty($pos3)) {
            $pos3 = 0;
        }
        $retval = true;
        if (count($path) <= 1) {
            return $retval;
        }
        array_shift($path);
        // remove 'root'
        /* @var $db NodeDatabase */
        $db = $this->_tree->getChild($path[0]);
        $retval = $db;
        if ($db === false) {
            return false;
        }
        $containers = $this->_addDbContainers($db, $type2, $pos2);
        array_shift($path);
        // remove db
        if ((count($path) <= 0 || !array_key_exists($path[0], $containers)) && count($containers) != 1) {
            return $retval;
        }
        if (count($containers) == 1) {
            $container = array_shift($containers);
        } else {
            $container = $db->getChild($path[0], true);
            if ($container === false) {
                return false;
            }
        }
        $retval = $container;
        if (count($container->children) <= 1) {
            $dbData = $db->getData($container->real_name, $pos2, $this->_searchClause2);
            foreach ($dbData as $item) {
                switch ($container->real_name) {
                    case 'events':
                        $node = NodeFactory::getInstance('NodeEvent', $item);
                        break;
                    case 'functions':
                        $node = NodeFactory::getInstance('NodeFunction', $item);
                        break;
                    case 'procedures':
                        $node = NodeFactory::getInstance('NodeProcedure', $item);
                        break;
                    case 'tables':
                        $node = NodeFactory::getInstance('NodeTable', $item);
                        break;
                    case 'views':
                        $node = NodeFactory::getInstance('NodeView', $item);
                        break;
                    default:
                        break;
                }
                if (isset($node)) {
                    if ($type2 == $container->real_name) {
                        $node->pos2 = $pos2;
                    }
                    $container->addChild($node);
                }
            }
        }
        if (count($path) > 1 && $path[0] != 'tables') {
            $retval = false;
            return $retval;
        }
        array_shift($path);
        // remove container
        if (count($path) <= 0) {
            return $retval;
        }
        /* @var $table NodeTable */
        $table = $container->getChild($path[0], true);
        if ($table === false) {
            if (!$db->getPresence('tables', $path[0])) {
                return false;
            }
            $node = NodeFactory::getInstance('NodeTable', $path[0]);
            if ($type2 == $container->real_name) {
                $node->pos2 = $pos2;
            }
            $container->addChild($node);
            $table = $container->getChild($path[0], true);
        }
        $retval = $table;
        $containers = $this->_addTableContainers($table, $pos2, $type3, $pos3);
        array_shift($path);
        // remove table
        if (count($path) <= 0 || !array_key_exists($path[0], $containers)) {
            return $retval;
        }
        $container = $table->getChild($path[0], true);
        $retval = $container;
        $tableData = $table->getData($container->real_name, $pos3);
        foreach ($tableData as $item) {
            switch ($container->real_name) {
                case 'indexes':
                    $node = NodeFactory::getInstance('NodeIndex', $item);
                    break;
                case 'columns':
                    $node = NodeFactory::getInstance('NodeColumn', $item);
                    break;
                case 'triggers':
                    $node = NodeFactory::getInstance('NodeTrigger', $item);
                    break;
                default:
                    break;
            }
            if (isset($node)) {
                $node->pos2 = $container->parent->pos2;
                if ($type3 == $container->real_name) {
                    $node->pos3 = $pos3;
                }
                $container->addChild($node);
            }
        }
        return $retval;
    }