فهرست منبع

added typespecial action to TableAjax

Piotr Labudda 8 سال پیش
والد
کامیت
b07c06fe67
2فایلهای تغییر یافته به همراه60 افزوده شده و 1 حذف شده
  1. 58 0
      SE/se-lib/Route/ViewTableAjax.php
  2. 2 1
      SE/se-lib/TableAjax.php

+ 58 - 0
SE/se-lib/Route/ViewTableAjax.php

@@ -1064,6 +1064,64 @@ class Route_ViewTableAjax extends RouteBase {
 		return $jsonData;
 	}
 
+	public function typespecialAction() { Response::sendTryCatchJson(array($this, 'typespecial'), $args = $_REQUEST); }
+	public function typespecial($args) { // @required idField, @optional: q (query), selected (selected value), idRecord (fetch value for given record)
+		$idField = V::get('idField', 0, $args, 'int');
+		if (!$idField) throw new HttpException("Bad Request - missing idField", 400);
+		$query = V::get('q', '', $_REQUEST);
+		DBG::log("\$query({$query})");
+
+		$cellInfo = DB::getPDO()->fetchFirst("
+			select *
+			from CRM_PROCES_idx_TABLES_INFO_VIEW
+			where ID_CELL = :id
+		", [ ':id' => $idField ]);
+		DBG::log($cellInfo, 'array', "cell info");
+		if (!$cellInfo) throw new HttpException("Bad Request - wrong idField", 400);
+		// 'ID_CELL' => '24310',
+		// 'CELL_NAME' => 'L_APPOITMENT_USER',
+		// 'CELL_LABEL' => 'Osoba odpowiedzialna',
+		// 'CELL_DESCRIPTION' => '',
+		// 'CELL_SORT_PRIO' => '3',
+		// 'ID_TABLE' => '13051',
+		// 'TABLE_NAME' => 'TEST_PERMS',
+		// 'TABLE_LABEL' => 'Test permy',
+		// 'TABLE_DESCRIPTION' => '',
+		// 'ID_DATABASE' => '36',
+		$namespace = (false !== strpos($cellInfo['TABLE_NAME'], '/')) ? $cellInfo['TABLE_NAME'] : "default_db/{$cellInfo['TABLE_NAME']}";
+		if (!$namespace) throw new HttpException("Bad Request - wrong idField, cannot find namespace", 400);
+
+		$acl = Core_AclHelper::getAclByNamespace($namespace);
+		$fieldName = $cellInfo['CELL_NAME'];
+
+		$jsonData = array();
+		$typeSpecial = Typespecial::getInstance($idField, $fieldName);
+		if ($typeSpecial) {
+
+			// if (idRecord or selected) { // TODO
+			// $jsonData->data = $typeSpecial->getReturnData($acl->getID(), $id, $fieldName, '');
+			// $jsonData->namespace = 'default_db/' . V::get('tbl_name', '', $jsonData->data);
+
+			$rawRows = null;
+			$rows = $typeSpecial->getValuesWithExports($query);
+			DBG::log($rows, 'array', "\$rows({$query})");
+			foreach ($rows as $kID => $vItem) {
+				$itemJson = new stdClass();
+				$itemJson->id = $vItem->id;
+				$itemJson->name = $vItem->param_out;
+				if (!empty($vItem->exports)) {
+					$itemJson->exports = $vItem->exports;
+				}
+				if (!empty($vItem->{'$order'})) {
+					$itemJson->{'$order'} = $vItem->{'$order'};
+				}
+				$jsonData[] = $itemJson;
+			}
+		}
+
+		return $jsonData;
+	}
+
 	/**
 	 * @param $_GET['namespace'] = AclNamespace
 	 * @param $_GET['format'] = 'csv' | 'html'

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

@@ -2094,7 +2094,7 @@ jQuery(document).ready(function(){
 		exit;
 	}
 
-	private function sendTypeSpecial($fldID, $args) {
+	private function sendTypeSpecial($fldID, $args) { // TODO: mv to index.php?_route=ViewTableAjax&_task=typespecial&idField=" + idField, // &q=... or &selected=... or &idRecord=...
 		$DBG = ('1' == V::get('DBG', '', $_REQUEST));
 
 		header("Content-type: application/json");
@@ -2351,6 +2351,7 @@ jQuery(document).ready(function(){
 		$listItems = $queryFeatures->getItems();
 		$primaryKeyField = $acl->getPrimaryKeyField();
 		$items = []; foreach ($listItems as $item) $items[ $item[$primaryKeyField] ] = $item;
+
 		// TODO: add virtual data by Typespecial
 		if (!empty($vCols) && !empty($items)) {
 			foreach ($vCols as $vColID => $vCol) {