소스 검색

added onBeforeFetchData action to trigger actions before fetch data from StaorgeAcl

Piotr Labudda 8 년 전
부모
커밋
e541f93aff
2개의 변경된 파일18개의 추가작업 그리고 8개의 파일을 삭제
  1. 7 0
      SE/se-lib/AclQueryFeatures.php
  2. 11 8
      SE/se-lib/Schema/PrzypomnijStorageAcl.php

+ 7 - 0
SE/se-lib/AclQueryFeatures.php

@@ -468,6 +468,7 @@ class AclQueryFeatures {
 	}
 
 	public function getTotal() {
+		$this->_beforeFetchData();
 		if ($this->_legacyMode) return $this->_acl->getTotal($this->_params);
 		if (null !== $this->_total) return $this->_total;
 		$this->_total = $this->getQuery()->fetchTotal();
@@ -479,6 +480,7 @@ class AclQueryFeatures {
 
 	public function getItems() {
 		$this->_logToFile('getItems() ...');
+		$this->_beforeFetchData();
 		if ($this->_legacyMode) return $this->_acl->getItems($this->_params);// TODO: array_map( $r => (array)$r )
 		// 'limit' => 10,
 		//	'limitstart' => 0,
@@ -518,7 +520,12 @@ class AclQueryFeatures {
 		return $items;
 	}
 
+	function _beforeFetchData() {
+		if (method_exists($this->_acl, 'onBeforeFetchData')) $this->_acl->onBeforeFetchData();
+	}
+
 	public function getItem($primaryKey) { // TODO: throw exception if not found?
+		$this->_beforeFetchData();
 		if ($this->_legacyMode) return (array)$this->_acl->getItem($primaryKey, $this->_params);
 		$select = $this->prepareSelect();
 		$pkField = $this->_acl->getPrimaryKeyField();

+ 11 - 8
SE/se-lib/Schema/PrzypomnijStorageAcl.php

@@ -91,9 +91,12 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 		");
 	}
 
-	public function __construct() {
+	function __construct() {
 		parent::__construct($this->_simpleSchema);
 		$this->idUser = User::getID(); // default - current user
+	}
+
+	function onBeforeFetchData() {
 		self::updateCacheIfNeeded();
 	}
 
@@ -269,7 +272,7 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 		}
 	}
 
-	// public function getTotal($params = []) {
+	// function getTotal($params = []) {
 	// 	self::updateCacheIfNeeded();
 	// 	$sqlWhere = $this->_parseWhere($params);
 	// 	return DB::getPDO()->fetchValue("
@@ -278,7 +281,7 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 	// 		{$sqlWhere}
 	// 	");
 	// }
-	// public function getItem($pk, $params = []) {
+	// function getItem($pk, $params = []) {
 	// 	self::updateCacheIfNeeded();
 	// 	if (!$pk) throw new Exception("Missing primary key '{$this->_namespace}'");
 	// 	$pkField = $this->getSqlPrimaryKeyField();
@@ -292,7 +295,7 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 	// 	return $this->buildFeatureFromSqlRow($item, $params);
 	// }
 	//
-	// public function getItems($params = []) {
+	// function getItems($params = []) {
 	// 	self::updateCacheIfNeeded();
 	// 	$sqlWhere = $this->_parseWhere($params);
 	//
@@ -329,12 +332,12 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 	// 	}, $query->fetchAll());
 	// }
 
-	public function buildQuery($params = array()) {
+	function buildQuery($params = array()) {
 		Lib::loadClass('AclQueryFeatures');
 		return new AclQueryFeatures($this, $params, $legacyMode = false);
 	}
 
-	public function _parseWhere($params = []) {
+	function _parseWhere($params = []) {
 		$sqlWhere = [];
 		DBG::log($params, 'array', "SystemObject::_parseWhere");
 		// if (!empty($params['#refFrom'])) {
@@ -386,7 +389,7 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 		return (!empty($sqlWhere)) ? "where " . implode(" and ", $sqlWhere) : '';
 	}
 
-	public function buildFeatureFromSqlRow($item, $params = []) {
+	function buildFeatureFromSqlRow($item, $params = []) {
 		// DBG::log($params, 'array', "buildFeatureFromSqlRow... '{$item['namespace']}'");
 		// $exNs = explode('/', $item['namespace']);
 		// $item['name'] = array_pop($exNs);
@@ -413,7 +416,7 @@ class Schema_PrzypomnijStorageAcl extends Core_AclSimpleSchemaBase {
 		return $item;
 	}
 
-	// public function updateItem($itemPatch) { // @required [ 'namespace' => ... ] (primaryKey)
+	// function updateItem($itemPatch) { // @required [ 'namespace' => ... ] (primaryKey)
 	// 	$pkField = $this->getPrimaryKeyField();
 	// 	$pk = V::get($pkField, null, $itemPatch);
 	// 	if (null === $pk) throw new Exception("BUG missing primary key field for '{$this->_namespace}' updateItem");