Explorar el Código

fixed Typespecial for Projekty.LINK_PROBLEMS

Piotr Labudda hace 9 años
padre
commit
e0f1d5705f

+ 1 - 1
SE/schema/gui/company/biuro_biall_net_pl/default_db.in7_mk_baza_dystrybucji.php

@@ -1,5 +1,5 @@
 <?php
 
-class Schema__biuro_biall_net_pl__default_db__in7_mk_baza_dystrybucji extends Schema_TableBase {
+class Schema__biuro_biall_net_pl__default_db__in7_mk_baza_dystrybucji extends Schema__Core__default_db__in7_mk_baza_dystrybucji {
 
 }

+ 32 - 0
SE/schema/gui/core/default_db.in7_mk_baza_dystrybucji.php

@@ -2,4 +2,36 @@
 
 class Schema__Core__default_db__in7_mk_baza_dystrybucji extends Schema_TableBase {
 
+  public function initTypes() {
+    parent::initTypes();
+    $this->_types['LINK_PROBLEMS'] = 'p5:typeSpecialSimpleLink';
+    $this->_params['LINK_PROBLEMS'] = [
+      'format' => '<a href="index.php?_route=ViewTableAjax&namespace=default_db/PROBLEMS&ff_ID_PROJECT={ID}">Zadania: {TASKS_INFO_trigger}</a><br><a href="index.php?_route=ViewTableAjax&namespace=default_db/IN7_DZIENNIK_KORESP&ff_ID_PROJECT={ID}">Pisma: {IN7_DZIENNIK_KORESP_INFO_trigger}</a>',
+      'aliasMap' => [
+        'IN7_DZIENNIK_KORESP_INFO_trigger' => 'IN7_DZIENNIK_KORESP_INFO_trigger',
+        'TASKS_INFO_trigger' => 'TASKS_INFO_trigger',
+        'ID' => 'ID'
+      ]
+    ];
+    // field 'LINK_PROBLEMS' depends on fields: TASKS_INFO_trigger, IN7_DZIENNIK_KORESP_INFO_trigger -- user need access to this fields
+
+    // TODO: move generate value for field with xsd type `p5:typeSpecialSimpleLink` function from frontend to backend
+    // field LINK_PROBLEMS was evaluated on front end by definied Typespecial
+  }
+
+  public function getPrimaryKeyField() {
+		return 'ID';
+	}
+
+  public function fixFieldValue($fieldName, /* array */ $item) {// TODO: generate value for special fields on backend (need outputFormat? xml, html, etc.)
+    switch ($fieldName) {
+      case 'LINK_PROBLEMS': {
+        // <a href="index.php?_route=ViewTableAjax&namespace=default_db/PROBLEMS&ff_ID_PROJECT={ID}">Zadania: {TASKS_INFO_trigger}</a>
+        // <br><a href="index.php?_route=ViewTableAjax&namespace=default_db/IN7_DZIENNIK_KORESP&ff_ID_PROJECT={ID}">Pisma: {IN7_DZIENNIK_KORESP_INFO_trigger}</a>
+        return $value;
+      } break;
+      default: return $value;
+    }
+  }
+
 }

+ 24 - 0
SE/se-lib/Schema/TableBase.php

@@ -5,6 +5,9 @@ class Schema_TableBase {
 
 	public $idDatabase;
 	public $tblName;
+	public $_types;
+	public $_restrictions;
+	public $_params;
 
 	public function __construct($idDatabase, $tblName) {
 		$this->idDatabase = $idDatabase;
@@ -21,6 +24,10 @@ class Schema_TableBase {
 		// TODO:? $this->_types['WWW'] = new Type_Link($params = ['maxLength' => 255, ...]);
 	}
 
+	public function getType($fieldName) {
+		return V::get($fieldName, '', $this->_types);
+	}
+
 	public function fixTypes($types) {
 		if (empty($this->_types)) return $types;
 		foreach ($types as $fldName => $type) {
@@ -176,4 +183,21 @@ class Schema_TableBase {
 		return $field;
 	}
 
+	public function getPrimaryKeyField() {// TODO: use this method in TableAcl, Data_Source, etc.
+		return 'ID';
+	}
+
+	public function fixItemFieldValue($fieldName, /* array */ $item) {
+		return $value;
+	}
+
+	public function getFieldParam($fieldName, $paramKey) {
+		return (empty($this->_params[$fieldName]))
+			? null
+			: (empty($this->_params[$fieldName][$paramKey]))
+				? null
+				: $this->_params[$fieldName][$paramKey]
+		;
+	}
+
 }

+ 33 - 21
SE/se-lib/TableAcl.php

@@ -2,6 +2,10 @@
 
 Lib::loadClass('Core_AclBase');
 Lib::loadClass('SchemaException');
+Lib::loadClass('Typespecial');
+Lib::loadClass('ProcesHelper');
+Lib::loadClass('Schema_TableFactory');
+Lib::loadClass('DataSourceFactory');
 
 /**
  * $_SESSION['TableAcl_cache'][$tableID] = array(
@@ -572,7 +576,6 @@ class TableAcl extends Core_AclBase {
 			}
 		}
 
-		Lib::loadClass('Typespecial');
 		$typeSpecial = Typespecial::getInstance($fieldID, $colName);
 		if ($typeSpecial) {
 			throw new Exception("TODO: TypeSpecial");
@@ -615,7 +618,6 @@ class TableAcl extends Core_AclBase {
 			return $out;
 		}
 
-		Lib::loadClass('Typespecial');
 		$typeSpecial = Typespecial::getInstance($fieldID, $colName);
 
 		$html = new stdClass();
@@ -903,7 +905,6 @@ class TableAcl extends Core_AclBase {
 		if (empty($tableConfig)) {
 			throw new Exception("Brak danych konfiguracyjnych do tabeli nr {$idTable} #TACL" . __LINE__);
 
-			Lib::loadClass('ProcesHelper');
 			$zasobObj = ProcesHelper::getZasobTableInfo($idTable);
 			if (!$zasobObj) {
 				return null;// TODO: throw new Exception("Zasob TABELA ID={$idTable} nie istnieje");
@@ -940,7 +941,6 @@ class TableAcl extends Core_AclBase {
 	public function loadSchema() {
 		if ($this->_schemaLoaded) return;
 		$srvName = $_SERVER['SERVER_NAME'];
-		Lib::loadClass('Schema_TableFactory');
 		$this->_schemaClass = Schema_TableFactory::build($this->_name, $this->_db, $srvName);
 		$this->_schemaLoaded = true;
 	}
@@ -1005,11 +1005,12 @@ class TableAcl extends Core_AclBase {
 			}
 		}
 
-		$fieldIds = array_keys($this->_fields);
-		Lib::loadClass('Typespecial');
-		$vColsIdList = Typespecial::initFields($fieldIds);
-		if (!empty($vColsIdList)) {
-			$this->_virtualFieldsIdList = $vColsIdList;
+		{// TODO: replace this by $this->_schemaClass (from DataSourceFactory::build(...))
+			$fieldIds = array_keys($this->_fields);
+			$vColsIdList = Typespecial::initFields($fieldIds);
+			if (!empty($vColsIdList)) {
+				$this->_virtualFieldsIdList = $vColsIdList;
+			}
 		}
 	}
 
@@ -1584,7 +1585,6 @@ class TableAcl extends Core_AclBase {
 	}
 
 	private function _getDataSource($cols) {
-		Lib::loadClass('DataSourceFactory');
 		$dsConfig = array();
 		$dsConfig['source_id'] = $this->getDB();
 		$dsConfig['object_name'] = $this->getName();
@@ -1596,6 +1596,7 @@ class TableAcl extends Core_AclBase {
 	}
 
 	public function getPrimaryKeyField() {
+		// TODO: if ($this->_schemaClass) return $this->_schemaClass->getPrimaryKeyField();
 		$ds = $this->getDataSource();
 		return $ds->getPrimaryKeyField();
 	}
@@ -1756,25 +1757,36 @@ class TableAcl extends Core_AclBase {
 		return $attributes;
 	}
 
-	public function getXsdFieldType($fldName) {// @returns string - xsd type, TODO: throw Exception when field not found
+	public function getXsdFieldType($fieldName) {// @returns string - xsd type, TODO: throw Exception when field not found
+		if ($this->_schemaClass) {
+			$schemaType = $this->_schemaClass->getType($fieldName);
+			if ($schemaType) return $schemaType;
+		}
 		$fldType = 'xsd:string';
-		if ('A_RECORD_UPDATE_DATE' == $fldName) return 'xsd:string';
-		if ('A_RECORD_CREATE_DATE' == $fldName) return 'xsd:string';
-		if ($this->isIntegerField($fldName)) return 'xsd:integer';
-		else if ($this->isDecimalField($fldName)) return 'xsd:decimal';
-		else if ($this->isDateField($fldName)) return 'xsd:date';
-		else if ($this->isDateTimeField($fldName)) return 'xsd:dateTime';
-		else if ($this->isGeomField($fldName)) {
+		if ('A_RECORD_UPDATE_DATE' == $fieldName) return 'xsd:string';
+		if ('A_RECORD_CREATE_DATE' == $fieldName) return 'xsd:string';
+		if ($this->isIntegerField($fieldName)) return 'xsd:integer';
+		else if ($this->isDecimalField($fieldName)) return 'xsd:decimal';
+		else if ($this->isDateField($fieldName)) return 'xsd:date';
+		else if ($this->isDateTimeField($fieldName)) return 'xsd:dateTime';
+		else if ($this->isGeomField($fieldName)) {
 			//$fldType = 'gml:GeometryPropertyType';
-			$geomType = $this->getGeomFieldType($fldName);
+			$geomType = $this->getGeomFieldType($fieldName);
 			if ('polygon' == $geomType) return 'gml:PolygonPropertyType';
 			else if ('point' == $geomType) return 'gml:PointPropertyType';
 			else if ('linestring' == $geomType) return 'gml:LineStringPropertyType';
 			else return 'gml:GeometryPropertyType';
 		}
-		else if ($this->isEnumerationField($fldName)) return 'xsd:string';
-		else if ($this->isBinaryField($fldName)) return 'xsd:base64Binary';
+		else if ($this->isEnumerationField($fieldName)) return 'xsd:string';
+		else if ($this->isBinaryField($fieldName)) return 'xsd:base64Binary';
 		return $fldType;
 	}
 
+	public function getXsdFieldParam($fieldName, $paramKey) {
+		return ($this->_schemaClass)
+			? $this->_schemaClass->getFieldParam($fieldName, $paramKey)
+			: null
+		;
+	}
+
 }

+ 14 - 2
SE/se-lib/TableAjax.php

@@ -5723,7 +5723,7 @@ jQuery(document).ready(function(){
 		exit;
 	}
 
-	public function ajaxData($args) {
+	public function ajaxData($args) {// executed from url: "{$this->syncUrl"&_hash={$this->_htmlID}&_task=loadDataAjax"
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 		$acl = $this->_acl;
 
@@ -5812,7 +5812,7 @@ jQuery(document).ready(function(){
 					case 'xsd':
 						switch ($ex[1]) {
 							case 'string': $columnConfig->type = 'string'; break;
-							case 'ind': $columnConfig->type = 'number'; break;
+							case 'ind': $columnConfig->type = 'number'; break;// TODO: bug 'ind'?
 						}
 						break;
 				}
@@ -5856,6 +5856,18 @@ jQuery(document).ready(function(){
 				}
 			}
 
+			if ($columnConfig->xsdType) {// fix fields type p5:typeSpecialSimpleLink (previously defined by Typespecial)
+				switch ($columnConfig->xsdType) {
+					case 'p5:typeSpecialSimpleLink': {
+						$columnConfig->type = 'simpleLink';
+						$columnConfig->_tsRetId = 0;
+						$columnConfig->_tsSimpleLink = new stdClass();
+						$columnConfig->_tsSimpleLink->format = $acl->getXsdFieldParam($col, 'format');
+						$columnConfig->_tsSimpleLink->aliasMap = $acl->getXsdFieldParam($col, 'aliasMap');
+					} break;
+				}
+			}
+
 			// @see ajaxHiddenColsSave
 			if (UserProfile::isHiddenColumn($acl->getID(), $fieldID)) {
 				$columnConfig->hidden = true;