PM-1969-2009

This commit is contained in:
Roly Rudy Gutierrez Pinto
2015-03-31 16:33:28 -04:00
parent ec1a31e6a6
commit f02d684259
2 changed files with 128 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ class pmDynaform
public $lang = null;
public $langs = null;
public function __construct($fields)
public function __construct($fields = array())
{
$this->fields = $fields;
$this->getDynaform();
@@ -129,7 +129,7 @@ class pmDynaform
while ($rs->next()) {
$row = $rs->getRow();
$option = array(
"label" => $row[1],
"label" => isset($row[1]) ? $row[1] : $row[0],
"value" => $row[0]
);
array_push($json->options, $option);
@@ -368,6 +368,107 @@ class pmDynaform
exit();
}
public function synchronizeVariable($processUid, $newVariable, $oldVariable)
{
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(DynaformPeer::DYN_UID);
$criteria->addSelectColumn(DynaformPeer::DYN_CONTENT);
$criteria->add(DynaformPeer::PRO_UID, $processUid, Criteria::EQUAL);
$rsCriteria = DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$aRow = $rsCriteria->getRow();
$json = G::json_decode($aRow['DYN_CONTENT']);
$this->jsons($json, $newVariable, $oldVariable);
$json2 = G::json_encode($json);
//update dynaform
if ($json2 !== $aRow['DYN_CONTENT']) {
$con = Propel::getConnection(DynaformPeer::DATABASE_NAME);
$con->begin();
$oPro = DynaformPeer::retrieveByPk($aRow["DYN_UID"]);
$oPro->setDynContent($json2);
$oPro->save();
$con->commit();
}
}
}
private function jsons(&$json, $newVariable, $oldVariable)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
$this->jsons($value, $newVariable, $oldVariable);
}
if (!$sw1 && !$sw2) {
if ($key === "variable" && $json->variable === $oldVariable["VAR_NAME"]) {
$json->variable = $newVariable["VAR_NAME"];
if (isset($json->dataType))
$json->dataType = $newVariable["VAR_FIELD_TYPE"];
if (isset($json->name))
$json->name = $newVariable["VAR_NAME"];
if (isset($json->dbConnection) && $json->dbConnection === $oldVariable["VAR_DBCONNECTION"])
$json->dbConnection = $newVariable["VAR_DBCONNECTION"];
if (isset($json->sql) && $json->sql === $oldVariable["VAR_SQL"])
$json->sql = $newVariable["VAR_SQL"];
if (isset($json->options) && G::json_encode($json->options) === $oldVariable["VAR_ACCEPTED_VALUES"]) {
$json->options = G::json_decode($newVariable["VAR_ACCEPTED_VALUES"]);
}
}
}
}
}
public function isUsed($processUid, $variable)
{
$criteria = new Criteria("workflow");
$criteria->addSelectColumn(DynaformPeer::DYN_UID);
$criteria->addSelectColumn(DynaformPeer::DYN_CONTENT);
$criteria->add(DynaformPeer::PRO_UID, $processUid, Criteria::EQUAL);
$rsCriteria = DynaformPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$aRow = $rsCriteria->getRow();
$json = G::json_decode($aRow['DYN_CONTENT']);
if ($this->jsoni($json, $variable)) {
return $aRow['DYN_UID'];
}
}
return false;
}
private function jsoni(&$json, $variable)
{
foreach ($json as $key => $value) {
$sw1 = is_array($value);
$sw2 = is_object($value);
if ($sw1 || $sw2) {
if ($this->jsoni($value, $variable)) {
return true;
}
}
if (!$sw1 && !$sw2) {
if ($key === "variable" && $json->variable === $variable["var_name"]) {
return true;
}
}
}
return false;
}
private function clientToken()
{
$client = $this->getClientCredentials();
@@ -436,4 +537,3 @@ class pmDynaform
}
}

View File

@@ -129,7 +129,13 @@ class Variable
$cnn = \Propel::getConnection("workflow");
try {
$variable = \ProcessVariablesPeer::retrieveByPK($variableUid);
$oldVariable = array(
"VAR_NAME" => $variable->getVarName(),
"VAR_FIELD_TYPE" => $variable->getVarFieldType(),
"VAR_DBCONNECTION" => $variable->getVarDbconnection(),
"VAR_SQL" => $variable->getVarSql(),
"VAR_ACCEPTED_VALUES" => $variable->getVarAcceptedValues()
);
if ($variable->validate()) {
$cnn->begin();
if (isset($arrayData["VAR_NAME"])) {
@@ -163,6 +169,17 @@ class Variable
}
$variable->save();
$cnn->commit();
//update dynaforms
$newVariable = array(
"VAR_NAME" => $variable->getVarName(),
"VAR_FIELD_TYPE" => $variable->getVarFieldType(),
"VAR_DBCONNECTION" => $variable->getVarDbconnection(),
"VAR_SQL" => $variable->getVarSql(),
"VAR_ACCEPTED_VALUES" => $variable->getVarAcceptedValues()
);
\G::LoadClass('pmDynaform');
$pmDynaform = new \pmDynaform();
$pmDynaform->synchronizeVariable($processUid, $newVariable, $oldVariable);
} else {
$msg = "";
@@ -200,7 +217,13 @@ class Variable
$this->throwExceptionIfNotExistsVariable($variableUid);
$this->verifyUse($processUid, $variableUid);
$variable = $this->getVariable($processUid, $variableUid);
\G::LoadClass('pmDynaform');
$pmDynaform = new \pmDynaform();
$isUsed = $pmDynaform->isUsed($processUid, $variable);
if ($isUsed !== false) {
throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($variableUid, $isUsed)));
}
//Delete
$criteria = new \Criteria("workflow");