| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- Lib::loadClass('SchemaException');
- Lib::loadClass('Schema_TableBase');
- /**
- * Base class for all tables - Schema_TableBase
- * CoreTableClass extends from Schema_TableBase
- * CompanyTableClass extend from CoreTableClass
- *
- * WARNING: to add CompanyTableClass, add CoreTableClass first
- */
- class Schema_TableFactory {
- public static function build($tableName, $idSource = null, $hostName = '') {
- //_schemaClass
- $objectClassName = 'Schema_TableBase';
- $cleanHostName = str_replace(array(".", "-"), '_', $hostName);
- $cleanTableName = strtolower($tableName);
- $cleanSourceName = ($idSource == DB::getPDO()->getZasobId())? 'default_db' : "p5_{$idSource}";
- DBG::_('DBG_SCH', '>2', "Schema({$tableName}): cleanHostName({$cleanHostName}) cleanTableName({$cleanTableName}) cleanSourceName({$cleanSourceName})", null, __CLASS__, __FUNCTION__, __LINE__);
- // TODO: fetch form widgets from file config
- // "schema/gui/core/{$cleanSourceName}.{$cleanTableName}.php";
- // class Schema_Core_{$cleanSourceName}_{$cleanTableName};
- // TODO: override by company file config
- // "schema/gui/{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}.php";
- // class Schema_{$cleanHostName}_{$cleanSourceName}_{$cleanTableName};
- $pathCoreClass = APP_PATH_SCHEMA . "/gui/core/{$cleanSourceName}.{$cleanTableName}.php";
- //if (!file_exists($pathCoreClass)) throw new SchemaException("Core Class file not found '{$cleanSourceName}.{$cleanTableName}'");
- if (file_exists($pathCoreClass)) {
- require_once $pathCoreClass;
- $coreClassName = "Schema__Core__{$cleanSourceName}__{$cleanTableName}";
- if (!class_exists($coreClassName)) throw new SchemaException("Config error for schema core class {$cleanSourceName}:{$cleanTableName}");
- $pathCompanyClass = APP_PATH_SCHEMA . "/gui/company/{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}.php";
- $companyClassName = "Schema__{$cleanHostName}__{$cleanSourceName}__{$cleanTableName}";
- //if (!file_exists($pathCompanyClass)) throw new SchemaException("Host Class file not found '{$cleanHostName}/{$cleanSourceName}.{$cleanTableName}'");
- if ($cleanHostName && file_exists($pathCompanyClass)) {
- require_once $pathCompanyClass;
- if (!class_exists($companyClassName)) throw new SchemaException("Config error for schema company class {$cleanSourceName}:{$cleanTableName}");
- $objectClassName = $companyClassName;
- } else {
- $objectClassName = $coreClassName;
- }
- }
- DBG::_('DBG_SCH', '>2', "Schema({$tableName}): objectClassName('{$objectClassName}')", null, __CLASS__, __FUNCTION__, __LINE__);
- return new $objectClassName($idSource, $cleanTableName);
- }
- }
|