This commit is contained in:
Paula Quispe
2017-08-08 16:06:00 -04:00
parent a500ec3ea1
commit de4d75828b
3 changed files with 88 additions and 106 deletions

View File

@@ -14000,6 +14000,12 @@ msgstr "Not Required"
msgid "The variable name already exists!" msgid "The variable name already exists!"
msgstr "The variable name already exists!" msgstr "The variable name already exists!"
# TRANSLATION
# LABEL/DYNAFIELD_PHPNAME_ALREADY_EXIST
#: LABEL/DYNAFIELD_PHPNAME_ALREADY_EXIST
msgid "Name error encountered when creating the variable: {0}. Please rename the variable you are creating with a unique name. Avoid differentiating similarly-named variables with only capitalization and '_' characters."
msgstr "Name error encountered when creating the variable: {0}. Please rename the variable you are creating with a unique name. Avoid differentiating similarly-named variables with only capitalization and '_' characters."
# TRANSLATION # TRANSLATION
# LABEL/DYNAFIELD_EMPTY # LABEL/DYNAFIELD_EMPTY
#: LABEL/DYNAFIELD_EMPTY #: LABEL/DYNAFIELD_EMPTY

View File

@@ -3823,6 +3823,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_INSTRUCTIONS','en','Instructions','2014-01-15') , ( 'LABEL','ID_INSTRUCTIONS','en','Instructions','2014-01-15') ,
( 'LABEL','ID_NOT_REQUIRED','en','Not Required','2014-01-15') , ( 'LABEL','ID_NOT_REQUIRED','en','Not Required','2014-01-15') ,
( 'LABEL','DYNAFIELD_ALREADY_EXIST','en','The variable name already exists!','2015-04-24') , ( 'LABEL','DYNAFIELD_ALREADY_EXIST','en','The variable name already exists!','2015-04-24') ,
( 'LABEL','DYNAFIELD_PHPNAME_ALREADY_EXIST','en','Name error encountered when creating the variable: {0}. Please rename the variable you are creating with a unique name. Avoid differentiating similarly-named variables with only capitalization and ''_'' characters.','2017-08-09') ,
( 'LABEL','DYNAFIELD_EMPTY','en','The Field Name is empty','2014-10-21') , ( 'LABEL','DYNAFIELD_EMPTY','en','The Field Name is empty','2014-10-21') ,
( 'LABEL','DYNAFIELD_NODENAME_NUMBER','en','The field name should not start with a number','2014-01-15') , ( 'LABEL','DYNAFIELD_NODENAME_NUMBER','en','The field name should not start with a number','2014-01-15') ,
( 'LABEL','ID_EMPTY_NODENAME','en','The name field is empty','2014-01-15') , ( 'LABEL','ID_EMPTY_NODENAME','en','The name field is empty','2014-01-15') ,

View File

