Skip to content

This project helps to operate with tree structure based on Nested Sets method via MySQL

Notifications You must be signed in to change notification settings

george-zakharov/tree-structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tree structure project

Files

index.php

  • It is the entrance of the Application.
  • It requires NodeHandler.php and new object NodeHandler creates there.
  • At the top of the code block the possible realization of the inserting and deleting of nodes is presented under comments.
  • Inside <!-- Tree structure --> block of html there are $nodes->showTree() and $nodes->showTree(3) that provides representation of Nodes Tree in two modes:
    • $nodes->showTree() show the whole Tree of Nodes,
    • $nodes->showTree(3) show the part of Tree of Nodes limited by node with $id = 3.

main.css

  • This is the main stylesheet of the application.

App/DbConnector.php

  • Provides connection to Database via singleton pattern.
  • Parameters for connection stores in properties of the class DbConnector:
    • $host for host name,
    • $db_name for name of the Database,
    • $user for login,
    • $pass for password.
  • Main methods are:
    • getInstance() for class DbConnector,
    • getConnection() for PDO Object.

App/Model.php

  • This file store class Model to perform the operations with DB.
  • Main methods are:
    • getNodes() to show show whole tree of nodes or its part,
    • setNode() to add new node to the tree,
    • deleteNode() to delete node from tree.

App/NodeHandler.php

  • This method gives the representation of nodes to page index.php.
  • Main methods are:
    • showTree() to echo the whole tree of nodes or its part if parameter is provided,
    • addNewNode() to add now node to Database via Model.php to the root or specified level,
    • deleteNode() to delete node from Database via Model.php from the specified level or to delete the whole tree.

tree-structure-example.sql

  • This is the dump of the tables of my local tree-structure Database.
  • It is partly filled for example.

Database structure

  • Data stores via Nested Sets method.
  • For example is provided a catalogue (of cars) in such hierarchy:
  • vehicle
    • Type (Motorcycle, Automobile)
      • Brand (Audi, BMW, Ford)
        • Model (A1, A2, Focus, etc.)
          • Year (1999, 2003, etc.)
  • All nodes are nested on correspond levels.
  • New root level near vehicle can be added. For example, animal with its own hierarchy of nodes, but bonded with near root node by right_key and left_key.

About

This project helps to operate with tree structure based on Nested Sets method via MySQL

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published