Merged in victorsl/processmaker/HOR-172-3018-B (pull request #3773)
HOR-172
This commit is contained in:
@@ -176,22 +176,47 @@ class pmDynaform
|
||||
if (!isset($json->sql))
|
||||
$json->sql = "";
|
||||
$json->optionsSql = array();
|
||||
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];
|
||||
array_push($json->optionsSql, $option);
|
||||
|
||||
switch ((isset($json->datasource))? $json->datasource : 'database') {
|
||||
case 'dataVariable':
|
||||
$dataVariable = (preg_match('/^\s*@.(.+)\s*$/', $json->dataVariable, $arrayMatch))?
|
||||
$arrayMatch[1] : $json->dataVariable;
|
||||
|
||||
if (isset($this->fields['APP_DATA'][$dataVariable]) &&
|
||||
is_array($this->fields['APP_DATA'][$dataVariable]) &&
|
||||
!empty($this->fields['APP_DATA'][$dataVariable])
|
||||
) {
|
||||
foreach ($this->fields['APP_DATA'][$dataVariable] as $row) {
|
||||
$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
|
||||
@@ -565,7 +590,7 @@ class pmDynaform
|
||||
$data[$json->variable === "" ? $json->id : $json->variable] = $row[0];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,9 +713,9 @@ class pmDynaform
|
||||
" token: credentials,\n" .
|
||||
" submitRest: false\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" .
|
||||
" return false;\n".
|
||||
" return false;\n".
|
||||
" });\n" .
|
||||
" $(document).find('form').submit(function (e) {\n" .
|
||||
" e.preventDefault();\n" .
|
||||
|
||||
@@ -717,44 +717,85 @@ class Variable
|
||||
\G::LoadClass('pmDynaform');
|
||||
$pmDynaform = new \pmDynaform();
|
||||
$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
|
||||
$_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);
|
||||
$stmt = $cnn->createStatement();
|
||||
switch (($field !== null && isset($field->datasource))? $field->datasource : 'database') {
|
||||
case 'dataVariable':
|
||||
if (!isset($arrayVariable['app_uid'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
|
||||
$applicationUid = $arrayVariable['app_uid'];
|
||||
|
||||
$filter = "";
|
||||
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);
|
||||
$case = new \ProcessMaker\BusinessModel\Cases();
|
||||
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
$arrayApplicationData = $case->getApplicationRecordByPk(
|
||||
$applicationUid, ['$applicationUid' => 'app_uid']
|
||||
);
|
||||
|
||||
$arrayRecord[] = array(
|
||||
strtolower("VALUE") => $row[0],
|
||||
strtolower("TEXT") => isset($row[1]) ? $row[1] : $row[0]
|
||||
);
|
||||
$case = new \Cases();
|
||||
|
||||
$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
|
||||
|
||||
Reference in New Issue
Block a user