dimanche 24 janvier 2016

Output nested set for Google Visualisation

I am using Baum for Laravel to retrieve a nested set, but I can't begin to think how to get it into the format that my Google organisation chart needs it.

The outputted JSON:

var nodes = {"1":{"id":1,"parent_id":null,"lft":1,"rgt":10,"depth":0,"name":"Jing's Team","created_at":"-0001-11-30 00:00:00","updated_at":"2016-01-24 18:32:22","children":[{"id":2,"parent_id":1,"lft":2,"rgt":3,"depth":1,"name":"Ann's Team","created_at":"-0001-11-30 00:00:00","updated_at":"2016-01-24 18:32:22","children":[]},{"id":3,"parent_id":1,"lft":4,"rgt":9,"depth":1,"name":"Mike's Team","created_at":"-0001-11-30 00:00:00","updated_at":"2016-01-24 18:32:22","children":[{"id":4,"parent_id":3,"lft":5,"rgt":8,"depth":2,"name":"Laidy's Team","created_at":"-0001-11-30 00:00:00","updated_at":"2016-01-24 18:32:22","children":[{"id":5,"parent_id":4,"lft":6,"rgt":7,"depth":3,"name":"Steve's Team","created_at":"-0001-11-30 00:00:00","updated_at":"2016-01-24 18:32:22","children":[]}]}]}]}};

Which is generated with:

    Team::rebuild(true);
    $nodes = Team::where('id', Auth::user()->team_id)->first();
    $nodes = $nodes->getDescendantsAndSelf()->toHierarchy();

    return view('team.index', ['nodes' => $nodes]);

The way that Google organisation takes it:

data.addRows([
    [{v:'Mike', f:'Mike<div style="color:red; font-style:italic">President</div>'},
        '', 'The President'],
    [{v:'Jim', f:'Jim<div style="color:red; font-style:italic">Vice President</div>'},
        'Mike', 'VP'],
    ['Sam', 'Mike', ''],
    ['Bob', 'Jim', 'Bob Sponge'],
    ['Phil', 'Jim', 'Bob Sponge'],
    ['Carol', 'Bob', '']
]);

['NAME', 'PARENT_NAME', 'HOVER OVER TITLE']

How can parse the JSON to get it into the format that Google needs it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1VizWek
via IFTTT

Aucun commentaire:

Enregistrer un commentaire