I have a set of organizations and their members. All organizations have board members, and many board members are on the board of more than one organization.
I use JIT Hypertree to illustrate their relationship. The Hypertree JIT scheme requires that one element be the parent of all and drawn based on a single JSON array.
I would like the request for re-centering and refilling the chart to be based on the change. Then 2 levels would be good, but I could not decide how to do it.
The code that I am now manually typing for the three levels from the initial organization, but what I want is to re-curse through all the related entries.
So, it will start with Org and add an Org array for children (board members). Then take all the boards (except the current Org) for each board member and add them as children of the board member.
This will continue until each track ends — presumably with a member of the board who owns only one board.
Anyone have any tips on how to create this array and avoid duplicates?
$board = $center->board(); $top['id'] = $center->ID; $top['name'] = $center->Org; $top['children'] = array(); if ($board) { foreach ($board as $b) { $child['id'] = $b->ID; $child['name'] = (strlen(trim($b->Last)) > 0) ? $b->First . ' ' . $b->Last : 'Unknown'; $child['data']['orgname'] = $center->Org; $child['data']['relation'] = $b->Role; $child['data']['occupation'] = $b->Occupation; $child['children'] = array(); $childboards = $b->boards(); if ($childboards) { foreach ($childboards as $cb) { $gchild['id'] = $cb->ID; $gchild['name'] = $cb->Org; $gchild['data']['orgname'] = (strlen(trim($b->Last)) > 0) ? $b->First . ' ' . $b->Last : 'Unknown'; $gchild['children'] = array(); $childboardmembers = $cb->board(); if ($childboardmembers) { foreach ($childboardmembers as $cbm) { $ggchild['id'] = $cbm->ID; $ggchild['name'] = (strlen(trim($cbm->Last)) > 0) ? $cbm->First . ' ' . $cbm->Last : 'Unknown'; $ggchild['data']['orgname'] = $cb->Org; $ggchild['data']['relation'] = $cbm->Role; $ggchild['data']['occupation'] = $cbm->Occupation; $ggchild['children'] = array(); $gchild['children'][]= $ggchild; }} $child['children'][]= $gchild; }} $top['children'][] = $child; } } $top['data'] = array(); $top['data']['description'] = $center->Desc; echo json_encode($top);
// Edit 2011.10.24 In response to Re hakre, My data structure is a table of organizations with unique identifiers, a People table with unique identifiers, and then a bridge table for the two defining Organization (Entity) and Person and the role that Person plays in Entity. Typical many-to-many. No sub-boards at all. I made an image that now seems pointless, but I will add it below.
The data structure of the JIT library is a bit of a nut (for me) in that it looks like this in the example of its group:
Top: Nine Inch Nails Child: Jerome Dillon Child: Howlin Maggie (another band) {all the bands' members and then all of their bands...}
Thus, an organization (group) is treated as if it is a Person, although it consists of several Persons. And when I recursively use the code above, I get (I think) a scary bloat, but JSON is working correctly despite the bloat.
JSON Example and Visualization Example // End Edit