Adicion end point suggest field
This commit is contained in:
@@ -481,7 +481,6 @@ class Variable
|
||||
|
||||
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
@@ -586,5 +585,101 @@ class Variable
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all records by execute SQL suggest
|
||||
*
|
||||
* @param string $processUid Unique id of Process
|
||||
* @param string $variableName Variable name
|
||||
* @param array $arrayVariable The variables
|
||||
*
|
||||
* return array Return an array with all records
|
||||
*/
|
||||
public function executeSqlSuggest($processUid, $variableName, array $arrayVariable = array())
|
||||
{
|
||||
try {
|
||||
$arrayRecord = array();
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));
|
||||
|
||||
//Set data
|
||||
$variableDbConnectionUid = "";
|
||||
$variableSql = "";
|
||||
$sqlLimit = "";
|
||||
$variableSqlLimit = "";
|
||||
|
||||
$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);
|
||||
|
||||
//Get data
|
||||
$_SESSION["PROCESS"] = $processUid;
|
||||
|
||||
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
|
||||
$stmt = $cnn->createStatement();
|
||||
|
||||
$rs = $stmt->executeQuery(\G::replaceDataField($variableSql, $arrayVariable), \ResultSet::FETCHMODE_NUM);
|
||||
|
||||
|
||||
foreach ($arrayVariable as $keyRequest => $valueRequest) {
|
||||
$keyRequest = strtoupper($keyRequest);
|
||||
|
||||
if ($keyRequest == 'LIMIT') {
|
||||
if (strpos($variableSql, 'LIMIT')) {
|
||||
$variableSqlLimit = explode("LIMIT", $variableSql);
|
||||
$sqlLimit = " LIMIT " . $variableSqlLimit[1];
|
||||
$variableSql = $variableSqlLimit[0];
|
||||
} else {
|
||||
$sqlLimit = " LIMIT ". 0 . ", " . $valueRequest;
|
||||
}
|
||||
} else {
|
||||
if (strpos($variableSql, 'WHERE')) {
|
||||
$sqlConditionLike = " AND " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
|
||||
} else {
|
||||
$sqlConditionLike = " WHERE " . $keyRequest . " LIKE '%" . $valueRequest . "%'";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sqlQuery = $variableSql . $sqlConditionLike . $sqlLimit;
|
||||
|
||||
$rs = $stmt->executeQuery(\G::replaceDataField($sqlQuery, $arrayVariable), \ResultSet::FETCHMODE_NUM);
|
||||
|
||||
while ($rs->next()) {
|
||||
$row = $rs->getRow();
|
||||
|
||||
$arrayRecord[] = array(
|
||||
strtolower("VALUE") => $row[0],
|
||||
strtolower("TEXT") => $row[1]
|
||||
);
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayRecord;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user