manual merge of the upstream branch

This commit is contained in:
Gustavo Cruz
2015-03-05 16:49:50 -04:00
174 changed files with 27703 additions and 7810 deletions

View File

@@ -1970,4 +1970,222 @@ class Cases
return $aField;
}
/**
* Throw Message-Events for the Case
*
* @param string $elementOriginUid Unique id of Element Origin (unique id of Task)
* @param string $elementDestUid Unique id of Element Dest (unique id of Task)
* @param array $arrayApplicationData Case data
*
* return void
*/
public function throwMessageEventBetweenElementOriginAndElementDest($elementOriginUid, $elementDestUid, array $arrayApplicationData)
{
try {
//Verify if the Project is BPMN
$bpmn = new \ProcessMaker\Project\Bpmn();
if (!$bpmn->exists($arrayApplicationData["PRO_UID"])) {
return;
}
//Element origin and dest
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayElement = array(
"elementOrigin" => array("uid" => $elementOriginUid, "type" => "bpmnActivity"),
"elementDest" => array("uid" => $elementDestUid, "type" => "bpmnActivity")
);
foreach ($arrayElement as $key => $value) {
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $arrayApplicationData["PRO_UID"],
\MessageEventTaskRelationPeer::TAS_UID => $arrayElement[$key]["uid"]
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
$arrayElement[$key]["uid"] = $arrayMessageEventTaskRelationData["EVN_UID"];
$arrayElement[$key]["type"] = "bpmnEvent";
}
}
$elementOriginUid = $arrayElement["elementOrigin"]["uid"];
$elementOriginType = $arrayElement["elementOrigin"]["type"];
$elementDestUid = $arrayElement["elementDest"]["uid"];
$elementDestType = $arrayElement["elementDest"]["type"];
//Get Message-Events of throw type
$arrayEvent = $bpmn->getMessageEventsOfThrowTypeBetweenElementOriginAndElementDest(
$elementOriginUid,
$elementOriginType,
$elementDestUid,
$elementDestType
);
//Throw Message-Events
$messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
foreach ($arrayEvent as $value) {
//Message-Application throw
$result = $messageApplication->create($arrayApplicationData["APP_UID"], $arrayApplicationData["PRO_UID"], $value[0], $arrayApplicationData);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Catch Message-Events for the Cases
*
* @param bool $frontEnd Flag to represent progress bar
*
* return void
*/
public function catchMessageEvent($frontEnd = false)
{
try {
\G::LoadClass("wsBase");
//Set variables
$ws = new \wsBase();
$case = new \Cases();
$messageApplication = new \ProcessMaker\BusinessModel\MessageApplication();
$messageApplication->setFrontEnd($frontEnd);
//Get data
$totalMessageEvent = 0;
$counterStartMessageEvent = 0;
$counterIntermediateCatchMessageEvent = 0;
$counter = 0;
$flagFirstTime = false;
$messageApplication->frontEndShow("START");
do {
$flagNextRecords = false;
$arrayMessageApplicationUnread = $messageApplication->getMessageApplications(array("messageApplicationStatus" => "UNREAD"), null, null, 0, 1000);
if (!$flagFirstTime) {
$totalMessageEvent = $arrayMessageApplicationUnread["total"];
$flagFirstTime = true;
}
foreach ($arrayMessageApplicationUnread["data"] as $value) {
if ($counter + 1 > $totalMessageEvent) {
$flagNextRecords = false;
break;
}
$arrayMessageApplicationData = $value;
$processUid = $arrayMessageApplicationData["PRJ_UID"];
$taskUid = $arrayMessageApplicationData["TAS_UID"];
$messageApplicationUid = $arrayMessageApplicationData["MSGAPP_UID"];
$messageApplicationCorrelation = $arrayMessageApplicationData["MSGAPP_CORRELATION"];
$messageEventDefinitionUserUid = $arrayMessageApplicationData["MSGED_USR_UID"];
$messageEventDefinitionCorrelation = $arrayMessageApplicationData["MSGED_CORRELATION"];
$arrayVariable = $messageApplication->mergeVariables($arrayMessageApplicationData["MSGED_VARIABLES"], $arrayMessageApplicationData["MSGAPP_VARIABLES"]);
$flagCatched = false;
switch ($arrayMessageApplicationData["EVN_TYPE"]) {
case "START":
if ($messageEventDefinitionCorrelation == $messageApplicationCorrelation && $messageEventDefinitionUserUid != "") {
//Start and derivate new Case
$result = $ws->newCase($processUid, $messageEventDefinitionUserUid, $taskUid, $arrayVariable);
$arrayResult = json_decode(json_encode($result), true);
if ($arrayResult["status_code"] == 0) {
$applicationUid = $arrayResult["caseId"];
$result = $ws->derivateCase($messageEventDefinitionUserUid, $applicationUid, 1);
$flagCatched = true;
//Counter
$counterStartMessageEvent++;
}
}
break;
case "INTERMEDIATE":
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\AppDelegationPeer::APP_UID);
$criteria->addSelectColumn(\AppDelegationPeer::DEL_INDEX);
$criteria->addSelectColumn(\AppDelegationPeer::USR_UID);
$criteria->add(\AppDelegationPeer::PRO_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\AppDelegationPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
$criteria->add(\AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", \Criteria::EQUAL);
$criteria->add(\AppDelegationPeer::DEL_FINISH_DATE, null, \Criteria::ISNULL);
$rsCriteria = \AppDelegationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$applicationUid = $row["APP_UID"];
$delIndex = $row["DEL_INDEX"];
$userUid = $row["USR_UID"];
$arrayApplicationData = $case->loadCase($applicationUid);
if (\G::replaceDataField($messageEventDefinitionCorrelation, $arrayApplicationData["APP_DATA"]) == $messageApplicationCorrelation) {
//"Unpause" and derivate Case
$arrayApplicationData["APP_DATA"] = array_merge($arrayApplicationData["APP_DATA"], $arrayVariable);
$arrayResult = $case->updateCase($applicationUid, $arrayApplicationData);
$result = $ws->derivateCase($userUid, $applicationUid, $delIndex);
$flagCatched = true;
}
}
//Counter
if ($flagCatched) {
$counterIntermediateCatchMessageEvent++;
}
break;
}
//Message-Application catch
if ($flagCatched) {
$result = $messageApplication->update($messageApplicationUid, array("MSGAPP_STATUS" => "READ"));
}
$counter++;
//Progress bar
$messageApplication->frontEndShow("BAR", "Message-Events (unread): " . $counter . "/" . $totalMessageEvent . " " . $messageApplication->progressBar($totalMessageEvent, $counter));
$flagNextRecords = true;
}
} while ($flagNextRecords);
$messageApplication->frontEndShow("TEXT", "Total Message-Events unread: " . $totalMessageEvent);
$messageApplication->frontEndShow("TEXT", "Total cases started: " . $counterStartMessageEvent);
$messageApplication->frontEndShow("TEXT", "Total cases continued: " . $counterIntermediateCatchMessageEvent);
$messageApplication->frontEndShow("TEXT", "Total Message-Events pending: " . ($totalMessageEvent - ($counterStartMessageEvent + $counterIntermediateCatchMessageEvent)));
$messageApplication->frontEndShow("END");
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -13,7 +13,7 @@ class EmailServer
"MESS_PASSWORD" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerPassword"),
"MESS_FROM_MAIL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerFromMail"),
"MESS_FROM_NAME" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerFromName"),
"SMTPSECURE" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("No", "tls", "ssl"), "fieldNameAux" => "emailServerSecureConnection"),
"SMTPSECURE" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("No", "tls", "ssl", "none"), "fieldNameAux" => "emailServerSecureConnection"),
"MESS_TRY_SEND_INMEDIATLY" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "emailServerSendTestMail"),
"MAIL_TO" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "emailServerMailTo"),
"MESS_DEFAULT" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "emailServerDefault")

View File

