peterujah/hierarchical

Hierarchical - Light, simple PHP and mysql Hierarchy data and organization chart.

1.4 2022-10-13 09:38 UTC

This package is auto-updated.

Last update: 2024-05-13 12:47:31 UTC


README

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.

alt text

Installation

Installation is super-easy via Composer:

composer require peterujah/hierarchical

USAGES

Hierarchical can be use as an array, html or google organizations chart

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

 $hierarchy->add("foo22", "Foo")->under("vy7735");

Dump array

$hierarchy = new Hierarchical($conn, Hierarchical::LIST);
var_export($hierarchy->run("Peter", "vy7735"));

Display on google Organisation chart

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(<?php echo $hierarchy->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