Loading, please wait...

ARTDESIGN FRAMEWORK

DATABASE TREE

Description

ArtDesign FrameWork DataBase - Management of tree structures
DataBase Tree - Select, Select Children Elements, Get Depth Node, Get Parent ID, Select Parent Element, Select Tree Path, Get Number Of All Children Elements, Get Number Of Children Elements (Only Level 0), Get ID Of All Children Elements, Insert, Update, Delete, Copy, Move Element, Change Position All Children

Implementation

//01. SetUp DataBase Settings - /Path/To/ArtDesign/PHP/Settings/DataBase.php
$ConfigurationData = array(
    "SQLDefault" => array(
        "SQLType" => "mysql",
        "SQLHost" => "localhost",
        "SQLDataBase" => "data_base_name",
        "SQLUser" => "mysql_user",
        "SQLPassword" => "mysql_password",
        "SQLPDO" => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'",
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        )
    )
);
return $ConfigurationData;

//02. SetUp DataBase test table
CREATE TABLE IF NOT EXISTS `test` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `Lft` int(11) NOT NULL,
  `Rgt` int(11) NOT NULL,
  `Parent` int(11) NOT NULL,
  `Name` char(100) NOT NULL,
  `Family` char(100) NOT NULL,
  `Age` smallint(3) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

//03. Run DataBase Class
$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

Select

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$DBScript = $DataBase->SQLTreeSelect();

Select Children Elements (Level 0)

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectChildren($ID, true);
//Returns children elements (Level 0) to element with #5

Select All Children Elements

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectChildren($ID, false);
//Returns all children elements to element with # 5

Get Depth Node

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectDepthNode($ID);
//Returns Depth Node to element with #5

Get Parent ID

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectParentID($ID);
//Returns ID to parent element of element with #5

Select Parent Element

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectParent($ID);
//Returns parent element of element with #5

Select Tree Path

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectPath($ID);
//Returns all parents elements of element with #5 (including it)

Get Number Of All Children Elements

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectChildrenWithChildrenCount($ID);
//Returns the number of all parents elements of element with #5

Get Number Of Children Elements (Only Level 0)

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectChildrenWithOutChildrenCount($ID);
//Returns the number of all parents elements (Only Level 0) of element with #5

Get ID Of All Children Elements

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);
$DataBase->SQLTreeSettingsTree($SQLTreeDataBaseTable);
$SQLTreeSelect = array(
    "SQLTreeDataBaseColumns" => "ID, Lft, Rgt, Parent, Name, Family, Age",
    "SQLTreeDataBaseSearch" => "",
    "SQLTreeDataBaseStart" => 0,
    "SQLTreeDataBaseLimit" => "3",
    "SQLTreeDataBaseOrderBy" => "ASC"
);
$DataBase->SQLTreeSettingsSelect($SQLTreeSelect);
$ID = 5;
$DBScript = $DataBase->SQLTreeSelectChildrenID($ID);
//Returns ID to all children elements of element with #5

Insert

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$Parent = 0;
$Position = 1;
$Name = "Sam";
$Family = "Moe";
$Age = 21;
$DataBase->SQLTreeInsert(
    $Parent,
    array(
        "Name" => $Name,
        "Family" => $Family,
        "Age" => $Age
    ),
    $Position
);
//Insert като Level 0

$Parent = 5;
$Position = 2;
$Name = "Sam";
$Family = "Moe";
$Age = 21;
$DataBase->SQLTreeInsert(
    $Parent,
    array(
        "Name" => $Name,
        "Family" => $Family,
        "Age" => $Age
    ),
    $Position
);
//Insert as children element of element with #5 and position 2

Update

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$ID = 5;
$Name = "Sam";
$Family = "Moe";
$Age = 21;

$DataBase->SQLTreeUpdate(
    $ID,
    array(
        "Name" => $Name,
        "Family" => $Family,
        "Age" => $Age
    )
);
//Update Element with #5

Delete

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$ID = 5;
$DataBase->SQLTreeDelete(
    $ID,
    true,
    10
);
//Delete an element with #5, saveing its children elements and attachment them to element with #10
$ID = 5;
$DataBase->SQLTreeDelete(
    $ID,
    false
);
//Delete an element with #5 and all it's children elements 

Copy

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$ID = 5;
$Target = 10;
$Position = 2;
$DataBase->SQLTreeCopy(
    $ID,
    $Target,
    $Position
);
//Copy of element with #5 as children element of element with #10 and position 2

Move Element

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$ID = 5;
$Target = 10;
$Position = 2;
$DataBase->SQLTreeChangePosition(
    $ID,
    $Target,
    $Position
);
//Move the element with #5 (together with all its children elements) as children element of element with #10 and position 2

Change Position All Children

$ArtDesign = \ArtDesign\ArtDesign::GetInstance();
$DataBase = \ArtDesign\Engine\DataBase\SQL::GetInstance("SQLDefault");

$SQLTreeDataBaseTable = array(
    "SQLTreeDataBaseTable" => array(
        "test2"
    )
);

$ID = 5;
$Target = 10;

$DataBase->SQLTreeChangePositionAllChildren(
    $ID,
    $TargetID
);
//Move the children elements of element with #5 such as children elements of element #10