Recursing Properly Through Related Entities Recursing Properly Through Related Entities json json

Recursing Properly Through Related Entities


Your question is hard to answer in the sense that your data-structure is mainly unknown.

For the graphical represenation you only need to provide simple relationships if I understand that correctly:

*- Parent   +- Child   +- Child   ...   `- Child

Your data structure has a different format, I don't know specifically but it's something like:

Org <-- 1:n --> BoardBoard <-- n:n --> Board # If you have sub-boardsBoard <-- n:n --> Member

Whichever your data is represented, to map or transpose your data onto the required structure for the graphical representation, you need some functions that take care of that.

To do that you need to share classification/type between both and specific keys, so that you can look-up the needed data from the event to return the data. For example:

if (request_parent_is_org()){    $id = request_parent_id();    $parent = data_get_board($id);    $parent->addChildrent(data_get_board_children($id));}else{    ... # All the other decisions you need to take based on request type}view_response_to_json($parent);


What you have with your many-to-many data model is a graph. JIT is designed for trees.

To put it another way, JIT will not correctly show the crossing lines that are represented in the data whenever a single person is connected to multiple organizations.

I'd recommend a proper network graph visualization - D3.js has a great implementation for modern browsers.

The JSON data format it uses is actually easier to implement given your table structure - for all the organizations and people, you define objects:

{    "name": "Mme.Hucheloup",    "group": 1},{    "name": "Afton School Board",    "group": 2}

And for each association in your association table you define connection objects that wire them together:

{    "source": 1,    "target": 2},

The fancy coding in D3 takes care of the rest. Good luck!


You can use function below:

function get_orgs_and_childs ($child_id, $found = array()) {    array_push ($found, $child['name']);    if($child['children'])){            $found[] = get_parents($child['id'], $found);    }    return $found;}

Call it using:

$orgs = get_orgs_and_childs($child['id']);