Create a new tree

@param string $tree_name
@param string $tree_title

@return Tree
495977
public static function create(string $tree_name, string $tree_title): Tree
    {
        try {
            // Create a new tree
            DB::table('gedcom')->insert([
                'gedcom_name' => $tree_name,
            ]);

            $tree_id = (int) DB::connection()->getPdo()->lastInsertId();

            $tree = new self($tree_id, $tree_name, $tree_title);
        } catch (PDOException $ex) {
            // A tree with that name already exists?
            return self::findByName($tree_name);
        }

        $tree->setPreference('imported', '0');
        $tree->setPreference('title', $tree_title);

        // Set preferences from default tree
        (new Builder(DB::connection()))->from('gedcom_setting')->insertUsing(
            ['gedcom_id', 'setting_name', 'setting_value'],
            static function (Builder $query) use ($tree_id): void {
                $query
                    ->select([DB::raw($tree_id), 'setting_name', 'setting_value'])
                    ->from('gedcom_setting')
                    ->where('gedcom_id', '=', -1);
            }
        );

        (new Builder(DB::connection()))->from('default_resn')->insertUsing(
            ['gedcom_id', 'tag_type', 'resn'],
            static function (Builder $query) use ($tree_id): void {
                $query
                    ->select([DB::raw($tree_id), 'tag_type', 'resn'])
                    ->from('default_resn')
                    ->where('gedcom_id', '=', -1);
            }
        );

        // Gedcom and privacy settings
        $tree->setPreference('CONTACT_USER_ID', (string) Auth::id());
        $tree->setPreference('WEBMASTER_USER_ID', (string) Auth::id());
        $tree->setPreference('LANGUAGE', WT_LOCALE); // Default to the current admin’s language

        switch (WT_LOCALE) {
            case 'es':
                $tree->setPreference('SURNAME_TRADITION', 'spanish');
                break;
            case 'is':
                $tree->setPreference('SURNAME_TRADITION', 'icelandic');
                break;
            case 'lt':
                $tree->setPreference('SURNAME_TRADITION', 'lithuanian');
                break;
            case 'pl':
                $tree->setPreference('SURNAME_TRADITION', 'polish');
                break;
            case 'pt':
            case 'pt-BR':
                $tree->setPreference('SURNAME_TRADITION', 'portuguese');
                break;
            default:
                $tree->setPreference('SURNAME_TRADITION', 'paternal');
                break;
        }

        // Genealogy data
        // It is simpler to create a temporary/unimported GEDCOM than to populate all the tables...
        /* I18N: This should be a common/default/placeholder name of an individual. Put slashes around the surname. */
        $john_doe = I18N::translate('John /DOE/');
        $note     = I18N::translate('Edit this individual and replace their details with your own.');
        $gedcom   = "0 HEAD\n1 CHAR UTF-8\n0 @X1@ INDI\n1 NAME {$john_doe}\n1 SEX M\n1 BIRT\n2 DATE 01 JAN 1850\n2 NOTE {$note}\n0 TRLR\n";

        DB::table('gedcom_chunk')->insert([
            'gedcom_id'  => $tree_id,
            'chunk_data' => $gedcom,
        ]);

        // Update our cache
        self::$trees[$tree->id] = $tree;

        return $tree;
    }
654608
private function build_section_sub_tree($main_tree, $tree_level, $section_level) {
    $sub_sections = array();
    if (isset($main_tree[$tree_level]) && isset($main_tree[$tree_level][$section_level])) {
      $sub_sections = $main_tree[$tree_level][$section_level];
      $sub_tree_level = $tree_level + 1;
      foreach ($sub_sections as $sub_section_level => $sub_section) {
        $sub_sections[$sub_section_level]['sub'] = $this->build_section_sub_tree($main_tree, $sub_tree_level, $sub_section_level);
      }
    }
    return $sub_sections;
  }
1271803
def create_node(name, parent=None, ns='', tail=False, text=False):
    
    node = etree.Element(etree.QName(ns, name))
    if parent is not None:
        parent.append(node)
    if tail:
        node.tail = tail
    if text:
        node.text = text
    return node