@@ -2,6 +2,8 @@
namespace ProcessMaker\BusinessModel; namespace ProcessMaker\BusinessModel;
use \G; use \G;
use \Exception;
use \AdditionalTables;
class Variable class Variable
{ {
@@ -13,25 +15,22 @@ class Variable
* @param string $processUid Unique id of Process * @param string $processUid Unique id of Process
* @param array $arrayData Data * @param array $arrayData Data
* *
* return array Return data of the new Variable created * @return array, return data of the new Variable created
* @throws Exception
*/ */
public function create($processUid, array $arrayData) public function create($processUid, array $arrayData)
{ {
try { try {
//Verify data //Verify data
Validator::proUid($processUid, '$prj_uid'); Validator::proUid($processUid, '$prj_uid');
$arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->existsName($processUid, $arrayData["VAR_NAME"], ""); $this->existsName($processUid, $arrayData["VAR_NAME"], "");
$this->throwExceptionFieldDefinition($arrayData); $this->throwExceptionFieldDefinition($arrayData);
//Create //Create
$cnn = \Propel::getConnection("workflow"); $cnn = \Propel::getConnection("workflow");
try { try {
$variable = new \ProcessVariables(); $variable = new \ProcessVariables();
$sPkProcessVariables = \ProcessMaker\Util\Common::generateUID(); $sPkProcessVariables = \ProcessMaker\Util\Common::generateUID();
$variable->setVarUid($sPkProcessVariables); $variable->setVarUid($sPkProcessVariables);
@@ -43,13 +42,13 @@ class Variable
if (isset($arrayData["VAR_NAME"])) { if (isset($arrayData["VAR_NAME"])) {
$variable->setVarName($arrayData["VAR_NAME"]); $variable->setVarName($arrayData["VAR_NAME"]);
} else { } else {
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_name' ))); throw new Exception(G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_name' )));
} }
if (isset($arrayData["VAR_FIELD_TYPE"])) { if (isset($arrayData["VAR_FIELD_TYPE"])) {
$arrayData["VAR_FIELD_TYPE"] = $this->validateVarFieldType($arrayData["VAR_FIELD_TYPE"]); $arrayData["VAR_FIELD_TYPE"] = $this->validateVarFieldType($arrayData["VAR_FIELD_TYPE"]);
$variable->setVarFieldType($arrayData["VAR_FIELD_TYPE"]); $variable->setVarFieldType($arrayData["VAR_FIELD_TYPE"]);
} else { } else {
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_field_type' ))); throw new Exception(G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_field_type' )));
} }
if (isset($arrayData["VAR_FIELD_SIZE"])) { if (isset($arrayData["VAR_FIELD_SIZE"])) {
$variable->setVarFieldSize($arrayData["VAR_FIELD_SIZE"]); $variable->setVarFieldSize($arrayData["VAR_FIELD_SIZE"]);
@@ -57,7 +56,7 @@ class Variable
if (isset($arrayData["VAR_LABEL"])) { if (isset($arrayData["VAR_LABEL"])) {
$variable->setVarLabel($arrayData["VAR_LABEL"]); $variable->setVarLabel($arrayData["VAR_LABEL"]);
} else { } else {
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_label' ))); throw new Exception(G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_label' )));
} }
if (isset($arrayData["VAR_DBCONNECTION"])) { if (isset($arrayData["VAR_DBCONNECTION"])) {
$variable->setVarDbconnection($arrayData["VAR_DBCONNECTION"]); $variable->setVarDbconnection($arrayData["VAR_DBCONNECTION"]);
@@ -78,7 +77,7 @@ class Variable
$variable->setVarDefault($arrayData["VAR_DEFAULT"]); $variable->setVarDefault($arrayData["VAR_DEFAULT"]);
} }
if (isset($arrayData["VAR_ACCEPTED_VALUES"])) { if (isset($arrayData["VAR_ACCEPTED_VALUES"])) {
$encodeAcceptedValues = \G::json_encode($arrayData["VAR_ACCEPTED_VALUES"]); $encodeAcceptedValues = G::json_encode($arrayData["VAR_ACCEPTED_VALUES"]);
$variable->setVarAcceptedValues($encodeAcceptedValues); $variable->setVarAcceptedValues($encodeAcceptedValues);
} }
if (isset($arrayData["INP_DOC_UID"])) { if (isset($arrayData["INP_DOC_UID"])) {
@@ -94,10 +93,10 @@ class Variable
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
} }
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg); throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
} }
} catch (\Exception $e) { } catch (Exception $e) {
$cnn->rollback(); $cnn->rollback();
throw $e; throw $e;
@@ -108,7 +107,7 @@ class Variable
return $variable; return $variable;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -120,7 +119,8 @@ class Variable
* @param string $variableUid Unique id of Variable * @param string $variableUid Unique id of Variable
* @param array $arrayData Data * @param array $arrayData Data
* *
* return array Return data of the Variable updated * @return array,return data of the Variable updated
* @throws Exception
*/ */
public function update($processUid, $variableUid, $arrayData) public function update($processUid, $variableUid, $arrayData)
{ {
@@ -128,7 +128,6 @@ class Variable
//Verify data //Verify data
Validator::proUid($processUid, '$prj_uid'); Validator::proUid($processUid, '$prj_uid');
$arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->throwExceptionFieldDefinition($arrayData); $this->throwExceptionFieldDefinition($arrayData);
//Update //Update
@@ -150,7 +149,6 @@ class Variable
$cnn->begin(); $cnn->begin();
if (isset($arrayData["VAR_NAME"])) { if (isset($arrayData["VAR_NAME"])) {
$this->existsName($processUid, $arrayData["VAR_NAME"], $variableUid); $this->existsName($processUid, $arrayData["VAR_NAME"], $variableUid);
$variable->setVarName($arrayData["VAR_NAME"]); $variable->setVarName($arrayData["VAR_NAME"]);
} }
if (isset($arrayData["VAR_FIELD_TYPE"])) { if (isset($arrayData["VAR_FIELD_TYPE"])) {
@@ -176,7 +174,7 @@ class Variable
$variable->setVarDefault($arrayData["VAR_DEFAULT"]); $variable->setVarDefault($arrayData["VAR_DEFAULT"]);
} }
if (isset($arrayData["VAR_ACCEPTED_VALUES"])) { if (isset($arrayData["VAR_ACCEPTED_VALUES"])) {
$encodeAcceptedValues = \G::json_encode($arrayData["VAR_ACCEPTED_VALUES"]); $encodeAcceptedValues = G::json_encode($arrayData["VAR_ACCEPTED_VALUES"]);
$variable->setVarAcceptedValues($encodeAcceptedValues); $variable->setVarAcceptedValues($encodeAcceptedValues);
} }
if (isset($arrayData["INP_DOC_UID"])) { if (isset($arrayData["INP_DOC_UID"])) {
@@ -206,15 +204,15 @@ class Variable
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage(); $msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
} }
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg); throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
} }
} catch (\Exception $e) { } catch (Exception $e) {
$cnn->rollback(); $cnn->rollback();
throw $e; throw $e;
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -225,35 +223,31 @@ class Variable
* @param string $processUid Unique id of Process * @param string $processUid Unique id of Process
* @param string $variableUid Unique id of Variable * @param string $variableUid Unique id of Variable
* *
* return void * @return void
* @throws Exception
*/ */
public function delete($processUid, $variableUid) public function delete($processUid, $variableUid)
{ {
try { try {
//Verify data //Verify data
Validator::proUid($processUid, '$prj_uid'); Validator::proUid($processUid, '$prj_uid');
$this->throwExceptionIfNotExistsVariable($variableUid); $this->throwExceptionIfNotExistsVariable($variableUid);
//Verify variable //Verify variable
$this->throwExceptionIfVariableIsAssociatedAditionalTable($variableUid); $this->throwExceptionIfVariableIsAssociatedAditionalTable($variableUid);
$variable = $this->getVariable($processUid, $variableUid); $variable = $this->getVariable($processUid, $variableUid);
$pmDynaform = new \pmDynaform(); $pmDynaform = new \pmDynaform();
$isUsed = $pmDynaform->isUsed($processUid, $variable); $isUsed = $pmDynaform->isUsed($processUid, $variable);
if ($isUsed !== false) { if ($isUsed !== false) {
$titleDynaform=$pmDynaform->getDynaformTitle($isUsed); $titleDynaform=$pmDynaform->getDynaformTitle($isUsed);
throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($titleDynaform))); throw new Exception(G::LoadTranslation("ID_VARIABLE_IN_USE", array($titleDynaform)));
} }
//Delete //Delete
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid); $criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid);
\ProcessVariablesPeer::doDelete($criteria); \ProcessVariablesPeer::doDelete($criteria);
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -263,19 +257,18 @@ class Variable
* @param string $processUid Unique id of Process * @param string $processUid Unique id of Process
* @param string $variableUid Unique id of Variable * @param string $variableUid Unique id of Variable
* *
* return array Return an array with data of a Variable * @return array, return an array with data of a Variable
* @throws Exception
*/ */
public function getVariable($processUid, $variableUid) public function getVariable($processUid, $variableUid)
{ {
try { try {
//Verify data //Verify data
Validator::proUid($processUid, '$prj_uid'); Validator::proUid($processUid, '$prj_uid');
$this->throwExceptionIfNotExistsVariable($variableUid); $this->throwExceptionIfNotExistsVariable($variableUid);
//Get data //Get data
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
$criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID);
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
@@ -292,23 +285,18 @@ class Variable
$criteria->addSelectColumn(\DbSourcePeer::DBS_PORT); $criteria->addSelectColumn(\DbSourcePeer::DBS_PORT);
$criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME); $criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME);
$criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE); $criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE);
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL);
$criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID, \Criteria::LEFT_JOIN); $criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID, \Criteria::LEFT_JOIN);
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next(); $rsCriteria->next();
$arrayVariables = array(); $arrayVariables = array();
while ($aRow = $rsCriteria->getRow()) { while ($aRow = $rsCriteria->getRow()) {
$VAR_ACCEPTED_VALUES = \G::json_decode($aRow['VAR_ACCEPTED_VALUES'], true); $VAR_ACCEPTED_VALUES = G::json_decode($aRow['VAR_ACCEPTED_VALUES'], true);
if(sizeof($VAR_ACCEPTED_VALUES)) { if(sizeof($VAR_ACCEPTED_VALUES)) {
$encodeAcceptedValues = preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", \G::json_encode($VAR_ACCEPTED_VALUES)); $encodeAcceptedValues = preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", G::json_encode($VAR_ACCEPTED_VALUES));
} else { } else {
$encodeAcceptedValues = $aRow['VAR_ACCEPTED_VALUES']; $encodeAcceptedValues = $aRow['VAR_ACCEPTED_VALUES'];
} }
@@ -331,7 +319,7 @@ class Variable
//Return //Return
return $arrayVariables; return $arrayVariables;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -342,7 +330,8 @@ class Variable
* *
* @param string $processUid Unique id of Process * @param string $processUid Unique id of Process
* *
* return array Return an array with data of a DynaForm * @return array, return an array with data of a DynaForm
* @throws Exception
*/ */
public function getVariables($processUid) public function getVariables($processUid)
{ {
@@ -352,7 +341,6 @@ class Variable
//Get data //Get data
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
$criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID);
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
@@ -369,22 +357,17 @@ class Variable
$criteria->addSelectColumn(\DbSourcePeer::DBS_PORT); $criteria->addSelectColumn(\DbSourcePeer::DBS_PORT);
$criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME); $criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME);
$criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE); $criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE);
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID . " AND " . \DbSourcePeer::PRO_UID . " = '" . $processUid . "'", \Criteria::LEFT_JOIN); $criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID . " AND " . \DbSourcePeer::PRO_UID . " = '" . $processUid . "'", \Criteria::LEFT_JOIN);
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next(); $rsCriteria->next();
$arrayVariables = array(); $arrayVariables = array();
while ($aRow = $rsCriteria->getRow()) { while ($aRow = $rsCriteria->getRow()) {
$VAR_ACCEPTED_VALUES = \G::json_decode($aRow['VAR_ACCEPTED_VALUES'], true); $VAR_ACCEPTED_VALUES = G::json_decode($aRow['VAR_ACCEPTED_VALUES'], true);
if(sizeof($VAR_ACCEPTED_VALUES)) { if(sizeof($VAR_ACCEPTED_VALUES)) {
$encodeAcceptedValues = preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", \G::json_encode($VAR_ACCEPTED_VALUES)); $encodeAcceptedValues = preg_replace("/\\\\u([a-f0-9]{4})/e", "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", G::json_encode($VAR_ACCEPTED_VALUES));
} else { } else {
$encodeAcceptedValues = $aRow['VAR_ACCEPTED_VALUES']; $encodeAcceptedValues = $aRow['VAR_ACCEPTED_VALUES'];
} }
@@ -407,7 +390,7 @@ class Variable
//Return //Return
return $arrayVariables; return $arrayVariables;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -416,7 +399,8 @@ class Variable
* Verify field definition * Verify field definition
* *
* @param array $aData Unique id of Variable to exclude * @param array $aData Unique id of Variable to exclude
* * @return void
* @throws Exception
*/ */
public function throwExceptionFieldDefinition($aData) public function throwExceptionFieldDefinition($aData)
{ {
@@ -428,10 +412,6 @@ class Variable
if (isset($aData["VAR_FIELD_TYPE"])) { if (isset($aData["VAR_FIELD_TYPE"])) {
Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type'); Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type');
Validator::isNotEmpty($aData['VAR_FIELD_TYPE'], '$var_field_type'); Validator::isNotEmpty($aData['VAR_FIELD_TYPE'], '$var_field_type');
/*if ($aData["VAR_FIELD_TYPE"] != 'string' && $aData["VAR_FIELD_TYPE"] != 'integer' && $aData["VAR_FIELD_TYPE"] != 'boolean' && $aData["VAR_FIELD_TYPE"] != 'float' &&
$aData["VAR_FIELD_TYPE"] != 'datetime' && $aData["VAR_FIELD_TYPE"] != 'date_of_birth' && $aData["VAR_FIELD_TYPE"] != 'date') {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('$var_field_type')));
}*/
} }
if (isset($aData["VAR_FIELD_SIZE"])) { if (isset($aData["VAR_FIELD_SIZE"])) {
Validator::isInteger($aData["VAR_FIELD_SIZE"], '$var_field_size'); Validator::isInteger($aData["VAR_FIELD_SIZE"], '$var_field_size');
@@ -449,10 +429,10 @@ class Variable
if (isset($aData["VAR_NULL"])) { if (isset($aData["VAR_NULL"])) {
Validator::isInteger($aData['VAR_NULL'], '$var_null'); Validator::isInteger($aData['VAR_NULL'], '$var_null');
if ($aData["VAR_NULL"] != 0 && $aData["VAR_NULL"] !=1 ) { if ($aData["VAR_NULL"] != 0 && $aData["VAR_NULL"] !=1 ) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array('$var_null','0, 1' ))); throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array('$var_null','0, 1' )));
} }
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -460,8 +440,10 @@ class Variable
/** /**
* Verify if exists the name of a variable * Verify if exists the name of a variable
* *
* @param string $processUid Unique id of Process * @param string $processUid, unique id of Process
* @param string $variableName Name * @param string $variableName, name of variable
* @param string $variableUidToExclude
* @throws Exception
* *
*/ */
public function existsName($processUid, $variableName, $variableUidToExclude = "") public function existsName($processUid, $variableName, $variableUidToExclude = "")
@@ -471,25 +453,23 @@ class Variable
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
if ($variableUidToExclude != "") { if ($variableUidToExclude != "") {
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUidToExclude, \Criteria::NOT_EQUAL); $criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUidToExclude, \Criteria::NOT_EQUAL);
} }
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) { while ($rsCriteria->next()) {
$row = $rsCriteria->getRow(); $row = $rsCriteria->getRow();
if ($variableName === $row["VAR_NAME"]) {
if ($variableName == $row["VAR_NAME"]) { throw new Exception(G::LoadTranslation("DYNAFIELD_ALREADY_EXIST"));
throw new \Exception(\G::LoadTranslation("DYNAFIELD_ALREADY_EXIST")); }
if (AdditionalTables::getPHPName($variableName) === AdditionalTables::getPHPName($row["VAR_NAME"])) {
throw new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", array($row["VAR_NAME"])));
} }
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -499,21 +479,20 @@ class Variable
* *
* @param string $sql SQL * @param string $sql SQL
* *
* return array Return an array with required variables in the SQL * @return array, return an array with required variables in the SQL
* @throws Exception
*/ */
public function sqlGetRequiredVariables($sql) public function sqlGetRequiredVariables($sql)
{ {
try { try {
$arrayVariableRequired = array(); $arrayVariableRequired = array();
preg_match_all("/@[@%#\?\x24\=]([A-Za-z_]\w*)/", $sql, $arrayMatch, PREG_SET_ORDER); preg_match_all("/@[@%#\?\x24\=]([A-Za-z_]\w*)/", $sql, $arrayMatch, PREG_SET_ORDER);
foreach ($arrayMatch as $value) { foreach ($arrayMatch as $value) {
$arrayVariableRequired[] = $value[1]; $arrayVariableRequired[] = $value[1];
} }
return $arrayVariableRequired; return $arrayVariableRequired;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -525,17 +504,17 @@ class Variable
* @param string $variableSql SQL * @param string $variableSql SQL
* @param array $arrayVariable The variables * @param array $arrayVariable The variables
* *
* return void Throw exception if some required variable in the SQL is missing in the variables * @return void Throw exception if some required variable in the SQL is missing in the variables
* @throws Exception
*/ */
public function throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, array $arrayVariable) public function throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, array $arrayVariable)
{ {
try { try {
$arrayResult = array_diff(array_unique($this->sqlGetRequiredVariables($variableSql)), array_keys($arrayVariable)); $arrayResult = array_diff(array_unique($this->sqlGetRequiredVariables($variableSql)), array_keys($arrayVariable));
if (count($arrayResult) > 0) { if (count($arrayResult) > 0) {
throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_REQUIRED_VARIABLES_FOR_QUERY", array($variableName, implode(", ", $arrayResult)))); throw new Exception(G::LoadTranslation("ID_PROCESS_VARIABLE_REQUIRED_VARIABLES_FOR_QUERY", array($variableName, implode(", ", $arrayResult))));
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -547,13 +526,14 @@ class Variable
* @param string $variableName Variable name * @param string $variableName Variable name
* @param array $arrayVariable The variables * @param array $arrayVariable The variables
* *
* return array Return an array with all records * @return array, return an array with all records
* @throws Exception
*/ */
public function executeSql($processUid, $variableName, array $arrayVariable = array()) public function executeSql($processUid, $variableName, array $arrayVariable = array())
{ {
try { try {
return $this->executeSqlControl($processUid, $arrayVariable); return $this->executeSqlControl($processUid, $arrayVariable);
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -563,7 +543,8 @@ class Variable
* *
* @param string $variableUid Unique id of variable * @param string $variableUid Unique id of variable
* *
* return void Throw exception if does not exist the variable in table PROCESS_VARIABLES * @return void
* @throws Exception, throw exception if does not exist the variable in table PROCESS_VARIABLES
*/ */
public function throwExceptionIfNotExistsVariable($variableUid) public function throwExceptionIfNotExistsVariable($variableUid)
{ {
@@ -571,9 +552,9 @@ class Variable
$obj = \ProcessVariablesPeer::retrieveByPK($variableUid); $obj = \ProcessVariablesPeer::retrieveByPK($variableUid);
if (is_null($obj)) { if (is_null($obj)) {
throw new \Exception('var_uid: '.$variableUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST")); throw new Exception('var_uid: '.$variableUid. ' '.G::LoadTranslation("ID_DOES_NOT_EXIST"));
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -584,30 +565,25 @@ class Variable
* @param string $variableUid Unique id of variable * @param string $variableUid Unique id of variable
* *
* @return void Throw exception * @return void Throw exception
* @throws Exception
*/ */
public function throwExceptionIfVariableIsAssociatedAditionalTable($variableUid) public function throwExceptionIfVariableIsAssociatedAditionalTable($variableUid)
{ {
try { try {
$criteria = new \Criteria('workflow'); $criteria = new \Criteria('workflow');
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
$criteria->addJoin(\ProcessVariablesPeer::PRJ_UID, \AdditionalTablesPeer::PRO_UID, \Criteria::INNER_JOIN); $criteria->addJoin(\ProcessVariablesPeer::PRJ_UID, \AdditionalTablesPeer::PRO_UID, \Criteria::INNER_JOIN);
$arrayCondition = []; $arrayCondition = [];
$arrayCondition[] = array(\AdditionalTablesPeer::ADD_TAB_UID, \FieldsPeer::ADD_TAB_UID, \Criteria::EQUAL); $arrayCondition[] = array(\AdditionalTablesPeer::ADD_TAB_UID, \FieldsPeer::ADD_TAB_UID, \Criteria::EQUAL);
$arrayCondition[] = array(\ProcessVariablesPeer::VAR_NAME, \FieldsPeer::FLD_NAME, \Criteria::EQUAL); $arrayCondition[] = array(\ProcessVariablesPeer::VAR_NAME, \FieldsPeer::FLD_NAME, \Criteria::EQUAL);
$criteria->addJoinMC($arrayCondition, \Criteria::INNER_JOIN); $criteria->addJoinMC($arrayCondition, \Criteria::INNER_JOIN);
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL);
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) { if ($rsCriteria->next()) {
throw new \Exception(\G::LoadTranslation('ID_VARIABLE_ASSOCIATED_WITH_REPORT_TABLE', array($variableUid))); throw new Exception(G::LoadTranslation('ID_VARIABLE_ASSOCIATED_WITH_REPORT_TABLE', array($variableUid)));
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -615,8 +591,10 @@ class Variable
/** /**
* Verify if the variable is being used in a Dynaform * Verify if the variable is being used in a Dynaform
* *
* @param string $processUid Unique id of Process * @param string $processUid, Unique id of Process
* @param string $variableUid Unique id of Variable * @param string $variableUid, Unique id of Variable
* @return void
* @throws Exception
* *
*/ */
public function verifyUse($processUid, $variableUid) public function verifyUse($processUid, $variableUid)
@@ -631,10 +609,8 @@ class Variable
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) { while ($rsCriteria->next()) {
$row = $rsCriteria->getRow(); $row = $rsCriteria->getRow();
$contentDecode = G::json_decode($row["DYN_CONTENT"], true);
$contentDecode = \G::json_decode($row["DYN_CONTENT"], true);
$content = $contentDecode['items'][0]['items']; $content = $contentDecode['items'][0]['items'];
if (is_array($content)) { if (is_array($content)) {
foreach ($content as $key => $value) { foreach ($content as $key => $value) {
@@ -649,14 +625,14 @@ class Variable
$rsCriteria->next(); $rsCriteria->next();
if ($rsCriteria->getRow()) { if ($rsCriteria->getRow()) {
throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($variableUid, $row["DYN_UID"]))); throw new Exception(G::LoadTranslation("ID_VARIABLE_IN_USE", array($variableUid, $row["DYN_UID"])));
} }
} }
} }
} }
} }
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -668,13 +644,14 @@ class Variable
* @param string $variableName Variable name * @param string $variableName Variable name
* @param array $arrayVariable The variables * @param array $arrayVariable The variables
* *
* return array Return an array with all records * @return array, return an array with all records
* @throws Exception
*/ */
public function executeSqlSuggest($processUid, $variableName, array $arrayVariable = array()) public function executeSqlSuggest($processUid, $variableName, array $arrayVariable = array())
{ {
try { try {
return $this->executeSqlControl($processUid, $arrayVariable); return $this->executeSqlControl($processUid, $arrayVariable);
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -698,7 +675,7 @@ class Variable
return sizeof($row) ? $row : false; return sizeof($row) ? $row : false;
} }
return false; return false;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -712,7 +689,8 @@ class Variable
* @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist * @param bool $throwException Flag to throw the exception if the main parameters are invalid or do not exist
* (TRUE: throw the exception; FALSE: returns FALSE) * (TRUE: throw the exception; FALSE: returns FALSE)
* *
* @return array Returns an array with Variable record, ThrowTheException/FALSE otherwise * @return array, returns an array with Variable record
* @throws Exception, ThrowTheException/FALSE otherwise
*/ */
public function getVariableRecordByName( public function getVariableRecordByName(
$projectUid, $projectUid,
@@ -722,20 +700,17 @@ class Variable
) { ) {
try { try {
$criteria = new \Criteria('workflow'); $criteria = new \Criteria('workflow');
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $projectUid, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL); $criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria); $rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) { if ($rsCriteria->next()) {
$arrayVariableData = $rsCriteria->getRow(); $arrayVariableData = $rsCriteria->getRow();
} else { } else {
if ($throwException) { if ($throwException) {
throw new \Exception( throw new Exception(
$arrayVariableNameForException['$variableName'] . ': ' . $variableName. ' ' . $arrayVariableNameForException['$variableName'] . ': ' . $variableName. ' ' .
\G::LoadTranslation('ID_DOES_NOT_EXIST') G::LoadTranslation('ID_DOES_NOT_EXIST')
); );
} else { } else {
return false; return false;
@@ -744,7 +719,7 @@ class Variable
//Return //Return
return $arrayVariableData; return $arrayVariableData;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }
@@ -753,7 +728,7 @@ class Variable
{ {
$vType = strtolower($type); $vType = strtolower($type);
if(!in_array($vType, $this->variableTypes)) { if(!in_array($vType, $this->variableTypes)) {
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED")); throw new Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED"));
} }
return $vType; return $vType;
} }
@@ -774,7 +749,7 @@ class Variable
* @param type $proUid * @param type $proUid
* @param array $params * @param array $params
* @return array * @return array
* @throws \Exception * @throws Exception
*/ */
public function executeSqlControl($proUid, array $params = array()) public function executeSqlControl($proUid, array $params = array())
{ {
@@ -829,7 +804,7 @@ class Variable
} }
} }
return $result; return $result;
} catch (\Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
} }
} }