Merge branch 'master' of bitbucket.org:colosa/processmaker into LISTS

This commit is contained in:
Brayan Pereyra
2015-02-06 15:48:38 -04:00
59 changed files with 3085 additions and 1157 deletions

View File

@@ -225,7 +225,7 @@ class EmailServer
try {
$arrayTestMailResult = $this->sendTestMail($arrayDataMail);
} catch (Exception $error) {
} catch (Exception $e) {
$arrayTestMailResult["status"] = false;
$arrayTestMailResult["message"] = $e->getMessage();

View File

@@ -1,415 +0,0 @@
<?php
namespace ProcessMaker\BusinessModel;
class Message
{
/**
* Create Message for a Process
*
* @param string $processUid Unique id of Message
* @param array $arrayData Data
*
* return array Return data of the new Message created
*/
public function create($processUid, array $arrayData)
{
try {
//Verify data
Validator::proUid($processUid, '$prj_uid');
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->existsName($processUid, $arrayData["MES_NAME"]);
$this->throwExceptionFieldDefinition($arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$message = new \Message();
$sPkMessage = \ProcessMaker\Util\Common::generateUID();
$message->setMesUid($sPkMessage);
$message->setPrjUid($processUid);
if ($message->validate()) {
$cnn->begin();
if (isset($arrayData["MES_NAME"])) {
$message->setMesName($arrayData["MES_NAME"]);
} else {
throw new \Exception(\G::LoadTranslation("ID_CAN_NOT_BE_NULL", array('$mes_name' )));
}
if (isset($arrayData["MES_DETAIL"])) {
foreach ($arrayData["MES_DETAIL"] as $i => $type) {
$messageDetail = new \MessageDetail();
$sPkMessageDetail = \ProcessMaker\Util\Common::generateUID();
$messageDetail->setMdUid($sPkMessageDetail);
$messageDetail->setMdType($type["md_type"]);
$messageDetail->setMdName($type["md_name"]);
$messageDetail->setMesUid($sPkMessage);
$messageDetail->save();
}
}
$message->save();
$cnn->commit();
} else {
$msg = "";
foreach ($message->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
$message = $this->getMessage($processUid, $sPkMessage);
return $message;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Message
*
* @param string $processUid Unique id of Process
* @param string $messageUid Unique id of Message
* @param array $arrayData Data
*
* return array Return data of the Message updated
*/
public function update($processUid, $messageUid, $arrayData)
{
try {
//Verify data
Validator::proUid($processUid, '$prj_uid');
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->throwExceptionFieldDefinition($arrayData);
//Update
$cnn = \Propel::getConnection("workflow");
try {
$message = \MessagePeer::retrieveByPK($messageUid);
if (is_null($message)) {
throw new \Exception('mes_uid: '.$messageUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST"));
} else {
$cnn->begin();
if (isset($arrayData["MES_NAME"])) {
$this->existsName($processUid, $arrayData["MES_NAME"]);
$message->setMesName($arrayData["MES_NAME"]);
}
if (isset($arrayData["MES_DETAIL"])) {
foreach ($arrayData["MES_DETAIL"] as $i => $type) {
$messageDetail = \MessageDetailPeer::retrieveByPK($type["md_uid"]);
if (is_null($messageDetail)) {
throw new \Exception('md_uid: '.$type["md_uid"]. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST"));
} else {
$messageDetail->setMdType($type["md_type"]);
$messageDetail->setMdName($type["md_name"]);
$messageDetail->save();
}
}
}
$message->save();
$cnn->commit();
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message
*
* @param string $processUid Unique id of Process
* @param string $messageUid Unique id of Message
*
* return void
*/
public function delete($processUid, $messageUid)
{
try {
//Verify data
Validator::proUid($processUid, '$prj_uid');
$this->throwExceptionIfNotExistsMessage($messageUid);
//Delete
$criteria = new \Criteria("workflow");
$criteria->add(\MessagePeer::MES_UID, $messageUid);
\MessagePeer::doDelete($criteria);
//Delete Detail
$criteriaDetail = new \Criteria("workflow");
$criteriaDetail->add(\MessageDetailPeer::MES_UID, $messageUid);
\MessageDetailPeer::doDelete($criteriaDetail);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message
* @param string $processUid Unique id of Process
* @param string $messageUid Unique id of Message
*
* return array Return an array with data of a Message
*/
public function getMessage($processUid, $messageUid)
{
try {
//Verify data
Validator::proUid($processUid, '$prj_uid');
$this->throwExceptionIfNotExistsMessage($messageUid);
//Get data
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessagePeer::MES_UID);
$criteria->addSelectColumn(\MessagePeer::MES_NAME);
$criteria->addSelectColumn(\MessagePeer::PRJ_UID);
$criteria->add(\MessagePeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\MessagePeer::MES_UID, $messageUid, \Criteria::EQUAL);
$rsCriteria = \MessagePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$arrayMessage = array();
while ($aRow = $rsCriteria->getRow()) {
$oCriteriaU = new \Criteria('workflow');
$oCriteriaU->setDistinct();
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_UID);
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_NAME);
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_TYPE);
$oCriteriaU->add(\MessageDetailPeer::MES_UID, $aRow['MES_UID']);
$oDatasetU = \MessageDetailPeer::doSelectRS($oCriteriaU);
$oDatasetU->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$aType = array();
while ($oDatasetU->next()) {
$aRowU = $oDatasetU->getRow();
$aType[] = array('md_uid' => $aRowU['MD_UID'],
'md_name' => $aRowU['MD_NAME'],
'md_type' => $aRowU['MD_TYPE']);
}
$arrayMessage = array('mes_uid' => $aRow['MES_UID'],
'prj_uid' => $aRow['PRJ_UID'],
'mes_name' => $aRow['MES_NAME'],
'mes_detail' => $aType);
$rsCriteria->next();
}
//Return
return $arrayMessage;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of Message
*
* @param string $processUid Unique id of Message
*
* return array Return an array with data of a Message
*/
public function getMessages($processUid)
{
try {
//Verify data
Validator::proUid($processUid, '$prj_uid');
//Get data
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessagePeer::MES_UID);
$criteria->addSelectColumn(\MessagePeer::MES_NAME);
$criteria->addSelectColumn(\MessagePeer::PRJ_UID);
$criteria->add(\MessagePeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$rsCriteria = \MessagePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$arrayMessages = array();
while ($aRow = $rsCriteria->getRow()) {
$oCriteriaU = new \Criteria('workflow');
$oCriteriaU->setDistinct();
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_UID);
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_NAME);
$oCriteriaU->addSelectColumn(\MessageDetailPeer::MD_TYPE);
$oCriteriaU->add(\MessageDetailPeer::MES_UID, $aRow['MES_UID']);
$oDatasetU = \MessageDetailPeer::doSelectRS($oCriteriaU);
$oDatasetU->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$aType = array();
while ($oDatasetU->next()) {
$aRowU = $oDatasetU->getRow();
$aType[] = array('md_uid' => $aRowU['MD_UID'],
'md_name' => $aRowU['MD_NAME'],
'mes_type' => $aRowU['MD_TYPE']);
}
$arrayMessages[] = array('mes_uid' => $aRow['MES_UID'],
'prj_uid' => $aRow['PRJ_UID'],
'mes_name' => $aRow['MES_NAME'],
'mes_detail' => $aType);
$rsCriteria->next();
}
//Return
return $arrayMessages;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify field definition
*
* @param array $aData Unique id of Message to exclude
*
*/
public function throwExceptionFieldDefinition($aData)
{
try {
if (isset($aData["MES_NAME"])) {
Validator::isString($aData['MES_NAME'], '$mes_name');
Validator::isNotEmpty($aData['MES_NAME'], '$mes_name');
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the name of a message
*
* @param string $processUid Unique id of Process
* @param string $messageName Name
*
*/
public function existsName($processUid, $messageName)
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessagePeer::MES_UID);
$criteria->add(\MessagePeer::MES_NAME, $messageName, \Criteria::EQUAL);
$criteria->add(\MessagePeer::PRJ_UID, $processUid, \Criteria::EQUAL);
$rsCriteria = \MessagePeer::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;
}
}
/**
* 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;
}
}
/**
* Verify if does not exist the message in table MESSAGE
*
* @param string $messageUid Unique id of variable
*
* return void Throw exception if does not exist the message in table MESSAGE
*/
public function throwExceptionIfNotExistsMessage($messageUid)
{
try {
$obj = \MessagePeer::retrieveByPK($messageUid);
if (is_null($obj)) {
throw new \Exception('mes_uid: '.$messageUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST"));
}
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,727 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageType
{
private $arrayFieldDefinition = array(
"MSGT_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"MSGT_NAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeName"),
"MSGT_VARIABLES" => array("type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageTypeVariables")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"start" => "START",
"limit" => "LIMIT"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messageTypes for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Message-Type
*
* @param string $messageTypeUid Unique id of Message-Type
*
* return bool Return true if exists the Message-Type, false otherwise
*/
public function exists($messageTypeUid)
{
try {
$obj = \MessageTypePeer::retrieveByPK($messageTypeUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Name of a Message-Type
*
* @param string $projectUid Unique id of Project
* @param string $messageTypeName Name
* @param string $messageTypeUidToExclude Unique id of Message to exclude
*
* return bool Return true if exists the Name of a Message-Type, false otherwise
*/
public function existsName($projectUid, $messageTypeName, $messageTypeUidToExclude = "")
{
try {
$criteria = $this->getMessageTypeCriteria();
if ($messageTypeUidToExclude != "") {
$criteria->add(\MessageTypePeer::MSGT_UID, $messageTypeUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageTypePeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$criteria->add(\MessageTypePeer::MSGT_NAME, $messageTypeName, \Criteria::EQUAL);
//QUERY
$rsCriteria = \MessageTypePeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
public function throwExceptionCheckIfThereIsRepeatedVariableName(array $arrayDataVariables)
{
try {
$i = 0;
$arrayDataVarAux = $arrayDataVariables;
while ($i <= count($arrayDataVariables) - 1) {
if (array_key_exists("MSGTV_NAME", $arrayDataVariables[$i])) {
$msgtvNameAux = $arrayDataVariables[$i]["MSGTV_NAME"];
$counter = 0;
foreach ($arrayDataVarAux as $key => $value) {
if ($value["MSGTV_NAME"] == $msgtvNameAux) {
$counter = $counter + 1;
}
}
if ($counter > 1) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_NAME_VARIABLE_EXISTS", array($value["MSGTV_NAME"])));
}
}
$i = $i + 1;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Name of a Message-Type
*
* @param string $projectUid Unique id of Project
* @param string $messageTypeName Name
* @param string $fieldNameForException Field name for the exception
* @param string $messageTypeUidToExclude Unique id of Message-Type to exclude
*
* return void Throw exception if exists the title of a Message-Type
*/
public function throwExceptionIfExistsName($projectUid, $messageTypeName, $fieldNameForException, $messageTypeUidToExclude = "")
{
try {
if ($this->existsName($projectUid, $messageTypeName, $messageTypeUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_NAME_ALREADY_EXISTS", array($fieldNameForException, $messageTypeName)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageTypeUid Unique id of Message-Type
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageTypeUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageTypeData = ($messageTypeUid == "")? array() : $this->getMessageType($messageTypeUid, true);
$flagInsert = ($messageTypeUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageTypeData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["MSGT_NAME"])) {
$this->throwExceptionIfExistsName($projectUid, $arrayData["MSGT_NAME"], $this->arrayFieldNameForException["messageTypeName"], $messageTypeUid);
}
if (isset($arrayData["MSGT_VARIABLES"]) && count($arrayData["MSGT_VARIABLES"]) > 0) {
$this->throwExceptionCheckIfThereIsRepeatedVariableName($arrayData["MSGT_VARIABLES"]);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exist the Message-Type
*
* @param string $messageTypeUid Unique id of Message-Type
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exist the Message-Type
*/
public function throwExceptionIfNotExistsMessageType($messageTypeUid, $fieldNameForException)
{
try {
$obj = \MessageTypePeer::retrieveByPK($messageTypeUid);
if (!$this->exists($messageTypeUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_DOES_NOT_EXIST", array($fieldNameForException, $messageTypeUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Type
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Type created
*/
public function create($projectUid, array $arrayData)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
if (isset($arrayData["MSGT_VARIABLES"]) && is_array($arrayData["MSGT_VARIABLES"])) {
foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
$arrayData["MSGT_VARIABLES"][$key] = array_change_key_case($value, CASE_UPPER);
}
}
unset($arrayData["MSGT_UID"]);
unset($arrayData["PRJ_UID"]);
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageType = new \MessageType();
$messageType->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageTypeUid = \ProcessMaker\Util\Common::generateUID();
$messageType->setMsgtUid($messageTypeUid);
$messageType->setPrjUid($projectUid);
if ($messageType->validate()) {
$cnn->begin();
$result = $messageType->save();
$cnn->commit();
if (isset($arrayData["MSGT_VARIABLES"]) && count($arrayData["MSGT_VARIABLES"]) > 0) {
$variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
$variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
$arrayVariable = $value;
$arrayResult = $variable->create($messageTypeUid, $arrayVariable);
}
}
//Return
return $this->getMessageType($messageTypeUid);
} else {
$msg = "";
foreach ($messageType->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Single create Message-Type
*
* @param array $arrayData Data
*
* return int Return integer
*/
public function singleCreate(array $arrayData)
{
try {
$cnn = \Propel::getConnection("workflow");
try {
$messageType = new \MessageType();
$messageType->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($messageType->validate()) {
$cnn->begin();
$result = $messageType->save();
$cnn->commit();
//Return
return $result;
} else {
$msg = "";
foreach ($messageType->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Message-Type
*
* @param string $messageTypeUid Unique id of Message-Type
* @param array $arrayData Data
*
* return array Return data of the Message-Type updated
*/
public function update($messageTypeUid, $arrayData)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
$arrayDataBackup = $arrayData;
unset($arrayData["MSGT_UID"]);
unset($arrayData["PRJ_UID"]);
if (isset($arrayData["MSGT_VARIABLES"]) && is_array($arrayData["MSGT_VARIABLES"])) {
foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
$arrayData["MSGT_VARIABLES"][$key] = array_change_key_case($value, CASE_UPPER);
}
}
//Set variables
$arrayMessageTypeData = $this->getMessageType($messageTypeUid, true);
//Verify data
$this->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
$this->throwExceptionIfDataIsInvalid($messageTypeUid, $arrayMessageTypeData["PRJ_UID"], $arrayData);
//Update
$cnn = \Propel::getConnection("workflow");
try {
$messageType = \MessageTypePeer::retrieveByPK($messageTypeUid);
$messageType->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($messageType->validate()) {
$cnn->begin();
$result = $messageType->save();
$cnn->commit();
//----- *****
$variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
$variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$criteria = new \Criteria("workflow");
$criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
\MessageTypeVariablePeer::doDelete($criteria);
if (isset($arrayData["MSGT_VARIABLES"]) && count($arrayData["MSGT_VARIABLES"]) > 0) {
$variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
$variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
foreach ($arrayData["MSGT_VARIABLES"] as $key => $value) {
$arrayVariable = $value;
$arrayResult = $variable->create($messageTypeUid, $arrayVariable);
}
}
//----- *****
//Return
$arrayData = $arrayDataBackup;
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} else {
$msg = "";
foreach ($messageType->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message-Type
*
* @param string $messageTypeUid Unique id of Message-Type
*
* return void
*/
public function delete($messageTypeUid)
{
try {
$this->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
//Delete Message-Type-Variable
$criteria = new \Criteria("workflow");
$criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
\MessageTypeVariablePeer::doDelete($criteria);
//Delete Message-Type
$criteria = $this->getMessageTypeCriteria();
$criteria->add(\MessageTypePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
\MessageTypePeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Type
*
* return object
*/
public function getMessageTypeCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageTypePeer::MSGT_UID);
$criteria->addSelectColumn(\MessageTypePeer::PRJ_UID);
$criteria->addSelectColumn(\MessageTypePeer::MSGT_NAME);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Type
*/
public function getMessageTypeDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGT_UID") => $record["MSGT_UID"],
$this->getFieldNameByFormatFieldName("MSGT_NAME") => $record["MSGT_NAME"],
$this->getFieldNameByFormatFieldName("MSGT_VARIABLES") => $record["MSGT_VARIABLES"]
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Message-Type
*
* @param string $projectUid {@min 32}{@max 32}
* @param array $arrayFilterData Data of the filters
* @param string $sortField Field name to sort
* @param string $sortDir Direction of sorting (ASC, DESC)
* @param int $start Start
* @param int $limit Limit
*
* return array Return an array with all Message
*/
public function getMessageTypes($projectUid, $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
{
try {
$arrayMessage = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
//Get data
if (!is_null($limit) && $limit . "" == "0") {
return $arrayMessage;
}
//SQL
$criteria = $this->getMessageTypeCriteria();
$criteria->add(\MessageTypePeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
$criteria->add(
$criteria->getNewCriterion(\MessageTypePeer::MSGT_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)
);
}
//Number records total
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addSelectColumn("COUNT(" . \MessageTypePeer::MSGT_UID . ") AS NUM_REC");
$rsCriteriaCount = \MessageTypePeer::doSelectRS($criteriaCount);
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteriaCount->next();
$row = $rsCriteriaCount->getRow();
$numRecTotal = $row["NUM_REC"];
//SQL
if (!is_null($sortField) && trim($sortField) != "") {
$sortField = strtoupper($sortField);
if (in_array($sortField, array("MSGT_NAME"))) {
$sortField = \MessageTypePeer::TABLE_NAME . "." . $sortField;
} else {
$sortField = \MessageTypePeer::MSGT_NAME;
}
} else {
$sortField = \MessageTypePeer::MSGT_NAME;
}
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
$criteria->addDescendingOrderByColumn($sortField);
} else {
$criteria->addAscendingOrderByColumn($sortField);
}
if (!is_null($start)) {
$criteria->setOffset((int)($start));
}
if (!is_null($limit)) {
$criteria->setLimit((int)($limit));
}
$rsCriteria = \MessageTypePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayVariable = array();
$variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
$variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$criteriaMessageTypeVariable = $variable->getMessageTypeVariableCriteria();
$criteriaMessageTypeVariable->add(\MessageTypeVariablePeer::MSGT_UID, $row["MSGT_UID"], \Criteria::EQUAL);
$rsCriteriaMessageTypeVariable = \MessageTypeVariablePeer::doSelectRS($criteriaMessageTypeVariable);
$rsCriteriaMessageTypeVariable->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteriaMessageTypeVariable->next()) {
$row2 = $rsCriteriaMessageTypeVariable->getRow();
$arrayVariable[] = $variable->getMessageTypeVariableDataFromRecord($row2, false);
}
$row["MSGT_VARIABLES"] = $arrayVariable;
$arrayMessage[] = $this->getMessageTypeDataFromRecord($row);
}
//Return
return array(
"total" => $numRecTotal,
"start" => (int)((!is_null($start))? $start : 0),
"limit" => (int)((!is_null($limit))? $limit : 0),
"filter" => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "",
"data" => $arrayMessage
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Type
*
* @param string $messageTypeUid Unique id of Message-Type
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Type
*/
public function getMessageType($messageTypeUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
//Get data
//SQL
$criteria = $this->getMessageTypeCriteria();
$criteria->add(\MessageTypePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
$rsCriteria = \MessageTypePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Variable
$arrayVariable = array();
$variable = new \ProcessMaker\BusinessModel\MessageType\Variable();
$variable->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$criteriaMessageTypeVariable = $variable->getMessageTypeVariableCriteria();
$criteriaMessageTypeVariable->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
$rsCriteriaMessageTypeVariable = \MessageTypeVariablePeer::doSelectRS($criteriaMessageTypeVariable);
$rsCriteriaMessageTypeVariable->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteriaMessageTypeVariable->next()) {
$row2 = $rsCriteriaMessageTypeVariable->getRow();
if (!$flagGetRecord) {
$arrayVariable[] = $variable->getMessageTypeVariableDataFromRecord($row2, false);
} else {
unset($row2["MSGTV_UID"]);
$arrayVariable[] = $row2;
}
}
$row["MSGT_VARIABLES"] = $arrayVariable;
//Return
return (!$flagGetRecord)? $this->getMessageTypeDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,598 @@
<?php
namespace ProcessMaker\BusinessModel\MessageType;
class Variable
{
private $arrayFieldDefinition = array(
"MSGTV_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeVariableUid"),
"MSGT_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
"MSGTV_NAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeVariableName"),
"MSGTV_DEFAULT_VALUE" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageTypeVariableDefaultValue")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"start" => "START",
"limit" => "LIMIT"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set the format of the fields name (uppercase, lowercase)
*
* @param bool $flag Value that set the format
*
* return void
*/
public function setFormatFieldNameInUppercase($flag)
{
try {
$this->formatFieldNameInUppercase = $flag;
$this->setArrayFieldNameForException($this->arrayFieldNameForException);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set exception messages for fields
*
* @param array $arrayData Data with the fields
*
* return void
*/
public function setArrayFieldNameForException(array $arrayData)
{
try {
foreach ($arrayData as $key => $value) {
$this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get the name of the field according to the format
*
* @param string $fieldName Field name
*
* return string Return the field name according the format
*/
public function getFieldNameByFormatFieldName($fieldName)
{
try {
return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Message-Type-Variable
*
* @param string $messageTypeVariableUid Unique id of Message-Type-Variable
*
* return bool Return true if exists the Message-Type-Variable, false otherwise
*/
public function exists($messageTypeVariableUid)
{
try {
$obj = \MessageTypeVariablePeer::retrieveByPK($messageTypeVariableUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Name of a Message-Type-Variable
*
* @param string $messageTypeUid Unique id of Project
* @param string $messageTypeVariableName Name
* @param string $messageTypeVariableUidToExclude Unique id of Message-Type-Variable to exclude
*
* return bool Return true if exists the Name of a Message-Type-Variable, false otherwise
*/
public function existsName($messageTypeUid, $messageTypeVariableName, $messageTypeVariableUidToExclude = "")
{
try {
$criteria = $this->getMessageTypeVariableCriteria();
if ($messageTypeVariableUidToExclude != "") {
$criteria->add(\MessageTypeVariablePeer::MSGTV_UID, $messageTypeVariableUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
$criteria->add(\MessageTypeVariablePeer::MSGTV_NAME, $messageTypeVariableName, \Criteria::EQUAL);
//QUERY
$rsCriteria = \MessageTypeVariablePeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Name of a Message-Type-Variable
*
* @param string $messageTypeUid Unique id of Project
* @param string $messageTypeVariableName Name
* @param string $fieldNameForException Field name for the exception
* @param string $messageTypeVariableUidToExclude Unique id of Message to exclude
*
* return void Throw exception if exists the Name of a Message-Type-Variable
*/
public function throwExceptionIfExistsName($messageTypeUid, $messageTypeVariableName, $fieldNameForException, $messageTypeVariableUidToExclude = "")
{
try {
if ($this->existsName($messageTypeUid, $messageTypeVariableName, $messageTypeVariableUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_VARIABLE_NAME_ALREADY_EXISTS", array($fieldNameForException, $messageTypeVariableName)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageTypeVariableUid Unique id of Message-Type-Variable
* @param string $messageTypeUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageTypeVariableUid, $messageTypeUid, array $arrayData)
{
try {
//Set variables
$arrayMsgTypeVarData = ($messageTypeVariableUid == "")? array() : $this->getMessageTypeVariable($messageTypeVariableUid, true);
$flagInsert = ($messageTypeVariableUid == "")? true : false;
$arrayFinalData = array_merge($arrayMsgTypeVarData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["MSGTV_NAME"])) {
$this->throwExceptionIfExistsName($messageTypeUid, $arrayData["MSGTV_NAME"], $this->arrayFieldNameForException["messageTypeVariableName"], $messageTypeVariableUid);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exist the Message-Type-Variable
*
* @param string $messageTypeVariableUid Unique id of Message-Type-Variable
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exist the Message-Type-Variable
*/
public function throwExceptionIfNotExistsMessageTypeVariable($messageTypeVariableUid, $fieldNameForException)
{
try {
if (!$this->exists($messageTypeVariableUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_TYPE_VARIABLE_DOES_NOT_EXIST", array($fieldNameForException, $messageTypeVariableUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Variable
*
* @param string $messageUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message created
*/
public function create($messageTypeUid, array $arrayData)
{
try {
//Verify data
$validator = new \ProcessMaker\BusinessModel\Validator();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
unset($arrayData["MSGTV_UID"]);
unset($arrayData["MSGT_UID"]);
//Verify data
$messageType->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
$this->throwExceptionIfDataIsInvalid("", $messageTypeUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageTypeVariable = new \MessageTypeVariable();
$messageTypeVariable->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageTypeVariableUid = \ProcessMaker\Util\Common::generateUID();
$messageTypeVariable->setMsgtvUid($messageTypeVariableUid);
$messageTypeVariable->setMsgtUid($messageTypeUid);
if ($messageTypeVariable->validate()) {
$cnn->begin();
$result = $messageTypeVariable->save();
$cnn->commit();
//Return
return $this->getMessageTypeVariable($messageTypeVariableUid);
} else {
$msg = "";
foreach ($messageTypeVariable->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Single create Message-Type-Variable
*
* @param array $arrayData Data
*
* return int Return integer
*/
public function singleCreate(array $arrayData)
{
try {
$cnn = \Propel::getConnection("workflow");
try {
$messageTypeVariable = new \MessageTypeVariable();
$messageTypeVariable->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($messageTypeVariable->validate()) {
$cnn->begin();
$result = $messageTypeVariable->save();
$cnn->commit();
//Return
return $result;
} else {
$msg = "";
foreach ($messageTypeVariable->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Update Message-Type-Variable
*
* @param string $messageTypeVariable Uid Unique id of Message-Type-Variable
* @param array $arrayData Data
*
* return array Return data of the Message-Type-Variable updated
*/
public function update($messageTypeVariableUid, array $arrayData)
{
try {
//Verify data
$validator = new \ProcessMaker\BusinessModel\Validator();
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
//Set data
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
unset($arrayData["MSGTV_UID"]);
unset($arrayData["MSGT_UID"]);
//Set variables
$arrayMessageTypeVariableData = $this->getMessageTypeVariable($messageTypeVariableUid, true);
//Verify data
$this->throwExceptionIfNotExistsMessageTypeVariable($messageTypeVariableUid, $this->arrayFieldNameForException["messageTypeVariableUid"]);
$this->throwExceptionIfDataIsInvalid($messageTypeVariableUid, $arrayMessageTypeVariableData["MSGT_UID"], $arrayData);
//Update
$cnn = \Propel::getConnection("workflow");
try {
$messageTypeVariable = \MessageTypeVariablePeer::retrieveByPK($messageTypeVariableUid);
$messageTypeVariable->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if ($messageTypeVariable->validate()) {
$cnn->begin();
$result = $messageTypeVariable->save();
$cnn->commit();
//Return
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} else {
$msg = "";
foreach ($messageTypeVariable->getValidationFailures() as $validationFailure) {
$msg = $msg . (($msg != "")? "\n" : "") . $validationFailure->getMessage();
}
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
throw $e;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Delete Message-Type-Variable
*
* @param string $messageTypeVariable Uid Unique id of Message-Type
*
* return void
*/
public function delete($messageTypeVariableUid)
{
try {
$this->throwExceptionIfNotExistsMessageTypeVariable($messageTypeVariableUid, $this->arrayFieldNameForException["messageTypeVariableUid"]);
$criteria = $this->getMessageTypeVariableCriteria();
$criteria->add(\MessageTypeVariablePeer::MSGTV_UID, $messageTypeVariableUid, \Criteria::EQUAL);
\MessageTypeVariablePeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Type-Variable
*
* return object
*/
public function getMessageTypeVariableCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageTypeVariablePeer::MSGTV_UID);
$criteria->addSelectColumn(\MessageTypeVariablePeer::MSGT_UID);
$criteria->addSelectColumn(\MessageTypeVariablePeer::MSGTV_NAME);
$criteria->addSelectColumn(\MessageTypeVariablePeer::MSGTV_DEFAULT_VALUE);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Type-Variable
*/
public function getMessageTypeVariableDataFromRecord(array $record, $includeUid = true)
{
try {
$arrayRecord = array();
if ($includeUid) {
$arrayRecord[$this->getFieldNameByFormatFieldName("MSGTV_UID")] = $record["MSGTV_UID"];
}
$arrayRecord[$this->getFieldNameByFormatFieldName("MSGTV_NAME")] = $record["MSGTV_NAME"];
$arrayRecord[$this->getFieldNameByFormatFieldName("MSGTV_DEFAULT_VALUE")] = $record["MSGTV_DEFAULT_VALUE"] . "";
return $arrayRecord;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Message-Type-Variable
*
* @param string $messageTypeUid {@min 32}{@max 32}
* @param array $arrayFilterData Data of the filters
* @param string $sortField Field name to sort
* @param string $sortDir Direction of sorting (ASC, DESC)
* @param int $start Start
* @param int $limit Limit
*
* return array Return an array with all Message-Type-Variable
*/
public function getMessageTypeVariables($messageTypeUid, $arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
{
try {
$arrayMessage = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
$messageType->throwExceptionIfNotExistsMessageType($messageTypeUid, $this->arrayFieldNameForException["messageTypeUid"]);
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
//Get data
if (!is_null($limit) && $limit . "" == "0") {
return $arrayMessage;
}
//SQL
$criteria = $this->getMessageTypeVariableCriteria();
$criteria->add(\MessageTypeVariablePeer::MSGT_UID, $messageTypeUid, \Criteria::EQUAL);
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
$criteria->add(
$criteria->getNewCriterion(\MessageTypeVariablePeer::MSGTV_NAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)
);
}
//Number records total
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addSelectColumn("COUNT(" . \MessageTypeVariablePeer::MSGTV_UID . ") AS NUM_REC");
$rsCriteriaCount = \MessageTypeVariablePeer::doSelectRS($criteriaCount);
$rsCriteriaCount->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteriaCount->next();
$row = $rsCriteriaCount->getRow();
$numRecTotal = $row["NUM_REC"];
//SQL
if (!is_null($sortField) && trim($sortField) != "") {
$sortField = strtoupper($sortField);
if (in_array($sortField, array("MSGTV_NAME"))) {
$sortField = \MessageTypeVariablePeer::TABLE_NAME . "." . $sortField;
} else {
$sortField = \MessageTypeVariablePeer::MSGTV_NAME;
}
} else {
$sortField = \MessageTypeVariablePeer::MSGTV_NAME;
}
if (!is_null($sortDir) && trim($sortDir) != "" && strtoupper($sortDir) == "DESC") {
$criteria->addDescendingOrderByColumn($sortField);
} else {
$criteria->addAscendingOrderByColumn($sortField);
}
if (!is_null($start)) {
$criteria->setOffset((int)($start));
}
if (!is_null($limit)) {
$criteria->setLimit((int)($limit));
}
$rsCriteria = \MessageTypeVariablePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$arrayMessage[] = $this->getMessageTypeVariableDataFromRecord($row);
}
//Return
return array(
"total" => $numRecTotal,
"start" => (int)((!is_null($start))? $start : 0),
"limit" => (int)((!is_null($limit))? $limit : 0),
"filter" => (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]))? $arrayFilterData["filter"] : "",
"data" => $arrayMessage
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Type-Variable
*
* @param string $messageTypeVariableUid Unique id of Message-Type-Variable
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Type-Variable
*/
public function getMessageTypeVariable($messageTypeVariableUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageTypeVariable($messageTypeVariableUid, $this->arrayFieldNameForException["messageTypeVariableUid"]);
//Get data
//SQL
$criteria = $this->getMessageTypeVariableCriteria();
$criteria->add(\MessageTypeVariablePeer::MSGTV_UID, $messageTypeVariableUid, \Criteria::EQUAL);
$rsCriteria = \MessageTypeVariablePeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageTypeVariableDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -1,6 +1,8 @@
<?php
namespace ProcessMaker\BusinessModel;
use \G;
class Variable
{
/**
@@ -487,7 +489,7 @@ class Variable
$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)));
throw new \Exception(G::LoadTranslation("ID_PROCESS_VARIABLE_DOES_NOT_EXIST", array(strtolower("VAR_NAME"), $variableName)));
}
//Verify data
@@ -499,7 +501,9 @@ class Variable
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
$stmt = $cnn->createStatement();
$rs = $stmt->executeQuery(\G::replaceDataField($variableSql, $arrayVariable), \ResultSet::FETCHMODE_NUM);
$replaceFields = G::replaceDataField($variableSql, $arrayVariable);
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) {
$row = $rs->getRow();
@@ -661,8 +665,9 @@ class Variable
$cnn = \Propel::getConnection(($variableDbConnectionUid . "" != "")? $variableDbConnectionUid : "workflow");
$stmt = $cnn->createStatement();
$replaceFields = G::replaceDataField($sqlQuery, $arrayVariable);
$rs = $stmt->executeQuery(\G::replaceDataField($sqlQuery, $arrayVariable), \ResultSet::FETCHMODE_NUM);
$rs = $stmt->executeQuery($replaceFields, \ResultSet::FETCHMODE_NUM);
while ($rs->next()) {
$row = $rs->getRow();