948135
public function buildTree($data, $row_level = 'parent')
    {
        $new = [];
        foreach ($data as $a) {
            if (null === $a->{$row_level}) {
                $a->{$row_level} = 0;
            }
            $new[$a->{$row_level}][] = $a;
        }

        return $this->createTree($new, Arr::get($new, 0, []));
    }
1201871
public function alternateTreeTitle()
    {
        if ($this->owner->SubsiteID == 0) {
            return ' * ' . $this->owner->Title;
        }

        return $this->owner->Title;
    }
1183866
def __make_tree(self):
        """"""

        # create div with "container" class
        div = E.DIV(E.CLASS("container"))

        # append header with title
        div.append(E.H2(self.__title))

        # next, iterate through subtrees appending each tree to div
        for subtree in self.__subtrees:
            div.append(subtree.get_html())

        # Connect div to body
        body = E.BODY(div)

        # attach body to html
        self.__htmltree = E.HTML(
            E.HEAD(
                E.TITLE(self.__title)
                ),
            body
            )
88525
public static function gedcomHeader(Tree $tree, string $char): string
    {
        // Default values for a new header
        $HEAD = '0 HEAD';
        $SOUR = "\n1 SOUR " . Webtrees::NAME . "\n2 NAME " . Webtrees::NAME . "\n2 VERS " . Webtrees::VERSION;
        $DEST = "\n1 DEST DISKETTE";
        $DATE = "\n1 DATE " . strtoupper(date('d M Y')) . "\n2 TIME " . date('H:i:s');
        $GEDC = "\n1 GEDC\n2 VERS 5.5.1\n2 FORM Lineage-Linked";
        $CHAR = "\n1 CHAR " . $char;
        $FILE = "\n1 FILE " . $tree->name();
        $COPR = '';
        $LANG = '';
        $SUBN = '';
        $SUBM = "\n1 SUBM @SUBM@\n0 @SUBM@ SUBM\n1 NAME " . Auth::user()->userName(); // The SUBM record is mandatory

        // Preserve some values from the original header
        $record = GedcomRecord::getInstance('HEAD', $tree);
        $fact   = $record->facts(['COPR'])->first();
        if ($fact instanceof Fact) {
            $COPR = "\n1 COPR " . $fact->value();
        }
        $fact = $record->facts(['LANG'])->first();
        if ($fact instanceof Fact) {
            $LANG = "\n1 LANG " . $fact->value();
        }
        // Link to actual SUBM/SUBN records, if they exist
        $subn = DB::table('other')
            ->where('o_type', '=', 'SUBN')
            ->where('o_file', '=', $tree->id())
            ->value('o_id');
        if ($subn) {
            $SUBN = "\n1 SUBN @{$subn}@";
        }
        $subm = DB::table('other')
            ->where('o_type', '=', 'SUBM')
            ->where('o_file', '=', $tree->id())
            ->value('o_id');
        if ($subm) {
            $SUBM = "\n1 SUBM @{$subm}@";
        }

        return $HEAD . $SOUR . $DEST . $DATE . $SUBM . $SUBN . $FILE . $COPR . $GEDC . $CHAR . $LANG . "\n";
    }
188555
protected function create_navigation(\stdClass $tree) {
        if ($this->firstelement) {
            $html = \html_writer::start_tag('ul', ['class' => 'treeview parent block_tree list', 'id' => 'my-tree']);
            $this->firstelement = false;
        } else {
            $html = \html_writer::start_tag('ul', ['class' => 'parent', 'role' => 'group']);
        }
        foreach ($tree->children as $child) {
            if (isset($child->children)) {
                $html .= \html_writer::start_tag('li', ['class' => 'menu-item', 'role' => 'treeitem', 'aria-expanded' => 'false']);
                $html .= $child->name;
                $html .= $this->create_navigation($child);
            } else {
                $html .= \html_writer::start_tag('li', ['class' => 'item', 'role' => 'treeitem', 'aria-expanded' => 'false']);
                // Normal display.
                if (isset($child->datavar)) {
                    $html .= \html_writer::link('#', $child->name, ['data-var' => $child->datavar]);
                } else {
                    $html .= \html_writer::link($child->url, $child->name, ['target' => '_blank']);
                }
            }
            $html .= \html_writer::end_tag('li');
        }
        $html .= \html_writer::end_tag('ul');
        return $html;
    }
