2014-06-27 16:38:14 -04:00
|
|
|
<?php
|
|
|
|
|
namespace ProcessMaker\BusinessModel;
|
|
|
|
|
|
2015-02-04 12:38:08 -04:00
|
|
|
use \G;
|
|
|
|
|
|
2014-06-27 16:38:14 -04:00
|
|
|
class Variable
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Create Variable for a Process
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param array $arrayData Data
|
|
|
|
|
*
|
|
|
|
|
* return array Return data of the new Variable created
|
|
|
|
|
*/
|
|
|
|
|
public function create($processUid, array $arrayData)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data
|
2014-06-30 16:31:27 -04:00
|
|
|
Validator::proUid($processUid, '$prj_uid');
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
|
|
|
|
|
|
|
|
|
$this->existsName($processUid, $arrayData["VAR_NAME"]);
|
|
|
|
|
|
2014-08-27 10:40:13 -04:00
|
|
|
$this->throwExceptionFieldDefinition($arrayData);
|
2014-06-30 16:31:27 -04:00
|
|
|
|
2014-06-27 16:38:14 -04:00
|
|
|
//Create
|
|
|
|
|
$cnn = \Propel::getConnection("workflow");
|
|
|
|
|
try {
|
|
|
|
|
$variable = new \ProcessVariables();
|
|
|
|
|
|
|
|
|
|
$sPkProcessVariables = \ProcessMaker\Util\Common::generateUID();
|
|
|
|
|
|
|
|
|
|
$variable->setVarUid($sPkProcessVariables);
|
|
|
|
|
$variable->setPrjUid($processUid);
|
|
|
|
|
|
|
|
|
|
if ($variable->validate()) {
|
|
|
|
|
$cnn->begin();
|
|
|
|
|
|
2014-07-02 12:13:52 -04:00
|
|
|
if (isset($arrayData["VAR_NAME"])) {
|
|
|
|
|
$variable->setVarName($arrayData["VAR_NAME"]);
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_name' )));
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_FIELD_TYPE"])) {
|
|
|
|
|
$variable->setVarFieldType($arrayData["VAR_FIELD_TYPE"]);
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_field_type' )));
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_FIELD_SIZE"])) {
|
|
|
|
|
$variable->setVarFieldSize($arrayData["VAR_FIELD_SIZE"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_LABEL"])) {
|
|
|
|
|
$variable->setVarLabel($arrayData["VAR_LABEL"]);
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$var_label' )));
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_DBCONNECTION"])) {
|
|
|
|
|
$variable->setVarDbconnection($arrayData["VAR_DBCONNECTION"]);
|
|
|
|
|
} else {
|
|
|
|
|
$variable->setVarDbconnection("");
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_SQL"])) {
|
|
|
|
|
$variable->setVarSql($arrayData["VAR_SQL"]);
|
|
|
|
|
} else {
|
|
|
|
|
$variable->setVarSql("");
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_NULL"])) {
|
|
|
|
|
$variable->setVarNull($arrayData["VAR_NULL"]);
|
|
|
|
|
} else {
|
|
|
|
|
$variable->setVarNull(0);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_DEFAULT"])) {
|
|
|
|
|
$variable->setVarDefault($arrayData["VAR_DEFAULT"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_ACCEPTED_VALUES"])) {
|
2014-08-01 10:25:33 -04:00
|
|
|
$encodeAcceptedValues = json_encode($arrayData["VAR_ACCEPTED_VALUES"]);
|
|
|
|
|
$variable->setVarAcceptedValues($encodeAcceptedValues);
|
2014-07-02 12:13:52 -04:00
|
|
|
}
|
2014-06-27 16:38:14 -04:00
|
|
|
$variable->save();
|
|
|
|
|
$cnn->commit();
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$msg = "";
|
|
|
|
|
|
|
|
|
|
foreach ($variable->getValidationFailures() as $validationFailure) {
|
|
|
|
|
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$cnn->rollback();
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
2014-07-02 12:13:52 -04:00
|
|
|
$variable = $this->getVariable($processUid, $sPkProcessVariables);
|
2014-06-27 16:38:14 -04:00
|
|
|
|
2014-07-02 12:13:52 -04:00
|
|
|
return $variable;
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update Variable
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param string $variableUid Unique id of Variable
|
|
|
|
|
* @param array $arrayData Data
|
|
|
|
|
*
|
|
|
|
|
* return array Return data of the Variable updated
|
|
|
|
|
*/
|
|
|
|
|
public function update($processUid, $variableUid, $arrayData)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data
|
2014-06-30 16:31:27 -04:00
|
|
|
Validator::proUid($processUid, '$prj_uid');
|
2014-06-27 16:38:14 -04:00
|
|
|
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
2014-06-30 16:31:27 -04:00
|
|
|
|
2014-08-27 10:40:13 -04:00
|
|
|
$this->throwExceptionFieldDefinition($arrayData);
|
2014-07-02 12:13:52 -04:00
|
|
|
|
2014-06-27 16:38:14 -04:00
|
|
|
//Update
|
|
|
|
|
$cnn = \Propel::getConnection("workflow");
|
|
|
|
|
try {
|
|
|
|
|
$variable = \ProcessVariablesPeer::retrieveByPK($variableUid);
|
2015-04-17 14:08:13 -04:00
|
|
|
$dbConnection = \DbSourcePeer::retrieveByPK($variable->getVarDbconnection(), $variable->getPrjUid());
|
|
|
|
|
|
2015-03-31 16:33:28 -04:00
|
|
|
$oldVariable = array(
|
|
|
|
|
"VAR_NAME" => $variable->getVarName(),
|
|
|
|
|
"VAR_FIELD_TYPE" => $variable->getVarFieldType(),
|
|
|
|
|
"VAR_DBCONNECTION" => $variable->getVarDbconnection(),
|
2015-04-17 14:08:13 -04:00
|
|
|
"VAR_DBCONNECTION_LABEL" => $dbConnection !== null ? '[' . $dbConnection->getDbsServer() . ':' . $dbConnection->getDbsPort() . '] ' . $dbConnection->getDbsType() . ': ' . $dbConnection->getDbsDatabaseName() : 'PM Database',
|
2015-03-31 16:33:28 -04:00
|
|
|
"VAR_SQL" => $variable->getVarSql(),
|
|
|
|
|
"VAR_ACCEPTED_VALUES" => $variable->getVarAcceptedValues()
|
|
|
|
|
);
|
2014-06-27 16:38:14 -04:00
|
|
|
if ($variable->validate()) {
|
|
|
|
|
$cnn->begin();
|
2014-07-02 12:13:52 -04:00
|
|
|
if (isset($arrayData["VAR_NAME"])) {
|
|
|
|
|
$this->existsName($processUid, $arrayData["VAR_NAME"]);
|
|
|
|
|
$variable->setVarName($arrayData["VAR_NAME"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_FIELD_TYPE"])) {
|
|
|
|
|
$variable->setVarFieldType($arrayData["VAR_FIELD_TYPE"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_FIELD_SIZE"])) {
|
|
|
|
|
$variable->setVarFieldSize($arrayData["VAR_FIELD_SIZE"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_LABEL"])) {
|
|
|
|
|
$variable->setVarLabel($arrayData["VAR_LABEL"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_DBCONNECTION"])) {
|
|
|
|
|
$variable->setVarDbconnection($arrayData["VAR_DBCONNECTION"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_SQL"])) {
|
|
|
|
|
$variable->setVarSql($arrayData["VAR_SQL"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_NULL"])) {
|
|
|
|
|
$variable->setVarNull($arrayData["VAR_NULL"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_DEFAULT"])) {
|
|
|
|
|
$variable->setVarDefault($arrayData["VAR_DEFAULT"]);
|
|
|
|
|
}
|
|
|
|
|
if (isset($arrayData["VAR_ACCEPTED_VALUES"])) {
|
2014-08-01 10:25:33 -04:00
|
|
|
$encodeAcceptedValues = json_encode($arrayData["VAR_ACCEPTED_VALUES"]);
|
|
|
|
|
$variable->setVarAcceptedValues($encodeAcceptedValues);
|
2014-07-02 12:13:52 -04:00
|
|
|
}
|
2014-06-27 16:38:14 -04:00
|
|
|
$variable->save();
|
|
|
|
|
$cnn->commit();
|
2015-03-31 16:33:28 -04:00
|
|
|
//update dynaforms
|
2015-04-17 14:08:13 -04:00
|
|
|
$dbConnection = \DbSourcePeer::retrieveByPK($variable->getVarDbconnection(), $variable->getPrjUid());
|
2015-03-31 16:33:28 -04:00
|
|
|
$newVariable = array(
|
|
|
|
|
"VAR_NAME" => $variable->getVarName(),
|
|
|
|
|
"VAR_FIELD_TYPE" => $variable->getVarFieldType(),
|
|
|
|
|
"VAR_DBCONNECTION" => $variable->getVarDbconnection(),
|
2015-04-17 14:08:13 -04:00
|
|
|
"VAR_DBCONNECTION_LABEL" => $dbConnection !== null ? '[' . $dbConnection->getDbsServer() . ':' . $dbConnection->getDbsPort() . '] ' . $dbConnection->getDbsType() . ': ' . $dbConnection->getDbsDatabaseName() : 'PM Database',
|
2015-03-31 16:33:28 -04:00
|
|
|
"VAR_SQL" => $variable->getVarSql(),
|
|
|
|
|
"VAR_ACCEPTED_VALUES" => $variable->getVarAcceptedValues()
|
|
|
|
|
);
|
|
|
|
|
\G::LoadClass('pmDynaform');
|
|
|
|
|
$pmDynaform = new \pmDynaform();
|
|
|
|
|
$pmDynaform->synchronizeVariable($processUid, $newVariable, $oldVariable);
|
2014-06-27 16:38:14 -04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$msg = "";
|
|
|
|
|
|
|
|
|
|
foreach ($variable->getValidationFailures() as $validationFailure) {
|
|
|
|
|
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . "\n" . $msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$cnn->rollback();
|
|
|
|
|
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete Variable
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param string $variableUid Unique id of Variable
|
|
|
|
|
*
|
|
|
|
|
* return void
|
|
|
|
|
*/
|
|
|
|
|
public function delete($processUid, $variableUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data
|
2014-06-30 16:31:27 -04:00
|
|
|
Validator::proUid($processUid, '$prj_uid');
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$this->throwExceptionIfNotExistsVariable($variableUid);
|
2014-08-01 10:25:33 -04:00
|
|
|
|
2015-03-31 16:33:28 -04:00
|
|
|
$variable = $this->getVariable($processUid, $variableUid);
|
|
|
|
|
\G::LoadClass('pmDynaform');
|
|
|
|
|
$pmDynaform = new \pmDynaform();
|
|
|
|
|
$isUsed = $pmDynaform->isUsed($processUid, $variable);
|
|
|
|
|
if ($isUsed !== false) {
|
2015-04-08 12:33:23 -04:00
|
|
|
$titleDynaform=$pmDynaform->getDynaformTitle($isUsed);
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($titleDynaform)));
|
2015-03-31 16:33:28 -04:00
|
|
|
}
|
2014-06-27 16:38:14 -04:00
|
|
|
//Delete
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid);
|
|
|
|
|
|
|
|
|
|
\ProcessVariablesPeer::doDelete($criteria);
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of a Variable
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param string $variableUid Unique id of Variable
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of a Variable
|
|
|
|
|
*/
|
|
|
|
|
public function getVariable($processUid, $variableUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data
|
2014-06-30 16:31:27 -04:00
|
|
|
Validator::proUid($processUid, '$prj_uid');
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$this->throwExceptionIfNotExistsVariable($variableUid);
|
|
|
|
|
|
|
|
|
|
//Get data
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_FIELD_TYPE);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_FIELD_SIZE);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_LABEL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DBCONNECTION);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_SQL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NULL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DEFAULT);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_ACCEPTED_VALUES);
|
2015-04-17 14:08:13 -04:00
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_SERVER);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_PORT);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE);
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL);
|
2015-04-17 14:08:13 -04:00
|
|
|
$criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID, \Criteria::LEFT_JOIN);
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
|
|
|
|
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
$arrayVariables = array();
|
|
|
|
|
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$arrayVariables = array('var_uid' => $aRow['VAR_UID'],
|
|
|
|
|
'prj_uid' => $aRow['PRJ_UID'],
|
|
|
|
|
'var_name' => $aRow['VAR_NAME'],
|
|
|
|
|
'var_field_type' => $aRow['VAR_FIELD_TYPE'],
|
2014-07-02 12:13:52 -04:00
|
|
|
'var_field_size' => (int)$aRow['VAR_FIELD_SIZE'],
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_label' => $aRow['VAR_LABEL'],
|
2015-04-17 14:08:13 -04:00
|
|
|
'var_dbconnection' => $aRow['VAR_DBCONNECTION'] === 'none' ? 'workflow' : $aRow['VAR_DBCONNECTION'],
|
|
|
|
|
'var_dbconnection_label' => $aRow['DBS_SERVER'] !== null ? '[' . $aRow['DBS_SERVER'] . ':' . $aRow['DBS_PORT'] . '] ' . $aRow['DBS_TYPE'] . ': ' . $aRow['DBS_DATABASE_NAME'] : 'PM Database',
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_sql' => $aRow['VAR_SQL'],
|
2014-07-02 12:13:52 -04:00
|
|
|
'var_null' => (int)$aRow['VAR_NULL'],
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_default' => $aRow['VAR_DEFAULT'],
|
|
|
|
|
'var_accepted_values' => $aRow['VAR_ACCEPTED_VALUES']);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
}
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayVariables;
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get data of Variables
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with data of a DynaForm
|
|
|
|
|
*/
|
|
|
|
|
public function getVariables($processUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
//Verify data
|
2014-06-30 16:31:27 -04:00
|
|
|
Validator::proUid($processUid, '$prj_uid');
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
//Get data
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::PRJ_UID);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_FIELD_TYPE);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_FIELD_SIZE);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_LABEL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DBCONNECTION);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_SQL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NULL);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_DEFAULT);
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_ACCEPTED_VALUES);
|
2015-04-17 14:08:13 -04:00
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_SERVER);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_PORT);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_DATABASE_NAME);
|
|
|
|
|
$criteria->addSelectColumn(\DbSourcePeer::DBS_TYPE);
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
2015-04-17 14:08:13 -04:00
|
|
|
$criteria->addJoin(\ProcessVariablesPeer::VAR_DBCONNECTION, \DbSourcePeer::DBS_UID, \Criteria::LEFT_JOIN);
|
2014-06-27 16:38:14 -04:00
|
|
|
|
|
|
|
|
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
|
|
|
|
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
$arrayVariables = array();
|
|
|
|
|
|
|
|
|
|
while ($aRow = $rsCriteria->getRow()) {
|
|
|
|
|
$arrayVariables[] = array('var_uid' => $aRow['VAR_UID'],
|
|
|
|
|
'prj_uid' => $aRow['PRJ_UID'],
|
|
|
|
|
'var_name' => $aRow['VAR_NAME'],
|
|
|
|
|
'var_field_type' => $aRow['VAR_FIELD_TYPE'],
|
2014-07-02 12:13:52 -04:00
|
|
|
'var_field_size' => (int)$aRow['VAR_FIELD_SIZE'],
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_label' => $aRow['VAR_LABEL'],
|
2015-04-17 14:08:13 -04:00
|
|
|
'var_dbconnection' => $aRow['VAR_DBCONNECTION'] === 'none' ? 'workflow' : $aRow['VAR_DBCONNECTION'],
|
|
|
|
|
'var_dbconnection_label' => $aRow['DBS_SERVER'] !== null ? '[' . $aRow['DBS_SERVER'] . ':' . $aRow['DBS_PORT'] . '] ' . $aRow['DBS_TYPE'] . ': ' . $aRow['DBS_DATABASE_NAME'] : 'PM Database',
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_sql' => $aRow['VAR_SQL'],
|
2014-07-02 12:13:52 -04:00
|
|
|
'var_null' => (int)$aRow['VAR_NULL'],
|
2014-06-27 16:38:14 -04:00
|
|
|
'var_default' => $aRow['VAR_DEFAULT'],
|
|
|
|
|
'var_accepted_values' => $aRow['VAR_ACCEPTED_VALUES']);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
}
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayVariables;
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-06-30 16:31:27 -04:00
|
|
|
* Verify field definition
|
2014-06-27 16:38:14 -04:00
|
|
|
*
|
2014-06-30 16:31:27 -04:00
|
|
|
* @param array $aData Unique id of Variable to exclude
|
2014-06-27 16:38:14 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2014-06-30 16:31:27 -04:00
|
|
|
public function throwExceptionFieldDefinition($aData)
|
2014-06-27 16:38:14 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-06-30 16:31:27 -04:00
|
|
|
if (isset($aData["VAR_NAME"])) {
|
|
|
|
|
Validator::isString($aData['VAR_NAME'], '$var_name');
|
2014-07-02 12:13:52 -04:00
|
|
|
Validator::isNotEmpty($aData['VAR_NAME'], '$var_name');
|
2014-06-30 16:31:27 -04:00
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_FIELD_TYPE"])) {
|
|
|
|
|
Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type');
|
2014-07-02 12:13:52 -04:00
|
|
|
Validator::isNotEmpty($aData['VAR_FIELD_TYPE'], '$var_field_type');
|
2014-08-27 10:40:13 -04:00
|
|
|
/*if ($aData["VAR_FIELD_TYPE"] != 'string' && $aData["VAR_FIELD_TYPE"] != 'integer' && $aData["VAR_FIELD_TYPE"] != 'boolean' && $aData["VAR_FIELD_TYPE"] != 'float' &&
|
2014-07-07 16:09:04 -04:00
|
|
|
$aData["VAR_FIELD_TYPE"] != 'datetime' && $aData["VAR_FIELD_TYPE"] != 'date_of_birth' && $aData["VAR_FIELD_TYPE"] != 'date') {
|
2014-07-04 09:56:01 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_FOR", array('$var_field_type')));
|
2014-08-27 10:40:13 -04:00
|
|
|
}*/
|
2014-06-30 16:31:27 -04:00
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_FIELD_SIZE"])) {
|
|
|
|
|
Validator::isInteger($aData["VAR_FIELD_SIZE"], '$var_field_size');
|
|
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_LABEL"])) {
|
|
|
|
|
Validator::isString($aData['VAR_LABEL'], '$var_label');
|
2014-07-02 12:13:52 -04:00
|
|
|
Validator::isNotEmpty($aData['VAR_LABEL'], '$var_label');
|
2014-06-30 16:31:27 -04:00
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_DBCONNECTION"])) {
|
|
|
|
|
Validator::isString($aData['VAR_DBCONNECTION'], '$var_dbconnection');
|
|
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_SQL"])) {
|
|
|
|
|
Validator::isString($aData['VAR_SQL'], '$var_sql');
|
|
|
|
|
}
|
|
|
|
|
if (isset($aData["VAR_NULL"])) {
|
2014-07-01 11:30:44 -04:00
|
|
|
Validator::isInteger($aData['VAR_NULL'], '$var_null');
|
2014-07-02 08:59:22 -04:00
|
|
|
if ($aData["VAR_NULL"] != 0 && $aData["VAR_NULL"] !=1 ) {
|
2014-07-01 11:30:44 -04:00
|
|
|
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array('$var_null','0, 1' )));
|
|
|
|
|
}
|
2014-06-30 16:31:27 -04:00
|
|
|
}
|
2014-06-27 16:38:14 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if exists the name of a variable
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param string $variableName Name
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function existsName($processUid, $variableName)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $variableName, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
if ($rsCriteria->getRow()) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("DYNAFIELD_ALREADY_EXIST"));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-30 16:26:12 -04:00
|
|
|
/**
|
|
|
|
|
* Get required variables in the SQL
|
|
|
|
|
*
|
|
|
|
|
* @param string $sql SQL
|
|
|
|
|
*
|
|
|
|
|
* return array Return an array with required variables in the SQL
|
|
|
|
|
*/
|
|
|
|
|
public function sqlGetRequiredVariables($sql)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$arrayVariableRequired = array();
|
|
|
|
|
|
|
|
|
|
preg_match_all("/@[@%#\?\x24\=]([A-Za-z_]\w*)/", $sql, $arrayMatch, PREG_SET_ORDER);
|
|
|
|
|
|
|
|
|
|
foreach ($arrayMatch as $value) {
|
|
|
|
|
$arrayVariableRequired[] = $value[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $arrayVariableRequired;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if some required variable in the SQL is missing in the variables
|
|
|
|
|
*
|
|
|
|
|
* @param string $variableName Variable name
|
|
|
|
|
* @param string $variableSql SQL
|
|
|
|
|
* @param array $arrayVariable The variables
|
|
|
|
|
*
|
|
|
|
|
* return void Throw exception if some required variable in the SQL is missing in the variables
|
|
|
|
|
*/
|
|
|
|
|
public function throwExceptionIfSomeRequiredVariableSqlIsMissingInVariables($variableName, $variableSql, array $arrayVariable)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$arrayResult = array_diff(array_unique($this->sqlGetRequiredVariables($variableSql)), array_keys($arrayVariable));
|
|
|
|
|
|
|
|
|
|
if (count($arrayResult) > 0) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_PROCESS_VARIABLE_REQUIRED_VARIABLES_FOR_QUERY", array($variableName, implode(", ", $arrayResult))));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all records by execute SQL
|
|
|
|
|
*
|
|
|
|
|
* @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 executeSql($processUid, $variableName, array $arrayVariable = array())
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$arrayRecord = array();
|
|
|
|
|
|
|
|
|
|
//Verify data
|
|
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
|
|
|
|
|
|
|
|
|
$process->throwExceptionIfNotExistsProcess($processUid, strtolower("PRJ_UID"));
|
|
|
|
|
|
|
|
|
|
//Set data
|
2015-04-03 14:31:32 -04:00
|
|
|
\G::LoadClass('pmDynaform');
|
|
|
|
|
$pmDynaform = new \pmDynaform();
|
|
|
|
|
$field = $pmDynaform->searchField($arrayVariable["dyn_uid"], $arrayVariable["field_id"]);
|
|
|
|
|
$variableDbConnectionUid = $field !== null ? $field->dbConnection : "";
|
|
|
|
|
$variableSql = $field !== null ? $field->sql : "";
|
|
|
|
|
|
2014-06-30 16:26:12 -04:00
|
|
|
//Get data
|
|
|
|
|
$_SESSION["PROCESS"] = $processUid;
|
|
|
|
|
|
|
|
|
|
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
|
|
|
|
|
$stmt = $cnn->createStatement();
|
|
|
|
|
|
2015-02-04 12:38:08 -04:00
|
|
|
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
|
|
|
|
|
|
|
|
|
|
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
|
2014-06-30 16:26:12 -04:00
|
|
|
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
|
|
|
|
$arrayRecord[] = array(
|
|
|
|
|
strtolower("VALUE") => $row[0],
|
2015-04-03 14:31:32 -04:00
|
|
|
strtolower("TEXT") => isset($row[1]) ? $row[1] : $row[0]
|
2014-06-30 16:26:12 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayRecord;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-02 09:28:21 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if does not exist the variable in table PROCESS_VARIABLES
|
|
|
|
|
*
|
|
|
|
|
* @param string $variableUid Unique id of variable
|
|
|
|
|
*
|
|
|
|
|
* return void Throw exception if does not exist the variable in table PROCESS_VARIABLES
|
|
|
|
|
*/
|
|
|
|
|
public function throwExceptionIfNotExistsVariable($variableUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$obj = \ProcessVariablesPeer::retrieveByPK($variableUid);
|
|
|
|
|
|
|
|
|
|
if (is_null($obj)) {
|
|
|
|
|
throw new \Exception('var_uid: '.$variableUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST"));
|
|
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-01 10:25:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if the variable is being used in a Dynaform
|
|
|
|
|
*
|
|
|
|
|
* @param string $processUid Unique id of Process
|
|
|
|
|
* @param string $variableUid Unique id of Variable
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function verifyUse($processUid, $variableUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\DynaformPeer::DYN_CONTENT);
|
|
|
|
|
$criteria->addSelectColumn(\DynaformPeer::DYN_UID);
|
|
|
|
|
$criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \DynaformPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
while ($rsCriteria->next()) {
|
|
|
|
|
|
|
|
|
|
$row = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
$contentDecode = json_decode($row["DYN_CONTENT"], true);
|
|
|
|
|
$content = $contentDecode['items'][0]['items'];
|
2014-08-27 10:08:12 -04:00
|
|
|
if (is_array($content)) {
|
|
|
|
|
foreach ($content as $key => $value) {
|
|
|
|
|
if (isset($value[0]["variable"])) {
|
|
|
|
|
$criteria = new \Criteria("workflow");
|
|
|
|
|
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_NAME);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::PRJ_UID, $processUid, \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::VAR_NAME, $value[0]["variable"], \Criteria::EQUAL);
|
|
|
|
|
$criteria->add(\ProcessVariablesPeer::VAR_UID, $variableUid, \Criteria::EQUAL);
|
|
|
|
|
$rsCriteria = \ProcessVariablesPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rsCriteria->next();
|
|
|
|
|
|
|
|
|
|
if ($rsCriteria->getRow()) {
|
|
|
|
|
throw new \Exception(\G::LoadTranslation("ID_VARIABLE_IN_USE", array($variableUid, $row["DYN_UID"])));
|
|
|
|
|
}
|
2014-08-01 10:25:33 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-08 12:43:07 -04:00
|
|
|
}
|
2014-08-01 10:25:33 -04:00
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-09 15:22:40 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 = "";
|
2015-01-09 17:07:49 -04:00
|
|
|
$sqlConditionLike = "";
|
2014-10-09 15:22:40 -04:00
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2014-10-10 11:59:49 -04:00
|
|
|
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
|
|
|
|
|
$stmt = $cnn->createStatement();
|
2015-02-04 12:38:08 -04:00
|
|
|
$replaceFields = G::replaceDataField($sqlQuery, $arrayVariable);
|
2014-10-10 11:59:49 -04:00
|
|
|
|
2015-02-04 12:38:08 -04:00
|
|
|
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
|
2014-10-09 15:22:40 -04:00
|
|
|
|
|
|
|
|
while ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
|
|
|
|
$arrayRecord[] = array(
|
|
|
|
|
strtolower("VALUE") => $row[0],
|
|
|
|
|
strtolower("TEXT") => $row[1]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayRecord;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-27 16:38:14 -04:00
|
|
|
}
|