Преглед на файлове

updated _schemaClass in TableAcl

Piotr Labudda преди 9 години
родител
ревизия
fdde800900
променени са 2 файла, в които са добавени 19 реда и са изтрити 15 реда
  1. 2 2
      SE/se-lib/Schema/TableFactory.php
  2. 17 13
      SE/se-lib/TableAcl.php

+ 2 - 2
SE/se-lib/Schema/TableFactory.php

@@ -19,7 +19,7 @@ class Schema_TableFactory {
 		$cleanTableName = strtolower($tableName);
 		$cleanSourceName = ($idSource == DB::getPDO()->getZasobId())? 'default_db' : "p5_{$idSource}";
 
-		DBG::_('DBG_SCH', '>2', "Schema({$tableName}): cleanHostName({$cleanHostName}) cleanTableName({$cleanTableName}) cleanSourceName({$cleanSourceName})", null, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log("Schema({$tableName}): cleanHostName({$cleanHostName}) cleanTableName({$cleanTableName}) cleanSourceName({$cleanSourceName})");
 		// TODO: fetch form widgets from file config
 		//       "schema/gui/core/{$cleanSourceName}.{$cleanTableName}.php";
 		//       class Schema_Core_{$cleanSourceName}_{$cleanTableName};
@@ -44,7 +44,7 @@ class Schema_TableFactory {
 				$objectClassName = $coreClassName;
 			}
 		}
-		DBG::_('DBG_SCH', '>2', "Schema({$tableName}): objectClassName('{$objectClassName}')", null, __CLASS__, __FUNCTION__, __LINE__);
+		DBG::log("Schema({$tableName}): objectClassName('{$objectClassName}')");
 		return new $objectClassName($idSource, $cleanTableName);
 	}
 

+ 17 - 13
SE/se-lib/TableAcl.php

@@ -1419,6 +1419,9 @@ class TableAcl extends Core_AclBase {
 	}
 
 	public function getHistItems($id) {
+		if ($this->_schemaClass && method_exists($this->_schemaClass, 'hasGetHistItems') && $this->_schemaClass->hasGetHistItems()) {
+			return $this->_schemaClass->getHistItems($id);
+		}
 		$ds = $this->getDataSource();
 		return $ds->getHistItems($id);
 	}
@@ -1490,21 +1493,14 @@ class TableAcl extends Core_AclBase {
 			return 0;// nothing to change
 		}
 
-		$ds = $this->getDataSource();
-		$primaryKeyField = $ds->getPrimaryKeyField();
-		if (empty($itemPatch[$primaryKeyField])) {
-			throw new HttpException("Item Primary Key not set!", 400);
-		}
+		$primaryKeyField = $this->getPrimaryKeyField();
+		if (empty($itemPatch[$primaryKeyField])) throw new HttpException("Item Primary Key not set!", 400);
 
 		$primaryKey = $itemPatch[$primaryKeyField];
 		$itemOld = $this->getItem($primaryKey);
-		if (!$itemOld) {
-			throw new HttpException("Item not exists!", 404);
-		}
+		if (!$itemOld) throw new HttpException("Item not exists!", 404);
 
-		if (!$this->canWriteRecord($itemOld) && !$this->hasPermSuperWrite()) {
-			throw new HttpException("Brak dostępu do rekordu", 403);
-		}
+		if (!$this->canWriteRecord($itemOld) && !$this->hasPermSuperWrite()) throw new HttpException("Brak dostępu do rekordu", 403);
 
 		// $itemPatch from user input to $itemPatchChecked
 		$itemPatchChecked = array();
@@ -1536,7 +1532,12 @@ class TableAcl extends Core_AclBase {
 		}
 		$itemPatchChecked[$primaryKeyField] = $primaryKey;
 
-		$affected = $ds->updateItem($itemPatchChecked);
+		if ($this->_schemaClass && method_exists($this->_schemaClass, 'hasUpdateItem') && $this->_schemaClass->hasUpdateItem()) {
+			$affected = $this->_schemaClass->updateItem($itemPatchChecked);
+		} else {
+			$ds = $this->getDataSource();
+			$affected = $ds->updateItem($itemPatchChecked);
+		}
 
 		return $affected;
 	}
@@ -1595,7 +1596,10 @@ class TableAcl extends Core_AclBase {
 	}
 
 	public function getPrimaryKeyField() {
-		// TODO: if ($this->_schemaClass) return $this->_schemaClass->getPrimaryKeyField();
+		if ($this->_schemaClass) {
+			$pkField = $this->_schemaClass->getPrimaryKeyField();
+			if ($pkField) return $pkField;
+		}
 		$ds = $this->getDataSource();
 		return $ds->getPrimaryKeyField();
 	}