|
|
@@ -5,6 +5,7 @@ Lib::loadClass('RouteBase');
|
|
|
Lib::loadClass('Schema_TableFactory');
|
|
|
Lib::loadClass('Response');
|
|
|
Lib::loadClass('UI');
|
|
|
+Lib::loadClass('OBJ');
|
|
|
|
|
|
/*
|
|
|
# Storage:
|
|
|
@@ -73,26 +74,6 @@ class Route_Storage extends RouteBase {
|
|
|
UI::dol();
|
|
|
}
|
|
|
|
|
|
- public function getCoreObjectFromFile($objectName) {
|
|
|
- if ('default_db/' === substr($objectName, 0, 11)) {
|
|
|
- return array('name' => substr($objectName, 11));
|
|
|
- }
|
|
|
-
|
|
|
- $filePath = APP_PATH_SCHEMA . "/gui/core/{$objectName}.json";
|
|
|
- if (!file_exists($filePath)) throw new Exception("File not exists", 404);
|
|
|
-
|
|
|
- $json = file_get_contents($filePath);
|
|
|
- DBG::_('DBG', '>1', "{$objectName} filePath", $filePath, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- DBG::_('DBG', '>1', "{$objectName} file content", $json, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- $json = @json_decode($json, $assoc = true);
|
|
|
- DBG::_('DBG', '>1', "{$objectName} json_last_error()", json_last_error(), __CLASS__, __FUNCTION__, __LINE__);
|
|
|
- if (null == $json && 0 !== json_last_error()) throw new Exception("Parse json error for object '{$objectName}': " . json_last_error());
|
|
|
- $jsonParent = array();
|
|
|
- $parent = (is_array($json['parent_object']))? end($json['parent_object']) : $json['parent_object'];
|
|
|
- $jsonParent = $this->getCoreObjectFromFile($parent);
|
|
|
- return array_merge_recursive($jsonParent, $json);
|
|
|
- }
|
|
|
-
|
|
|
public function coreObjectStructAction() {
|
|
|
UI::gora();
|
|
|
UI::menu();
|
|
|
@@ -101,10 +82,41 @@ class Route_Storage extends RouteBase {
|
|
|
|
|
|
$object = V::get('object', '', $_REQUEST, 'word');
|
|
|
if (empty($object)) throw new Exception("Missing Object name");
|
|
|
- $json = $this->getCoreObjectFromFile($object);
|
|
|
+ $json = OBJ::getCoreObjectFromFile($object);
|
|
|
+
|
|
|
+ $label = OBJ::getLabel($json);
|
|
|
+ $parentList = OBJ::getParentList($json);
|
|
|
+?>
|
|
|
+<div class="container">
|
|
|
+ <h1>Obiekt <code><?php echo $label; ?></code></h1>
|
|
|
+ <?php if (!empty($parentList)) : ?>
|
|
|
+ <p>Dziedziczy z: <?php echo implode(", ", $parentList); ?></p>
|
|
|
+ <?php endif; ?>
|
|
|
+ Struktura:
|
|
|
+ <table class="table table-bordered table-hovered">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>nazwa</th>
|
|
|
+ <th>typ</th>
|
|
|
+ <th>label</th>
|
|
|
+ <th>json</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <?php foreach (OBJ::getFields($json) as $fieldName => $field) : ?>
|
|
|
+ <tr>
|
|
|
+ <td><?php echo $fieldName; ?></td>
|
|
|
+ <td><?php echo $field['type']; ?></td>
|
|
|
+ <td><?php echo $field['label']; ?></td>
|
|
|
+ <td><?php echo json_encode($field); ?></td>
|
|
|
+ </tr>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+</div>
|
|
|
+<?php
|
|
|
DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
|
-
|
|
|
} catch (Exception $e) {
|
|
|
UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
|
|
|
}
|
|
|
@@ -116,15 +128,11 @@ class Route_Storage extends RouteBase {
|
|
|
UI::menu();
|
|
|
$this->navView();
|
|
|
try {
|
|
|
- $files = glob(APP_PATH_SCHEMA . "/gui/core/*.json", GLOB_NOSORT);
|
|
|
- //DBG::_(true, true, "files", $files);
|
|
|
+ $coreObjlist = OBJ::getCoreObjectList();
|
|
|
$objectList = array();
|
|
|
- foreach ($files as $filePath) {
|
|
|
+ foreach ($coreObjlist as $objName) {
|
|
|
$objItem = array();
|
|
|
- $fileName = basename($filePath);
|
|
|
- $objName = substr($fileName, 0, -5);// remove ext '.json'
|
|
|
$objItem['name'] = $objName;
|
|
|
- $objItem['file_name'] = $fileName;
|
|
|
$objItem['label'] = "";// TODO: read from json
|
|
|
$objItem['struktura'] = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . $objName . '">' . "struct" . '</a>';
|
|
|
$objectList[] = $objItem;
|