| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * json files in schema/gui/core/
- * default_db-{tbl_name}.json - config for raw table - no 'parent_object' defined
- * {object_name}.json - config for object - require 'parent_object' (another object or default_db-* raw table object)
- */
- class OBJ {
- public static function getLabel($json) {
- if (empty($json['label'])) return null;
- return (is_array($json['label']))? end($json['label']) : $json['label'];
- }
- // @returns array of parent object names
- public static function getParentList($json) {
- if (empty($json['parent_object'])) return array();
- return (!is_array($json['parent_object']))? array($json['parent_object']) : array_reverse($json['parent_object']);
- }
- public static function getFields($json) {
- if (empty($json['fields'])) return array();
- return $json['fields'];
- }
- public static function getCoreObjectFromFile($objectName) {
- $objectFileName = str_replace("/", '-', $objectName);
- $filePath = APP_PATH_SCHEMA . "/gui/core/{$objectFileName}.json";
- if (!file_exists($filePath)) throw new Exception("File not exists {$filePath}", 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());
- if (empty($json['parent_object'])) return $json;
- $jsonParent = array();
- $parent = (is_array($json['parent_object']))? end($json['parent_object']) : $json['parent_object'];
- $jsonParent = self::getCoreObjectFromFile($parent);
- return array_merge_recursive($jsonParent, $json);
- }
- public static function getCoreObjectList() {
- $objectList = array();
- $files = glob(APP_PATH_SCHEMA . "/gui/core/*.json", GLOB_NOSORT);
- //DBG::_(true, true, "files", $files, __CLASS__, __FUNCTION__, __LINE__);
- foreach ($files as $filePath) {
- $fileName = basename($filePath);
- $objName = substr($fileName, 0, -5);// remove ext '.json'
- $objectList[] = $objName;
- }
- return $objectList;
- }
- }
|