Explorar el Código

added Core Acl Base getXsdTypes, fixed error msg in Code Acl Base

Piotr Labudda hace 8 años
padre
commit
2b90b24b35

+ 42 - 41
SE/se-lib/Core/AclBase.php

@@ -18,19 +18,20 @@ class Core_AclBase {
   public $_db = 0; // database id zasobu
   public $_rootTableName = null;
 
-  public function getNamespace() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getSourceName() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  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 getNamespace() { throw new HttpException("Acl::getNamespace() Not implemented", 501); }
+  public function getSourceName() { throw new HttpException("Acl::getSourceName() Not implemented", 501); }
+  public function getName() { throw new HttpException("Acl::getName() Not implemented", 501); }
+  public function getRootTableName() { throw new HttpException("Acl::getRootTableName() Not implemented", 501); }
+  public function getXsdTypes() { throw new HttpException("Acl::getXsdTypes() Not implemented", 501); } // @returns [ fieldName => xsdType, ... ]
+  public function getXsdFieldType($fieldName) { throw new HttpException("Acl::getXsdFieldType() Not implemented", 501); }
   public function hasSimpleSchema() { return false; }
-  public function getSimpleSchema() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function getSimpleSchema() { throw new HttpException("Acl::getSimpleSchema() Not implemented", 501); }
   // TODO: get more xsd restrictions like minOccurs, maxOccurs, nillable and restrictions
 
   public function getID() { return $this->_zasobID; }
   public function getDatabaseID() { return $this->_db; }
-  public function init($force = false) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isInitialized() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function init($force = false) { throw new HttpException("Acl::init() Not implemented", 501); }
+  public function isInitialized() { throw new HttpException("Acl::isInitialized() Not implemented", 501); }
   public function hasField($fieldName) {// TODO: fix use Core_AclFields or ACL::getObjectFields($namespace) - use cache - one place to store structure
     foreach ($this->getFields() as $field) {
       if ($fieldName === $field['name']) return true;
@@ -47,7 +48,7 @@ class Core_AclBase {
   		$field['label'] = $label;
   		$this->_fields[$fieldID] = $field;
     */
-    throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501);
+    throw new HttpException("Acl::getFields() Not implemented", 501);
   }
 	public function getFieldLabel($fieldName) {
 		// DBG::log($this->getFields(), 'array', "DBG getFieldLabel({$fieldName})");
@@ -76,35 +77,35 @@ class Core_AclBase {
 		}
 		return $fieldName;
 	}
-  public function getFieldListByIdZasob() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: RMME - one field list function
-  public function getLocalFieldList() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: RMME - one field list function
-  public function getRealFieldListByIdZasob() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: RMME - one field list function
-  public function getVirtualFieldListByIdZasob() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: RMME - one field list function
+  public function getFieldListByIdZasob() { throw new HttpException("Acl::getFieldListByIdZasob() Not implemented", 501); }// TODO: RMME - one field list function
+  public function getLocalFieldList() { throw new HttpException("Acl::getLocalFieldList() Not implemented", 501); }// TODO: RMME - one field list function
+  public function getRealFieldListByIdZasob() { throw new HttpException("Acl::getRealFieldListByIdZasob() Not implemented", 501); }// TODO: RMME - one field list function
+  public function getVirtualFieldListByIdZasob() { throw new HttpException("Acl::getVirtualFieldListByIdZasob() Not implemented", 501); }// TODO: RMME - one field list function
   // TODO: public function getFieldList(); // @retuns array of field names
 
   public function isIntegerField($fieldName) { return ('xsd:integer' == $this->getXsdFieldType($fieldName)); }
-  public function isDecimalField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isGeomField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isDateField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isDateTimeField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isTimeField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isStringField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isTextField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isBinaryField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function isEnumerationField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getEnumerations($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getFieldType($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-
-  public function getFieldIdByName($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: legacy
-  public function isAllowed($idZasob, $taskPerm, $record = null) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: legacy
-  public function hasFieldPerm($idZasob, $taskPerm) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: legacy
+  public function isDecimalField($fieldName) { throw new HttpException("Acl::isDecimalField() Not implemented", 501); }
+  public function isGeomField($fieldName) { throw new HttpException("Acl::isGeomField() Not implemented", 501); }
+  public function isDateField($fieldName) { throw new HttpException("Acl::isDateField() Not implemented", 501); }
+  public function isDateTimeField($fieldName) { throw new HttpException("Acl::isDateTimeField() Not implemented", 501); }
+  public function isTimeField($fieldName) { throw new HttpException("Acl::isTimeField() Not implemented", 501); }
+  public function isStringField($fieldName) { throw new HttpException("Acl::isStringField() Not implemented", 501); }
+  public function isTextField($fieldName) { throw new HttpException("Acl::isTextField() Not implemented", 501); }
+  public function isBinaryField($fieldName) { throw new HttpException("Acl::isBinaryField() Not implemented", 501); }
+  public function isEnumerationField($fieldName) { throw new HttpException("Acl::isEnumerationField() Not implemented", 501); }
+  public function getEnumerations($fieldName) { throw new HttpException("Acl::getEnumerations() Not implemented", 501); }
+  public function getFieldType($fieldName) { throw new HttpException("Acl::getFieldType() Not implemented", 501); }
+
+  public function getFieldIdByName($fieldName) { throw new HttpException("Acl::getFieldIdByName() Not implemented", 501); }// TODO: legacy
+  public function isAllowed($idZasob, $taskPerm, $record = null) { throw new HttpException("Acl::isAllowed() Not implemented", 501); }// TODO: legacy
+  public function hasFieldPerm($idZasob, $taskPerm) { throw new HttpException("Acl::hasFieldPerm() Not implemented", 501); }// TODO: legacy
 
   // TODO: replace isAllowed, hasFieldPerm, getFieldIdByName
-  public function canCreateField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function canReadField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function canReadObjectField($fieldName, $record) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function canWriteField($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function canWriteObjectField($fieldName, $record) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function canCreateField($fieldName) { throw new HttpException("Acl::canCreateField() Not implemented", 501); }
+  public function canReadField($fieldName) { throw new HttpException("Acl::canReadField() Not implemented", 501); }
+  public function canReadObjectField($fieldName, $record) { throw new HttpException("Acl::canReadObjectField() Not implemented", 501); }
+  public function canWriteField($fieldName) { throw new HttpException("Acl::canWriteField() Not implemented", 501); }
+  public function canWriteObjectField($fieldName, $record) { throw new HttpException("Acl::canWriteObjectField() Not implemented", 501); }
   public function canWriteRecord($record) {// TODO: AclHelper?
 		$record = (array)$record;
 		$dbgArr = array();
@@ -216,9 +217,9 @@ class Core_AclBase {
     Lib::loadClass('AclQueryFeatures');
 		return new AclQueryFeatures($this, $params, $legacyMode = true);
   }
-  public function getItems($params = array()) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: use ParseOgcQuery
-  public function getTotal($params = array()) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }// TODO: use ParseOgcQuery
-  public function getItem($primaryKey, $params = []) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function getItems($params = array()) { throw new HttpException("Acl::getItems() Not implemented", 501); }// TODO: use ParseOgcQuery
+  public function getTotal($params = array()) { throw new HttpException("Acl::getTotal() Not implemented", 501); }// TODO: use ParseOgcQuery
+  public function getItem($primaryKey, $params = []) { throw new HttpException("Acl::getItem() Not implemented", 501); }
 
   public function itemsFetchRefs(&$items) {
     $DBG = V::get('DBG_DS', 0, $_GET, 'int');
@@ -255,11 +256,11 @@ class Core_AclBase {
     return $items;
   }
 
-  public function addItem($todoItem) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function updateItem($itemPatch) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getGeomFieldType($fieldName) { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getPrimaryKeyField() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
-  public function getAttributesFromZasoby() { throw new HttpException("Acl function " . __FUNCTION__ . " Not implemented", 501); }
+  public function addItem($todoItem) { throw new HttpException("Acl::addItem() Not implemented", 501); }
+  public function updateItem($itemPatch) { throw new HttpException("Acl::updateItem() Not implemented", 501); }
+  public function getGeomFieldType($fieldName) { throw new HttpException("Acl::getGeomFieldType() Not implemented", 501); }
+  public function getPrimaryKeyField() { throw new HttpException("Acl::getPrimaryKeyField() Not implemented", 501); }
+  public function getAttributesFromZasoby() { throw new HttpException("Acl::getAttributesFromZasoby() Not implemented", 501); }
 
   public function validateDeleteXml($action) {// @returns action tags, throws Exceptions
     $DBG = V::get('DBG_XML', 0, $_GET, 'int');

+ 10 - 5
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -177,7 +177,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function getSimpleSchemaTree() {
     $tree = array();
     $tree['@namespace'] = $this->getNamespace();
-    foreach ($this->getXsdTypes() as $fieldName => $field) {
+    foreach ($this->getFieldsWithXsdTypes() as $fieldName => $field) {
       $tree[$fieldName] = $field;
       if (is_array($field) && 'ref_uri:' == substr($field['xsdType'], 0, 8)) {
         $tree[$fieldName] = $this->_getSimpleSchemaTreeRec(substr($field['xsdType'], 8), $this->getNamespace());
@@ -206,7 +206,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     } else {
       $acl = Core_AclHelper::getAclByNamespace($ref);
       $tree['@namespace'] = $acl->getNamespace();
-      foreach ($acl->getXsdTypes() as $fieldName => $field) {
+      foreach ($acl->getFieldsWithXsdTypes() as $fieldName => $field) {
         // echo "<p>DBG: F._getSimpleSchemaTreeRec({$ref}) \$namespacePath[$namespacePath] - 2/'{$fieldName}'</p>";
         $tree[$fieldName] = $field;
         if (is_array($field) && 'ref_uri:' == substr($field['xsdType'], 0, 8)) {
@@ -224,7 +224,12 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   }
   public function getName() { return $this->_name; }
   public function getRootTableName() { return $this->_rootTableName; }
-  public function getXsdTypes() { return $this->_xsdTypes; }
+  public function getXsdTypes() { // @returns [ fieldName => xsdType, ... ]
+    return array_map(function ($field) {
+      return $field['xsdType'];
+    }, $this->_xsdTypes);
+  }
+  public function getFieldsWithXsdTypes() { return $this->_xsdTypes; } // @returns [ fieldName => [ 'xsdType' => , ... ], ... ]
 
   public function getNamespace() { return $this->_namespace; }
   public function getSourceName() { return $this->_sourceNamespace; }
@@ -242,7 +247,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   }
   public function getFields() {// @returns array - $this->_fields
     $fieldsById = array();
-    foreach ($this->getXsdTypes() as $fieldName => $field) {
+    foreach ($this->getFieldsWithXsdTypes() as $fieldName => $field) {
       $field['name'] = $fieldName;
       $field['label'] = V::get('label', $fieldName, $field);
       if ('p5:www_link' == $field['xsdType']) $field['simpleType'] = 'p5:www_link';
@@ -308,7 +313,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function getXsdFieldType($fieldName) {
     $xsdTypes = $this->getXsdTypes();
     if (empty($xsdTypes[$fieldName])) throw new Exception("Field '{$fieldName}' not exists");
-    return $xsdTypes[$fieldName]['xsdType'];
+    return $xsdTypes[$fieldName];
   }
   public function isGeomField($fieldName) {
     if ('File' == $fieldName) return false;

+ 6 - 1
SE/se-lib/Schema/AccessOwnerStorageAcl.php

@@ -14,7 +14,12 @@ class Schema_AccessOwnerStorageAcl extends Core_AclBase {
 	public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
 	public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
 	public function getVirtualFieldListByIdZasob() { return array(); }
-	public function getXsdTypes() {// TODO: mv to Core_AclBase
+	public function getXsdTypes() { // @returns [ fieldName => xsdType, ... ]
+		return array_map(function ($field) {
+			return $field['xsdType'];
+		}, $this->getFieldsWithXsdTypes());
+	}
+	public function getFieldsWithXsdTypes() {
 		$xsdTypes = array();
 		foreach ($this->getFields() as $idZasob => $field) {
 			$xsdTypes[ $field['name'] ] = $field;

+ 1 - 1
SE/se-lib/Schema/SystemObjectFieldStorageAcl.php

@@ -467,7 +467,7 @@ class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
 					// TODO: check query by xpath or use different param prefix
 					throw new Exception("Field '{$fieldName}' not found in '{$this->_namespace}'");
 				}
-				if ('p5:' == substr($xsdFields[$fieldName]['xsdType'], 0, 3)) {
+				if ('p5:' == substr($xsdFields[$fieldName], 0, 3)) {
 					continue;
 				}
 				$filterParams[$fieldName] = $v;

+ 7 - 1
SE/se-lib/TableAcl.php

@@ -2013,7 +2013,13 @@ class TableAcl extends Core_AclBase {
 		return null;
 	}
 
-	public function getXsdTypes() {
+	public function getXsdTypes() { // @returns [ fieldName => xsdType, ... ]
+		$thisGetXsdType = [ $this, 'getXsdFieldType' ];
+		return array_map(function ($field) use ($thisGetXsdType) {
+			return $thisGetXsdType( $field['name'] );
+		}, $this->getFields());
+	}
+	public function getFieldsWithXsdTypes() {
 		$xsdTypes = [];
 		foreach ($this->getFields() as $idZasob => $field) {
 			$xsdTypes[ $field['name'] ] = [