Jelajahi Sumber

+ handle ref filter in Export Table Route

Piotr Labudda 7 tahun lalu
induk
melakukan
2c251664af
1 mengubah file dengan 48 tambahan dan 10 penghapusan
  1. 48 10
      SE/se-lib/Route/ExportTableAjax.php

+ 48 - 10
SE/se-lib/Route/ExportTableAjax.php

@@ -2,33 +2,70 @@
 
 
 Lib::loadClass('RouteBase');
 Lib::loadClass('RouteBase');
 Lib::loadClass('Core_AclHelper');
 Lib::loadClass('Core_AclHelper');
+Lib::loadClass('Response');
 
 
 
 
 class Route_ExportTableAjax extends RouteBase {
 class Route_ExportTableAjax extends RouteBase {
 
 
     /**
     /**
-	 * @param $_GET['namespace'] = AclNamespace
-	 * @param $_GET['format'] = 'csv' | 'html'
-	 * @param $_GET['flds'] = csv - coma separated field names
-	 * @param $_GET['sortCol'] = FieldName
-	 * @param $_GET['sortDir'] = SortDir ('desc' | 'asc')
-	 * @param $_GET['f_{$fieldName}'] = filter
-	 * @param $_GET['sf_{$fieldName}'] = force filter
+	 * @param $_REQUEST['namespace'] = AclNamespace
+	 * @param $_REQUEST['format'] = 'csv' | 'html'
+	 * @param $_REQUEST['flds'] = csv - coma separated field names
+	 * @param $_REQUEST['sortCol'] = FieldName
+	 * @param $_REQUEST['sortDir'] = SortDir ('desc' | 'asc')
+	 * @param $_REQUEST['f_{$fieldName}'] = filter
+	 * @param $_REQUEST['sf_{$fieldName}'] = force filter
+	 * @param $_POST['backRefNS'] - back ref filter
+	 * @param $_POST['backRefPK']
+	 * @param $_POST['backRefField']
+	 * @param $_POST['childRefNS'] - child ref filter
+	 * @param $_POST['childRefPK']
 	 */
 	 */
 	function defaultAction() {
 	function defaultAction() {
-		$args = $_GET;
+		if (!empty($_POST)) {
+			$backRefFilter = [
+				'namespace' => V::get('backRefNS', '', $_POST),
+				'primaryKey' => V::get('backRefPK', '', $_POST),
+				'fieldName' => V::get('backRefField', '', $_POST),
+			];
+			$childRefFilter = [
+				'namespace' => V::get('childRefNS', '', $_POST),
+				'primaryKey' => V::get('childRefPK', '', $_POST),
+			];
+
+			return $this->executeExport(
+				$_REQUEST // `f_%` may be sent by GET
+				, (!empty($backRefFilter['namespace']) && !empty($backRefFilter['primaryKey'])) ? $backRefFilter : null
+				, (!empty($childRefFilter['namespace']) && !empty($childRefFilter['primaryKey'])) ? $childRefFilter : null
+			);
+		}
+		$this->executeExport($_GET);
+	}
+
+	function executeExport($args, $backRefFilter = null, $childRefFilter = null) {
 		$namespace = V::get('namespace', '', $args, 'word');
 		$namespace = V::get('namespace', '', $args, 'word');
 		if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
 		if (!$namespace) throw new HttpException("Bad Request - missing namespace", 400);
 		$acl = Core_AclHelper::getAclByNamespace($namespace);
 		$acl = Core_AclHelper::getAclByNamespace($namespace);
 
 
 		$exportLimit = 10000;
 		$exportLimit = 10000;
 		$params = array();
 		$params = array();
+
+		if ($backRefFilter) {
+			$params['__backRef'] = $backRefFilter;
+			DBG::log($params, 'array', '$params __backRef');
+		}
+		if ($childRefFilter) {
+			$params['__childRef'] = $childRefFilter;
+			DBG::log($params, 'array', '$params __childRef');
+		}
+
 		$params['limit'] = $exportLimit;
 		$params['limit'] = $exportLimit;
 		// $params['limitstart'] = 0;
 		// $params['limitstart'] = 0;
 		$params['order_by'] = V::get('sortCol', '', $args);
 		$params['order_by'] = V::get('sortCol', '', $args);
 		$params['order_dir'] = V::get('sortDir', '', $args);
 		$params['order_dir'] = V::get('sortDir', '', $args);
 		$params['cols'] = array($acl->getPrimaryKeyField());
 		$params['cols'] = array($acl->getPrimaryKeyField());
-		$toExportFields = explode(',', V::get('flds', '', $_GET));
+		$toExportFields = explode(',', V::get('flds', '', $args));
+		$toExportFields = array_filter($toExportFields, [ 'V', 'filterNotEmpty' ]);
 		if (empty($toExportFields)) throw new Exception("Nie wybrano żandych pól do exportu.");
 		if (empty($toExportFields)) throw new Exception("Nie wybrano żandych pól do exportu.");
 		$allowedExportFieldList = Core_AclHelper::getExportFieldList($acl);
 		$allowedExportFieldList = Core_AclHelper::getExportFieldList($acl);
 		foreach ($toExportFields as $fieldName) {
 		foreach ($toExportFields as $fieldName) {
@@ -56,7 +93,7 @@ class Route_ExportTableAjax extends RouteBase {
 			throw $e;
 			throw $e;
 		}
 		}
 
 
-		$format = V::get('format', 'html', $_GET);
+		$format = V::get('format', 'html', $args);
 		switch ($format) {
 		switch ($format) {
 			case 'html': return $this->_exportToHTML($acl, $items, $toExportFields, $format);
 			case 'html': return $this->_exportToHTML($acl, $items, $toExportFields, $format);
 			case 'xls': return $this->_exportToXLS($acl, $items, $toExportFields, $format);
 			case 'xls': return $this->_exportToXLS($acl, $items, $toExportFields, $format);
@@ -66,6 +103,7 @@ class Route_ExportTableAjax extends RouteBase {
 		}
 		}
 		die("Nieobsługiwany format danych.");
 		die("Nieobsługiwany format danych.");
 	}
 	}
+
 	function _exportToHTML($acl, $items, $toExportFields, $format = 'html') {
 	function _exportToHTML($acl, $items, $toExportFields, $format = 'html') {
 		$labels = array();
 		$labels = array();
 		foreach ($toExportFields as $fieldName) {
 		foreach ($toExportFields as $fieldName) {