@@ -275,6 +275,10 @@ class FilesManager
$_FILES['prf_file']['name'] = $_FILES['prf_file']['name'].$extention;
}
$file = end(explode("/",$path));
if(strpos($file,"\\") > 0) {
$file = str_replace('\\', '/', $file);
$file = end(explode("/",$file));
}
$path = str_replace($file,'',$path);
if ($file == $_FILES['prf_file']['name']) {
if ($_FILES['prf_file']['error'] != 1) {

View File

@@ -13,7 +13,10 @@ class InputDocument
"INP_DOC_PUBLISHED" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("PRIVATE", "PUBLIC"), "fieldNameAux" => "inputDocumentPublished"),
"INP_DOC_VERSIONING" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentVersioning"),
"INP_DOC_DESTINATION_PATH" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentDestinationPath"),
"INP_DOC_TAGS" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentTags")
"INP_DOC_TAGS" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "inputDocumentTags"),
"INP_DOC_TYPE_FILE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "inputDocumentTypeFile"),
"INP_DOC_MAX_FILESIZE" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "inputDocumentMaxFilesize"),
"INP_DOC_MAX_FILESIZE_UNIT" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "inputDocumentMaxFilesizeUnit")
);
private $formatFieldNameInUppercase = true;
@@ -454,6 +457,9 @@ class InputDocument
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_VERSIONING);
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_DESTINATION_PATH);
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TAGS);
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TYPE_FILE);
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_MAX_FILESIZE);
$criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_MAX_FILESIZE_UNIT);
$criteria->addAlias("CT", \ContentPeer::TABLE_NAME);
$criteria->addAlias("CD", \ContentPeer::TABLE_NAME);
@@ -506,7 +512,10 @@ class InputDocument
$this->getFieldNameByFormatFieldName("INP_DOC_PUBLISHED") => $record["INP_DOC_PUBLISHED"] . "",
$this->getFieldNameByFormatFieldName("INP_DOC_VERSIONING") => (int)($record["INP_DOC_VERSIONING"]),
$this->getFieldNameByFormatFieldName("INP_DOC_DESTINATION_PATH") => $record["INP_DOC_DESTINATION_PATH"] . "",
$this->getFieldNameByFormatFieldName("INP_DOC_TAGS") => $record["INP_DOC_TAGS"] . ""
$this->getFieldNameByFormatFieldName("INP_DOC_TAGS") => $record["INP_DOC_TAGS"] . "",
$this->getFieldNameByFormatFieldName("INP_DOC_TYPE_FILE") => $record["INP_DOC_TYPE_FILE"] . "",
$this->getFieldNameByFormatFieldName("INP_DOC_MAX_FILESIZE") => (int)($record["INP_DOC_MAX_FILESIZE"]),
$this->getFieldNameByFormatFieldName("INP_DOC_MAX_FILESIZE_UNIT") => $record["INP_DOC_MAX_FILESIZE_UNIT"] . ""
);
} catch (\Exception $e) {
throw $e;

View File

@@ -0,0 +1,670 @@
<?php
namespace ProcessMaker\BusinessModel;
use G;
use Criteria;
use UsersPeer;
use AppDelegationPeer;
use AppDelayPeer;
class Light
{
/**
* Method get list start case
*
* @param $userId User id
* @return array
* @throws \Exception
*/
public function getProcessListStartCase($userId)
{
$response = null;
try {
$oProcess = new \Process();
$oCase = new \Cases();
//Get ProcessStatistics Info
$start = 0;
$limit = '';
$proData = $oProcess->getAllProcesses( $start, $limit, null, null, false, true );
$processListInitial = $oCase->getStartCasesPerType( $userId, 'category' );
$processList = array ();
foreach ($processListInitial as $key => $procInfo) {
if (isset( $procInfo['pro_uid'] )) {
if (trim( $procInfo['cat'] ) == "") {
$procInfo['cat'] = "_OTHER_";
}
$processList[$procInfo['catname']][$procInfo['value']] = $procInfo;
}
}
ksort( $processList );
foreach ($processList as $key => $processInfo) {
ksort( $processList[$key] );
}
foreach ($proData as $key => $proInfo) {
$proData[$proInfo['PRO_UID']] = $proInfo;
}
$task = new \ProcessMaker\BusinessModel\Task();
$task->setFormatFieldNameInUppercase(false);
$task->setArrayParamException(array("taskUid" => "act_uid", "stepUid" => "step_uid"));
$response = array();
foreach ($processList as $key => $processInfo) {
$tempTreeChildren = array ();
foreach ($processList[$key] as $keyChild => $processInfoChild) {
$tempTreeChild['text'] = htmlentities($keyChild, ENT_QUOTES, 'UTF-8'); //ellipsis ( $keyChild, 50 );
$tempTreeChild['processId'] = $processInfoChild['pro_uid'];
$tempTreeChild['taskId'] = $processInfoChild['uid'];
$forms = $task->getSteps($processInfoChild['uid']);
$newForm = array();
$c = 0;
foreach ($forms as $k => $form) {
if ($form['step_type_obj'] == "DYNAFORM") {
$newForm[$c]['formId'] = $form['step_uid_obj'];
$newForm[$c]['index'] = $c+1;
$newForm[$c]['title'] = $form['obj_title'];
$newForm[$c]['description'] = $form['obj_description'];
$c++;
}
}
$tempTreeChild['forms'] = $newForm;
if (isset( $proData[$processInfoChild['pro_uid']] )) {
$tempTreeChildren[] = $tempTreeChild;
}
}
$response = array_merge($response, $tempTreeChildren);
}
} catch (\Exception $e) {
throw $e;
}
return $response;
}
/**
* Get counters each type of list
* @param $userId
* @return array
* @throws \Exception
*/
public function getCounterCase($userId)
{
try {
$userUid = (isset( $userId ) && $userId != '') ? $userId : null;
$oAppCache = new \AppCacheView();
$aTypes = Array ();
$aTypes['to_do'] = 'toDo';
$aTypes['draft'] = 'draft';
$aTypes['cancelled'] = 'cancelled';
$aTypes['sent'] = 'participated';
$aTypes['paused'] = 'paused';
$aTypes['completed'] = 'completed';
$aTypes['selfservice'] = 'unassigned';
$aCount = $oAppCache->getAllCounters( array_keys( $aTypes ), $userUid );
$response = Array ();
foreach ($aCount as $type => $count) {
$response[$aTypes[$type]] = $count;
}
} catch (\Exception $e) {
throw $e;
}
return $response;
}
/**
* @param $sAppUid
* @return Criteria
*/
public function getTransferHistoryCriteria($sAppUid)
{
$c = new Criteria('workflow');
$c->addAsColumn('TAS_TITLE', 'TAS_TITLE.CON_VALUE');
$c->addSelectColumn(UsersPeer::USR_FIRSTNAME);
$c->addSelectColumn(UsersPeer::USR_LASTNAME);
$c->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
$c->addSelectColumn(AppDelegationPeer::PRO_UID);
$c->addSelectColumn(AppDelegationPeer::TAS_UID);
$c->addSelectColumn(AppDelegationPeer::APP_UID);
$c->addSelectColumn(AppDelegationPeer::DEL_INDEX);
///-- $c->addAsColumn('USR_NAME', "CONCAT(USR_LASTNAME, ' ', USR_FIRSTNAME)");
$sDataBase = 'database_' . strtolower(DB_ADAPTER);
if (G::LoadSystemExist($sDataBase)) {
G::LoadSystem($sDataBase);
$oDataBase = new \database();
$c->addAsColumn('USR_NAME', $oDataBase->concatString("USR_LASTNAME", "' '", "USR_FIRSTNAME"));
$c->addAsColumn(
'DEL_FINISH_DATE', $oDataBase->getCaseWhen("DEL_FINISH_DATE IS NULL", "'-'", AppDelegationPeer::DEL_FINISH_DATE)
);
$c->addAsColumn(
'APP_TYPE', $oDataBase->getCaseWhen("DEL_FINISH_DATE IS NULL", "'IN_PROGRESS'", AppDelayPeer::APP_TYPE)
);
}
$c->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
$c->addSelectColumn(AppDelayPeer::APP_ENABLE_ACTION_DATE);
$c->addSelectColumn(AppDelayPeer::APP_DISABLE_ACTION_DATE);
//APP_DELEGATION LEFT JOIN USERS
$c->addJoin(AppDelegationPeer::USR_UID, UsersPeer::USR_UID, Criteria::LEFT_JOIN);
//APP_DELAY FOR MORE DESCRIPTION
//$c->addJoin(AppDelegationPeer::DEL_INDEX, AppDelayPeer::APP_DEL_INDEX, Criteria::LEFT_JOIN);
//$c->addJoin(AppDelegationPeer::APP_UID, AppDelayPeer::APP_UID, Criteria::LEFT_JOIN);
$del = \DBAdapter::getStringDelimiter();
$app = array();
$app[] = array(AppDelegationPeer::DEL_INDEX, AppDelayPeer::APP_DEL_INDEX);
$app[] = array(AppDelegationPeer::APP_UID, AppDelayPeer::APP_UID);
$c->addJoinMC($app, Criteria::LEFT_JOIN);
//LEFT JOIN CONTENT TAS_TITLE
$c->addAlias("TAS_TITLE", 'CONTENT');
$del = \DBAdapter::getStringDelimiter();
$appTitleConds = array();
$appTitleConds[] = array(AppDelegationPeer::TAS_UID, 'TAS_TITLE.CON_ID');
$appTitleConds[] = array('TAS_TITLE.CON_CATEGORY', $del . 'TAS_TITLE' . $del);
$appTitleConds[] = array('TAS_TITLE.CON_LANG', $del . SYS_LANG . $del);
$c->addJoinMC($appTitleConds, Criteria::LEFT_JOIN);
//WHERE
$c->add(AppDelegationPeer::APP_UID, $sAppUid);
//ORDER BY
$c->clearOrderByColumns();
$c->addAscendingOrderByColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
return $c;
}
/**
* GET history of case
*
* @param $app_uid
* @return array
* @throws \Exception
*/
public function getCasesListHistory($app_uid)
{
G::LoadClass( 'case' );
G::LoadClass( "BasePeer" );
//global $G_PUBLISH;
$c = $this->getTransferHistoryCriteria( $app_uid );
//$result = new \stdClass();
$aProcesses = Array ();
$rs = \GulliverBasePeer::doSelectRs( $c );
$rs->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
$rs->next();
for ($j = 0; $j < $rs->getRecordCount(); $j ++) {
$result = $rs->getRow();
$result["ID_HISTORY"] = $result["PRO_UID"] . '_' . $result["APP_UID"] . '_' . $result["TAS_UID"];
$aProcesses[] = $result;
$rs->next();
$processUid = $result["PRO_UID"];
}
$process = new \Process();
$arrayProcessData = $process->load($processUid);
//$newDir = '/tmp/test/directory';
//G::verifyPath( $newDir );
$result = array();
$result["processName"] = $arrayProcessData["PRO_TITLE"];
//$result["PRO_DESCRIPTION"] = $arrayProcessData["PRO_DESCRIPTION"];
$result['flow'] = $aProcesses;
return $result;
}
/**
* starting one case
*
* @param string $userId
* @param string $proUid
* @param string $taskUid
* @return array
* @throws \Exception
*/
public function startCase($userId = '', $proUid = '', $taskUid = '')
{
try {
$oCase = new \Cases();
$this->lookinginforContentProcess( $proUid );
$aData = $oCase->startCase( $taskUid, $userId );
$response = array();
$response['caseId'] = $aData['APPLICATION'];
$response['caseIndex'] = $aData['INDEX'];
$response['caseNumber'] = $aData['CASE_NUMBER'];
} catch (Exception $e) {
$response['status'] = 'failure';
$response['message'] = $e->getMessage();
}
return $response;
}
public function lookinginforContentProcess ($sproUid)
{
$oContent = new \Content();
///we are looking for a pro title for this process $sproUid
$oCriteria = new \Criteria( 'workflow' );
$oCriteria->add( \ContentPeer::CON_CATEGORY, 'PRO_TITLE' );
$oCriteria->add( \ContentPeer::CON_LANG, 'en' );
$oCriteria->add( \ContentPeer::CON_ID, $sproUid );
$oDataset = \ContentPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
$oDataset->next();
$aRow = $oDataset->getRow();
if (! is_array( $aRow )) {
$oC = new \Criteria( 'workflow' );
$oC->addSelectColumn( \TaskPeer::TAS_UID );
$oC->add( \TaskPeer::PRO_UID, $sproUid );
$oDataset1 = \TaskPeer::doSelectRS( $oC );
$oDataset1->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
while ($oDataset1->next()) {
$aRow1 = $oDataset1->getRow();
$oCriteria1 = new \Criteria( 'workflow' );
$oCriteria1->add( ContentPeer::CON_CATEGORY, 'TAS_TITLE' );
$oCriteria1->add( ContentPeer::CON_LANG, SYS_LANG );
$oCriteria1->add( ContentPeer::CON_ID, $aRow1['TAS_UID'] );
$oDataset2 = ContentPeer::doSelectRS( $oCriteria1 );
$oDataset2->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset2->next();
$aRow2 = $oDataset2->getRow();
Content::insertContent( 'TAS_TITLE', '', $aRow2['CON_ID'], 'en', $aRow2['CON_VALUE'] );
}
$oC2 = new Criteria( 'workflow' );
$oC2->add( ContentPeer::CON_CATEGORY, 'PRO_TITLE' );
$oC2->add( ContentPeer::CON_LANG, SYS_LANG );
$oC2->add( ContentPeer::CON_ID, $sproUid );
$oDataset3 = ContentPeer::doSelectRS( $oC2 );
$oDataset3->setFetchmode( ResultSet::FETCHMODE_ASSOC );
$oDataset3->next();
$aRow3 = $oDataset3->getRow();
Content::insertContent( 'PRO_TITLE', '', $aRow3['CON_ID'], 'en', $aRow3['CON_VALUE'] );
}
return 1;
}
/**
* Route Case
*
* @param string $applicationUid Unique id of Case
* @param string $userUid Unique id of User
* @param string $delIndex
* @param string $bExecuteTriggersBeforeAssignment
*
* return array Return an array with Task Case
*/
public function updateRouteCase($applicationUid, $userUid, $delIndex)
{
try {
if (!$delIndex) {
$delIndex = \AppDelegation::getCurrentIndex($applicationUid);
}
\G::LoadClass('wsBase');
$ws = new \wsBase();
$fields = $ws->derivateCase($userUid, $applicationUid, $delIndex, $bExecuteTriggersBeforeAssignment = false);
$array = json_decode(json_encode($fields), true);
if ($array ["status_code"] != 0) {
throw (new \Exception($array ["message"]));
} else {
unset($array['status_code']);
unset($array['message']);
unset($array['timestamp']);
}
} catch (\Exception $e) {
throw $e;
}
return $fields;
}
/**
* Get user Data
*
* @param string $applicationUid Unique id of Case
* @param string $userUid Unique id of User
* @param string $delIndex
* @param string $bExecuteTriggersBeforeAssignment
*
* return array Return an array with Task Case
*/
public function getUserData($userUid)
{
try {
$direction = PATH_IMAGES_ENVIRONMENT_USERS . $userUid . ".gif";
if (! file_exists( $direction )) {
$direction = PATH_HOME . 'public_html/images/user.gif';
}
$gestor = fopen($direction, "r");
$contenido = fread($gestor, filesize($direction));
fclose($gestor);
$oUser = new \Users();
$aUserLog = $oUser->loadDetailed($userUid);
$response['userId'] = $aUserLog['USR_UID'];
$response['firstName'] = $aUserLog['USR_FIRSTNAME'];
$response['lastName'] = $aUserLog['USR_LASTNAME'];
$response['fullName'] = $aUserLog['USR_FIRSTNAME'].' '.$aUserLog['USR_LASTNAME'];
$response['email'] = $aUserLog['USR_EMAIL'];
$response['userRole'] = $aUserLog['USR_ROLE_NAME'];
$response['userPhone'] = $aUserLog['USR_PHONE'];
$response['updateDate'] = $aUserLog['USR_UPDATE_DATE'];
$response['userPhoto'] = base64_encode($contenido);
} catch (\Exception $e) {
throw $e;
}
return $response;
}
/**
* Download files and resize dimensions in file type image
* if not type image return content file
*
* return array Return an array with Task Case
*/
public function downloadFile($app_uid, $request_data)
{
try {
$oAppDocument = new \AppDocument();
$arrayFiles = array();
foreach ($request_data as $key => $fileData) {
if (! isset( $fileData['version'] )) {
//Load last version of the document
$docVersion = $oAppDocument->getLastAppDocVersion( $fileData['fileId'] );
} else {
$docVersion = $fileData['version'];
}
$oAppDocument->Fields = $oAppDocument->load( $fileData['fileId'], $docVersion );
$sAppDocUid = $oAppDocument->getAppDocUid();
$iDocVersion = $oAppDocument->getDocVersion();
$info = pathinfo( $oAppDocument->getAppDocFilename() );
$ext = (isset($info['extension'])?$info['extension']:'');//BUG fix: must handle files without any extension
//$app_uid = \G::getPathFromUID($oAppDocument->Fields['APP_UID']);
$file = \G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $sAppDocUid);
$realPath = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '_' . $iDocVersion . '.' . $ext;
$realPath1 = PATH_DOCUMENT . $app_uid . '/' . $file[0] . $file[1] . '.' . $ext;
$width = isset($fileData['width']) ? $fileData['width']:null;
$height = isset($fileData['height']) ? $fileData['height']:null;
if (file_exists( $realPath )) {
switch($ext){
case 'jpg':
case 'jpeg':
case 'gif':
case 'png':
$arrayFiles[$key]['fileId'] = $fileData['fileId'];
$arrayFiles[$key]['fileContent'] = base64_encode($this->imagesThumbnails($realPath, $ext, $width, $height));
break;
default:
$fileTmp = fopen($realPath, "r");
$content = fread($fileTmp, filesize($realPath));
$arrayFiles[$key]['fileId'] = $fileData['fileId'];
$arrayFiles[$key]['fileContent'] = base64_encode($content);
fclose($fileTmp);
break;
}
} elseif (file_exists( $realPath1 )) {
switch($ext){
case 'jpg':
case 'jpeg':
case 'gif':
case 'png':
$arrayFiles[$key]['fileId'] = $fileData['fileId'];
$arrayFiles[$key]['fileContent'] = $this->imagesThumbnails($realPath1, $ext, $width, $height);
break;
default:
$fileTmp = fopen($realPath, "r");
$content = fread($fileTmp, filesize($realPath));
$arrayFiles[$key]['fileId'] = $fileData['fileId'];
$arrayFiles[$key]['fileContent'] = base64_encode($content);
fclose($fileTmp);
break;
}
}
}
} catch (\Exception $e) {
throw $e;
}
return $arrayFiles;
}
/**
* resize image if send width or height
*
* @param $path
* @param $extensions
* @param null $newWidth
* @param null $newHeight
* @return string
*/
public function imagesThumbnails($path, $extensions, $newWidth = null, $newHeight = null)
{
switch($extensions){
case 'jpg':
case 'jpeg':
$imgTmp = imagecreatefromjpeg($path);
break;
case 'gif':
$imgTmp = imagecreatefromgif($path);
break;
case 'png':
$imgTmp = imagecreatefrompng($path);
break;
}
$width = imagesx($imgTmp);
$height = imagesy($imgTmp);
$ratio = $width / $height;
$isThumbnails = false;
if (isset($newWidth) && !isset($newHeight)) {
$newwidth = $newWidth;
$newheight = round($newwidth / $ratio);
$isThumbnails = true;
} elseif (!isset($newWidth) && isset($newHeight)) {
$newheight = $newHeight;
$newwidth = round($newheight / $ratio);
$isThumbnails = true;
} elseif (isset($newWidth) && isset($newHeight)) {
$newwidth = $newWidth;
$newheight = $newHeight;
$isThumbnails = true;
}
$thumb = $imgTmp;
if ($isThumbnails) {
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($thumb, $imgTmp, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ob_start();
switch($extensions){
case 'jpg':
case 'jpeg':
imagejpeg($thumb);
break;
case 'gif':
imagegif($thumb);
break;
case 'png':
imagepng($thumb);
break;
}
$image = ob_get_clean();
imagedestroy($thumb);
return $image;
}
public function logout($oauthAccessTokenId, $refresh)
{
$aFields = array();
if (!isset($_GET['u'])) {
$aFields['URL'] = '';
} else {
$aFields['URL'] = htmlspecialchars(addslashes(stripslashes(strip_tags(trim(urldecode($_GET['u']))))));
}
if (!isset($_SESSION['G_MESSAGE'])) {
$_SESSION['G_MESSAGE'] = '';
}
if (!isset($_SESSION['G_MESSAGE_TYPE'])) {
$_SESSION['G_MESSAGE_TYPE'] = '';
}
$msg = $_SESSION['G_MESSAGE'];
$msgType = $_SESSION['G_MESSAGE_TYPE'];
if (!isset($_SESSION['FAILED_LOGINS'])) {
$_SESSION['FAILED_LOGINS'] = 0;
$_SESSION["USERNAME_PREVIOUS1"] = "";
$_SESSION["USERNAME_PREVIOUS2"] = "";
}
$sFailedLogins = $_SESSION['FAILED_LOGINS'];
$usernamePrevious1 = $_SESSION["USERNAME_PREVIOUS1"];
$usernamePrevious2 = $_SESSION["USERNAME_PREVIOUS2"];
$aFields['LOGIN_VERIFY_MSG'] = G::loadTranslation('LOGIN_VERIFY_MSG');
//start new session
@session_destroy();
session_start();
session_regenerate_id();
setcookie("workspaceSkin", SYS_SKIN, time() + 24*60*60, "/sys".SYS_SYS);
if (strlen($msg) > 0) {
$_SESSION['G_MESSAGE'] = $msg;
}
if (strlen($msgType) > 0) {
$_SESSION['G_MESSAGE_TYPE'] = $msgType;
}
$_SESSION['FAILED_LOGINS'] = $sFailedLogins;
$_SESSION["USERNAME_PREVIOUS1"] = $usernamePrevious1;
$_SESSION["USERNAME_PREVIOUS2"] = $usernamePrevious2;
/*----------------------------------********---------------------------------*/
if (!class_exists('pmLicenseManager')) {
G::LoadClass('pmLicenseManager');
}
$licenseManager =& \pmLicenseManager::getSingleton();
if (in_array(md5($licenseManager->result), array('38afd7ae34bd5e3e6fc170d8b09178a3', 'ba2b45bdc11e2a4a6e86aab2ac693cbb'))) {
$G_PUBLISH = new \Publisher();
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/licenseExpired', '', array(), 'licenseUpdate');
G::RenderPage('publish');
die();
}
/*----------------------------------********---------------------------------*/
try {
$oatoken = new \OauthAccessTokens();
$result = $oatoken->remove($oauthAccessTokenId);
$response["status"] = "OK";
} catch (Exception $e) {
$response["status"] = "ERROR";
$response["message"] = $e->getMessage();
}
return $response;
}
/**
* Get information for status paused and participated or other status
*
* @param $userUid
* @param $type
* @param $app_uid
* @throws \Exception
*/
public function getInformation($userUid, $type, $app_uid)
{
switch ($type) {
case 'paused':
case 'participated':
$oCase = new \Cases();
$iDelIndex = $oCase->getCurrentDelegationCase( $app_uid );
$aFields = $oCase->loadCase( $app_uid, $iDelIndex );
$this->getInfoResume($userUid, $aFields, $type);
break;
}
}
/**
* view in html response for status
*
* @param $userUid
* @param $Fields
* @param $type
* @throws \Exception
*/
public function getInfoResume($userUid, $Fields, $type)
{
//print_r($Fields);die;
/* Includes */
G::LoadClass( 'case' );
/* Prepare page before to show */
//$oCase = new \Cases();
// $participated = $oCase->userParticipatedInCase( $Fields['APP_UID'], $userUid );
// if ($RBAC->userCanAccess( 'PM_ALLCASES' ) < 0 && $participated == 0) {
// /*if (strtoupper($Fields['APP_STATUS']) != 'COMPLETED') {
// $oCase->thisIsTheCurrentUser($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['USER_LOGGED'], 'SHOW_MESSAGE');
// }*/
// $aMessage['MESSAGE'] = G::LoadTranslation( 'ID_NO_PERMISSION_NO_PARTICIPATED' );
// $G_PUBLISH = new Publisher();
// $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
// G::RenderPage( 'publishBlank', 'blank' );
// die();
// }
$objProc = new \Process();
$aProc = $objProc->load( $Fields['PRO_UID'] );
$Fields['PRO_TITLE'] = $aProc['PRO_TITLE'];
$objTask = new \Task();
if (isset($_SESSION['ACTION']) && ($_SESSION['ACTION'] == 'jump')) {
$task = explode('-', $Fields['TAS_UID']);
$Fields['TAS_TITLE'] = '';
for( $i = 0; $i < sizeof($task)-1; $i ++ ) {
$aTask = $objTask->load( $task[$i] );
$Fields['TAS_TITLE'][] = $aTask['TAS_TITLE'];
}
$Fields['TAS_TITLE'] = implode(" - ", array_values($Fields['TAS_TITLE']));
} else {
$aTask = $objTask->load( $Fields['TAS_UID'] );
$Fields['TAS_TITLE'] = $aTask['TAS_TITLE'];
}
require_once(PATH_GULLIVER .'../thirdparty/smarty/libs/Smarty.class.php');
$G_PUBLISH = new \Publisher();
$G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'cases/cases_Resume.xml', '', $Fields, '' );
$G_PUBLISH->RenderContent();
}
}

View File

@@ -1,6 +1,5 @@
<?php
namespace ProcessMaker\BusinessModel;
use \G;
/**
@@ -18,7 +17,7 @@ class Lists {
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*/
*/
public function getList($listName = 'inbox', $dataList = array(), $total = false)
{
Validator::isArray($dataList, '$dataList');
@@ -31,7 +30,6 @@ class Lists {
$userUid = $dataList["userId"];
$filters["paged"] = isset( $dataList["paged"] ) ? $dataList["paged"] : true;
$filters['count'] = isset( $dataList['count'] ) ? $dataList['count'] : true;
$filters["category"] = isset( $dataList["category"] ) ? $dataList["category"] : "";
$filters["process"] = isset( $dataList["process"] ) ? $dataList["process"] : "";
$filters["search"] = isset( $dataList["search"] ) ? $dataList["search"] : "";
@@ -44,6 +42,8 @@ class Lists {
$filters["sort"] = isset( $dataList["sort"] ) ? $dataList["sort"] : "";
$filters["dir"] = isset( $dataList["dir"] ) ? $dataList["dir"] : "DESC";
$filters["action"] = isset( $dataList["action"] ) ? $dataList["action"] : "";
// Select list
switch ($listName) {
case 'inbox':
@@ -62,6 +62,14 @@ class Lists {
$list = new \ListCompleted();
$listpeer = 'ListCompletedPeer';
break;
case 'paused':
$list = new \ListPaused();
$listpeer = 'ListPausedPeer';
break;
case 'canceled':
$list = new \ListCanceled();
$listpeer = 'ListCanceledPeer';
break;
case 'my_inbox':
$list = new \ListMyInbox();
$listpeer = 'ListMyInboxPeer';
@@ -77,7 +85,7 @@ class Lists {
$filters["start"] = (int)$filters["start"];
$filters["start"] = abs($filters["start"]);
if ($filters["start"] != 0) {
$filters["start"]--;
$filters["start"]+1;
}
$filters["limit"] = (int)$filters["limit"];
@@ -126,14 +134,36 @@ class Lists {
$result = $list->loadList($userUid, $filters);
if (!empty($result)) {
foreach ($result as &$value) {
$value = array_change_key_case($value, CASE_LOWER);
if (isset($value['DEL_PREVIOUS_USR_UID'])) {
$value['PREVIOUS_USR_UID'] = $value['DEL_PREVIOUS_USR_UID'];
$value['PREVIOUS_USR_USERNAME'] = $value['DEL_PREVIOUS_USR_USERNAME'];
$value['PREVIOUS_USR_FIRSTNAME'] = $value['DEL_PREVIOUS_USR_FIRSTNAME'];
$value['PREVIOUS_USR_LASTNAME'] = $value['DEL_PREVIOUS_USR_LASTNAME'];
}
if (isset($value['DEL_DUE_DATE'])) {
$value['DEL_TASK_DUE_DATE'] = $value['DEL_DUE_DATE'];
}
if (isset($value['APP_PAUSED_DATE'])) {
$value['APP_UPDATE_DATE'] = $value['APP_PAUSED_DATE'];
}
if (isset($value['DEL_CURRENT_USR_USERNAME'])) {
$value['USR_USERNAME'] = $value['DEL_CURRENT_USR_USERNAME'];
$value['USR_FIRSTNAME'] = $value['DEL_CURRENT_USR_FIRSTNAME'];
$value['USR_LASTNAME'] = $value['DEL_CURRENT_USR_LASTNAME'];
$value['APP_UPDATE_DATE'] = $value['DEL_DELEGATE_DATE'];
}
if (isset($value['APP_STATUS'])) {
$value['APP_STATUS_LABEL'] = G::LoadTranslation( "ID_{$value['APP_STATUS']}" );
}
//$value = array_change_key_case($value, CASE_LOWER);
}
}
$response = array();
if ($filters["paged"]) {
$filtersData = array();
$filtersData['start'] = $filters["start"]+1;
$filtersData['start'] = $filters["start"];
$filtersData['limit'] = $filters["limit"];
$filtersData['sort'] = G::toLower($filters["sort"]);
$filtersData['dir'] = G::toLower($filters["dir"]);
@@ -144,10 +174,10 @@ class Lists {
$filtersData['date_to'] = $filters["dateTo"];
$response['filters'] = $filtersData;
$response['data'] = $result;
$response['totalCount'] = $list->countTotal($userUid, $filtersData);
} else {
$response = $result;
}
return $response;
}
}

View File

@@ -0,0 +1,426 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageApplication
{
private $arrayFieldNameForException = array(
"start" => "START",
"limit" => "LIMIT"
);
private $frontEnd = false;
/**
* Verify if exists the Message-Application
*
* @param string $messageApplicationUid Unique id of Message-Application
*
* return bool Return true if exists the Message-Application, false otherwise
*/
public function exists($messageApplicationUid)
{
try {
$obj = \MessageApplicationPeer::retrieveByPK($messageApplicationUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Application for the Case
*
* @param string $applicationUid Unique id of Case
* @param string $projectUid Unique id of Project
* @param string $eventUidThrow Unique id of Event (throw)
* @param array $arrayApplicationData Case data
*
* return bool Return true if been created, false otherwise
*/
public function create($applicationUid, $projectUid, $eventUidThrow, array $arrayApplicationData)
{
try {
$flagCreate = true;
//Set data
//Message-Event-Relation - Get unique id of Event (catch)
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$arrayMessageEventRelationData = $messageEventRelation->getMessageEventRelationWhere(
array(
\MessageEventRelationPeer::PRJ_UID => $projectUid,
\MessageEventRelationPeer::EVN_UID_THROW => $eventUidThrow
),
true
);
if (!is_null($arrayMessageEventRelationData)) {
$eventUidCatch = $arrayMessageEventRelationData["EVN_UID_CATCH"];
} else {
$flagCreate = false;
}
//Message-Application - Get data ($eventUidThrow)
$messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
if ($messageEventDefinition->existsEvent($projectUid, $eventUidThrow)) {
$arrayMessageEventDefinitionData = $messageEventDefinition->getMessageEventDefinitionByEvent($projectUid, $eventUidThrow, true);
$arrayMessageApplicationVariables = $arrayMessageEventDefinitionData["MSGED_VARIABLES"];
$messageApplicationCorrelation = \G::replaceDataField($arrayMessageEventDefinitionData["MSGED_CORRELATION"], $arrayApplicationData["APP_DATA"]);
foreach ($arrayMessageApplicationVariables as $key => $value) {
$arrayMessageApplicationVariables[$key] = \G::replaceDataField($value, $arrayApplicationData["APP_DATA"]);
}
} else {
$flagCreate = false;
}
if (!$flagCreate) {
//Return
return false;
}
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageApplication = new \MessageApplication();
$messageApplicationUid = \ProcessMaker\Util\Common::generateUID();
$messageApplication->setMsgappUid($messageApplicationUid);
$messageApplication->setAppUid($applicationUid);
$messageApplication->setPrjUid($projectUid);
$messageApplication->setEvnUidThrow($eventUidThrow);
$messageApplication->setEvnUidCatch($eventUidCatch);
$messageApplication->setMsgappVariables(serialize($arrayMessageApplicationVariables));
$messageApplication->setMsgappCorrelation($messageApplicationCorrelation);
$messageApplication->setMsgappThrowDate("now");
if ($messageApplication->validate()) {
$cnn->begin();
$result = $messageApplication->save();
$cnn->commit();
//Return
return true;
} else {
$msg = "";
foreach ($messageApplication->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-Application
*
* @param string $messageApplicationUid Unique id of Message-Application
* @param array $arrayData Data
*
* return bool Return true if been updated, false otherwise
*/
public function update($messageApplicationUid, array $arrayData)
{
try {
//Verify data
if (!$this->exists($messageApplicationUid)) {
//Return
return false;
}
//Update
$cnn = \Propel::getConnection("workflow");
try {
$messageApplication = \MessageApplicationPeer::retrieveByPK($messageApplicationUid);
$messageApplication->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageApplication->setMsgappCatchDate("now");
if ($messageApplication->validate()) {
$cnn->begin();
$result = $messageApplication->save();
$cnn->commit();
//Return
return true;
} else {
$msg = "";
foreach ($messageApplication->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;
}
}
/**
* Get criteria for Message-Application
*
* return object
*/
public function getMessageApplicationCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_UID);
$criteria->addSelectColumn(\MessageApplicationPeer::APP_UID);
$criteria->addSelectColumn(\MessageApplicationPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageApplicationPeer::EVN_UID_THROW);
$criteria->addSelectColumn(\MessageApplicationPeer::EVN_UID_CATCH);
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_VARIABLES);
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_CORRELATION);
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_THROW_DATE);
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_CATCH_DATE);
$criteria->addSelectColumn(\MessageApplicationPeer::MSGAPP_STATUS);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set front end flag
*
* @param bool $flag Flag
*
* return void
*/
public function setFrontEnd($flag)
{
try {
$this->frontEnd = $flag;
} catch (Exception $e) {
throw $e;
}
}
/**
* Progress bar
*
* @param int $total Total
* @param int $count Count
*
* return string Return a string that represent progress bar
*/
public function progressBar($total, $count)
{
try {
$p = (int)(($count * 100) / $total);
$n = (int)($p / 2);
return "[" . str_repeat("|", $n) . str_repeat(" ", 50 - $n) . "] $p%";
} catch (Exception $e) {
throw $e;
}
}
/**
* Show front end
*
* @param string $option Option
* @param string $data Data string
*
* return void
*/
public function frontEndShow($option, $data = "")
{
try {
if (!$this->frontEnd) {
return;
}
$numc = 100;
switch ($option) {
case "BAR":
echo "\r" . "| " . $data . str_repeat(" ", $numc - 2 - strlen($data));
break;
case "TEXT":
echo "\r" . "| " . $data . str_repeat(" ", $numc - 2 - strlen($data)) . "\n";
break;
default:
//START, END
echo "\r" . "+" . str_repeat("-", $numc - 2) . "+" . "\n";
break;
}
} catch (Exception $e) {
throw $e;
}
}
/**
* Merge and get variables
*
* @param array $arrayVariableName Variables
* @param array $arrayVariableValue Values
*
* return array Return an array
*/
public function mergeVariables(array $arrayVariableName, array $arrayVariableValue)
{
try {
$arrayVariable = array();
foreach ($arrayVariableName as $key => $value) {
if (preg_match("/^@[@%#\?\x24\=]([A-Za-z_]\w*)$/", $value, $arrayMatch) && isset($arrayVariableValue[$key])) {
$arrayVariable[$arrayMatch[1]] = $arrayVariableValue[$key];
}
}
//Return
return $arrayVariable;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Message-Applications
*
* @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-Applications
*/
public function getMessageApplications($arrayFilterData = null, $sortField = null, $sortDir = null, $start = null, $limit = null)
{
try {
$arrayMessageApplication = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException);
//Get data
if (!is_null($limit) && $limit . "" == "0") {
return $arrayMessageApplication;
}
//SQL
$criteria = $this->getMessageApplicationCriteria();
$criteria->addSelectColumn(\BpmnEventPeer::EVN_UID);
$criteria->addSelectColumn(\BpmnEventPeer::EVN_TYPE);
$criteria->addSelectColumn(\BpmnEventPeer::EVN_MARKER);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_USR_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_VARIABLES);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_CORRELATION);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::TAS_UID);
$arrayEventType = array("START", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGECATCH");
$criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \BpmnEventPeer::EVN_UID, \Criteria::INNER_JOIN);
$criteria->add(\BpmnEventPeer::EVN_TYPE, $arrayEventType, \Criteria::IN);
$criteria->add(\BpmnEventPeer::EVN_MARKER, $arrayEventMarker, \Criteria::IN);
$criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \MessageEventDefinitionPeer::EVN_UID, \Criteria::INNER_JOIN);
$criteria->addJoin(\MessageApplicationPeer::EVN_UID_CATCH, \MessageEventTaskRelationPeer::EVN_UID, \Criteria::INNER_JOIN);
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["messageApplicationStatus"]) && trim($arrayFilterData["messageApplicationStatus"]) != "") {
$criteria->add(\MessageApplicationPeer::MSGAPP_STATUS, $arrayFilterData["messageApplicationStatus"], \Criteria::EQUAL);
}
//Number records total
$criteriaCount = clone $criteria;
$criteriaCount->clearSelectColumns();
$criteriaCount->addSelectColumn("COUNT(" . \MessageApplicationPeer::MSGAPP_UID . ") AS NUM_REC");
$rsCriteriaCount = \MessageApplicationPeer::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("MSGAPP_THROW_DATE", "MSGAPP_CATCH_DATE", "MSGAPP_STATUS"))) {
$sortField = \MessageApplicationPeer::TABLE_NAME . "." . $sortField;
} else {
$sortField = \MessageApplicationPeer::MSGAPP_THROW_DATE;
}
} else {
$sortField = \MessageApplicationPeer::MSGAPP_THROW_DATE;
}
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 = \MessageApplicationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$row["MSGAPP_VARIABLES"] = unserialize($row["MSGAPP_VARIABLES"]);
$row["MSGED_VARIABLES"] = unserialize($row["MSGED_VARIABLES"]);
$arrayMessageApplication[] = $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["messageApplicationStatus"]))? $arrayFilterData["messageApplicationStatus"] : "",
"data" => $arrayMessageApplication
);
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,721 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventDefinition
{
private $arrayFieldDefinition = array(
"MSGED_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
"MSGT_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageTypeUid"),
"MSGED_USR_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionUserUid"),
"MSGED_VARIABLES" => array("type" => "array", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionVariables"),
"MSGED_CORRELATION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "messageEventDefinitionCorrelation")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* 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-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
*
* return bool Return true if exists the Message-Event-Definition, false otherwise
*/
public function exists($messageEventDefinitionUid)
{
try {
$obj = \MessageEventDefinitionPeer::retrieveByPK($messageEventDefinitionUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Event of a Message-Event-Definition
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param string $messageEventDefinitionUidToExclude Unique id of Message-Event-Definition to exclude
*
* return bool Return true if exists the Event of a Message-Event-Definition, false otherwise
*/
public function existsEvent($projectUid, $eventUid, $messageEventDefinitionUidToExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
if ($messageEventDefinitionUidToExclude != "") {
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageEventDefinitionPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Definition
*/
public function throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventDefinitionUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventDefinitionUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if is registered the Event
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param string $fieldNameForException Field name for the exception
* @param string $messageEventDefinitionUidToExclude Unique id of Message-Event-Definition to exclude
*
* return void Throw exception if is registered the Event
*/
public function throwExceptionIfEventIsRegistered($projectUid, $eventUid, $fieldNameForException, $messageEventDefinitionUidToExclude = "")
{
try {
if ($this->existsEvent($projectUid, $eventUid, $messageEventDefinitionUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_ALREADY_REGISTERED", array($fieldNameForException, $eventUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventDefinitionUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventDefinitionData = ($messageEventDefinitionUid == "")? array() : $this->getMessageEventDefinition($messageEventDefinitionUid, true);
$flagInsert = ($messageEventDefinitionUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventDefinitionData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["EVN_UID"])) {
$this->throwExceptionIfEventIsRegistered($projectUid, $arrayData["EVN_UID"], $this->arrayFieldNameForException["eventUid"], $messageEventDefinitionUid);
}
if (isset($arrayData["EVN_UID"])) {
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayData["EVN_UID"]);
if (is_null($bpmnEvent)) {
throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_EXIST", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"])));
}
if (!in_array($bpmnEvent->getEvnType(), $arrayEventType) || !in_array($bpmnEvent->getEvnMarker(), $arrayEventMarker)) {
throw new \Exception(\G::LoadTranslation("ID_EVENT_NOT_IS_MESSAGE_EVENT", array($this->arrayFieldNameForException["eventUid"], $arrayData["EVN_UID"])));
}
}
if (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" != "") {
$messageType->throwExceptionIfNotExistsMessageType($arrayData["MSGT_UID"], $this->arrayFieldNameForException["messageTypeUid"]);
}
$flagCheckData = false;
$flagCheckData = (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" != "")? true : $flagCheckData;
$flagCheckData = (isset($arrayData["MSGED_VARIABLES"]))? true : $flagCheckData;
if ($flagCheckData && $arrayFinalData["MSGT_UID"] . "" != "") {
$arrayMessageTypeVariable = array();
$arrayMessageTypeData = $messageType->getMessageType($arrayFinalData["MSGT_UID"], true);
foreach ($arrayMessageTypeData["MSGT_VARIABLES"] as $value) {
$arrayMessageTypeVariable[$value["MSGTV_NAME"]] = $value["MSGTV_DEFAULT_VALUE"];
}
if (count($arrayMessageTypeVariable) != count($arrayFinalData["MSGED_VARIABLES"]) || count(array_diff_key($arrayMessageTypeVariable, $arrayFinalData["MSGED_VARIABLES"])) > 0) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_VARIABLES_DO_NOT_MEET_DEFINITION"));
}
}
if (isset($arrayData["MSGED_USR_UID"])) {
$process->throwExceptionIfNotExistsUser($arrayData["MSGED_USR_UID"], $this->arrayFieldNameForException["messageEventDefinitionUserUid"]);
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Definition for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Definition created
*/
public function create($projectUid, array $arrayData, $flagValidateArrayData = true)
{
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);
unset($arrayData["MSGED_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
if ($flagValidateArrayData) {
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
}
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventDefinition = new \MessageEventDefinition();
if (!isset($arrayData["MSGT_UID"]) || $arrayData["MSGT_UID"] . "" == "") {
$arrayData["MSGT_UID"] = "";
$arrayData["MSGED_VARIABLES"] = array();
}
if (!isset($arrayData["MSGED_VARIABLES"])) {
$arrayData["MSGED_VARIABLES"] = array();
}
if (isset($arrayData["MSGED_USR_UID"]) && $arrayData["MSGED_USR_UID"] != "") {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\UsersPeer::USR_UID);
$criteria->add(\UsersPeer::USR_UID, $arrayData["MSGED_USR_UID"], \Criteria::EQUAL);
//QUERY
$rsCriteria = \UsersPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if (!$rsCriteria->next()) {
$arrayData["MSGED_USR_UID"] = "";
}
}
$messageEventDefinitionUid = \ProcessMaker\Util\Common::generateUID();
$messageEventDefinition->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventDefinition->setMsgedUid($messageEventDefinitionUid);
$messageEventDefinition->setPrjUid($projectUid);
if (isset($arrayData["MSGED_VARIABLES"])) {
$messageEventDefinition->setMsgedVariables(serialize($arrayData["MSGED_VARIABLES"]));
}
if ($messageEventDefinition->validate()) {
$cnn->begin();
$result = $messageEventDefinition->save();
$cnn->commit();
//Task - User
if (isset($arrayData["MSGED_USR_UID"]) && $arrayData["MSGED_USR_UID"] != "") {
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayData["EVN_UID"]);
//Event - START-MESSAGE-EVENT
if (!is_null($bpmnEvent) && $bpmnEvent->getEvnType() == "START" && $bpmnEvent->getEvnMarker() == "MESSAGECATCH") {
//Message-Event-Task-Relation - Get Task
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $projectUid,
\MessageEventTaskRelationPeer::EVN_UID => $bpmnEvent->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Assign
$task = new \Tasks();
$result = $task->assignUser($arrayMessageEventTaskRelationData["TAS_UID"], $arrayData["MSGED_USR_UID"], 1);
}
}
}
//Return
return $this->getMessageEventDefinition($messageEventDefinitionUid);
} else {
$msg = "";
foreach ($messageEventDefinition->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-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param array $arrayData Data
*
* return array Return data of the Message-Event-Definition updated
*/
public function update($messageEventDefinitionUid, 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);
$arrayDataBackup = $arrayData;
unset($arrayData["MSGED_UID"]);
unset($arrayData["PRJ_UID"]);
//Set variables
$arrayMessageEventDefinitionData = $this->getMessageEventDefinition($messageEventDefinitionUid, true);
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
$this->throwExceptionIfDataIsInvalid($messageEventDefinitionUid, $arrayMessageEventDefinitionData["PRJ_UID"], $arrayData);
//Update
$cnn = \Propel::getConnection("workflow");
try {
$messageEventDefinition = \MessageEventDefinitionPeer::retrieveByPK($messageEventDefinitionUid);
if (isset($arrayData["MSGT_UID"]) && $arrayData["MSGT_UID"] . "" == "") {
$arrayData["MSGED_VARIABLES"] = array();
}
$messageEventDefinition->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
if (isset($arrayData["MSGED_VARIABLES"])) {
$messageEventDefinition->setMsgedVariables(serialize($arrayData["MSGED_VARIABLES"]));
}
if ($messageEventDefinition->validate()) {
$cnn->begin();
$result = $messageEventDefinition->save();
$cnn->commit();
//Task - User
if (isset($arrayData["MSGED_USR_UID"]) && $arrayData["MSGED_USR_UID"] != $arrayMessageEventDefinitionData["MSGED_USR_UID"]) {
$bpmnEvent = \BpmnEventPeer::retrieveByPK($arrayMessageEventDefinitionData["EVN_UID"]);
//Event - START-MESSAGE-EVENT
if (!is_null($bpmnEvent) && $bpmnEvent->getEvnType() == "START" && $bpmnEvent->getEvnMarker() == "MESSAGECATCH") {
//Message-Event-Task-Relation - Get Task
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $arrayMessageEventDefinitionData["PRJ_UID"],
\MessageEventTaskRelationPeer::EVN_UID => $bpmnEvent->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Unassign
$taskUser = new \TaskUser();
$criteria = new \Criteria("workflow");
$criteria->add(\TaskUserPeer::TAS_UID, $arrayMessageEventTaskRelationData["TAS_UID"]);
$rsCriteria = \TaskUserPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$result = $taskUser->remove($row["TAS_UID"], $row["USR_UID"], $row["TU_TYPE"], $row["TU_RELATION"]);
}
//Assign
$task = new \Tasks();
$result = $task->assignUser($arrayMessageEventTaskRelationData["TAS_UID"], $arrayData["MSGED_USR_UID"], 1);
}
}
}
//Return
$arrayData = $arrayDataBackup;
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} else {
$msg = "";
foreach ($messageEventDefinition->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-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
*
* return void
*/
public function delete($messageEventDefinitionUid)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
//Delete
$criteria = new \Criteria("workflow");
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUid, \Criteria::EQUAL);
$result = \MessageEventDefinitionPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Set Message-Event-Definition-Variables by Message-Type for a record
*
* @param array $record Record
*
* return array Return the record
*/
public function setMessageEventDefinitionVariablesForRecordByMessageType(array $record)
{
try {
$record["MSGED_VARIABLES"] = ($record["MSGED_VARIABLES"] . "" != "")? unserialize($record["MSGED_VARIABLES"]) : array();
if ($record["MSGT_UID"] . "" != "") {
$arrayMessageTypeVariable = array();
$messageType = new \ProcessMaker\BusinessModel\MessageType();
if ($messageType->exists($record["MSGT_UID"])) {
$arrayMessageTypeData = $messageType->getMessageType($record["MSGT_UID"], true);
foreach ($arrayMessageTypeData["MSGT_VARIABLES"] as $value) {
$arrayMessageTypeVariable[$value["MSGTV_NAME"]] = (isset($record["MSGED_VARIABLES"][$value["MSGTV_NAME"]]))? $record["MSGED_VARIABLES"][$value["MSGTV_NAME"]] : $value["MSGTV_DEFAULT_VALUE"];
}
}
$record["MSGED_VARIABLES"] = $arrayMessageTypeVariable;
}
//Return
return $record;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Definition
*
* return object
*/
public function getMessageEventDefinitionCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGT_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_USR_UID);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_VARIABLES);
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_CORRELATION);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Definition
*/
public function getMessageEventDefinitionDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGED_UID") => $record["MSGED_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID") => $record["EVN_UID"],
$this->getFieldNameByFormatFieldName("MSGT_UID") => $record["MSGT_UID"] . "",
$this->getFieldNameByFormatFieldName("MSGED_USR_UID") => $record["MSGED_USR_UID"] . "",
$this->getFieldNameByFormatFieldName("MSGED_VARIABLES") => $record["MSGED_VARIABLES"],
$this->getFieldNameByFormatFieldName("MSGED_CORRELATION") => $record["MSGED_CORRELATION"] . ""
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get all Message-Event-Definitions
*
* @param string $projectUid Unique id of Project
*
* return array Return an array with all Message-Event-Definitions
*/
public function getMessageEventDefinitions($projectUid)
{
try {
$arrayMessageEventDefinition = array();
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
$arrayMessageEventDefinition[] = $this->getMessageEventDefinitionDataFromRecord($row);
}
//Return
return $arrayMessageEventDefinition;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition
*
* @param string $messageEventDefinitionUid Unique id of Message-Event-Definition
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Definition
*/
public function getMessageEventDefinition($messageEventDefinitionUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventDefinition($messageEventDefinitionUid, $this->arrayFieldNameForException["messageEventDefinitionUid"]);
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::MSGED_UID, $messageEventDefinitionUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
//Return
return (!$flagGetRecord)? $this->getMessageEventDefinitionDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Definition by unique id of Event
*
* @param string $projectUid Unique id of Project
* @param string $eventUid Unique id of Event
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Definition by unique id of Event
*/
public function getMessageEventDefinitionByEvent($projectUid, $eventUid, $flagGetRecord = false)
{
try {
//Verify data
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
if (!$this->existsEvent($projectUid, $eventUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_DEFINITION_DOES_NOT_IS_REGISTERED", array($this->arrayFieldNameForException["eventUid"], $eventUid)));
}
//Get data
$criteria = $this->getMessageEventDefinitionCriteria();
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
$criteria->add(\MessageEventDefinitionPeer::EVN_UID, $eventUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $this->setMessageEventDefinitionVariablesForRecordByMessageType($rsCriteria->getRow());
//Return
return (!$flagGetRecord)? $this->getMessageEventDefinitionDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,451 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventRelation
{
private $arrayFieldDefinition = array(
"MSGER_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventRelationUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID_THROW" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUidThrow"),
"EVN_UID_CATCH" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUidCatch")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* 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-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
*
* return bool Return true if exists the Message-Event-Relation, false otherwise
*/
public function exists($messageEventRelationUid)
{
try {
$obj = \MessageEventRelationPeer::retrieveByPK($messageEventRelationUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if exists the Event-Relation of a Message-Event-Relation
*
* @param string $projectUid Unique id of Project
* @param string $eventUidThrow Unique id of Event (throw)
* @param string $eventUidCatch Unique id of Event (catch)
* @param string $messageEventRelationUidToExclude Unique id of Message-Event-Relation to exclude
*
* return bool Return true if exists the Event-Relation of a Message-Event-Relation, false otherwise
*/
public function existsEventRelation($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventRelationPeer::MSGER_UID);
$criteria->add(\MessageEventRelationPeer::PRJ_UID, $projectUid, \Criteria::EQUAL);
if ($messageEventRelationUidToExclude != "") {
$criteria->add(\MessageEventRelationPeer::MSGER_UID, $messageEventRelationUidToExclude, \Criteria::NOT_EQUAL);
}
$criteria->add(\MessageEventRelationPeer::EVN_UID_THROW, $eventUidThrow, \Criteria::EQUAL);
$criteria->add(\MessageEventRelationPeer::EVN_UID_CATCH, $eventUidCatch, \Criteria::EQUAL);
$rsCriteria = \MessageEventRelationPeer::doSelectRS($criteria);
return ($rsCriteria->next())? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Relation
*/
public function throwExceptionIfNotExistsMessageEventRelation($messageEventRelationUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventRelationUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_RELATION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventRelationUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if is registered the Event-Relation
*
* @param string $projectUid Unique id of Project
* @param string $eventUidThrow Unique id of Event (throw)
* @param string $eventUidCatch Unique id of Event (catch)
* @param string $messageEventRelationUidToExclude Unique id of Message-Event-Relation to exclude
*
* return void Throw exception if is registered the Event-Relation
*/
public function throwExceptionIfEventRelationIsRegistered($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude = "")
{
try {
if ($this->existsEventRelation($projectUid, $eventUidThrow, $eventUidCatch, $messageEventRelationUidToExclude)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_RELATION_ALREADY_REGISTERED"));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventRelationUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventRelationData = ($messageEventRelationUid == "")? array() : $this->getMessageEventRelation($messageEventRelationUid, true);
$flagInsert = ($messageEventRelationUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventRelationData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
//Verify data
if (isset($arrayData["EVN_UID_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
$this->throwExceptionIfEventRelationIsRegistered($projectUid, $arrayFinalData["EVN_UID_THROW"], $arrayFinalData["EVN_UID_CATCH"], $messageEventRelationUid);
}
if (isset($arrayData["EVN_UID_THROW"]) || isset($arrayData["EVN_UID_CATCH"])) {
//Flow
$bpmnFlow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_TYPE => "MESSAGE",
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $arrayFinalData["EVN_UID_THROW"],
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent",
\BpmnFlowPeer::FLO_ELEMENT_DEST => $arrayFinalData["EVN_UID_CATCH"],
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => "bpmnEvent"
));
if (is_null($bpmnFlow)) {
throw new \Exception(\G::LoadTranslation(
"ID_MESSAGE_EVENT_RELATION_DOES_NOT_EXIST_MESSAGE_FLOW",
array(
$this->arrayFieldNameForException["eventUidThrow"], $arrayFinalData["EVN_UID_THROW"],
$this->arrayFieldNameForException["eventUidCatch"], $arrayFinalData["EVN_UID_CATCH"]
)
));
}
//Check and validate Message Flow
$bpmn = new \ProcessMaker\Project\Bpmn();
$bpmn->throwExceptionFlowIfIsAnInvalidMessageFlow(array(
"FLO_TYPE" => "MESSAGE",
"FLO_ELEMENT_ORIGIN" => $arrayFinalData["EVN_UID_THROW"],
"FLO_ELEMENT_ORIGIN_TYPE" => "bpmnEvent",
"FLO_ELEMENT_DEST" => $arrayFinalData["EVN_UID_CATCH"],
"FLO_ELEMENT_DEST_TYPE" => "bpmnEvent"
));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Relation for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Relation 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);
unset($arrayData["MSGER_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventRelation = new \MessageEventRelation();
$messageEventRelationUid = \ProcessMaker\Util\Common::generateUID();
$messageEventRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventRelation->setMsgerUid($messageEventRelationUid);
$messageEventRelation->setPrjUid($projectUid);
if ($messageEventRelation->validate()) {
$cnn->begin();
$result = $messageEventRelation->save();
$cnn->commit();
//Return
return $this->getMessageEventRelation($messageEventRelationUid);
} else {
$msg = "";
foreach ($messageEventRelation->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;
}
}
/**
* Delete Message-Event-Relation
*
* @param array $arrayCondition Conditions
*
* return void
*/
public function deleteWhere(array $arrayCondition)
{
try {
//Delete
$criteria = new \Criteria("workflow");
foreach ($arrayCondition as $key => $value) {
if (is_array($value)) {
$criteria->add($key, $value[0], $value[1]);
} else {
$criteria->add($key, $value, \Criteria::EQUAL);
}
}
$result = \MessageEventRelationPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Relation
*
* return object
*/
public function getMessageEventRelationCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventRelationPeer::MSGER_UID);
$criteria->addSelectColumn(\MessageEventRelationPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventRelationPeer::EVN_UID_THROW);
$criteria->addSelectColumn(\MessageEventRelationPeer::EVN_UID_CATCH);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Relation from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Relation
*/
public function getMessageEventRelationDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGER_UID") => $record["MSGER_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID_THROW") => $record["EVN_UID_THROW"],
$this->getFieldNameByFormatFieldName("EVN_UID_CATCH") => $record["EVN_UID_CATCH"]
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Relation
*
* @param string $messageEventRelationUid Unique id of Message-Event-Relation
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Relation
*/
public function getMessageEventRelation($messageEventRelationUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventRelation($messageEventRelationUid, $this->arrayFieldNameForException["messageEventRelationUid"]);
//Get data
$criteria = $this->getMessageEventRelationCriteria();
$criteria->add(\MessageEventRelationPeer::MSGER_UID, $messageEventRelationUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventRelationDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Relation
*
* @param array $arrayCondition Conditions
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Relation, otherwise null
*/
public function getMessageEventRelationWhere(array $arrayCondition, $flagGetRecord = false)
{
try {
//Get data
$criteria = $this->getMessageEventRelationCriteria();
foreach ($arrayCondition as $key => $value) {
if (is_array($value)) {
$criteria->add($key, $value[0], $value[1]);
} else {
$criteria->add($key, $value, \Criteria::EQUAL);
}
}
$rsCriteria = \MessageEventRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventRelationDataFromRecord($row) : $row;
} else {
//Return
return null;
}
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -0,0 +1,360 @@
<?php
namespace ProcessMaker\BusinessModel;
class MessageEventTaskRelation
{
private $arrayFieldDefinition = array(
"MSGETR_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "messageEventTaskRelationUid"),
"PRJ_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectUid"),
"EVN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "eventUid"),
"TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array();
/**
* 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-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
*
* return bool Return true if exists the Message-Event-Task-Relation, false otherwise
*/
public function exists($messageEventTaskRelationUid)
{
try {
$obj = \MessageEventTaskRelationPeer::retrieveByPK($messageEventTaskRelationUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Verify if does not exists the Message-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param string $fieldNameForException Field name for the exception
*
* return void Throw exception if does not exists the Message-Event-Task-Relation
*/
public function throwExceptionIfNotExistsMessageEventTaskRelation($messageEventTaskRelationUid, $fieldNameForException)
{
try {
if (!$this->exists($messageEventTaskRelationUid)) {
throw new \Exception(\G::LoadTranslation("ID_MESSAGE_EVENT_TASK_RELATION_DOES_NOT_EXIST", array($fieldNameForException, $messageEventTaskRelationUid)));
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Validate the data if they are invalid (INSERT and UPDATE)
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return void Throw exception if data has an invalid value
*/
public function throwExceptionIfDataIsInvalid($messageEventTaskRelationUid, $projectUid, array $arrayData)
{
try {
//Set variables
$arrayMessageEventTaskRelationData = ($messageEventTaskRelationUid == "")? array() : $this->getMessageEventTaskRelation($messageEventTaskRelationUid, true);
$flagInsert = ($messageEventTaskRelationUid == "")? true : false;
$arrayFinalData = array_merge($arrayMessageEventTaskRelationData, $arrayData);
//Verify data - Field definition
$process = new \ProcessMaker\BusinessModel\Process();
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, $flagInsert);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Message-Event-Task-Relation for a Project
*
* @param string $projectUid Unique id of Project
* @param array $arrayData Data
*
* return array Return data of the new Message-Event-Task-Relation 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);
unset($arrayData["MSGETR_UID"]);
unset($arrayData["PRJ_UID"]);
//Verify data
$process->throwExceptionIfNotExistsProcess($projectUid, $this->arrayFieldNameForException["projectUid"]);
$this->throwExceptionIfDataIsInvalid("", $projectUid, $arrayData);
//Create
$cnn = \Propel::getConnection("workflow");
try {
$messageEventTaskRelation = new \MessageEventTaskRelation();
$messageEventTaskRelationUid = \ProcessMaker\Util\Common::generateUID();
$messageEventTaskRelation->fromArray($arrayData, \BasePeer::TYPE_FIELDNAME);
$messageEventTaskRelation->setMsgetrUid($messageEventTaskRelationUid);
$messageEventTaskRelation->setPrjUid($projectUid);
if ($messageEventTaskRelation->validate()) {
$cnn->begin();
$result = $messageEventTaskRelation->save();
$cnn->commit();
//Return
return $this->getMessageEventTaskRelation($messageEventTaskRelationUid);
} else {
$msg = "";
foreach ($messageEventTaskRelation->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;
}
}
/**
* Delete Message-Event-Task-Relation
*
* @param array $arrayCondition Conditions
*
* return void
*/
public function deleteWhere(array $arrayCondition)
{
try {
//Delete
$criteria = new \Criteria("workflow");
foreach ($arrayCondition as $key => $value) {
if (is_array($value)) {
$criteria->add($key, $value[0], $value[1]);
} else {
$criteria->add($key, $value, \Criteria::EQUAL);
}
}
$result = \MessageEventTaskRelationPeer::doDelete($criteria);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get criteria for Message-Event-Task-Relation
*
* return object
*/
public function getMessageEventTaskRelationCriteria()
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::MSGETR_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::PRJ_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::TAS_UID);
return $criteria;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation from a record
*
* @param array $record Record
*
* return array Return an array with data Message-Event-Task-Relation
*/
public function getMessageEventTaskRelationDataFromRecord(array $record)
{
try {
return array(
$this->getFieldNameByFormatFieldName("MSGETR_UID") => $record["MSGETR_UID"],
$this->getFieldNameByFormatFieldName("EVN_UID") => $record["EVN_UID"],
$this->getFieldNameByFormatFieldName("TAS_UID") => $record["TAS_UID"]
);
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation
*
* @param string $messageEventTaskRelationUid Unique id of Message-Event-Task-Relation
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Task-Relation
*/
public function getMessageEventTaskRelation($messageEventTaskRelationUid, $flagGetRecord = false)
{
try {
//Verify data
$this->throwExceptionIfNotExistsMessageEventTaskRelation($messageEventTaskRelationUid, $this->arrayFieldNameForException["messageEventTaskRelationUid"]);
//Get data
$criteria = $this->getMessageEventTaskRelationCriteria();
$criteria->add(\MessageEventTaskRelationPeer::MSGETR_UID, $messageEventTaskRelationUid, \Criteria::EQUAL);
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$rsCriteria->next();
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventTaskRelationDataFromRecord($row) : $row;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Get data of a Message-Event-Task-Relation
*
* @param array $arrayCondition Conditions
* @param bool $flagGetRecord Value that set the getting
*
* return array Return an array with data of a Message-Event-Task-Relation, otherwise null
*/
public function getMessageEventTaskRelationWhere(array $arrayCondition, $flagGetRecord = false)
{
try {
//Get data
$criteria = $this->getMessageEventTaskRelationCriteria();
foreach ($arrayCondition as $key => $value) {
if (is_array($value)) {
$criteria->add($key, $value[0], $value[1]);
} else {
$criteria->add($key, $value, \Criteria::EQUAL);
}
}
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Return
return (!$flagGetRecord)? $this->getMessageEventTaskRelationDataFromRecord($row) : $row;
} else {
//Return
return null;
}
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -213,23 +213,23 @@ class Process
if ($arrayFieldDefinition[$fieldName]["empty"] && $fieldValue . "" == "") {
//
} else {
$eregDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])";
$eregHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)(?:\:[0-5]\d)?";
$eregDatetime = $eregDate . "\s" . $eregHour;
$regexpDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])";
$regexpHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)(?:\:[0-5]\d)?";
$regexpDatetime = $regexpDate . "\s" . $regexpHour;
switch ($arrayFieldDefinition[$fieldName]["type"]) {
case "date":
if (!preg_match("/^" . $eregDate . "$/", $fieldValue)) {
if (!preg_match("/^" . $regexpDate . "$/", $fieldValue)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
}
break;
case "hour":
if (!preg_match("/^" . $eregHour . "$/", $fieldValue)) {
if (!preg_match("/^" . $regexpHour . "$/", $fieldValue)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
}
break;
case "datetime":
if (!preg_match("/^" . $eregDatetime . "$/", $fieldValue)) {
if (!preg_match("/^" . $regexpDatetime . "$/", $fieldValue)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
}
break;
@@ -239,9 +239,12 @@ class Process
case 2:
switch ($arrayFieldDefinition[$fieldName]["type"]) {
case "array":
$regexpArray1 = "\s*array\s*\(";
$regexpArray2 = "\)\s*";
//type
if (!is_array($fieldValue)) {
if ($fieldValue != "" && !preg_match("/^\s*array\s*\(.*\)\s*$/", $fieldValue)) {
if ($fieldValue != "" && !preg_match("/^" . $regexpArray1 . ".*" . $regexpArray2 . "$/", $fieldValue)) {
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_THIS_MUST_BE_ARRAY", array($fieldNameAux)));
}
}
@@ -255,7 +258,13 @@ class Process
}
if (is_string($fieldValue) && trim($fieldValue) . "" != "") {
eval("\$arrayAux = $fieldValue;");
//eval("\$arrayAux = $fieldValue;");
if (preg_match("/^" . $regexpArray1 . "(.*)" . $regexpArray2 . "$/", $fieldValue, $arrayMatch)) {
if (trim($arrayMatch[1], " ,") != "") {
$arrayAux = array(0);
}
}
}
if (count($arrayAux) == 0) {

View File

@@ -395,9 +395,17 @@ class WebEntry
$fileContent .= "\$_SESSION[\"PROCESS\"] = \"" . $processUid . "\";\n";
$fileContent .= "\$_SESSION[\"CURRENT_DYN_UID\"] = \"" . $dynaFormUid . "\";\n";
$fileContent .= "\$G_PUBLISH = new Publisher();\n";
$fileContent .= "G::LoadClass('pmDynaform');\n";
$fileContent .= "\$a = new pmDynaform('".$arrayWebEntryData["DYN_UID"]."', array());\n";
$fileContent .= "if(\$a->isResponsive()){";
$fileContent .= "\$a->printWebEntry('".$fileName."Post.php');";
$fileContent .= "}else {";
$fileContent .= "\$G_PUBLISH->AddContent(\"dynaform\", \"xmlform\", \"" . $processUid . "/" . $dynaFormUid . "\", \"\", array(), \"" . $fileName . "Post.php\");\n";
$fileContent .= "G::RenderPage(\"publish\", \"blank\");";
$fileContent .= "}";
file_put_contents($pathDataPublicProcess . PATH_SEP . $fileName . ".php", $fileContent);
//Creating the second file, the post file who receive the post form.

View File

@@ -359,9 +359,11 @@ class WebEntryEvent
//Task
$task = new \Task();
$prefix = "wee-";
$this->webEntryEventWebEntryTaskUid = $task->create(
array(
"TAS_UID" => \ProcessMaker\Util\Common::generateUID(),
"TAS_UID" => $prefix . substr(\ProcessMaker\Util\Common::generateUID(), (32 - strlen($prefix)) * -1),
"PRO_UID" => $projectUid,
"TAS_TYPE" => "WEBENTRYEVENT",
"TAS_TITLE" => "WEBENTRYEVENT",
@@ -765,6 +767,8 @@ class WebEntryEvent
throw new \Exception(\G::LoadTranslation("ID_REGISTRY_CANNOT_BE_UPDATED") . (($msg != "")? "\n" . $msg : ""));
}
} catch (\Exception $e) {
$cnn->rollback();
$this->deleteWebEntry($this->webEntryEventWebEntryUid, $this->webEntryEventWebEntryTaskUid);
throw $e;

View File

@@ -73,8 +73,7 @@ abstract class Importer
{
$this->prepare();
$name = $this->importData["tables"]["bpmn"]["project"][0]["prj_name"];
//Verify data
switch ($option) {
case self::IMPORT_OPTION_CREATE_NEW:
if ($this->targetExists()) {
@@ -94,23 +93,12 @@ abstract class Importer
self::IMPORT_STAT_TARGET_ALREADY_EXISTS
);
}
$generateUid = false;
break;
case self::IMPORT_OPTION_OVERWRITE:
$this->removeProject();
// this option shouldn't generate new uid for all objects
$generateUid = false;
break;
case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW:
$this->disableProject();
// this option should generate new uid for all objects
$generateUid = true;
$name = "New - " . $name . " - " . date("M d, H:i");
break;
case self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW:
// this option should generate new uid for all objects
$generateUid = true;
$name = \G::LoadTranslation("ID_COPY_OF") . " - " . $name . " - " . date("M d, H:i");
break;
}
@@ -149,6 +137,36 @@ abstract class Importer
break;
}
//Import
$name = $this->importData["tables"]["bpmn"]["project"][0]["prj_name"];
switch ($option) {
case self::IMPORT_OPTION_CREATE_NEW:
//Shouldn't generate new UID for all objects
$generateUid = false;
break;
case self::IMPORT_OPTION_OVERWRITE:
//Shouldn't generate new UID for all objects
$this->removeProject();
$generateUid = false;
break;
case self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW:
//Should generate new UID for all objects
$this->disableProject();
$name = "New - " . $name . " - " . date("M d, H:i");
$generateUid = true;
break;
case self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW:
//Should generate new UID for all objects
$name = \G::LoadTranslation("ID_COPY_OF") . " - " . $name . " - " . date("M d, H:i");
$generateUid = true;
break;
}
$this->importData["tables"]["bpmn"]["project"][0]["prj_name"] = $name;
$this->importData["tables"]["bpmn"]["diagram"][0]["dia_name"] = $name;
$this->importData["tables"]["bpmn"]["process"][0]["pro_name"] = $name;
@@ -374,7 +392,7 @@ abstract class Importer
foreach ($arrayWorkflowTables["tasks"] as $key => $value) {
$arrayTaskData = $value;
if (!in_array($arrayTaskData["TAS_TYPE"], array("GATEWAYTOGATEWAY", "WEBENTRYEVENT"))) {
if (!in_array($arrayTaskData["TAS_TYPE"], array("GATEWAYTOGATEWAY", "WEBENTRYEVENT", "END-MESSAGE-EVENT", "START-MESSAGE-EVENT", "INTERMEDIATE-THROW-MESSAGE-EVENT", "INTERMEDIATE-CATCH-MESSAGE-EVENT"))) {
$result = $workflow->updateTask($arrayTaskData["TAS_UID"], $arrayTaskData);
}
}

View File

@@ -17,11 +17,21 @@ class BpmnWorkflow extends Project\Bpmn
*/
protected $wp;
const BPMN_GATEWAY_COMPLEX = "COMPLEX";
const BPMN_GATEWAY_PARALLEL = "PARALLEL";
const BPMN_GATEWAY_INCLUSIVE = "INCLUSIVE";
const BPMN_GATEWAY_EXCLUSIVE = "EXCLUSIVE";
const BPMN_GATEWAY_COMPLEX = "COMPLEX";
const BPMN_GATEWAY_PARALLEL = "PARALLEL";
const BPMN_GATEWAY_INCLUSIVE = "INCLUSIVE";
const BPMN_GATEWAY_EXCLUSIVE = "EXCLUSIVE";
const BPMN_GATEWAY_EVENTBASED = "EVENTBASED";
private $arrayTaskAttribute = array(
"gateway-to-gateway" => array("type" => "GATEWAYTOGATEWAY", "prefix" => "gtg-"),
"end-message-event" => array("type" => "END-MESSAGE-EVENT", "prefix" => "eme-"),
"start-message-event" => array("type" => "START-MESSAGE-EVENT", "prefix" => "sme-"),
"intermediate-throw-message-event" => array("type" => "INTERMEDIATE-THROW-MESSAGE-EVENT", "prefix" => "itme-"),
"intermediate-catch-message-event" => array("type" => "INTERMEDIATE-CATCH-MESSAGE-EVENT", "prefix" => "icme-")
);
private $arrayMessageEventTaskRelation = array();
/**
* OVERRIDES
@@ -247,18 +257,19 @@ class BpmnWorkflow extends Project\Bpmn
//WebEntry-Event - Update
$this->updateWebEntryEventByEvent($data["FLO_ELEMENT_ORIGIN"], array("ACT_UID" => $data["FLO_ELEMENT_DEST"]));
break;
case "bpmnEvent":
$messageEventRelationUid = $this->createMessageEventRelationByBpmnFlow(\BpmnFlowPeer::retrieveByPK($floUid));
break;
}
break;
case "bpmnActivity":
switch ($data["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnEvent":
$actUid = $data["FLO_ELEMENT_ORIGIN"];
$evnUid = $data["FLO_ELEMENT_DEST"];
$event = \BpmnEventPeer::retrieveByPK($evnUid);
$event = \BpmnEventPeer::retrieveByPK($data["FLO_ELEMENT_DEST"]);
// setting as end task
if ($event && $event->getEvnType() == "END") {
$this->wp->setEndTask($actUid);
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
$this->wp->setEndTask($data["FLO_ELEMENT_ORIGIN"]);
}
break;
}
@@ -306,7 +317,7 @@ class BpmnWorkflow extends Project\Bpmn
) {
$event = \BpmnEventPeer::retrieveByPK($flowBefore->getFloElementDest());
if (!is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
//Remove as end task
$this->wp->setEndTask($flowBefore->getFloElementOrigin(), false);
@@ -322,7 +333,7 @@ class BpmnWorkflow extends Project\Bpmn
) {
$event = \BpmnEventPeer::retrieveByPK($flowBefore->getFloElementDest());
if (!is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
//Remove as end task
$this->wp->setEndTask($flowBefore->getFloElementOrigin(), false);
}
@@ -336,6 +347,27 @@ class BpmnWorkflow extends Project\Bpmn
) {
$this->wp->removeRouteFromTo($flowBefore->getFloElementOrigin(), $flowBefore->getFloElementDest());
}
//Verify case: Event1(message) -> Event2(message) -----Update-to----> Event(message) -> Event(message)
if ($flowBefore->getFloType() == "MESSAGE" &&
$flowBefore->getFloElementOriginType() == "bpmnEvent" && $flowBefore->getFloElementDestType() == "bpmnEvent"
) {
//Delete Message-Event-Relation
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelation->deleteWhere(array(
\MessageEventRelationPeer::PRJ_UID => $flowBefore->getPrjUid(),
\MessageEventRelationPeer::EVN_UID_THROW => $flowBefore->getFloElementOrigin(),
\MessageEventRelationPeer::EVN_UID_CATCH => $flowBefore->getFloElementDest()
));
//Create Message-Event-Relation
if ($flowCurrent->getFloType() == "MESSAGE" &&
$flowCurrent->getFloElementOriginType() == "bpmnEvent" && $flowCurrent->getFloElementDestType() == "bpmnEvent"
) {
$messageEventRelationUid = $this->createMessageEventRelationByBpmnFlow($flowCurrent);
}
}
}
public function removeFlow($floUid)
@@ -379,7 +411,7 @@ class BpmnWorkflow extends Project\Bpmn
// => find the corresponding task and unset it as start task
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementDest());
if (! is_null($event) && $event->getEvnType() == "END") {
if (!is_null($event) && $event->getEvnType() == "END" && $event->getEvnMarker() == "EMPTY") {
$activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementOrigin());
if (! is_null($activity)) {
@@ -396,6 +428,23 @@ class BpmnWorkflow extends Project\Bpmn
break;
}
break;
case "bpmnEvent":
switch ($flow->getFloElementDestType()) {
//Event1 -> Event2
case "bpmnEvent":
if ($flow->getFloType() == "MESSAGE") {
//Delete Message-Event-Relation
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelation->deleteWhere(array(
\MessageEventRelationPeer::PRJ_UID => $flow->getPrjUid(),
\MessageEventRelationPeer::EVN_UID_THROW => $flow->getFloElementOrigin(),
\MessageEventRelationPeer::EVN_UID_CATCH => $flow->getFloElementDest()
));
}
break;
}
break;
}
}
@@ -411,12 +460,12 @@ class BpmnWorkflow extends Project\Bpmn
$eventUid = parent::addEvent($data);
$event = \BpmnEventPeer::retrieveByPK($eventUid);
//Delete case scheduler
// create case scheduler
if ($event && $event->getEvnMarker() == "TIMER" && $event->getEvnType() == "START") {
$this->wp->addCaseScheduler($eventUid);
}
//Delete WebEntry-Event
// create web entry
if ($event && $event->getEvnMarker() == "MESSAGE" && $event->getEvnType() == "START") {
$this->wp->addWebEntry($eventUid);
}
@@ -428,19 +477,63 @@ class BpmnWorkflow extends Project\Bpmn
{
$event = \BpmnEventPeer::retrieveByPK($eventUid);
// delete case scheduler
//Delete case scheduler
if ($event && $event->getEvnMarker() == "TIMER" && $event->getEvnType() == "START") {
$this->wp->removeCaseScheduler($eventUid);
}
// delete web entry
if (!is_null($event) && $event->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if (!is_null($event)) {
//WebEntry-Event - Delete
if ($event->getEvnType() == "START") {
$webEntryEvent = new \ProcessMaker\BusinessModel\WebEntryEvent();
if ($webEntryEvent->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($event->getPrjUid(), $eventUid, true);
if ($webEntryEvent->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayWebEntryEventData = $webEntryEvent->getWebEntryEventByEvent($event->getPrjUid(), $eventUid, true);
$webEntryEvent->delete($arrayWebEntryEventData["WEE_UID"]);
$webEntryEvent->delete($arrayWebEntryEventData["WEE_UID"]);
}
}
//Message-Event-Definition - Delete
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
if (!is_null($event) &&
in_array($event->getEvnType(), $arrayEventType) && in_array($event->getEvnMarker(), $arrayEventMarker)
) {
$messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
if ($messageEventDefinition->existsEvent($event->getPrjUid(), $eventUid)) {
$arrayMessageEventDefinitionData = $messageEventDefinition->getMessageEventDefinitionByEvent($event->getPrjUid(), $eventUid, true);
$messageEventDefinition->delete($arrayMessageEventDefinitionData["MSGED_UID"]);
}
}
//Message-Event-Task-Relation - Delete
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayMessageEventTaskRelationData = $messageEventTaskRelation->getMessageEventTaskRelationWhere(
array(
\MessageEventTaskRelationPeer::PRJ_UID => $event->getPrjUid(),
\MessageEventTaskRelationPeer::EVN_UID => $event->getEvnUid()
),
true
);
if (!is_null($arrayMessageEventTaskRelationData)) {
//Task - Delete
$arrayTaskData = $this->wp->getTask($arrayMessageEventTaskRelationData["TAS_UID"]);
if (!is_null($arrayTaskData)) {
$this->wp->removeTask($arrayMessageEventTaskRelationData["TAS_UID"]);
}
//Message-Event-Task-Relation - Delete
$messageEventTaskRelation->deleteWhere(array(\MessageEventTaskRelationPeer::MSGETR_UID => $arrayMessageEventTaskRelationData["MSGETR_UID"]));
//Array - Delete element
unset($this->arrayMessageEventTaskRelation[$eventUid]);
}
}
@@ -462,6 +555,84 @@ class BpmnWorkflow extends Project\Bpmn
//}
}
public function createTaskByElement($elementUid, $elementType, $key)
{
try {
if (isset($this->arrayMessageEventTaskRelation[$elementUid])) {
$taskUid = $this->arrayMessageEventTaskRelation[$elementUid];
} else {
$taskPosX = 0;
$taskPosY = 0;
$flow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $elementUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => $elementType
));
if (!is_null($flow)) {
$arrayFlowData = $flow->toArray();
$taskPosX = (int)($arrayFlowData["FLO_X1"]);
$taskPosY = (int)($arrayFlowData["FLO_Y1"]);
} else {
$flow = \BpmnFlow::findOneBy(array(
\BpmnFlowPeer::FLO_ELEMENT_DEST => $elementUid,
\BpmnFlowPeer::FLO_ELEMENT_DEST_TYPE => $elementType
));
if (!is_null($flow)) {
$arrayFlowData = $flow->toArray();
$taskPosX = (int)($arrayFlowData["FLO_X2"]);
$taskPosY = (int)($arrayFlowData["FLO_Y2"]);
}
}
$prefix = $this->arrayTaskAttribute[$key]["prefix"];
$taskType = $this->arrayTaskAttribute[$key]["type"];
$taskUid = $this->wp->addTask(array(
"TAS_UID" => $prefix . substr(Util\Common::generateUID(), (32 - strlen($prefix)) * -1),
"TAS_TYPE" => $taskType,
"TAS_TITLE" => $taskType,
"TAS_POSX" => $taskPosX,
"TAS_POSY" => $taskPosY
));
if ($elementType == "bpmnEvent" &&
in_array($key, array("end-message-event", "start-message-event", "intermediate-catch-message-event"))
) {
if ($key == "intermediate-catch-message-event") {
//Task - User
//Assign to admin
$task = new \Tasks();
$result = $task->assignUser($taskUid, "00000000000000000000000000000001", 1);
}
//Message-Event-Task-Relation - Create
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$arrayResult = $messageEventTaskRelation->create(
$this->wp->getUid(),
array(
"EVN_UID" => $elementUid,
"TAS_UID" => $taskUid
)
);
//Array - Add element
$this->arrayMessageEventTaskRelation[$elementUid] = $taskUid;
}
}
//Return
return $taskUid;
} catch (\Exception $e) {
throw $e;
}
}
public function mapBpmnGatewayToWorkflowRoutes($activityUid, $gatewayUid)
{
try {
@@ -504,21 +675,28 @@ class BpmnWorkflow extends Project\Bpmn
}
}
break;
//case "TO_DO":
case self::BPMN_GATEWAY_EVENTBASED:
$routeType = "EVALUATE";
break;
//default
default:
throw new \LogicException("Unsupported Gateway type: " . $arrayGatewayData["GAT_TYPE"]);
break;
}
$arrayGatewayFlowData = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $gatewayUid,
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_TYPE => array("MESSAGE", \Criteria::NOT_EQUAL),
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $gatewayUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnGateway"
));
if ($arrayGatewayFlowData > 0) {
if ($arrayFlow > 0) {
$this->wp->resetTaskRoutes($activityUid);
}
foreach ($arrayGatewayFlowData as $value) {
foreach ($arrayFlow as $value) {
$arrayFlowData = $value->toArray();
$routeDefault = (array_key_exists("FLO_TYPE", $arrayFlowData) && $arrayFlowData["FLO_TYPE"] == "DEFAULT")? 1 : 0;
@@ -526,37 +704,59 @@ class BpmnWorkflow extends Project\Bpmn
switch ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnActivity":
case "bpmnEvent":
//Gateway ----> Activity
//Gateway ----> Event
if ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"] == "bpmnEvent") {
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if ($event->getEvnType() == "END") {
$result = $this->wp->addRoute($activityUid, -1, $routeType, $routeCondition, $routeDefault);
}
} else {
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
}
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
case "bpmnGateway":
//Gateway ----> Gateway
$taskUid = $this->wp->addTask(array(
"TAS_TYPE" => "GATEWAYTOGATEWAY",
"TAS_TITLE" => "GATEWAYTOGATEWAY",
"TAS_POSX" => (int)($arrayFlowData["FLO_X1"]),
"TAS_POSY" => (int)($arrayFlowData["FLO_Y1"])
));
$taskUid = $this->createTaskByElement(
$gatewayUid,
"bpmnGateway",
"gateway-to-gateway"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$this->mapBpmnGatewayToWorkflowRoutes($taskUid, $arrayFlowData["FLO_ELEMENT_DEST"]);
break;
case "bpmnEvent":
//Gateway ----> Event
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnGateway -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]);
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
$result = $this->wp->addRoute($activityUid, -1, $routeType, $routeCondition, $routeDefault);
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
}
}
break;
default:
//For processmaker is only allowed flows between: "gateway -> activity", "gateway -> gateway"
//For ProcessMaker is only allowed flows between: "gateway -> activity", "gateway -> gateway", "gateway -> event"
//any another flow is considered invalid
throw new \LogicException(
"For ProcessMaker is only allowed flows between: \"gateway -> activity\", \"gateway -> gateway\" " . PHP_EOL .
"For ProcessMaker is only allowed flows between: \"gateway -> activity\", \"gateway -> gateway\", \"gateway -> event\"" . PHP_EOL .
"Given: bpmnGateway -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]
);
}
@@ -566,29 +766,196 @@ class BpmnWorkflow extends Project\Bpmn
}
}
public function mapBpmnEventToWorkflowRoutes($activityUid, $eventUid, $routeType = "SEQUENTIAL", $routeCondition = "", $routeDefault = 0)
{
try {
$arrayEventData = \BpmnEvent::findOneBy(\BpmnEventPeer::EVN_UID, $eventUid)->toArray();
$arrayEventType = array("START", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
if (!is_null($arrayEventData) &&
in_array($arrayEventData["EVN_TYPE"], $arrayEventType) && in_array($arrayEventData["EVN_MARKER"], $arrayEventMarker)
) {
//Event - INTERMEDIATE-CATCH-MESSAGE-EVENT
if ($arrayEventData["EVN_TYPE"] == "INTERMEDIATE" && $arrayEventData["EVN_MARKER"] == "MESSAGECATCH") {
$taskUid = $this->createTaskByElement(
$eventUid,
"bpmnEvent",
"intermediate-catch-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$activityUid = $taskUid;
$routeType = "SEQUENTIAL";
$routeCondition = "";
$routeDefault = 0;
}
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_TYPE => array("MESSAGE", \Criteria::NOT_EQUAL),
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $eventUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnEvent"
));
foreach ($arrayFlow as $value) {
$arrayFlowData = $value->toArray();
switch ($arrayFlowData["FLO_ELEMENT_DEST_TYPE"]) {
case "bpmnActivity":
//Event ----> Activity
$result = $this->wp->addRoute($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
case "bpmnGateway":
//Event ----> Gateway
$this->mapBpmnGatewayToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"]);
break;
case "bpmnEvent":
//Event ----> Event
$event = \BpmnEventPeer::retrieveByPK($arrayFlowData["FLO_ELEMENT_DEST"]);
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnEvent -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]);
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
$result = $this->wp->addRoute($activityUid, -1, $routeType, $routeCondition, $routeDefault);
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activityUid, $taskUid, $routeType, $routeCondition, $routeDefault);
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activityUid, $arrayFlowData["FLO_ELEMENT_DEST"], $routeType, $routeCondition, $routeDefault);
break;
}
}
break;
default:
//For ProcessMaker is only allowed flows between: "event -> activity", "event -> gateway", "event -> event"
//any another flow is considered invalid
throw new \LogicException(
"For ProcessMaker is only allowed flows between: \"event -> activity\", \"event -> gateway\", \"event -> event\"" . PHP_EOL .
"Given: bpmnEvent -> " . $arrayFlowData["FLO_ELEMENT_DEST_TYPE"]
);
}
}
}
} catch (\Exception $e) {
throw $e;
}
}
public function mapBpmnFlowsToWorkflowRoutes()
{
$this->wp->deleteTaskGatewayToGateway($this->wp->getUid());
//Task - Delete dummies
$this->wp->deleteTaskByArrayType(
$this->wp->getUid(),
array(
$this->arrayTaskAttribute["gateway-to-gateway"]["type"]
)
);
$activities = $this->getActivities();
//Activities
foreach ($this->getActivities() as $value) {
$activity = $value;
foreach ($activities as $activity) {
$flows = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $activity["ACT_UID"],
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_TYPE => array("MESSAGE", \Criteria::NOT_EQUAL),
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $activity["ACT_UID"],
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnActivity"
));
foreach ($flows as $flow) {
foreach ($arrayFlow as $value2) {
$flow = $value2;
switch ($flow->getFloElementDestType()) {
case "bpmnActivity":
// (activity -> activity)
//Activity -> Activity
$this->wp->addRoute($activity["ACT_UID"], $flow->getFloElementDest(), "SEQUENTIAL");
break;
case "bpmnGateway":
// (activity -> gateway)
// we must find the related flows: gateway -> <object>
//Activity -> Gateway
//We must find the related flows: gateway -> <object>
$this->mapBpmnGatewayToWorkflowRoutes($activity["ACT_UID"], $flow->getFloElementDest());
break;
case "bpmnEvent":
//Activity -> Event
$event = \BpmnEventPeer::retrieveByPK($flow->getFloElementDest());
if (!is_null($event)) {
switch ($event->getEvnType()) {
case "START":
throw new \LogicException("Incorrect design" . PHP_EOL . "Given: bpmnActivity -> " . $flow->getFloElementDestType());
break;
case "END":
//$event->getEvnMarker(): EMPTY or MESSAGETHROW
switch ($event->getEvnMarker()) {
case "EMPTY":
//This it's already implemented
break;
case "MESSAGETHROW":
$taskUid = $this->createTaskByElement(
$event->getEvnUid(),
"bpmnEvent",
"end-message-event"
);
$result = $this->wp->addRoute($activity["ACT_UID"], $taskUid, "SEQUENTIAL");
$result = $this->wp->addRoute($taskUid, -1, "SEQUENTIAL");
break;
}
break;
case "INTERMEDIATE":
$this->mapBpmnEventToWorkflowRoutes($activity["ACT_UID"], $flow->getFloElementDest());
break;
}
}
break;
}
}
}
//Events - Message-Event
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW", "MESSAGECATCH");
foreach ($this->getEvents() as $value) {
$event = $value;
if (in_array($event["EVN_TYPE"], $arrayEventType) && in_array($event["EVN_MARKER"], $arrayEventMarker)) {
switch ($event["EVN_TYPE"]) {
case "START":
$taskUid = $this->createTaskByElement(
$event["EVN_UID"],
"bpmnEvent",
"start-message-event"
);
$this->wp->setStartTask($taskUid);
$this->mapBpmnEventToWorkflowRoutes($taskUid, $event["EVN_UID"]);
break;
case "END":
break;
case "INTERMEDIATE":
break;
}
}
}
@@ -789,6 +1156,27 @@ class BpmnWorkflow extends Project\Bpmn
$bwp->update($projectRecord);
//Array - Set empty
$bwp->arrayMessageEventTaskRelation = array();
//Message-Event-Task-Relation - Get all records
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::EVN_UID);
$criteria->addSelectColumn(\MessageEventTaskRelationPeer::TAS_UID);
$criteria->add(\MessageEventTaskRelationPeer::PRJ_UID, $bwp->wp->getUid(), \Criteria::EQUAL);
$rsCriteria = \MessageEventTaskRelationPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
//Array - Add element
$bwp->arrayMessageEventTaskRelation[$row["EVN_UID"]] = $row["TAS_UID"];
}
/*
* Diagram's Laneset Handling
*/
@@ -895,7 +1283,12 @@ class BpmnWorkflow extends Project\Bpmn
$activity = $bwp->getActivity($activityData["ACT_UID"]);
if ($activity["BOU_CONTAINER"] != $activityData["BOU_CONTAINER"]) {
$activity = null;
}
if ($forceInsert || is_null($activity)) {
if ($generateUid) {
//Activity
@@ -928,6 +1321,7 @@ class BpmnWorkflow extends Project\Bpmn
$diagram["activities"][$i] = $activityData;
$whiteList[] = $activityData["ACT_UID"];
}
$activities = $bwp->getActivities();
@@ -949,6 +1343,10 @@ class BpmnWorkflow extends Project\Bpmn
$artifact = $bwp->getArtifact($artifactData["ART_UID"]);
if ($artifact["BOU_CONTAINER"] != $artifactData["BOU_CONTAINER"]) {
$artifact = null;
}
if ($forceInsert || is_null($artifact)) {
if ($generateUid) {
//Artifact
@@ -1009,6 +1407,10 @@ class BpmnWorkflow extends Project\Bpmn
$gateway = $bwp->getGateway($gatewayData["GAT_UID"]);
if ($gateway["BOU_CONTAINER"] != $gatewayData["BOU_CONTAINER"]) {
$gateway = null;
}
if ($forceInsert || is_null($gateway)) {
if ($generateUid) {
//Gateway
@@ -1083,6 +1485,10 @@ class BpmnWorkflow extends Project\Bpmn
$event = $bwp->getEvent($eventData["EVN_UID"]);
if ($event["BOU_CONTAINER"] != $eventData["BOU_CONTAINER"]) {
$event = null;
}
if ($forceInsert || is_null($event)) {
if ($generateUid) {
//Event
@@ -1139,6 +1545,10 @@ class BpmnWorkflow extends Project\Bpmn
$dataObject = $bwp->getData($dataObjectData["DAT_UID"]);
if ($dataObject["BOU_CONTAINER"] != $dataObjectData["BOU_CONTAINER"]) {
$dataObject = null;
}
if ($forceInsert || is_null($dataObject)) {
if ($generateUid) {
//Data
@@ -1193,9 +1603,13 @@ class BpmnWorkflow extends Project\Bpmn
$participantData = array_change_key_case($participantData, CASE_UPPER);
unset($participantData["_EXTENDED"]);
$dataObject = $bwp->getParticipant($participantData["PAR_UID"]);
$participant = $bwp->getParticipant($participantData["PAR_UID"]);
if ($forceInsert || is_null($dataObject)) {
if ($participant["BOU_CONTAINER"] != $participantData["BOU_CONTAINER"]) {
$participant = null;
}
if ($forceInsert || is_null($participant)) {
if ($generateUid) {
//Participant
@@ -1221,7 +1635,7 @@ class BpmnWorkflow extends Project\Bpmn
}
$bwp->addParticipant($participantData);
} elseif (! $bwp->isEquals($dataObject, $participantData)) {
} elseif (! $bwp->isEquals($participant, $participantData)) {
$bwp->updateParticipant($participantData["PAR_UID"], $participantData);
} else {
Util\Logger::log("Update Participant ({$participantData["PAR_UID"]}) Skipped - No changes required");
@@ -1356,5 +1770,34 @@ class BpmnWorkflow extends Project\Bpmn
throw $e;
}
}
public function createMessageEventRelationByBpmnFlow(\BpmnFlow $bpmnFlow)
{
try {
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelationUid = "";
if ($bpmnFlow->getFloType() == "MESSAGE" &&
$bpmnFlow->getFloElementOriginType() == "bpmnEvent" && $bpmnFlow->getFloElementDestType() == "bpmnEvent" &&
!$messageEventRelation->existsEventRelation($bpmnFlow->getPrjUid(), $bpmnFlow->getFloElementOrigin(), $bpmnFlow->getFloElementDest())
) {
$arrayResult = $messageEventRelation->create(
$bpmnFlow->getPrjUid(),
array(
"EVN_UID_THROW" => $bpmnFlow->getFloElementOrigin(),
"EVN_UID_CATCH" => $bpmnFlow->getFloElementDest()
)
);
$messageEventRelationUid = $arrayResult["MSGER_UID"];
}
//Return
return $messageEventRelationUid;
} catch (\Exception $e) {
throw $e;
}
}
}

View File

@@ -91,6 +91,19 @@ class Bpmn extends Handler
}
}
public function exists($projectUid)
{
try {
$obj = ProjectPeer::retrieveByPK($projectUid);
return (!is_null($obj))? true : false;
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
public static function load($prjUid)
{
$me = new self();
@@ -588,6 +601,8 @@ class Bpmn extends Handler
//Return
return false;
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
@@ -625,12 +640,55 @@ class Bpmn extends Handler
}
}
public function throwExceptionFlowIfIsAnInvalidMessageFlow(array $bpmnFlow)
{
try {
if ($bpmnFlow["FLO_TYPE"] == "MESSAGE" &&
$bpmnFlow["FLO_ELEMENT_ORIGIN_TYPE"] == "bpmnEvent" && $bpmnFlow["FLO_ELEMENT_DEST_TYPE"] == "bpmnEvent"
) {
$flagValid = true;
$arrayEventType = array("START", "END", "INTERMEDIATE");
$arrayAux = array(
array("eventUid" => $bpmnFlow["FLO_ELEMENT_ORIGIN"], "eventMarker" => "MESSAGETHROW"),
array("eventUid" => $bpmnFlow["FLO_ELEMENT_DEST"], "eventMarker" => "MESSAGECATCH")
);
foreach ($arrayAux as $value) {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\BpmnEventPeer::EVN_UID);
$criteria->add(\BpmnEventPeer::EVN_UID, $value["eventUid"], \Criteria::EQUAL);
$criteria->add(\BpmnEventPeer::EVN_TYPE, $arrayEventType, \Criteria::IN);
$criteria->add(\BpmnEventPeer::EVN_MARKER, $value["eventMarker"], \Criteria::EQUAL);
$rsCriteria = \BpmnEventPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
$flagValid = false;
break;
}
}
if (!$flagValid) {
throw new \RuntimeException("Invalid Message Flow.");
}
}
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
public function addFlow($data)
{
self::log("Add Flow with data: ", $data);
// setting defaults
$data['FLO_UID'] = array_key_exists('FLO_UID', $data) ? $data['FLO_UID'] : Common::generateUID();
if (array_key_exists('FLO_STATE', $data)) {
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
}
@@ -680,17 +738,23 @@ class Bpmn extends Handler
));
}
//Check and validate Message Flow
$this->throwExceptionFlowIfIsAnInvalidMessageFlow($data);
//Create
$flow = new Flow();
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
$flow->setPrjUid($this->getUid());
$flow->setDiaUid($this->getDiagram("object")->getDiaUid());
$flow->setFloPosition($this->getFlowNextPosition($data["FLO_UID"], $data["FLO_TYPE"], $data["FLO_ELEMENT_ORIGIN"]));
$flow->save();
self::log("Add Flow Success!");
return $flow->getFloUid();
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
@@ -703,7 +767,12 @@ class Bpmn extends Handler
if (array_key_exists('FLO_STATE', $data)) {
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
}
try {
//Check and validate Message Flow
$this->throwExceptionFlowIfIsAnInvalidMessageFlow($data);
//Update
$flow = FlowPeer::retrieveByPk($floUid);
$flow->fromArray($data);
$flow->save();
@@ -1242,6 +1311,8 @@ class Bpmn extends Handler
//Return
return $this->getGateway2($gatewayUid);
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
@@ -1288,5 +1359,99 @@ class Bpmn extends Handler
throw $oException;
}
}
public function getElementsBetweenElementOriginAndElementDest(
$elementOriginUid,
$elementOriginType,
$elementDestUid,
$elementDestType,
$index
) {
try {
if ($elementOriginType == $elementDestType && $elementOriginUid == $elementDestUid) {
$arrayEvent = array();
$arrayEvent[$index] = array($elementDestUid, $elementDestType);
//Return
return $arrayEvent;
} else {
//Flows
$arrayFlow = \BpmnFlow::findAllBy(array(
\BpmnFlowPeer::FLO_TYPE => array("MESSAGE", \Criteria::NOT_EQUAL),
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $elementOriginUid,
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => $elementOriginType
));
foreach ($arrayFlow as $value) {
$arrayFlowData = $value->toArray();
$arrayEvent = $this->getElementsBetweenElementOriginAndElementDest(
$arrayFlowData["FLO_ELEMENT_DEST"],
$arrayFlowData["FLO_ELEMENT_DEST_TYPE"],
$elementDestUid,
$elementDestType,
$index + 1
);
if (count($arrayEvent) > 0) {
$arrayEvent[$index] = array($elementOriginUid, $elementOriginType);
//Return
return $arrayEvent;
}
}
//Return
return array();
}
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
public function getMessageEventsOfThrowTypeBetweenElementOriginAndElementDest(
$elementOriginUid,
$elementOriginType,
$elementDestUid,
$elementDestType
) {
try {
$arrayEventType = array("END", "INTERMEDIATE");
$arrayEventMarker = array("MESSAGETHROW");
$arrayEventAux = $this->getElementsBetweenElementOriginAndElementDest(
$elementOriginUid,
$elementOriginType,
$elementDestUid,
$elementDestType,
0
);
ksort($arrayEventAux);
$arrayEvent = array();
foreach ($arrayEventAux as $value) {
if ($value[1] == "bpmnEvent") {
$event = \BpmnEventPeer::retrieveByPK($value[0]);
if (!is_null($event) &&
in_array($event->getEvnType(), $arrayEventType) && in_array($event->getEvnMarker(), $arrayEventMarker)
) {
$arrayEvent[] = $value;
}
}
}
//Return
return $arrayEvent;
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
}

View File

@@ -764,6 +764,13 @@ class Workflow extends Handler
$oCriteria->add(\CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
\ProcessUserPeer::doDelete($oCriteria);
//Delete SubProcess
$criteria = new \Criteria("workflow");
$criteria->add(\SubProcessPeer::PRO_PARENT, $sProcessUID, \Criteria::EQUAL);
$result = \SubProcessPeer::doDelete($criteria);
//Delete WebEntries
$webEntry = new \ProcessMaker\BusinessModel\WebEntry();
@@ -815,6 +822,33 @@ class Workflow extends Handler
$messageType->delete($row["MSGT_UID"]);
}
//Delete Message-Event-Relation
$messageEventRelation = new \ProcessMaker\BusinessModel\MessageEventRelation();
$messageEventRelation->deleteWhere(array(\MessageEventRelationPeer::PRJ_UID => $sProcessUID));
//Delete Message-Event-Task-Relation
$messageEventTaskRelation = new \ProcessMaker\BusinessModel\MessageEventTaskRelation();
$messageEventTaskRelation->deleteWhere(array(\MessageEventTaskRelationPeer::PRJ_UID => $sProcessUID));
//Delete Message-Event-Definition
$messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\MessageEventDefinitionPeer::MSGED_UID);
$criteria->add(\MessageEventDefinitionPeer::PRJ_UID, $sProcessUID, \Criteria::EQUAL);
$rsCriteria = \MessageEventDefinitionPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$row = $rsCriteria->getRow();
$messageEventDefinition->delete($row["MSGED_UID"]);
}
//Delete the process
try {
$oProcess->remove($sProcessUID);
@@ -1184,6 +1218,23 @@ class Workflow extends Handler
}
}
}
//Update MESSAGE_EVENT_DEFINITION.EVN_UID
if (isset($arrayWorkflowData["messageEventDefinition"])) {
foreach ($arrayWorkflowData["messageEventDefinition"] as $key => $value) {
$messageEventDefinitionEventUid = $arrayWorkflowData["messageEventDefinition"][$key]["EVN_UID"];
foreach ($arrayUid as $value2) {
$arrayItem = $value2;
if ($arrayItem["old_uid"] == $messageEventDefinitionEventUid) {
$arrayWorkflowData["messageEventDefinition"][$key]["EVN_UID"] = $arrayItem["new_uid"];
break;
}
}
}
}
//Workflow tables
$workflowData = (object)($arrayWorkflowData);
@@ -1236,7 +1287,7 @@ class Workflow extends Handler
}
}
public function deleteTaskGatewayToGateway($processUid)
public function deleteTaskByArrayType($processUid, array $arrayTaskType)
{
try {
$task = new \Tasks();
@@ -1245,7 +1296,7 @@ class Workflow extends Handler
$criteria->addSelectColumn(\TaskPeer::TAS_UID);
$criteria->add(\TaskPeer::PRO_UID, $processUid, \Criteria::EQUAL);
$criteria->add(\TaskPeer::TAS_TYPE, "GATEWAYTOGATEWAY", \Criteria::EQUAL);
$criteria->add(\TaskPeer::TAS_TYPE, $arrayTaskType, \Criteria::IN);
$rsCriteria = \TaskPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);

View File

@@ -0,0 +1,734 @@
<?php
namespace ProcessMaker\Services\Api;
use \G;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
*
* Process Api Controller
*
* @protected
*/
class Light extends Api
{
/**
* Get list counters
* @return array
*
* @copyright Colosa - Bolivia
*
* @url GET /counters
*/
public function countersCases ()
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$counterCase = $oMobile->getCounterCase($this->getUserId());
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $counterCase;
}
/**
* Get list process start
* @return array
*
* @copyright Colosa - Bolivia
*
* @url GET /start-case
*/
public function getProcessListStartCase ()
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$startCase = $oMobile->getProcessListStartCase($this->getUserId());
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $startCase;
}
/**
* Get list Case To Do
*
* @copyright Colosa - Bolivia
*
* @url GET /todo
*/
public function doGetCasesListToDo(
$start = 0,
$limit = 10,
$sort = 'APP_CACHE_VIEW.APP_NUMBER',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$search = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['action'] = 'todo';
$dataList['paged'] = true;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['search'] = $search;
$oCases = new \ProcessMaker\BusinessModel\Cases();
$response = $oCases->getList($dataList);
$result = $this->parserDataTodo($response['data']);
return $result;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
public function parserDataTodo ($data)
{
$structure = array(
//'app_uid' => 'mongoId',
'app_uid' => 'caseId',
'app_title' => 'caseTitle',
'app_number' => 'caseNumber',
'app_update_date' => 'date',
'del_task_due_date' => 'dueDate',
//'' => 'status'
'user' => array(
'usrcr_usr_uid' => 'userId',
'usrcr_usr_firstname' => 'firstName',
'usrcr_usr_lastname' => 'lastName',
'usrcr_usr_username' => 'fullName',
),
'prevUser' => array(
'previous_usr_uid' => 'userId',
'previous_usr_firstname' => 'firstName',
'previous_usr_lastname' => 'lastName',
'previous_usr_username' => 'fullName',
),
'process' => array(
'pro_uid' => 'processId',
'app_pro_title' => 'name'
),
'task' => array(
'tas_uid' => 'taskId',
'app_tas_title' => 'name'
),
'inp_doc_uid' => 'documentUid' //Esta opcion es temporal
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
* Get list Cases Participated
*
* @copyright Colosa - Bolivia
*
* @url GET /participated
*/
public function doGetCasesListParticipated(
$start = 0,
$limit = 10,
$sort = 'APP_CACHE_VIEW.APP_NUMBER',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$search = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['action'] = 'sent';
$dataList['paged'] = true;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['search'] = $search;
$oCases = new \ProcessMaker\BusinessModel\Cases();
$response = $oCases->getList($dataList);
$result = $this->parserDataParticipated($response['data']);
return $result;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
public function parserDataParticipated ($data)
{
$structure = array(
//'app_uid' => 'mongoId',
'app_uid' => 'caseId',
'app_title' => 'caseTitle',
'app_number' => 'caseNumber',
'app_update_date' => 'date',
'del_task_due_date' => 'dueDate',
'currentUser' => array(
'usrcr_usr_uid' => 'userId',
'usrcr_usr_firstname' => 'firstName',
'usrcr_usr_lastname' => 'lastName',
'usrcr_usr_username' => 'fullName',
),
'prevUser' => array(
'previous_usr_uid' => 'userId',
'previous_usr_firstname' => 'firstName',
'previous_usr_lastname' => 'lastName',
'previous_usr_username' => 'fullName',
),
'process' => array(
'pro_uid' => 'processId',
'app_pro_title' => 'name'
),
'task' => array(
'tas_uid' => 'taskId',
'app_tas_title' => 'name'
)
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
* Get list Cases Paused
*
* @copyright Colosa - Bolivia
*
* @url GET /paused
*/
public function doGetCasesListPaused(
$start = 0,
$limit = 10,
$sort = 'APP_CACHE_VIEW.APP_NUMBER',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$search = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['action'] = 'paused';
$dataList['paged'] = true;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['search'] = $search;
$oCases = new \ProcessMaker\BusinessModel\Cases();
$response = $oCases->getList($dataList);
$result = $this->parserDataParticipated($response['data']);
return $result;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
public function parserDataPaused ($data)
{
$structure = array(
//'app_uid' => 'mongoId',
'app_uid' => 'caseId',
'app_title' => 'caseTitle',
'app_number' => 'caseNumber',
'app_update_date' => 'date',
'del_task_due_date' => 'dueDate',
'currentUser' => array(
'usrcr_usr_uid' => 'userId',
'usrcr_usr_firstname' => 'firstName',
'usrcr_usr_lastname' => 'lastName',
'usrcr_usr_username' => 'fullName',
),
'prevUser' => array(
'previous_usr_uid' => 'userId',
'previous_usr_firstname' => 'firstName',
'previous_usr_lastname' => 'lastName',
'previous_usr_username' => 'fullName',
),
'process' => array(
'pro_uid' => 'processId',
'app_pro_title' => 'name'
),
'task' => array(
'tas_uid' => 'taskId',
'app_tas_title' => 'name'
)
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
* Get list Cases Unassigned
*
* @copyright Colosa - Bolivia
*
* @url GET /unassigned
*/
public function doGetCasesListUnassigned(
$start = 0,
$limit = 0,
$sort = 'APP_CACHE_VIEW.APP_NUMBER',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$search = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['action'] = 'unassigned';
$dataList['paged'] = false;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['search'] = $search;
$oCases = new \ProcessMaker\BusinessModel\Cases();
$response = $oCases->getList($dataList);
$result = $this->parserDataUnassigned($response);
return $result;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
public function parserDataUnassigned ($data)
{
$structure = array(
//'app_uid' => 'mongoId',
'app_uid' => 'caseId',
'app_title' => 'caseTitle',
'app_number' => 'caseNumber',
'app_update_date' => 'date',
'del_task_due_date' => 'dueDate',
'currentUser' => array(
'usrcr_usr_uid' => 'userId',
'usrcr_usr_firstname' => 'firstName',
'usrcr_usr_lastname' => 'lastName',
'usrcr_usr_username' => 'fullName',
),
'prevUser' => array(
'previous_usr_uid' => 'userId',
'previous_usr_firstname' => 'firstName',
'previous_usr_lastname' => 'lastName',
'previous_usr_username' => 'fullName',
),
'process' => array(
'pro_uid' => 'processId',
'app_pro_title' => 'name'
),
'task' => array(
'tas_uid' => 'taskId',
'app_tas_title' => 'name'
)
);
$response = $this->replaceFields($data, $structure);
return $response;
}
public function replaceFields ($data, $structure)
{
$response = array();
foreach ($data as $field => $d) {
if (is_array($d)) {
$newData = array();
foreach ($d as $field => $value) {
if (array_key_exists($field, $structure)) {
$newName = $structure[$field];
$newData[$newName] = $value;
} else {
foreach ($structure as $name => $str) {
if (is_array($str) && array_key_exists($field, $str)) {
$newName = $str[$field];
$newData[$name][$newName] = $value;
}
}
}
}
$response[] = $newData;
} else {
if (array_key_exists($field, $structure)) {
$newName = $structure[$field];
$response[$newName] = $d;
} else {
foreach ($structure as $name => $str) {
if (is_array($str) && array_key_exists($field, $str)) {
$newName = $str[$field];
$response[$name][$newName] = $d;
}
}
}
}
}
return $response;
}
/**
* Get list History case
*
* @copyright Colosa - Bolivia
*
* @url GET /history/:app_uid
*
* @param string $app_uid {@min 32}{@max 32}
*/
public function doGetCasesListHistory($app_uid)
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$response = $oMobile->getCasesListHistory($app_uid);
$response['flow'] = $this->parserDataHistory($response['flow']);
$r = new \stdclass();
$r->data = $response;
$r->totalCount = count($response['flow']);
return $r;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
public function parserDataHistory ($data)
{
$structure = array(
//'' => 'caseId',
//'' => 'caseTitle',
//'' => 'processName',
//'' => 'ownerFullName',
//'flow' => array(
'TAS_TITLE' => 'taskName',
//'' => 'userId',
'USR_NAME' => 'userFullName',
'APP_TYPE' => 'flowStatus', // is null default Router in FE
'DEL_DELEGATE_DATE' => 'dueDate',
//)
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
*
* @url GET /project/:prj_uid/dynaforms
*
* @param string $prj_uid {@min 32}{@max 32}
*/
public function doGetDynaForms($prj_uid)
{
try {
$process = new \ProcessMaker\BusinessModel\Process();
$process->setFormatFieldNameInUppercase(false);
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$response = $process->getDynaForms($prj_uid);
$result = $this->parserDataDynaForm($response);
foreach ($result as $k => $form) {
$result[$k]['formContent'] = (isset($form['formContent']) && $form['formContent'] != null)?json_decode($form['formContent']):"";
$result[$k]['index'] = $k;
}
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $result;
}
/**
* @url GET /project/:prj_uid/activity/:act_uid/steps
*
* @param string $act_uid {@min 32}{@max 32}
* @param string $prj_uid {@min 32}{@max 32}
*/
public function doGetActivitySteps($act_uid, $prj_uid)
{
try {
$task = new \ProcessMaker\BusinessModel\Task();
$task->setFormatFieldNameInUppercase(false);
$task->setArrayParamException(array("taskUid" => "act_uid", "stepUid" => "step_uid"));
$activitySteps = $task->getSteps($act_uid);
//$step = new \ProcessMaker\Services\Api\Project\Activity\Step();
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$response = array();
for ($i = 0; $i < count($activitySteps); $i++) {
if ($activitySteps[$i]['step_type_obj'] == "DYNAFORM") {
$dataForm = $dynaForm->getDynaForm($activitySteps[$i]['step_uid_obj']);
$result = $this->parserDataDynaForm($dataForm);
$result['formContent'] = (isset($result['formContent']) && $result['formContent'] != null)?json_decode($result['formContent']):"";
$result['index'] = $i;
//$activitySteps[$i]["triggers"] = $step->doGetActivityStepTriggers($activitySteps[$i]["step_uid"], $act_uid, $prj_uid);
$response[] = $result;
}
}
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $response;
}
/**
* @url GET /project/dynaform/:dyn_uid
*
* @param string $dyn_uid {@min 32}{@max 32}
*/
public function doGetDynaForm($dyn_uid)
{
try {
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$response = $dynaForm->getDynaForm($dyn_uid);
$result = $this->parserDataDynaForm($response);
$result['formContent'] = (isset($result['formContent']) && $result['formContent'] != null)?json_decode($result['formContent']):"";
return $result;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url POST /project/dynaforms
*
*/
public function doGetDynaFormsId($request_data)
{
try {
$dynaForm = new \ProcessMaker\BusinessModel\DynaForm();
$dynaForm->setFormatFieldNameInUppercase(false);
$return = array();
foreach ($request_data['formId'] as $dyn_uid) {
$response = $dynaForm->getDynaForm($dyn_uid);
$result = $this->parserDataDynaForm($response);
$result['formContent'] = (isset($result['formContent']) && $result['formContent'] != null)?json_decode($result['formContent']):"";
$return[] = $result;
}
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $return;
}
public function parserDataDynaForm ($data)
{
$structure = array(
'dyn_uid' => 'formId',
'dyn_title' => 'formTitle',
'dyn_description' => 'formDescription',
//'dyn_type' => 'formType',
'dyn_content' => 'formContent'
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
* @url POST /process/:pro_uid/task/:task_uid/start-case
*
* @param string $pro_uid {@min 32}{@max 32}
* @param string $task_uid {@min 32}{@max 32}
*/
public function postStartCase($pro_uid, $task_uid)
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$result = $oMobile->startCase($this->getUserId(), $pro_uid, $task_uid);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $result;
}
/**
* Route Case
* @url PUT /cases/:app_uid/route-case
*
* @param string $app_uid {@min 32}{@max 32}
* @param string $del_index {@from body}
*/
public function doPutRouteCase($app_uid, $del_index = null)
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$response = $oMobile->updateRouteCase($app_uid, $this->getUserId(), $del_index);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $response;
}
/**
* @url GET /user/data
*/
public function doGetUserData()
{
try {
$userUid = $this->getUserId();
$oMobile = new \ProcessMaker\BusinessModel\Light();
$response = $oMobile->getUserData($userUid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
return $response;
}
/**
* @url POST /users/data
*/
public function doGetUsersData($request_data)
{
try {
$response = array();
$oMobile = new \ProcessMaker\BusinessModel\Light();
foreach ($request_data['user']['ids'] as $userUid) {
$response[] = $oMobile->getUserData($userUid);
}
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
return $response;
}
/**
* @url POST /case/:app_uid/input-document
*
* @param string $app_uid { @min 32}{@max 32}
* @param string $tas_uid {@min 32}{@max 32}
* @param string $app_doc_comment
* @param string $inp_doc_uid {@min 32}{@max 32}
*/
public function doPostInputDocument($app_uid, $tas_uid, $app_doc_comment, $inp_doc_uid)
{
try {
$userUid = $this->getUserId();
$inputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument();
$file = $inputDocument->addCasesInputDocument($app_uid, $tas_uid, $app_doc_comment, $inp_doc_uid, $userUid);
$response = $this->parserInputDocument($file);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $response;
}
public function parserInputDocument ($data)
{
$structure = array(
'app_doc_uid' => 'fileId',
'app_doc_filename' => 'fileName',
'app_doc_version' => 'version'
);
$response = $this->replaceFields($data, $structure);
return $response;
}
/**
* @url POST /case/:app_uid/input-document/location
*
* @param string $app_uid { @min 32}{@max 32}
* @param string $tas_uid {@min 32}{@max 32}
* @param string $app_doc_comment
* @param string $inp_doc_uid {@min 32}{@max 32}
* @param float $latitude {@min -90}{@max 90}
* @param float $longitude {@min -180}{@max 180}
*/
public function postInputDocumentLocation($app_uid, $tas_uid, $app_doc_comment, $inp_doc_uid, $latitude, $longitude)
{
try {
$userUid = $this->getUserId();
$inputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument();
$url = "http://maps.googleapis.com/maps/api/staticmap?center=".$latitude.','.$longitude."&format=jpg&size=600x600&zoom=15&markers=color:blue%7Clabel:S%7C".$latitude.','.$longitude;
$imageLocation = imagecreatefromjpeg($url);
$tmpfname = tempnam("php://temp","pmm");
imagejpeg($imageLocation, $tmpfname);
$_FILES["form"]["type"] = "image/jpeg";
$_FILES["form"]["name"] = 'Location.jpg';
$_FILES["form"]["tmp_name"] = $tmpfname;
$_FILES["form"]["error"] = 0;
$sizes = getimagesize($tmpfname);
$_FILES["form"]["size"] = ($sizes['0'] * $sizes['1']);
$file = $inputDocument->addCasesInputDocument($app_uid, $tas_uid, $app_doc_comment, $inp_doc_uid, $userUid);
$strPathName = PATH_DOCUMENT . G::getPathFromUID($app_uid) . PATH_SEP;
$strFileName = $file->app_doc_uid . "_" . $file->app_doc_version . ".jpg";
copy($tmpfname, $strPathName . "/" . $strFileName);
$response = $this->parserInputDocument($file);
unlink($tmpfname);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $response;
}
/**
* @url POST /case/:app_uid/download64
*
* @param string $app_uid {@min 32}{@max 32}
*/
public function postDownloadFile($app_uid, $request_data)
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$files = $oMobile->downloadFile($app_uid, $request_data);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $files;
}
/**
* @url POST /logout
*
* @param $access
* @param $refresh
* @return mixed
*/
public function postLogout($access, $refresh)
{
try {
$oMobile = new \ProcessMaker\BusinessModel\Light();
$files = $oMobile->logout($access, $refresh);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
return $files;
}
/**
* @url GET /:type/case/:app_uid
*
* @param $access
* @param $refresh
* @return mixed
*/
public function getInformation($type, $app_uid)
{
try {
$userUid = $this->getUserId();
$oMobile = new \ProcessMaker\BusinessModel\Light();
$oMobile->getInformation($userUid, $type, $app_uid);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}

View File

@@ -24,8 +24,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -45,12 +45,13 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
$date_to = ''
$date_to = '',
$action = ''
) {
try {
$dataList['userId'] = $this->getUserId();
@@ -62,13 +63,15 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to;
$dataList['action'] = $action;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getList('inbox', $dataList);
return $response;
@@ -80,8 +83,8 @@ class Lists extends Api
/**
* Get count list Inbox
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -95,8 +98,8 @@ class Lists extends Api
* @url GET /total
*/
public function doGetCountInbox(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -105,8 +108,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -129,8 +132,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -150,8 +153,8 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -167,8 +170,8 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -185,8 +188,8 @@ class Lists extends Api
/**
* Get count list Participated Last
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -200,8 +203,8 @@ class Lists extends Api
* @url GET /participated-last/total
*/
public function doGetCountParticipatedLast(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -210,8 +213,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -234,8 +237,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -254,8 +257,8 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -271,8 +274,8 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -289,8 +292,8 @@ class Lists extends Api
/**
* Get count list Participated History
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -303,8 +306,8 @@ class Lists extends Api
* @url GET /participated-history/total
*/
public function doGetCountParticipatedHistory(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -313,8 +316,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -329,6 +332,217 @@ class Lists extends Api
}
/**
* Get list Paused
*
* @param string $count {@from path}
* @param string $paged {@from path}
* @param string $start {@from path}
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
* @param string $date_to {@from path}
* @return array
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /paused
*/
public function doGetListPaused(
$count = true,
$paged = true,
$start = 0,
$limit = 0,
$sort = 'APP_PAUSED_DATE',
$dir = 'DESC',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
$date_to = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['paged'] = $paged;
$dataList['count'] = $count;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getList('paused', $dataList);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get count list Paused
*
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
* @param string $date_to {@from path}
* @return array
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /paused/total
*/
public function doGetCountPaused(
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
$date_to = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getList('paused', $dataList, true);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get list Canceled
*
* @param string $count {@from path}
* @param string $paged {@from path}
* @param string $start {@from path}
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
* @param string $date_to {@from path}
* @return array
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /canceled
*/
public function doGetListCanceled(
$count = true,
$paged = true,
$start = 0,
$limit = 0,
$sort = 'APP_CANCELED_DATE',
$dir = 'DESC',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
$date_to = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['paged'] = $paged;
$dataList['count'] = $count;
$dataList['start'] = $start;
$dataList['limit'] = $limit;
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getList('canceled', $dataList);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get count list Canceled
*
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
* @param string $date_to {@from path}
* @return array
*
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /canceled/total
*/
public function doGetCountCanceled(
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
$date_to = ''
) {
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getList('canceled', $dataList, true);
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get List Completed
*
@@ -338,8 +552,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -358,8 +572,8 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -375,8 +589,8 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -393,8 +607,8 @@ class Lists extends Api
/**
* Get count list Participated History
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -407,8 +621,8 @@ class Lists extends Api
* @url GET /completed/total
*/
public function doGetCountCompleted(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -417,8 +631,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -442,8 +656,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -462,8 +676,8 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -479,8 +693,8 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -497,8 +711,8 @@ class Lists extends Api
/**
* Get count list Participated History
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -511,8 +725,8 @@ class Lists extends Api
* @url GET /my-inbox/total
*/
public function doGetCountListMyInbox(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -521,8 +735,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -545,8 +759,8 @@ class Lists extends Api
* @param string $limit {@from path}
* @param string $sort {@from path}
* @param string $dir {@from path}
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -565,8 +779,8 @@ class Lists extends Api
$limit = 0,
$sort = 'APP_UPDATE_DATE',
$dir = 'DESC',
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -583,8 +797,8 @@ class Lists extends Api
$dataList['sort'] = $sort;
$dataList['dir'] = $dir;
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;
@@ -601,8 +815,8 @@ class Lists extends Api
/**
* Get count list Unassigned
*
* @param string $cat_uid {@from path}
* @param string $pro_uid {@from path}
* @param string $category {@from path}
* @param string $process {@from path}
* @param string $search {@from path}
* @param string $filter {@from path}
* @param string $date_from {@from path}
@@ -615,8 +829,8 @@ class Lists extends Api
* @url GET /unassigned/total
*/
public function doGetCountUnassigned(
$cat_uid = '',
$pro_uid = '',
$category = '',
$process = '',
$search = '',
$filter = '',
$date_from = '',
@@ -625,8 +839,8 @@ class Lists extends Api
try {
$dataList['userId'] = $this->getUserId();
$dataList['category'] = $cat_uid;
$dataList['process'] = $pro_uid;
$dataList['category'] = $category;
$dataList['process'] = $process;
$dataList['search'] = $search;
$dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from;

View File

@@ -0,0 +1,134 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
/**
* Project\MessageEventDefinition Api Controller
*
* @protected
*/
class MessageEventDefinition extends Api
{
private $messageEventDefinition;
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
$this->messageEventDefinition = new \ProcessMaker\BusinessModel\MessageEventDefinition();
$this->messageEventDefinition->setFormatFieldNameInUppercase(false);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definitions
*
* @param string $prj_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinitions($prj_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinitions($prj_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinition($prj_uid, $msged_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinition($msged_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url GET /:prj_uid/message-event-definition/event/:evn_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $evn_uid {@min 32}{@max 32}
*/
public function doGetMessageEventDefinitionEvent($prj_uid, $evn_uid)
{
try {
$response = $this->messageEventDefinition->getMessageEventDefinitionByEvent($prj_uid, $evn_uid);
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url POST /:prj_uid/message-event-definition
*
* @param string $prj_uid {@min 32}{@max 32}
* @param array $request_data
*
* @status 201
*/
public function doPostMessageEventDefinition($prj_uid, array $request_data)
{
try {
$arrayData = $this->messageEventDefinition->create($prj_uid, $request_data);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url PUT /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
* @param array $request_data
*/
public function doPutMessageEventDefinition($prj_uid, $msged_uid, array $request_data)
{
try {
$arrayData = $this->messageEventDefinition->update($msged_uid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
/**
* @url DELETE /:prj_uid/message-event-definition/:msged_uid
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $msged_uid {@min 32}{@max 32}
*/
public function doDeleteMessageEventDefinition($prj_uid, $msged_uid)
{
try {
$this->messageEventDefinition->delete($msged_uid);
} catch (\Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
}
}

View File

@@ -17,9 +17,10 @@ class PmPdo implements \OAuth2\Storage\AuthorizationCodeInterface,
{
protected $db;
protected $dbRBAC;
protected $config;
public function __construct($connection, $config = array())
public function __construct($connection, $config = array(), $connectionRBAC = null)
{
if (!$connection instanceof \PDO) {
if (!is_array($connection)) {
@@ -37,6 +38,23 @@ class PmPdo implements \OAuth2\Storage\AuthorizationCodeInterface,
}
$this->db = $connection;
// it's for Pm < 3
if (!is_null($connectionRBAC) &&(!$connectionRBAC instanceof \PDO)) {
if (!is_array($connectionRBAC)) {
throw new \InvalidArgumentException('First argument to OAuth2\Storage\Pdo must be an instance of PDO or a configuration array');
}
if (!isset($connectionRBAC['dsn'])) {
throw new \InvalidArgumentException('configuration array must contain "dsn"');
}
// merge optional parameters
$connectionRBAC = array_merge(array(
'username' => null,
'password' => null,
), $connectionRBAC);
$connectionRBAC = new \PDO($connectionRBAC['dsn'], $connectionRBAC['username'], $connectionRBAC['password']);
}
$this->dbRBAC = $connectionRBAC;
// debugging
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
@@ -45,7 +63,7 @@ class PmPdo implements \OAuth2\Storage\AuthorizationCodeInterface,
'access_token_table' => 'OAUTH_ACCESS_TOKENS',
'refresh_token_table' => 'OAUTH_REFRESH_TOKENS',
'code_table' => 'OAUTH_AUTHORIZATION_CODES',
'user_table' => 'USERS',
'user_table' => 'RBAC_USERS',
'jwt_table' => 'OAUTH_JWT',
), $config);
}
@@ -211,12 +229,15 @@ class PmPdo implements \OAuth2\Storage\AuthorizationCodeInterface,
// plaintext passwords are bad! Override this for your application
protected function checkPassword($user, $password)
{
return $user['USR_PASSWORD'] == md5($password);
return $user['USR_PASSWORD'] == \Bootstrap::hashPassword($password);
}
public function getUser($username)
{
$stmt = $this->db->prepare($sql = sprintf('SELECT * FROM %s WHERE USR_USERNAME=:username', $this->config['user_table']));
if (!is_null($this->dbRBAC)) {
$stmt = $this->dbRBAC->prepare($sql = sprintf('SELECT * FROM %s WHERE USR_USERNAME=:username', $this->config['user_table']));
}
$stmt->execute(array('username' => $username));
if (!$userInfo = $stmt->fetch()) {

View File

@@ -29,6 +29,10 @@ class Server implements iAuthenticate
protected static $dbUser;
protected static $dbPassword;
protected static $dsn;
protected static $dbUserRBAC;
protected static $dbPasswordRBAC;
protected static $dsnRBAC;
protected static $isRBAC = false;
protected static $workspace;
public function __construct()
@@ -42,9 +46,15 @@ class Server implements iAuthenticate
);
// $dsn is the Data Source Name for your database, for exmaple "mysql:dbname=my_oauth2_db;host=localhost"
$config = array('dsn' => self::$dsn, 'username' => self::$dbUser, 'password' => self::$dbPassword);
//var_dump($config); die;
$this->storage = new PmPdo($config);
$cnn = array('dsn' => self::$dsn, 'username' => self::$dbUser, 'password' => self::$dbPassword);
if (self::$isRBAC) {
$config = array();
$cnnrbac = array('dsn' => self::$dsnRBAC, 'username' => self::$dbUserRBAC, 'password' => self::$dbPasswordRBAC);
$this->storage = new PmPdo($cnn, $config, $cnnrbac);
} else {
$this->storage = new PmPdo($cnn);
}
// Pass a storage object or array of storage objects to the OAuth2 server class
$this->server = new \OAuth2\Server($this->storage, array('allow_implicit' => true));
@@ -112,6 +122,21 @@ class Server implements iAuthenticate
}
}
public static function setDatabaseSourceRBAC($user, $password = '', $dsn = '')
{
if (is_array($user)) {
self::$dbUserRBAC = $user['username'];
self::$dbPasswordRBAC = $user['password'];
self::$dsnRBAC = $user['dsn'];
self::$isRBAC = true;
} else {
self::$dbUserRBAC = $user;
self::$dbPasswordRBAC = $password;
self::$dsnRBAC = $dsn;
self::$isRBAC = true;
}
}
public static function setWorkspace($workspace)
{
self::$workspace = $workspace;

View File

@@ -39,7 +39,8 @@ debug = 1
process-variable = "ProcessMaker\Services\Api\Project\Variable"
message-type = "ProcessMaker\Services\Api\Project\MessageType"
message-type-variable = "ProcessMaker\Services\Api\Project\MessageType\Variable"
web-entry-event = "ProcessMaker\Services\Api\Project\WebEntryEvent"
web-entry-event = "ProcessMaker\Services\Api\Project\WebEntryEvent"
message-event-definition = "ProcessMaker\Services\Api\Project\MessageEventDefinition"
[alias: projects]
project = "ProcessMaker\Services\Api\Project"
@@ -97,3 +98,5 @@ debug = 1
[alias: emails]
email = "ProcessMaker\Services\Api\EmailServer"
[alias: light]
light = "ProcessMaker\Services\Api\Light"