HOR-172 "DbArray en ProcessMaker 3.x" SOLVED
Issue:
DbArray en ProcessMaker 3.x
Cause:
Nuevo requerimiento de funciones
Solution:
Se a implementado la nueva funcionalidad "datasource" para los fields de un DynaForm (Back-End)
This commit is contained in:
@@ -176,22 +176,47 @@ class pmDynaform
|
|||||||
if (!isset($json->sql))
|
if (!isset($json->sql))
|
||||||
$json->sql = "";
|
$json->sql = "";
|
||||||
$json->optionsSql = array();
|
$json->optionsSql = array();
|
||||||
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
|
|
||||||
try {
|
switch ((isset($json->datasource))? $json->datasource : 'database') {
|
||||||
$cnn = Propel::getConnection($json->dbConnection);
|
case 'dataVariable':
|
||||||
$stmt = $cnn->createStatement();
|
$dataVariable = (preg_match('/^\s*@.(.+)\s*$/', $json->dataVariable, $arrayMatch))?
|
||||||
$sql = G::replaceDataField($json->sql, $this->getValuesDependentFields($json));
|
$arrayMatch[1] : $json->dataVariable;
|
||||||
$rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
|
|
||||||
while ($rs->next()) {
|
if (isset($this->fields['APP_DATA'][$dataVariable]) &&
|
||||||
$row = $rs->getRow();
|
is_array($this->fields['APP_DATA'][$dataVariable]) &&
|
||||||
$option = new stdClass();
|
!empty($this->fields['APP_DATA'][$dataVariable])
|
||||||
$option->value = $row[0];
|
) {
|
||||||
$option->label = isset($row[1]) ? $row[1] : $row[0];
|
foreach ($this->fields['APP_DATA'][$dataVariable] as $row) {
|
||||||
array_push($json->optionsSql, $option);
|
$option = new stdClass();
|
||||||
|
$option->value = $row[0];
|
||||||
|
$option->label = (isset($row[1]))? $row[1] : $row[0];
|
||||||
|
|
||||||
|
$json->optionsSql[] = $option;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
break;
|
||||||
|
default:
|
||||||
}
|
//database
|
||||||
|
if ($json->dbConnection !== '' && $json->dbConnection !== 'none' && $json->sql !== '') {
|
||||||
|
try {
|
||||||
|
$cnn = Propel::getConnection($json->dbConnection);
|
||||||
|
$stmt = $cnn->createStatement();
|
||||||
|
$sql = G::replaceDataField($json->sql, $this->getValuesDependentFields($json));
|
||||||
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
|
||||||
|
|
||||||
|
while ($rs->next()) {
|
||||||
|
$row = $rs->getRow();
|
||||||
|
|
||||||
|
$option = new stdClass();
|
||||||
|
$option->value = $row[0];
|
||||||
|
$option->label = (isset($row[1]))? $row[1] : $row[0];
|
||||||
|
|
||||||
|
$json->optionsSql[] = $option;
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//data
|
//data
|
||||||
@@ -565,7 +590,7 @@ class pmDynaform
|
|||||||
$data[$json->variable === "" ? $json->id : $json->variable] = $row[0];
|
$data[$json->variable === "" ? $json->id : $json->variable] = $row[0];
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -688,9 +713,9 @@ class pmDynaform
|
|||||||
" token: credentials,\n" .
|
" token: credentials,\n" .
|
||||||
" submitRest: false\n" .
|
" submitRest: false\n" .
|
||||||
" });\n" .
|
" });\n" .
|
||||||
" $(document).find('form').find('button').on('click', function (e) {\n".
|
" $(document).find('form').find('button').on('click', function (e) {\n".
|
||||||
" e.preventDefault();\n" .
|
" e.preventDefault();\n" .
|
||||||
" return false;\n".
|
" return false;\n".
|
||||||
" });\n" .
|
" });\n" .
|
||||||
" $(document).find('form').submit(function (e) {\n" .
|
" $(document).find('form').submit(function (e) {\n" .
|
||||||
" e.preventDefault();\n" .
|
" e.preventDefault();\n" .
|
||||||
|
|||||||
@@ -717,44 +717,85 @@ class Variable
|
|||||||
\G::LoadClass('pmDynaform');
|
\G::LoadClass('pmDynaform');
|
||||||
$pmDynaform = new \pmDynaform();
|
$pmDynaform = new \pmDynaform();
|
||||||
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $variableName);
|
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $variableName);
|
||||||
$dbConnection = "workflow";
|
|
||||||
if ($field !== null && !empty($field->dbConnection)) {
|
|
||||||
$dbConnection = $field->dbConnection;
|
|
||||||
}
|
|
||||||
$variableSql = $field !== null ? $field->sql : "";
|
|
||||||
|
|
||||||
//Get data
|
//Get data
|
||||||
$_SESSION["PROCESS"] = $processUid;
|
$filter = str_replace('\'', '\'\'', (isset($arrayVariable['filter']))? $arrayVariable['filter'] : '');
|
||||||
|
$start = (isset($arrayVariable['start']))? $arrayVariable['start'] : 0;
|
||||||
|
$limit = (isset($arrayVariable['limit']))? $arrayVariable['limit'] : '';
|
||||||
|
|
||||||
$cnn = \Propel::getConnection($dbConnection);
|
switch (($field !== null && isset($field->datasource))? $field->datasource : 'database') {
|
||||||
$stmt = $cnn->createStatement();
|
case 'dataVariable':
|
||||||
|
if (!isset($arrayVariable['app_uid'])) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
|
$applicationUid = $arrayVariable['app_uid'];
|
||||||
|
|
||||||
$filter = "";
|
$case = new \ProcessMaker\BusinessModel\Cases();
|
||||||
if (isset($arrayVariable["filter"])) {
|
|
||||||
$filter = $arrayVariable["filter"];
|
|
||||||
}
|
|
||||||
$start = 0;
|
|
||||||
if (isset($arrayVariable["start"])) {
|
|
||||||
$start = $arrayVariable["start"];
|
|
||||||
}
|
|
||||||
$limit = "";
|
|
||||||
if (isset($arrayVariable["limit"])) {
|
|
||||||
$limit = $arrayVariable["limit"];
|
|
||||||
}
|
|
||||||
$parser = new \PHPSQLParser($replaceFields);
|
|
||||||
$filter = str_replace("'", "''", $filter);
|
|
||||||
$replaceFields = $this->queryModified($parser->parsed, $filter, "*searchtype*", $start, $limit, $dbConnection);
|
|
||||||
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
|
|
||||||
|
|
||||||
while ($rs->next()) {
|
$arrayApplicationData = $case->getApplicationRecordByPk(
|
||||||
$row = $rs->getRow();
|
$applicationUid, ['$applicationUid' => 'app_uid']
|
||||||
|
);
|
||||||
|
|
||||||
$arrayRecord[] = array(
|
$case = new \Cases();
|
||||||
strtolower("VALUE") => $row[0],
|
|
||||||
strtolower("TEXT") => isset($row[1]) ? $row[1] : $row[0]
|
$arrayApplicationData['APP_DATA'] = $case->unserializeData($arrayApplicationData['APP_DATA']);
|
||||||
);
|
|
||||||
|
$dataVariable = (preg_match('/^\s*@.(.+)\s*$/', $field->dataVariable, $arrayMatch))?
|
||||||
|
$arrayMatch[1] : $field->dataVariable;
|
||||||
|
|
||||||
|
if (isset($arrayApplicationData['APP_DATA'][$dataVariable]) &&
|
||||||
|
is_array($arrayApplicationData['APP_DATA'][$dataVariable]) &&
|
||||||
|
!empty($arrayApplicationData['APP_DATA'][$dataVariable])
|
||||||
|
) {
|
||||||
|
foreach ($arrayApplicationData['APP_DATA'][$dataVariable] as $row) {
|
||||||
|
$value = $row[0];
|
||||||
|
$text = (isset($row[1]))? $row[1] : $row[0];
|
||||||
|
|
||||||
|
if ($filter !== '') {
|
||||||
|
if (preg_match('/^.*' . $filter . '.*$/i', $text)) {
|
||||||
|
$arrayRecord[] = [strtolower('VALUE') => $value, strtolower('TEXT') => $text];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$arrayRecord[] = [strtolower('VALUE') => $value, strtolower('TEXT') => $text];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrayRecord = array_slice(
|
||||||
|
$arrayRecord,
|
||||||
|
(int)($start),
|
||||||
|
($limit !== '')? (int)($limit) : null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//database
|
||||||
|
$dbConnection = ($field !== null && !empty($field->dbConnection))? $field->dbConnection : 'workflow';
|
||||||
|
$variableSql = ($field !== null)? $field->sql : '';
|
||||||
|
|
||||||
|
$_SESSION['PROCESS'] = $processUid;
|
||||||
|
|
||||||
|
$cnn = \Propel::getConnection($dbConnection);
|
||||||
|
$stmt = $cnn->createStatement();
|
||||||
|
|
||||||
|
$replaceFields = \G::replaceDataField($variableSql, $arrayVariable);
|
||||||
|
|
||||||
|
$parser = new \PHPSQLParser($replaceFields);
|
||||||
|
|
||||||
|
$replaceFields = $this->queryModified(
|
||||||
|
$parser->parsed, $filter, '*searchtype*', $start, $limit, $dbConnection
|
||||||
|
);
|
||||||
|
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
|
||||||
|
|
||||||
|
while ($rs->next()) {
|
||||||
|
$row = $rs->getRow();
|
||||||
|
|
||||||
|
$value = $row[0];
|
||||||
|
$text = (isset($row[1]))? $row[1] : $row[0];
|
||||||
|
|
||||||
|
$arrayRecord[] = [strtolower('VALUE') => $value, strtolower('TEXT') => $text];
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
|
|||||||
Reference in New Issue
Block a user