Browse Source

added p5_objects:Korespondencja

Piotr Labudda 9 năm trước cách đây
mục cha
commit
b4414d3599

+ 22 - 6
SE/se-lib/Api/WfsServerBase.php

@@ -41,6 +41,8 @@ class Api_WfsServerBase {
 			return true;
 			return true;
 		} else if ('p5_objects' == $nsPrefix && 'TestPerms' == $type) {
 		} else if ('p5_objects' == $nsPrefix && 'TestPerms' == $type) {
 			return true;
 			return true;
+		} else if ('p5_objects' == $nsPrefix && 'Korespondencja' == $type) {
+			return true;
 		}
 		}
 		return false;
 		return false;
 	}
 	}
@@ -373,7 +375,8 @@ class Api_WfsServerBase {
 			$usrObjList[] = array($dataSourceName, $tblName);
 			$usrObjList[] = array($dataSourceName, $tblName);
 		}
 		}
 		$usrObjList[] = array('objects', 'File');
 		$usrObjList[] = array('objects', 'File');
-		if ('production' != V::get('P5_ENV', 'production', $_SERVER)) $usrObjList[] = array('objects', 'TestPerms');
+		$usrObjList[] = array('objects', 'TestPerms');
+		$usrObjList[] = array('objects', 'Korespondencja');
 		return $usrObjList;
 		return $usrObjList;
 	}
 	}
 
 
@@ -526,13 +529,26 @@ class Api_WfsServerBase {
 			$featureType['Abstract'] = "Pliki";
 			$featureType['Abstract'] = "Pliki";
 			$featureType['Keywords'] = "Pliki";
 			$featureType['Keywords'] = "Pliki";
 			$featureType['SRS'] = "EPSG:4326";
 			$featureType['SRS'] = "EPSG:4326";
-			// $featureType['LatLongBoundingBox'] = array();// TODO: feature LatLongBoundingBox
-			// $featureType['LatLongBoundingBox']['minx'] = "8.12328509871721";
-			// $featureType['LatLongBoundingBox']['miny'] = "38.8575126897477";
-			// $featureType['LatLongBoundingBox']['maxx'] = "9.838674658246807";
-			// $featureType['LatLongBoundingBox']['maxy'] = "41.31378404137082";
 			$featureTypes['File'] = $featureType;
 			$featureTypes['File'] = $featureType;
 		}
 		}
