|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
Lib::loadClass('Api_WfsNs');
|
|
|
+Lib::loadClass('Response');
|
|
|
|
|
|
class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
|
|
|
@@ -85,6 +86,191 @@ class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
UI::alert('danger', $e->getMessage());
|
|
|
UI::dol();
|
|
|
}
|
|
|
+
|
|
|
+ function raportOutputStatsAction() {
|
|
|
+ session_write_close();
|
|
|
+ $args = [];
|
|
|
+ $args['raportId'] = V::get('raportId', 0, $_GET, 'int');
|
|
|
+ $args['outputFormat'] = V::get('outputFormat', '', $_GET, 'word');
|
|
|
+ try {
|
|
|
+ if (!$args['raportId']) throw new Exception("Wrong param raportId");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ switch ($args['outputFormat']) {
|
|
|
+ case 'json': return $this->sendJsonErrorMsg($e->getMessage());
|
|
|
+ case 'xml': return $this->sendXmlErrorMsg($e->getMessage());
|
|
|
+ case 'html':
|
|
|
+ default: {
|
|
|
+ return $this->sendHtmlErrorMsg($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $stats = $this->getOutputStats($args['raportId']);
|
|
|
+
|
|
|
+ switch ($args['outputFormat']) {
|
|
|
+ case 'json': return $this->sendJsonStats($args['raportId'], $stats);
|
|
|
+ case 'xml': return $this->sendXmlStats($args['raportId'], $stats);
|
|
|
+ case 'html':
|
|
|
+ default: {
|
|
|
+ return $this->sendHtmlStats($args['raportId'], $stats);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function getOutputStats($raportId) {
|
|
|
+ $matrix = $this->getRaportOutputMatrix($raportId);
|
|
|
+ $listObjectsNs = $this->_getListPointChildNs();
|
|
|
+ $listPointChildAlias = $this->_getListPointChildAlias();
|
|
|
+
|
|
|
+ $listPathLength = array_reduce($matrix, function ($ret, $item) {
|
|
|
+ $ret[ $item['pk_Path'] ] = 1 + V::get($item['pk_Path'], 0, $ret);
|
|
|
+ return $ret;
|
|
|
+ }, []);
|
|
|
+ $listPathPk = array_keys($listPathLength);
|
|
|
+ $pointOccurs = array_reduce($matrix, function ($ret, $item) use ($listPointChildAlias) {
|
|
|
+ foreach ($listPointChildAlias as $alias) {
|
|
|
+ $pkField = "pk_{$alias}";
|
|
|
+ if ($item[$pkField]) {
|
|
|
+ $featureId = "{$alias}.{$item[$pkField]}";
|
|
|
+ $ret[$featureId] = 1 + V::getValue($ret[$featureId], 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ }, []);
|
|
|
+ asort($pointOccurs);
|
|
|
+ DBG::log($pointOccurs, 'array', '$pointOccurs');
|
|
|
+
|
|
|
+ $getPointFeatureIdFromPath = function ($item) {
|
|
|
+ $listPointChildAlias = $this->_getListPointChildAlias();
|
|
|
+ return array_reduce($listPointChildAlias, function ($ret, $objAlias) use ($item) {
|
|
|
+ $pk = V::get("pk_{$objAlias}", 0, $item);
|
|
|
+ if ($pk) $ret = "{$objAlias}.{$pk}";
|
|
|
+ return $ret;
|
|
|
+ }, null);
|
|
|
+ };
|
|
|
+ $prevItem = [];
|
|
|
+ $edges = array_reduce($matrix, function ($ret, $item) use (&$prevItem, $getPointFeatureIdFromPath) {
|
|
|
+ if (!empty($prevItem) && $prevItem['pk_Path'] === $item['pk_Path']) {
|
|
|
+ $ret[] = [ 'source' => $getPointFeatureIdFromPath($prevItem), 'target' => $getPointFeatureIdFromPath($item), 'pathId' => $item['pk_Path'] ];
|
|
|
+ $prevItem = array_merge([], $item);
|
|
|
+ return $ret;
|
|
|
+ } else {
|
|
|
+ $prevItem = array_merge([], $item);
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ DBG::log("edges - done");
|
|
|
+ $prevFeaturesOnPath = [];
|
|
|
+ $prevPathId = 0;
|
|
|
+ $allToAllEdges = array_reduce($matrix, function ($ret, $item) use (&$prevFeaturesOnPath, &$prevPathId, $getPointFeatureIdFromPath) {
|
|
|
+ $curFeatureId = $getPointFeatureIdFromPath($item);
|
|
|
+ if (!empty($prevFeaturesOnPath) && $prevPathId === $item['pk_Path']) {
|
|
|
+ foreach ($prevFeaturesOnPath as $idx => $prevFeatureId) {
|
|
|
+ $ret[] = [ 'source' => $prevFeatureId, 'target' => $curFeatureId, 'pathId' => $item['pk_Path'], 'length' => (1 + $idx) ];
|
|
|
+ }
|
|
|
+ array_unshift($prevFeaturesOnPath, $curFeatureId);
|
|
|
+ $prevPathId = $item['pk_Path'];
|
|
|
+ return $ret;
|
|
|
+ } else {
|
|
|
+ $prevFeaturesOnPath = [ $curFeatureId ];
|
|
|
+ $prevPathId = $item['pk_Path'];
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+ DBG::log("edges_all_to_all - done");
|
|
|
+
|
|
|
+ $stats = [];
|
|
|
+ // $stats['path_length'] = $listPathLength;
|
|
|
+ $stats['path_total'] = count($listPathLength);
|
|
|
+ $stats['point_total'] = count($matrix);
|
|
|
+ $stats['point_occurs'] = $pointOccurs;
|
|
|
+ $stats['edges_all_to_all'] = $allToAllEdges;
|
|
|
+ $stats['edges'] = $edges;
|
|
|
+ $stats['nodes'] = array_map([ $this, 'getFeature' ], array_keys($pointOccurs));
|
|
|
+ return $stats;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getFeature($featureId) {
|
|
|
+ list($objectName, $primaryKey) = explode(".", $featureId);
|
|
|
+ if (!$objectName) throw new Exception("Wrong featureId '{$featureId}' - missing objectName");
|
|
|
+ if (!$primaryKey) throw new Exception("Wrong featureId '{$featureId}' - missing primaryKey");
|
|
|
+ $tableName = $objectName;
|
|
|
+ $item = DB::getPDO()->fetchFirst(" select * from `{$tableName}` where id = :id ", [ ':id' => $primaryKey ]);
|
|
|
+ $getLabel = [ $this, '_getFeatureLabel' ];
|
|
|
+ return array_merge($item, [
|
|
|
+ '@label' => $getLabel($objectName, $item), // TODO: label depend on table / later format from xsd
|
|
|
+ '@object' => $objectName,
|
|
|
+ '@primaryKey' => $primaryKey,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ function _getFeatureLabel($objectName, $item) {
|
|
|
+ $primaryKey = $item['@primaryKey'];
|
|
|
+ switch ($objectName) {
|
|
|
+ case 'BI_audit_ENERGA_RUM_KONTRAHENCI': return V::get('Pelna_nazwa_kontrahenta', $primaryKey, $item);
|
|
|
+ case 'BI_audit_MSIG': return V::get('nazwa', $primaryKey, $item);
|
|
|
+ case 'BI_audit_MSIG_person': return V::getValue(
|
|
|
+ implode(" ", array_filter([
|
|
|
+ V::get('imiona', '', $item),
|
|
|
+ V::get('nazwisko', '', $item)
|
|
|
+ ], 'strlen'))
|
|
|
+ , "{$objectName} Nr {$primaryKey}"
|
|
|
+ );
|
|
|
+ case 'BI_audit_CEIDG': return V::get('firma', $primaryKey, $item);
|
|
|
+ case 'BI_audit_KRS': return V::get('nazwa', $primaryKey, $item);
|
|
|
+ case 'BI_audit_KRS_person': return V::getValue(
|
|
|
+ implode(" ", array_filter([
|
|
|
+ V::get('imiona', '', $item),
|
|
|
+ V::get('nazwisko', '', $item)
|
|
|
+ ], 'strlen'))
|
|
|
+ , "{$objectName} Nr {$primaryKey}"
|
|
|
+ );
|
|
|
+ case 'BI_audit_MSIG_company': return V::get('nazwa', $primaryKey, $item);
|
|
|
+ case 'BI_audit_KRS_company': return V::get('nazwa', $primaryKey, $item);
|
|
|
+ case 'TERYT_adresy': return "TERYT({$item['TERYT_SYM']}/{$item['TERYT_SYM_UL']})";
|
|
|
+ case 'BI_audit_MSIG_address': return V::getValue(
|
|
|
+ implode(", ", array_filter([
|
|
|
+ implode(" ", array_filter([
|
|
|
+ V::get('A_kod', '', $item),
|
|
|
+ V::get('S_miejscowosc', '', $item)
|
|
|
+ ], 'strlen')),
|
|
|
+ implode(" ", array_filter([
|
|
|
+ V::get('A_nrDomu', '', $item),
|
|
|
+ V::get('A_nrDomu', '', $item),
|
|
|
+ V::get('A_nrLokalu', '', $item)
|
|
|
+ ], 'strlen'))
|
|
|
+ ], 'strlen'))
|
|
|
+ , "{$objectName} Nr {$primaryKey}"
|
|
|
+ );
|
|
|
+
|
|
|
+ default: return "TODO: {$objectName} Nr {$primaryKey}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function sendJsonStats($raportId, $stats) {
|
|
|
+ Response::sendJson([
|
|
|
+ 'type' => "success",
|
|
|
+ 'msg' => "OK",
|
|
|
+ 'body' => $stats
|
|
|
+ ]);
|
|
|
+ die();
|
|
|
+ }
|
|
|
+ function sendXmlStats($raportId, $stats) {
|
|
|
+ print_r($stats);
|
|
|
+ }
|
|
|
+ function sendHtmlStats($raportId, $stats) {
|
|
|
+ UI::gora();
|
|
|
+ DBG::nicePrint($stats, "\$stats");
|
|
|
+ $dbgNode = function ($item) {
|
|
|
+ return [
|
|
|
+ 'object' => $item['@object'],
|
|
|
+ 'primaryKey' => $item['@primaryKey'],
|
|
|
+ 'label' => $item['@label'],
|
|
|
+ ];
|
|
|
+ };
|
|
|
+ UI::table([ 'rows' => array_map($dbgNode, $stats['nodes']) ]);
|
|
|
+ UI::dol();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
function raportView($args) {
|
|
|
$raportId = V::get('raportId', 0, $args, 'int');
|
|
|
$featureId = V::get('featureId', '', $args, '');
|
|
|
@@ -92,12 +278,16 @@ class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
echo $h('div', [ 'id' => "bi_audit_raport-network_graph" ], "TODO: loading data...");
|
|
|
echo $h('script', ['src'=>"static/vendor.js?v=a76e2988", 'type'=>"text/javascript"]);
|
|
|
echo $h('script', [ 'src' => "static/visjs/vis.min.js" ]);
|
|
|
+ $stats = $this->getOutputStats($raportId);
|
|
|
+ echo UI::h('link', [ 'href' => 'static/react-bootstrap-typeahead.min.css', 'type' => 'text/css', 'rel' => 'stylesheet' ]);
|
|
|
UI::inlineJS(__FILE__ . '.network-graph.js', [
|
|
|
'HTML_ID_REF_GRAPH' => 'bi_audit_raport-network_graph',
|
|
|
// 'TYPENAME' => Api_WfsNs::typeName($namespace),
|
|
|
// 'PRIMARY_KEY' => $primaryKey,
|
|
|
// 'WFS_URL' => Router::getRoute('WfsBiAudit')->getLink(),
|
|
|
- 'API_URL' => $this->getLink('getRaportNetworkGraphDataAjax'),
|
|
|
+ 'RAPORT_ID' => $raportId,
|
|
|
+ 'API_URL' => $this->getLink('raportOutputStats', [ 'outputFormat' => "json", 'raportId' => $raportId ]),
|
|
|
+ 'STATS' => $stats,
|
|
|
'DBG' => (V::get('DBG', 0, $_GET, 'int') > 0),
|
|
|
]);
|
|
|
|
|
|
@@ -106,16 +296,7 @@ class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
function getRaportNetworkGraphDataAjaxAction() {
|
|
|
|
|
|
}
|
|
|
- function getRaportOutputMatrix($raportId) {
|
|
|
- // Main Raport Acl NS: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA
|
|
|
- // - Found Paths in: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row
|
|
|
- // - Path Points in: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object
|
|
|
- $mainNs = [
|
|
|
- 'Raport' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
|
|
|
- 'Path' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
|
|
|
- 'Point' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
|
|
|
- ];
|
|
|
-
|
|
|
+ function _getListPointChildNs() {
|
|
|
$listObjectsNs = [];
|
|
|
$listObjectsNs[] = 'default_db__x3A__BI_audit_CEIDG:BI_audit_CEIDG';
|
|
|
$listObjectsNs[] = 'default_db__x3A__BI_audit_CEIDG_pelnomocnicy:BI_audit_CEIDG_pelnomocnicy';
|
|
|
@@ -133,6 +314,25 @@ class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
$listObjectsNs[] = 'default_db__x3A__BI_audit_MSIG_company:BI_audit_MSIG_company';
|
|
|
$listObjectsNs[] = 'default_db__x3A__BI_audit_MSIG_person:BI_audit_MSIG_person';
|
|
|
$listObjectsNs[] = 'default_db__x3A__TERYT_adresy:TERYT_adresy';
|
|
|
+ return $listObjectsNs;
|
|
|
+ }
|
|
|
+ function _getListPointChildAlias() {
|
|
|
+ return array_map(function ($objNs) {
|
|
|
+ // return str_replace([ 'BI_audit_' ], '', substr($objNs, strrpos($objNs, ':') + 1));
|
|
|
+ return substr($objNs, strrpos($objNs, ':') + 1);
|
|
|
+ }, $this->_getListPointChildNs());
|
|
|
+ }
|
|
|
+ function getRaportOutputMatrix($raportId) {
|
|
|
+ // Main Raport Acl NS: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA
|
|
|
+ // - Found Paths in: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row
|
|
|
+ // - Path Points in: default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object
|
|
|
+ $mainNs = [
|
|
|
+ 'Raport' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
|
|
|
+ 'Path' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row',
|
|
|
+ 'Point' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object',
|
|
|
+ ];
|
|
|
+
|
|
|
+ $listObjectsNs = $this->_getListPointChildNs();
|
|
|
|
|
|
$outRefTables = array_merge(
|
|
|
[ [ 'label' => 'Raport_to_Path', 'table' => ACL::getRefTable(Api_WfsNs::toNamespace($mainNs['Raport']), $mainNs['Path']) ] ],
|
|
|
@@ -153,16 +353,14 @@ class Route_UrlAction_BiAuditGraph extends RouteBase {
|
|
|
$refTables = array_combine( array_map(V::makePick('label'), $outRefTables), array_map(V::makePick('table'), $outRefTables) );
|
|
|
DBG::log($refTables, 'array', '$refTables');
|
|
|
|
|
|
- $fromPointRefTableAliases = array_map(function ($objNs) {
|
|
|
- return str_replace([ 'BI_audit_' ], '', substr($objNs, strrpos($objNs, ':') + 1));
|
|
|
- }, array_merge($listObjectsNs));
|
|
|
- DBG::log($fromPointRefTableAliases, 'array', '$fromPointRefTableAliases');
|
|
|
+ $listPointChildAlias = $this->_getListPointChildAlias();
|
|
|
+ DBG::log($listPointChildAlias, 'array', '$listPointChildAlias');
|
|
|
$sqlSelect = implode("\n , ", array_merge(
|
|
|
array_map(function ($tbl, $key) {
|
|
|
return "t_{$key}.ID as pk_{$key}";
|
|
|
}, $mainTables, array_keys($mainTables)),
|
|
|
- array_map(function ($tbl, $key) use ($fromPointRefTableAliases) {
|
|
|
- return "t_{$key}.ID as pk_{$fromPointRefTableAliases[$key]}";
|
|
|
+ array_map(function ($tbl, $key) use ($listPointChildAlias) {
|
|
|
+ return "t_{$key}.ID as pk_{$listPointChildAlias[$key]}";
|
|
|
}, $refFromPointTables, array_keys($refFromPointTables))
|
|
|
));
|
|
|
$sqlTablesFrom = [];
|