Przeglądaj źródła

updated simpleSchema acl - Zaliczka

Piotr Labudda 9 lat temu
rodzic
commit
47be0e9c3d

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

@@ -18,6 +18,7 @@ class Core_AclBase {
   public function getName() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   public function getRootTableName() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   public function getXsdFieldType($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function hasSimpleSchema() { return false; }
   public function getSimpleSchema() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
   // TODO: get more xsd restrictions like minOccurs, maxOccurs, nillable and restrictions
 

+ 56 - 1
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -54,6 +54,25 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in simpleSchema");
     $this->_rootTableName = $ns[1];
 
+    {// validate and fix _simpleSchema:
+      // - convert field scalar to [ '@type' => ... ]
+      // - check required @namespace attribute
+      foreach ($this->_simpleSchema as $keySchema => $schema) {
+        foreach ($schema as $fieldName => $params) {
+          if ('@' == substr($fieldName, 0, 1)) continue;// skip params
+          if (is_scalar($params)) {
+            $this->_simpleSchema[ $keySchema ][ $fieldName ] = [ '@type' => $params ];
+          } else if (!is_array($params)) {
+            throw new Exception("Parse error - simpleSchema field type");
+          }
+        }
+        if (empty($schema['@namespace'])) throw new Exception("Missing @namespace in schema for '{$keySchema}'");
+        $ns = explode('/', $schema['@namespace']);
+        $name = end($ns);
+        if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in schema for '{$keySchema}'");
+      }
+    }
+
     // $this->parseXsdTypes();// parse xsdTypes
     $this->_xsdTypes = array();
     {
@@ -65,7 +84,11 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
           $field = [ 'name' => $fieldName, 'perms' => '', 'idZasob' => $generatedIdZasob ];
 
           if (!empty($value['@type'])) $field['xsdType'] = "{$value['@type']}";
-          else if (!empty($value['@ref'])) $field['xsdType'] = "ref:{$value['@ref']}";
+          else if (!empty($value['@ref'])) {
+            $field['xsdType'] = (false !== strpos($value['@ref'], '/'))
+              ? "ref_uri:{$value['@ref']}"
+              : "ref:{$value['@ref']}";
+          }
           else throw new Exception("StorageAcl - field type not defined '{$key}'");
 
           if (!empty($value['@maxOccurs'])) $field['maxOccurs'] = $value['@maxOccurs'];
@@ -86,6 +109,38 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
 
   }
 
+  public function __toString() {
+    $out = "xsd @prefix(default_db__x3A__{$this->_rootTableName})" . "\n";
+    $aliasRefUri = array();
+    foreach ($this->_simpleSchema as $objectName => $schema) {
+      if ('root' == $objectName) $objectName = $this->_name;
+      $out .= "\t" . "{$objectName}";
+        $out .= " @namespace({$schema['@namespace']})";
+      $out .= "\n";
+      foreach ($schema as $fieldName => $field) {
+        if ('@' == substr($fieldName, 0, 1)) continue;// skip tags
+        $out .= "\t\t" . "{$fieldName}";
+        if (!empty($field['@type'])) {
+          $out .= " @type({$field['@type']})";
+          if (!empty($field['@alias'])) $out .= " @alias({$field['@alias']})";
+        } else if (!empty($field['@ref'])) {
+          $out .= " @ref({$field['@ref']})";
+          if (false !== strpos($field['@ref'], '/')) $aliasRefUri[ $fieldName ] = $field['@ref'];
+        } else {
+          $out .= " @BUG('missing @type or @ref')";
+        }
+        // TODO: maxOccurs, nillable, etc.
+        $out .= "\n";
+      }
+      foreach ($aliasRefUri as $fieldName => $nsUri) {
+        $out .= "\t" . "{$objectName} @ref({$nsUri})" . "\n";
+        // TODO: maxOccurs, nillable, etc.
+      }
+    }
+    return $out;
+  }
+
+  public function hasSimpleSchema() { return true; }
   public function getSimpleSchema() { return $this->_simpleSchema; }
   public function getName() { return $this->_name; }
   public function getRootTableName() { $this->_rootTableName; }

+ 13 - 7
SE/se-lib/Schema/DefaultDb/zaliczka/ZaliczkaStorageAcl.php

@@ -11,7 +11,8 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
       '@namespace' => 'default_db/ZALICZKA/Zaliczka',// Api_WfsNs::getBaseWfsUri() . '/default_db/Zaliczka'
       'id' => 'xsd:integer',
       'created' => 'xsd:date',
-      'worker' => 'ref:default_objects/AccessOwner',// TODO: 'alias_ref:default_objects:AccessOwner'
+      'worker' => [ '@ref' => 'default_objects/AccessOwner' ],// TODO: 'alias_ref:default_objects:AccessOwner'
+      // 'worker' => [ '@ref' => 'Worker' ],
       'kwota' => 'xsd:decimal',
       'pozycja' => [ '@ref' => 'ZaliczkaPozycja', '@maxOccurs' => 'unbounded' ]
     ],
@@ -24,15 +25,20 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
     ],
     'Korespondencja' => [
       '@namespace' => 'default_db/IN7_DZIENNIK_KORESP',
-      'id' => 'xsd:integer',
-      'title' => 'xsd:string',
-      'kategoriaKosztu' => 'xsd:string'
+      'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
+      'title' => [ '@type' => 'xsd:string', '@alias' => 'K_ZAWARTOS' ],
+      'kategoriaKosztu' => [ '@type' => 'xsd:string', '@alias' => 'KATEGORIA_KOSZTU' ]
     ],
     'Projekt' => [
       '@namespace' => 'default_db/IN7_MK_BAZA_DYSTRYBUCJI',
-      'id' => 'xsd:integer',
-      'nrBudowy' => 'xsd:string'
-    ]
+      'id' => [ '@type' => 'xsd:integer', '@alias' => 'ID' ],
+      'nrBudowy' => [ '@type' => 'xsd:string', '@alias' => 'M_DIST_DEALNUM' ],// TODO: ? M_DIST_DESC (szerszy opis)
+    ],
+    // 'Worker' => [
+    //   '@namespace' => 'default_objects/AccessOwner',
+    //   'login' => 'xsd:string',
+    //   'name' => 'xsd:string'
+    // ]
   ];
   // [
   //   '@typeName' => 'default_db__x3A__ZALICZKA:Zaliczka',