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:
Victor Saisa Lopez
2016-03-02 09:27:08 -04:00
parent f395d4b6e0
commit 64c418dfe2
2 changed files with 115 additions and 49 deletions

View File

@@ -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" .