1227803
private function generateNewTreeName(): string
    {
        $tree_name      = 'tree';
        $tree_number    = 1;
        $existing_trees = Tree::getNameList();

        while (array_key_exists($tree_name . $tree_number, $existing_trees)) {
            $tree_number++;
        }

        return $tree_name . $tree_number;
    }
386211
def create_tree(self):
        
        feature_indices = []
        for i in self.estimator.tree_.feature:
            n_features = self.n_features
            if self.n_features > 1 or (self.n_features == 1 and i >= 0):
                feature_indices.append([str(j) for j in range(n_features)][i])
        indentation = 1 if self.target_language in ['java', 'js',
                                                    'php', 'ruby'] else 0
        return self.create_branches(
            self.estimator.tree_.children_left,
            self.estimator.tree_.children_right,
            self.estimator.tree_.threshold,
            self.estimator.tree_.value,
            feature_indices, 0, indentation)
1350680
public static function treeChecked($field, $title, $value = [])
    {
        return self::tree($field, $title, $value)->showCheckbox(true);
    }
646725
private static function _getSelectTreeChildren(&$target,$pId,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel)
    {
        if($level<0){
            $level=9999;
        }
        if($currentLevel>$level){
            return;
        }
        $sep="";
        for($i=0;$i<$currentLevel;$i++){
            $sep.=$separator;
        }
        foreach ($source as $item){
            $_pid=$item[$pidField];
            if($_pid==$pId){
                $id=$item[$idField];
                $title=$sep.$prefix.$item[$titleField];
                $target[$id]=$title;
                self::_getSelectTreeChildren($target,$id,$source,$idField,$pidField,$titleField,$separator,$prefix,$level,$currentLevel+1);

            }
        }
    }
799129
protected function createNavItems(array $treeItems, NavItem $parent = null)
    {
        /** @var NavItem[] $navItems */
        $navItems = [];

        foreach ($treeItems as $treeItem) {
            if ($treeItem->isAsset) {
                continue;
            }

            $nav = $this->createNavItem($treeItem, $parent);
            if ($nav === null) {
                continue;
            }

            if (!isset($navItems[$nav->relUrl]) || !$navItems[$nav->relUrl]->children) {
                $navItems[$nav->relUrl] = $nav;
            }
        }

        return array_values($navItems);
    }
612912
protected CmsResourceTreeTable createTree(CmsObject cms, CmsResource root) {

        return new CmsResourceTreeTable(cms, root, m_filter);
    }
494046
function auto_create_parent($access_name) {
        $path = str_replace('.', '._items.', $access_name);
        $arr = explode('.', $access_name);
        $tmp = array_pop($arr);
        $default_title = ucwords(str_replace('_', ' ', $tmp));
        if (!Arr::path($this->items, $path . '.item')) {
            Arr::set_path($this->items, $path . '.item.text', $default_title);
            Arr::set_path($this->items, $path . '.item.url', '#');
        }
        if (!Arr::path($this->items, $path . '.access_name')) {
            Arr::set_path($this->items, $path . '.access_name', $access_name);
        }
    }
1274133
public static HtmlTree IFRAME(String src, String name, String title) {
        HtmlTree htmltree = new HtmlTree(HtmlTag.IFRAME);
        htmltree.addAttr(HtmlAttr.SRC, nullCheck(src));
        htmltree.addAttr(HtmlAttr.NAME, nullCheck(name));
        htmltree.addAttr(HtmlAttr.TITLE, nullCheck(title));
        return htmltree;
    }
240210
def newNode(name):
    
    ret = libxml2mod.xmlNewNode(name)
    if ret is None:raise treeError('xmlNewNode() failed')
    return xmlNode(_obj=ret)