Parse complete directory.gov.au export into gexf
Former-commit-id: 7be06add579fbd14042ea9084bc738168a62dcdf
--- /dev/null
+++ b/admin/directory.gexf.php
@@ -1,1 +1,59 @@
+<?php
+$nodes = Array(Array("id" => "gov", "label" => "Federal Government"));
+$edges = Array();
+
+function addEdge($source, $target) {
+ global $edges;
+ $edges[] = Array("id" => md5($source . $target), "source" => $source, "target" => $target);
+}
+
+function addNode($id, $label, $pid) {
+ global $nodes;
+ $nodes[] = Array("id" => $id, "label" => $label , "pid" => $pid);
+}
+
+function addChildren($parentID, $parentXML) {
+ foreach ($parentXML as $childXML) {
+
+ if ($childXML->getName() == "organization" || $childXML->getName() == "organizationalUnit" || $childXML->getName() == "person") {
+ $attr = $childXML->attributes();
+ $id = $attr['UUID'];
+ if ($childXML->getName() == "organization" || $childXML->getName() == "organizationalUnit") {
+
+ $label = $childXML->name;
+ } else if ($childXML->getName() == "person") {
+ $label = $childXML->fullName;
+ }
+ addNode($id, $label, $parentID);
+ addEdge($id, $parentID);
+ addChildren($id, $childXML);
+ }
+ }
+}
+
+if (file_exists('directoryexport.xml')) {
+ $xml = simplexml_load_file('directoryexport.xml');
+
+ addChildren("gov", $xml);
+} else {
+ exit('Failed to open directoryexport.xml');
+}
+ header('Content-Type: application/gexf+xml');
+echo '<?xml version="1.0" encoding="UTF-8"?>
+<gexf xmlns="http://www.gexf.net/1.2draft" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd" version="1.2">
+ <graph mode="static" defaultedgetype="directed">
+ <nodes>';
+foreach ($nodes as $node) {
+ echo ' <node id="' . $node['id'] . '" label="' . htmlentities($node['label'],ENT_XML1) . '" ' . (isset($node['pid']) ? 'pid="' . $node['pid'] . '"' : "") . ' />';
+}
+echo '</nodes>
+ <edges>';
+foreach ($edges as $edge) {
+ echo ' <edge id="' . $edge['id'] . '" source="' . $edge['source'] . '" target="' . $edge['target'] . '" />';
+}
+echo '</edges>
+ </graph>
+</gexf>';
+?>
+
--- /dev/null
+++ b/admin/directoryexport.xml
--- a/bubbletree.php
+++ b/bubbletree.php
@@ -24,7 +24,7 @@
$color = new Lux_Color();
$portfolios = Array();
-
+$total = 0;
$db = $server->get_db('disclosr-agencies');
try {
$rows = $db->get_view("app", "byDeptStateName", null, true)->rows;
@@ -42,10 +42,15 @@
foreach ($rows as $row) {
$employees = 0;
$portfolioid = 0;
- if ($row->value->employees) $employees = $row->value->employees;
+ if (isset($row->value->employees)) $employees = $row->value->employees;
if (isset($row->value->statistics->employees)) {
$agencyEmployeesArray = object_to_array($row->value->statistics->employees);
+if (isset($agencyEmployeesArray["2010-2011"]["value"])) {
$employees = $agencyEmployeesArray["2010-2011"]["value"];
+} else {
+ // get last year that is recorded? throw error?
+ continue;
+}
}
if (!($employees > 0)) $employees =0;
if (isset($row->value->parentOrg)) $portfolioid = $row->value->parentOrg;