Просмотр исходного кода

added getChildHistTable to simpleSchema

Piotr Labudda 9 лет назад
Родитель
Сommit
764b04af90

+ 5 - 0
SE/se-lib/Core/AclBase.php

@@ -699,6 +699,11 @@ class Core_AclBase {
     ");
   }
 
+  public function getChildHistTable($childName) {
+    throw new Exception("Not implemented getChildHistTable in AclBase - only SimpleSchema is supported");
+    // return Core_AclHelper::getChildHistTable($this->getRootTableName(), $childName, $schema);
+  }
+
   public function updateXml($action) {// @param $action = [ 'typeName' => '*:*', 'Filter'=>int, 'fields'=>[ `name`=>[`fld`, `fld`, ...], ... ] ]
     $DBG = V::get('DBG_XML', 0, $_GET, 'int');
     if($DBG){echo 'C.'.get_class($this).' L.' . __LINE__ . " updateXml action \$action:";print_r($action);echo "\n";}

+ 2 - 1
SE/se-lib/Core/AclHelper.php

@@ -428,8 +428,9 @@ class Core_AclHelper {// Helper class for Acl
       case 'xsd:integer': $sqlType = "int(11) NOT NULL DEFAULT 0"; break;
       case 'xsd:date': $sqlType = "date DEFAULT NULL"; break;
       case 'xsd:decimal': $sqlType = "decimal(" . V::get('@totalDigits', 16, $schema) . ", " . V::get('@fractionDigits', 2, $schema) . ") NOT NULL DEFAULT 0"; break;
+      // TODO: type alias like enum fields: @type => "{$prefix}:{$field_name}Type"
     }
-    if (!$sqlType && !empty($schema['@ref'])) $sqlType = "int(11) NOT NULL DEFAULT 0";
+    if (!$sqlType && !empty($schema['@ref'])) $sqlType = "int(11) NOT NULL DEFAULT 0";// TODO: type from ref instance @primaryKey - mostly int
     if (!$sqlType) throw new Exception("Unimplemented schema to sql for '{$rootTableName}/{$childName}' schema(".json_encode($schema).")");
     DB::getPDO()->exec("
       CREATE TABLE IF NOT EXISTS `{$histTable}` (

+ 9 - 0
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -459,4 +459,13 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     return $object;
   }
 
+  public function getChildHistTable($childName) {
+    if (empty($childName)) throw new Exception("Missing childName ('{$this->_namespace}')");
+    if (!array_key_exists($childName, $this->_simpleSchema['root'])) throw new Exception("Field '{$childName}' not found in shema for '{$this->_namespace}'");
+    if ('@' == substr($childName, 0, 1)) throw new Exception("Child hist table for attribute '{$childName}' not supported ('{$this->_namespace}')");
+    // TODO: allow child for '@instance'
+    $childSchema = $this->_simpleSchema['root'][$childName];
+    return Core_AclHelper::getChildHistTable($this->getRootTableName(), $childName, $childSchema);
+  }
+
 }