https://github.com/peterujah/hierarchical
Hierarchical - Light, simple PHP and mysql Hierarchy data and organization chart
https://github.com/peterujah/hierarchical
Last synced: 10 months ago
JSON representation
Hierarchical - Light, simple PHP and mysql Hierarchy data and organization chart
- Host: GitHub
- URL: https://github.com/peterujah/hierarchical
- Owner: peterujah
- License: mit
- Created: 2021-09-30T20:12:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-13T09:38:32.000Z (over 3 years ago)
- Last Synced: 2025-07-27T19:32:08.960Z (11 months ago)
- Language: PHP
- Homepage:
- Size: 136 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Hierarchical
Hierarchies represent relations between people or other types of related entities. The hierarchy structure determines which entities are in command of other entities.
Hierarchies can be stored in databases using table records that express what entities are below or above in the hierarchy tree.
This class can retrieve a hierarchy tree structure from a MySQL database table to easily visualize using the Google Organisation Chart API, Array or HTML.

## Installation
Installation is super-easy via Composer:
```md
composer require peterujah/hierarchical
```
# USAGES
Hierarchical can be use as an array, html or google organizations chart
```php
use Peterujah\NanoBlock\Hierarchical;
$hierarchy = new Hierarchical($conn, Hierarchical::LIST);
$hierarchy = new Hierarchical($conn, Hierarchical::HTML);
$hierarchy = new Hierarchical($conn, Hierarchical::CHART);
```
Assign new user to a position
```php
$hierarchy->add("foo22", "Foo")->under("vy7735");
```
Dump array
```php
$hierarchy = new Hierarchical($conn, Hierarchical::LIST);
var_export($hierarchy->run("Peter", "vy7735"));
```
Display on google Organisation chart
```javascript
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addColumn('string', 'ToolTip');
data.addRows(run("Peter", "vy7735");?>);
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
chart.draw(data, {'allowHtml':true});
}
```
Initalisation options `new Hierarchical($conn, Hierarchical::CHART)`
| Options | Description |
|-----------------|-------------------------------------------------------------------------------------|
| LIST | Retrieve result as an array |
| HTML | Retrieve result in HTML list |
| CHART | Retrieve result in json data for google chart |