public static function add($parent = false)
    {
        $db = Database::connection();
        $treeNodeParentID = 0;
        $treeID = 0;
        $treeNodeDisplayOrder = 0;
        $inheritPermissionsFromTreeNodeID = 0;
        if (is_object($parent)) {
            $treeNodeParentID = $parent->getTreeNodeID();
            $treeID = $parent->getTreeID();
            $inheritPermissionsFromTreeNodeID = $parent->getTreeNodePermissionsNodeID();
            $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$treeNodeParentID]);
            $parent->updateDateModified();
        } else {
            $parent = null;
        }

        $treeNodeTypeHandle = uncamelcase(strrchr(get_called_class(), '\\'));

        $dateModified = Core::make('date')->toDB();
        $dateCreated = Core::make('date')->toDB();

        $type = TreeNodeType::getByHandle($treeNodeTypeHandle);
        $db->executeQuery(
            'insert into TreeNodes (treeNodeTypeID, treeNodeParentID, treeNodeDisplayOrder, inheritPermissionsFromTreeNodeID, dateModified, dateCreated, treeID) values (?, ?, ?, ?, ?, ?, ?)',
            [
                $type->getTreeNodeTypeID(),
                $treeNodeParentID,
                $treeNodeDisplayOrder,
                $inheritPermissionsFromTreeNodeID,
                $dateModified,
                $dateCreated,
                $treeID,
            ]
        );
        $id = $db->lastInsertId();
        $node = self::getByID($id);

        if (!$inheritPermissionsFromTreeNodeID) {
            $node->setTreeNodePermissionsToOverride();
        }

        if ($parent !== null && $parent->childNodesLoaded) {
            $parent->childNodes[] = $node;
        }

        return $node;
    }