+		{// add p5_objects:File
+			$featureType = array();
+			$featureType['ns'] = "p5_objects";
+			$featureType['Title'] = "TestPerms";
+			$featureType['Abstract'] = "TestPerms";
+			$featureType['Keywords'] = "TestPerms";
+			$featureType['SRS'] = "EPSG:4326";
+			$featureTypes['TestPerms'] = $featureType;
+		}
+		{// add p5_objects:File
+			$featureType = array();
+			$featureType['ns'] = "p5_objects";
+			$featureType['Title'] = "Korespondencja";
+			$featureType['Abstract'] = "Korespondencja";
+			$featureType['Keywords'] = "Korespondencja";
+			$featureType['SRS'] = "EPSG:4326";
+			$featureTypes['Korespondencja'] = $featureType;
+		}
 		/*
 		/*
 			<FeatureType>
 			<FeatureType>
 				<Name>ppr06:AMBITIPAESAGGIO</Name>
 				<Name>ppr06:AMBITIPAESAGGIO</Name>

+ 138 - 0
SE/se-lib/KorespondencjaStorageAcl.php

@@ -0,0 +1,138 @@
+<?php
+
+Lib::loadClass('Core_AclBase');
+Lib::loadClass('FileStorage');
+
+class KorespondencjaStorageAcl extends Core_AclBase {
+
+  public function __construct() {
+    $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'IN7_DZIENNIK_KORESP');
+    // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__);
+  }
+  public function getSourceName() { return 'objects'; }
+  public function init($force = false) {}
+  public function isInitialized() { return true; }
+  public function getName() { return 'Korespondencja'; }
+  public function getRootTableName() { return 'IN7_DZIENNIK_KORESP'; }
+  public function getRealFieldListByIdZasob($force = false) {
+    $cols = $this->parentAcl->getRealFieldListByIdZasob();
+    $cols[100000] = 'File';
+    return $cols;
+  }
+  public function getFieldIdByName($fieldName) {
+    $fields = $this->getRealFieldListByIdZasob();
+		if (empty($fieldName)) return null;
+		foreach ($fields as $idField => $vFieldName) {
+			if ($vFieldName == $fieldName) return $idField;
+		}
+		return null;
+	}
+  public function getFieldType($colName) { return null; }
+  public function isAllowed($idZasob, $taskPerm, $record = null) {
+    if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->isAllowed($idZasob, $taskPerm, $record);
+    $fields = $this->getRealFieldListByIdZasob();
+    if (array_key_exists($idZasob, $fields)) {
+      if ('File' == $fields[$idZasob]) {
+        foreach ($fields as $idFld => $name) {
+          if ($idFld == $idZasob) continue;
+          if ($this->parentAcl->isAllowed($idFld, $taskPerm, $record)) return true;
+        }
+      }
+    }
+    return false;
+  }
+  public function hasFieldPerm($idZasob, $taskPerm) {
+    if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->hasFieldPerm($idZasob, $taskPerm);
+    $fields = $this->getRealFieldListByIdZasob();
+    if (array_key_exists($idZasob, $fields)) {
+      if ('File' == $fields[$idZasob]) {
+        foreach ($fields as $idFld => $name) {
+          if ($idFld == $idZasob) continue;
+          if ($this->parentAcl->hasFieldPerm($idFld, $taskPerm)) return true;
+        }
+      }
+    }
+    return false;
+  }
+  public function getItems($params = array()) {
+    $DBG = V::get('DBG_DS', 0, $_GET, 'int');
+    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
+    $items = array();
+    $rawItems = $this->parentAcl->getItems($params);
+    foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
+    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
+    if (empty($items)) return $items;
+    $this->fetchItemRef($items);
+    if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
+    return $items;
+  }
+  public function fetchItemRef(&$items) {
+    $DBG = V::get('DBG_DS', 0, $_GET, 'int');
+    $refs = array();// fieldName => xsdType
+    foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
+      $fieldType = $this->getXsdFieldType($fieldName);
+      if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
+    }
+    if (empty($refs)) return $items;
+    $fidList = array_keys($items);
+    $sqlPk = array(); foreach ($fidList as $pk) { $sqlPk[] = "'{$pk}'"; } $sqlPk = implode(", ", $sqlPk);
+    $baseRefTableName = $this->getRootTableName() . "__#REF__";
+    $refRows = array();// $fieldName => [ pk, ... ]
+    foreach ($refs as $fieldName => $type) {
+      $acl = $this->getAclFromTypeName($type);
+      $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
+      $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
+        select r.*
+        from `{$refTableName}` r
+        where r.PRIMARY_KEY in({$sqlPk})
+        -- TODO and r.INSTANCE = '{$refInstanceName}' -- for multiple types based on the same root table
+      ", $key = 'PRIMARY_KEY');
+      if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
+    }
+    foreach ($refRows as $fieldName => $refList) {
+      foreach ($refList as $pk => $ref) {
+        $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
+      }
+    }
+  }
+  public function addItem($itemTodo) {
+    return $this->parentAcl->addItem($itemTodo);
+  }
+  public function updateItem($itemPatch) {
+    return $this->parentAcl->updateItem($itemPatch);
+  }
+
+  public function getGeomFieldType($fieldName) { return null; }
+  public function getPrimaryKeyField() { return 'ID'; }
+  public function getID() { return 0; }
+  public function getAttributesFromZasoby() {
+		$attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
+    // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
+    // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
+    // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
+		return $attributes;
+	}
+  public function isEnumerationField($fieldName) { return false; }
+  public function validateFieldAction($fieldName, $taskPerm, $record = null) {
+    if ('File' == $fieldName) {
+      // return 'ref:p5_objects:File';
+      return true;
+    }
+		return $this->parentAcl->isAllowed($fieldID = $this->parentAcl->getFieldIdByName($fieldName), $taskPerm, $record);
+	}
+  public function getXsdFieldType($fieldName) {
+    if ('File' == $fieldName) return 'ref:p5_objects:File';
+    return $this->parentAcl->getXsdFieldType($fieldName);
+  }
+  public function isGeomField($fldName) { return $this->parentAcl->isGeomField($fldName); }
+
+}
+
+/*
+CREATE TABLE IF NOT EXISTS `IN7_DZIENNIK_KORESP__#REF__CRM_FILES` (
+  `PRIMARY_KEY` int(11) NOT NULL,
+  `REMOTE_PRIMARY_KEY` int(11) NOT NULL,
+  KEY `PRIMARY_KEY` (`PRIMARY_KEY`),
+  KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin2;
+*/

+ 4 - 0
SE/se-lib/UserAcl.php

@@ -169,6 +169,10 @@ class UserAcl {
 			// TODO: ObjectAcl::getAcl($objName);
 			// TODO: ObjectAcl::getAcl($objName);
 			Lib::loadClass('TestPermsStorageAcl');
 			Lib::loadClass('TestPermsStorageAcl');
 			return new TestPermsStorageAcl();
 			return new TestPermsStorageAcl();
+		} else if ('objects' == $sourceName && 'Korespondencja' == $objName) {
+			// TODO: ObjectAcl::getAcl($objName);
+			Lib::loadClass('KorespondencjaStorageAcl');
+			return new KorespondencjaStorageAcl();
 		} else throw new HttpException("Not Implemented", 501);
 		} else throw new HttpException("Not Implemented", 501);
 		return false;
 		return false;
 	}
 	}