PM-3877
This commit is contained in:
@@ -165,7 +165,7 @@ class pmDynaform
|
||||
}
|
||||
}
|
||||
//options & query
|
||||
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "dropdown" || $value === "checkgroup" || $value === "radio" || $value === "suggest" )) {
|
||||
if ($key === "type" && ($value === "text" || $value === "textarea" || $value === "hidden" || $value === "dropdown" || $value === "checkgroup" || $value === "radio" || $value === "suggest")) {
|
||||
if (!isset($json->dbConnection))
|
||||
$json->dbConnection = "none";
|
||||
if (!isset($json->sql))
|
||||
@@ -175,7 +175,8 @@ class pmDynaform
|
||||
$cnn = Propel::getConnection($json->dbConnection);
|
||||
$stmt = $cnn->createStatement();
|
||||
try {
|
||||
$rs = $stmt->executeQuery(G::replaceDataField($json->sql, array()), \ResultSet::FETCHMODE_NUM);
|
||||
$sql = G::replaceDataField($json->sql, $this->getValuesDependentFields($json));
|
||||
$rs = $stmt->executeQuery($sql, \ResultSet::FETCHMODE_NUM);
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
$option = new stdClass();
|
||||
@@ -205,6 +206,7 @@ class pmDynaform
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name];
|
||||
}
|
||||
$json->optionsSql = array();
|
||||
}
|
||||
if ($key === "type" && ($value === "dropdown")) {
|
||||
$json->data = new stdClass();
|
||||
@@ -226,6 +228,8 @@ class pmDynaform
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name])) {
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
}
|
||||
@@ -251,10 +255,11 @@ class pmDynaform
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name])) {
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
$json->optionsSql = array();
|
||||
}
|
||||
if ($key === "type" && ($value === "radio")) {
|
||||
$json->data = new stdClass();
|
||||
@@ -276,6 +281,8 @@ class pmDynaform
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name])) {
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
}
|
||||
@@ -315,6 +322,8 @@ class pmDynaform
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name])) {
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
}
|
||||
@@ -324,6 +333,8 @@ class pmDynaform
|
||||
$json->data->label = "";
|
||||
if (isset($this->fields["APP_DATA"][$json->name])) {
|
||||
$json->data->value = $this->fields["APP_DATA"][$json->name];
|
||||
}
|
||||
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
|
||||
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
|
||||
}
|
||||
}
|
||||
@@ -344,7 +355,7 @@ class pmDynaform
|
||||
$json->data->value = $links;
|
||||
$json->data->label = isset($this->fields["APP_DATA"][$json->name . "_label"]) ? $this->fields["APP_DATA"][$json->name . "_label"] : "[]";
|
||||
}
|
||||
if ($key === "type" && ($value === "file")) {
|
||||
if ($key === "type" && ($value === "file") && isset($json->variable)) {
|
||||
//todo
|
||||
$oCriteria = new Criteria("workflow");
|
||||
$oCriteria->addSelectColumn(ProcessVariablesPeer::INP_DOC_UID);
|
||||
@@ -472,6 +483,42 @@ class pmDynaform
|
||||
}
|
||||
}
|
||||
|
||||
private function getValuesDependentFields($json)
|
||||
{
|
||||
$data = array();
|
||||
if (isset($json->dbConnection) && isset($json->sql)) {
|
||||
$salida = array();
|
||||
preg_match_all('/\@(?:([\@\%\#\=\!Qq])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*?)*)\))/', $json->sql, $salida, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
|
||||
$variables = isset($salida[2]) ? $salida[2] : array();
|
||||
foreach ($variables as $key => $value) {
|
||||
$jsonSearch = $this->jsonsf(G::json_decode($this->record["DYN_CONTENT"]), $value[0], $json->variable === "" ? "id" : "variable");
|
||||
$a = $this->getValuesDependentFields($jsonSearch);
|
||||
foreach ($a as $i => $v) {
|
||||
$data[$i] = $v;
|
||||
}
|
||||
}
|
||||
if ($json->dbConnection !== "" && $json->dbConnection !== "none" && $json->sql !== "") {
|
||||
$cnn = Propel::getConnection($json->dbConnection);
|
||||
$stmt = $cnn->createStatement();
|
||||
try {
|
||||
$a = G::replaceDataField($json->sql, $data);
|
||||
$rs = $stmt->executeQuery($a, \ResultSet::FETCHMODE_NUM);
|
||||
$rs->next();
|
||||
$row = $rs->getRow();
|
||||
if (isset($row[0]) && $json->type !== "suggest") {
|
||||
$data[$json->variable === "" ? $json->id : $json->variable] = $row[0];
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($json->defaultValue) && $json->defaultValue !== "") {
|
||||
$data[$json->variable === "" ? $json->id : $json->variable] = $json->defaultValue;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function isResponsive()
|
||||
{
|
||||
return $this->record != null && $this->record["DYN_VERSION"] == 2 ? true : false;
|
||||
@@ -984,18 +1031,18 @@ class pmDynaform
|
||||
return $this->jsonsf($json, $field_id);
|
||||
}
|
||||
|
||||
private function jsonsf(&$json, $id)
|
||||
private function jsonsf(&$json, $id, $for = "id")
|
||||
{
|
||||
foreach ($json as $key => $value) {
|
||||
$sw1 = is_array($value);
|
||||
$sw2 = is_object($value);
|
||||
if ($sw1 || $sw2) {
|
||||
$val = $this->jsonsf($value, $id);
|
||||
$val = $this->jsonsf($value, $id, $for);
|
||||
if ($val !== null)
|
||||
return $val;
|
||||
}
|
||||
if (!$sw1 && !$sw2) {
|
||||
if ($key === "id" && $id === $value) {
|
||||
if ($key === $for && $id === $value) {
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,130 +672,58 @@ class Variable
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));
|
||||
|
||||
//Set data
|
||||
$variableDbConnectionUid = "";
|
||||
$variableSql = "";
|
||||
|
||||
$sqlCondition = "";
|
||||
$sqlOrderBy = "";
|
||||
$sqlLimit = "";
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DBCONNECTION);
|
||||
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_SQL);
|
||||
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
||||
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
||||
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
if ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$variableDbConnectionUid = $row["VAR_DBCONNECTION"];
|
||||
$variableSql = $row["VAR_SQL"];
|
||||
} else {
|
||||
throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_DOES_NOT_EXIST", array(strtolower("VAR_NAME"), $variableName)));
|
||||
}
|
||||
|
||||
//Verify data
|
||||
$this->throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, $arrayVariable);
|
||||
\G::LoadClass('pmDynaform');
|
||||
$pmDynaform = new \pmDynaform();
|
||||
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $variableName);
|
||||
$variableDbConnectionUid = $field !== null ? $field->dbConnection : "";
|
||||
$variableSql = $field !== null ? $field->sql : "";
|
||||
|
||||
//Get data
|
||||
$_SESSION["PROCESS"] = $processUid;
|
||||
|
||||
$selectFieldMain = "";
|
||||
|
||||
if (preg_match("/^SELECT\s(.+)\sFROM.+$/", $variableSql, $matches)) {
|
||||
$arrayFields = explode (",", $matches[1]);
|
||||
|
||||
if (!isset($arrayFields[1])) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_QUERY"));
|
||||
}
|
||||
|
||||
$selectFieldMain = $arrayFields[1];
|
||||
}
|
||||
|
||||
$filter = "";
|
||||
$filterOption = "";
|
||||
|
||||
if (array_key_exists("filter", $arrayVariable) && $arrayVariable["filter"] != "") {
|
||||
$filter = $arrayVariable["filter"];
|
||||
$filterOption = "filter";
|
||||
} else {
|
||||
if (array_key_exists("lfilter", $arrayVariable) && $arrayVariable["lfilter"] != "") {
|
||||
$filter = $arrayVariable["lfilter"];
|
||||
$filterOption = "lfilter";
|
||||
} else {
|
||||
if (array_key_exists("rfilter", $arrayVariable) && $arrayVariable["rfilter"] != "") {
|
||||
$filter = $arrayVariable["rfilter"];
|
||||
$filterOption = "rfilter";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($arrayVariable["lfilter"]);
|
||||
unset($arrayVariable["rfilter"]);
|
||||
unset($arrayVariable["filter"]);
|
||||
|
||||
if ($filter != "" && $filterOption != "") {
|
||||
$arrayVariable["filter"] = $filter;
|
||||
}
|
||||
|
||||
foreach ($arrayVariable as $keyRequest => $valueRequest) {
|
||||
switch ($keyRequest) {
|
||||
case "filter":
|
||||
$arraySearch = array(
|
||||
"filter" => "%" . $valueRequest . "%",
|
||||
"lfilter" => $valueRequest . "%",
|
||||
"rfilter" => "%" . $valueRequest
|
||||
);
|
||||
|
||||
$search = $arraySearch[$filterOption];
|
||||
|
||||
if (strpos($variableSql, "WHERE")) {
|
||||
$sqlCondition = " AND " . $selectFieldMain . " LIKE '" . $search . "'";
|
||||
} else {
|
||||
$sqlCondition = " WHERE " . $selectFieldMain . " LIKE '" . $search . "'";
|
||||
}
|
||||
break;
|
||||
case "order_by":
|
||||
$sqlOrderBy = " ORDER BY " . $selectFieldMain . " " . $valueRequest;
|
||||
break;
|
||||
case "limit":
|
||||
if (strpos($variableSql, "LIMIT")) {
|
||||
$variableSqlLimit = explode("LIMIT", $variableSql);
|
||||
$sqlLimit = " LIMIT " . $variableSqlLimit[1];
|
||||
$variableSql = $variableSqlLimit[0];
|
||||
} else {
|
||||
$sqlLimit = " LIMIT ". 0 . ", " . $valueRequest;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (strpos($variableSql, 'WHERE')) {
|
||||
$sqlCondition = " AND " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
|
||||
} else {
|
||||
$sqlCondition = " WHERE " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$sqlQuery = $variableSql . $sqlCondition . $sqlOrderBy . $sqlLimit;
|
||||
|
||||
$sqlQuery = G::replaceDataField($sqlQuery, $arrayVariable);
|
||||
|
||||
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
|
||||
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "") ? $variableDbConnectionUid : "workflow");
|
||||
$stmt = $cnn->createStatement();
|
||||
|
||||
$rs = $stmt->executeQuery($sqlQuery, \ResultSet::FETCHMODE_NUM);
|
||||
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
|
||||
|
||||
$a = strtolower($replaceFields);
|
||||
$a = str_replace("\n", " ", $a);
|
||||
$a = str_replace("\t", " ", $a);
|
||||
$ai = strpos($a, "select ");
|
||||
$aj = strpos($a, " from ");
|
||||
$sw = strpos($a, " order ");
|
||||
$b = substr($replaceFields, $ai + 6, $aj - ($ai + 6));
|
||||
$b = explode(",", $b);
|
||||
$b = isset($b[1]) ? $b[1] : $b[0];
|
||||
$c = strtolower($b);
|
||||
$ci = strpos($c, " as ");
|
||||
$c = $ci > 0 ? substr($b, $ci + 4) : $b;
|
||||
|
||||
$filter = "";
|
||||
if (isset($arrayVariable["filter"]))
|
||||
$filter = "WHERE " . $c . " LIKE '%" . $arrayVariable["filter"] . "%'";
|
||||
$order = " ORDER BY " . $c . " ASC";
|
||||
if (isset($arrayVariable["order"]))
|
||||
$order = " ORDER BY " . $c . " " . $arrayVariable["order"];
|
||||
if ($sw)
|
||||
$order = "";
|
||||
$start = 0;
|
||||
if (isset($arrayVariable["start"]))
|
||||
$start = $arrayVariable["start"];
|
||||
$limit = "";
|
||||
if (isset($arrayVariable["limit"]))
|
||||
$limit = "LIMIT " . $start . "," . $arrayVariable["limit"];
|
||||
|
||||
$replaceFields = "SELECT * FROM (" . $replaceFields . ") AS TEMP " . $filter . $order . " " . $limit;
|
||||
|
||||
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
|
||||
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
|
||||
$arrayRecord[] = array(
|
||||
strtolower("VALUE") => $row[0],
|
||||
strtolower("TEXT") => $row[1]
|
||||
strtolower("TEXT") => isset($row[1]) ? $row[1] : $row[0]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -805,4 +733,5 @@ class Variable
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user