Преглед на файлове

fixed fields list in Storage AclUsage

Piotr Labudda преди 8 години
родител
ревизия
224ee348aa
променени са 1 файла, в които са добавени 44 реда и са изтрити 11 реда
  1. 44 11
      SE/se-lib/Route/Storage/AclUsage.php

+ 44 - 11
SE/se-lib/Route/Storage/AclUsage.php

@@ -25,6 +25,7 @@ class Route_Storage_AclUsage extends RouteBase {
 				$namespace = Api_WfsNs::getBaseWfsUri() . '/' . str_replace(':', '/', $typeName);
 			}
 			$aclNamespace = null;
+			$aclXsdFieldTypes = null;
 			$rootTableName = null;
 			$idTable = null;
 			$idDatabase = null;
@@ -34,6 +35,9 @@ class Route_Storage_AclUsage extends RouteBase {
 				$idTable = $acl->getID();
 				$aclNamespace = $acl->getNamespace();
 				$idDatabase = $acl->getDatabaseID();
+				// DBG::nicePrint($acl, 'Acl: $acl class('.get_class($acl).')');
+				$aclXsdFieldTypes = $acl->getXsdTypes();
+				// DBG::nicePrint($aclXsdFieldTypes, 'Acl: $aclXsdFieldTypes');
 			} catch (Exception $e) {
 				DBG::log($e);
 			}
@@ -43,6 +47,11 @@ class Route_Storage_AclUsage extends RouteBase {
 					$rootTableName = $item['_rootTableName'];
 					$idTable = $item['idZasob'];
 					$aclNamespace = $item['namespace'];
+					$aclXsdFieldTypes = array_combine(
+						array_map( V::makePick('fieldNamespace'), $item['field'] ),
+						array_map( V::makePick('xsdType'), $item['field'] )
+					);
+					// DBG::nicePrint($aclXsdFieldTypes, 'SystemObject: $aclXsdFieldTypes');
 				} catch (Exception $e) {
 					DBG::log($e);
 				}
@@ -140,25 +149,54 @@ class Route_Storage_AclUsage extends RouteBase {
 			}
 
 			$databaseName = DB::getPDO( $idDatabase )->getDatabaseName();
+
+			// DBG::nicePrint($aclXsdFieldTypes, 'DBG: $aclXsdFieldTypes');
+			$aclXsdFieldTypes = array_map(function ($xsdType) {
+				return array_merge([
+					'type' => $xsdType
+				], ('ref:' === substr($xsdType, 0, 4))
+					? [
+						'type' => 'ref',
+						'typeDesc' => $xsdType,
+					]
+					: []
+				);
+			}, $aclXsdFieldTypes);
+			$realDatabaseFields = DB::getPDO()->fetchAll("
+				select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
+				from `information_schema`.`COLUMNS` t
+				where t.TABLE_SCHEMA = '{$databaseName}'
+					and t.TABLE_NAME like '{$rootTableName}'
+			");
+			// DBG::nicePrint($realDatabaseFields, 'DBG: $realDatabaseFields');
+			foreach ($realDatabaseFields as $row) {
+				$fieldName = $row['COLUMN_NAME'];
+				if (!array_key_exists($fieldName, $aclXsdFieldTypes)) {
+					$aclXsdFieldTypes[$fieldName] = [
+						'type' => "RAW:" . $row['DATA_TYPE'],
+					];
+				}
+				$aclXsdFieldTypes[$fieldName]['typeDesc'] = $row['COLUMN_TYPE'];
+			}
+
 			UI::table([
 				'caption' => "Powiązania komórek z procesem",
 				'cols_label' => $labelPermCols,
 				'cols_help' => $helpPermCols,
 				'rows' => array_map(
-					function ($row) use ($aclTableRows, $idTable, $renderProcesLink, $renderPermCell, $permCols) {
-						$fieldName = $row['COLUMN_NAME'];
+					function ($aclFieldType, $fieldName) use ($aclTableRows, $idTable, $renderProcesLink, $renderPermCell, $permCols) {
 						$item = [
 							'name' => $fieldName,
 							'typ' => UI::h('details', [], [
-								UI::h('summary', ['style'=>"cursor:pointer"], $row['DATA_TYPE']),
-								UI::h('p', [], $row['COLUMN_TYPE']),
+								UI::h('summary', ['style'=>"cursor:pointer;outline:none"], $aclFieldType['type']),
+								UI::h('p', [], $aclFieldType['typeDesc']),
 							]),
 							'w procesie' => [],
 							'idZasob' => 0,
 						];
 						foreach ($permCols as $colPerm) $item[$colPerm] = '';
 						foreach ($aclTableRows as $aclInfo) {
-							if (strtolower($aclInfo['CELL_NAME']) == strtolower($row['COLUMN_NAME'])) {
+							if (strtolower($aclInfo['CELL_NAME']) == strtolower($fieldName)) {
 								$item['w procesie'][] = $aclInfo['ID_PROCES'];
 								$item['idZasob'] = $aclInfo['ID_CELL'];
 								foreach ($permCols as $colPerm) $item[$colPerm] += $aclInfo[$colPerm];
@@ -171,12 +209,7 @@ class Route_Storage_AclUsage extends RouteBase {
 						$item['idZasob'] = ($item['idZasob']) ? $item['idZasob'] : UI::h('i', ['style'=>"color:silver"], "Brak");
 						foreach ($permCols as $colPerm) $item[$colPerm] = $renderPermCell($item[$colPerm]);
 						return $item;
-					}, DB::getPDO()->fetchAll("
-						select t.COLUMN_NAME, t.DATA_TYPE, t.COLUMN_TYPE
-						from `information_schema`.`COLUMNS` t
-						where t.TABLE_SCHEMA = '{$databaseName}'
-							and t.TABLE_NAME like '{$rootTableName}'
-					")
+					}, $aclXsdFieldTypes, array_keys($aclXsdFieldTypes)
 				)
 			]);