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

This commit is contained in:
Freddy Daniel Rojas Valda
2013-12-13 12:14:51 -04:00
7 changed files with 549 additions and 46 deletions

View File

@@ -3,6 +3,100 @@ namespace BusinessModel;
class Step
{
/**
* Checks if exists the record in table STEP
*
* @param string $taskUid Unique id of Task
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
* @param string $objectUid Unique id of Object
* @param int $position Position
* @param string $stepUidExclude Unique id of Step to exclude
*
* return bool Return true if exists the record in table STEP, false otherwise
*/
public function existsRecord($taskUid, $type, $objectUid, $position = 0, $stepUidExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\StepPeer::STEP_UID);
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
if ($stepUidExclude != "") {
$criteria->add(\StepPeer::STEP_UID, $stepUidExclude, \Criteria::NOT_EQUAL);
}
if ($type != "") {
$criteria->add(\StepPeer::STEP_TYPE_OBJ, $type, \Criteria::EQUAL);
}
if ($objectUid != "") {
$criteria->add(\StepPeer::STEP_UID_OBJ, $objectUid, \Criteria::EQUAL);
}
if ($position > 0) {
$criteria->add(\StepPeer::STEP_POSITION, $position, \Criteria::EQUAL);
}
$rsCriteria = \StepPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
return true;
} else {
return false;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Checks if exists the "Object UID" in the corresponding table
*
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
* @param string $objectUid Unique id of Object
*
* return strin Return empty string if $objectUid exists in the corresponding table, return string with data if $objectUid doesn't exist
*/
public function existsObjectUid($type, $objectUid)
{
try {
$msg = "";
switch ($type) {
case "DYNAFORM":
$dynaform = new \Dynaform();
if (!$dynaform->dynaformExists($objectUid)) {
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}");
}
break;
case "INPUT_DOCUMENT":
$inputdoc = new \InputDocument();
if (!$inputdoc->InputExists($objectUid)) {
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}");
}
break;
case "OUTPUT_DOCUMENT":
$outputdoc = new \OutputDocument();
if (!$outputdoc->OutputExists($objectUid)) {
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "OUTPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}");
}
break;
default:
$msg = str_replace(array("{0}", "{1}"), array($objectUid, $type), "The UID \"{0}\" doesn't exist in table {1}");
break;
}
return $msg;
} catch (\Exception $e) {
throw $e;
}
}
/**
* Create Step for a Task
*
@@ -10,11 +104,41 @@ class Step
* @param string $processUid
* @param array $arrayData
*
* return string Unique id of the new Step
* return array Data of the Step created
*/
public function create($taskUid, $processUid, $arrayData)
{
try {
//Verify data
$process = new \Process();
if (!$process->exists($processUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$task = new \Task();
if (!$task->taskExists($taskUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid, "TASK"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (isset($arrayData["step_type_obj"]) && isset($arrayData["step_uid_obj"])) {
$msg = $this->existsObjectUid($arrayData["step_type_obj"], $arrayData["step_uid_obj"]);
if ($msg != "") {
throw (new \Exception($msg));
}
if ($this->existsRecord($taskUid, $arrayData["step_type_obj"], $arrayData["step_uid_obj"])) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["step_type_obj"] . ", " . $arrayData["step_uid_obj"], "STEP"), "The record \"{0}\", exists in table {1}")));
}
}
if (isset($arrayData["step_position"]) && $this->existsRecord($taskUid, "", "", $arrayData["step_position"])) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["step_position"], $taskUid . ", " . $arrayData["step_position"], "STEP"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
}
//Create
$step = new \Step();
$stepUid = $step->create(array("PRO_UID" => $processUid, "TAS_UID" => $taskUid));
@@ -23,9 +147,11 @@ class Step
$arrayData["step_position"] = $step->getNextPosition($taskUid) - 1;
}
$this->update($stepUid, $arrayData);
$arrayData = $this->update($stepUid, $arrayData);
return $stepUid;
$arrayData["step_uid"] = $stepUid;
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
@@ -37,11 +163,39 @@ class Step
* @param string $stepUid
* @param array $arrayData
*
* return void
* return array Data of the Step updated
*/
public function update($stepUid, $arrayData)
{
try {
$arrayDataUid = $this->getDataUids($stepUid);
$taskUid = $arrayDataUid["TAS_UID"];
//Verify data
$step = new \Step();
if (!$step->StepExists($stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (isset($arrayData["step_type_obj"]) && isset($arrayData["step_uid_obj"])) {
$msg = $this->existsObjectUid($arrayData["step_type_obj"], $arrayData["step_uid_obj"]);
if ($msg != "") {
throw (new \Exception($msg));
}
if ($this->existsRecord($taskUid, $arrayData["step_type_obj"], $arrayData["step_uid_obj"], 0, $stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["step_type_obj"] . ", " . $arrayData["step_uid_obj"], "STEP"), "The record \"{0}\", exists in table {1}")));
}
}
if (isset($arrayData["step_position"]) && $this->existsRecord($taskUid, "", "", $arrayData["step_position"], $stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["step_position"], $taskUid . ", " . $arrayData["step_position"], "STEP"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
}
//Update
$step = new \Step();
$arrayUpdateData = array();
@@ -69,6 +223,8 @@ class Step
}
$step->update($arrayUpdateData);
return array_change_key_case($arrayUpdateData, CASE_LOWER);
} catch (\Exception $e) {
throw $e;
}
@@ -84,6 +240,13 @@ class Step
public function delete($stepUid)
{
try {
//Verify data
$step = new \Step();
if (!$step->StepExists($stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
}
//Get position
$criteria = new \Criteria("workflow");

View File

@@ -3,17 +3,62 @@ namespace BusinessModel\Step;
class Trigger
{
/**
* Checks if exists the record in table STEP_TRIGGER
*
* @param string $stepUid Unique id of Step
* @param string $type Type (BEFORE, AFTER)
* @param string $triggerUid Unique id of Trigger
* @param int $position Position
* @param string $triggerUidExclude Unique id of Trigger to exclude
*
* return bool Return true if exists the record in table STEP_TRIGGER, false otherwise
*/
public function existsRecord($stepUid, $type, $triggerUid, $position = 0, $triggerUidExclude = "")
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\StepTriggerPeer::STEP_UID);
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
if ($triggerUid != "") {
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
}
if ($position > 0) {
$criteria->add(\StepTriggerPeer::ST_POSITION, $position, \Criteria::EQUAL);
}
if ($triggerUidExclude != "") {
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUidExclude, \Criteria::NOT_EQUAL);
}
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
if ($rsCriteria->next()) {
return true;
} else {
return false;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* Assign Trigger to a Step
*
* @param string $stepUid Unique id of Step
* @param string $triggerUid Unique id of Trigger
* @param string $type Type (BEFORE, AFTER)
* @param string $triggerUid Unique id of Trigger
* @param array $arrayData Data
*
* return void
* return array Data of the Trigger assigned to a Step
*/
public function create($stepUid, $triggerUid, $type, $arrayData)
public function create($stepUid, $type, $triggerUid, $arrayData)
{
try {
$step = new \BusinessModel\Step();
@@ -22,6 +67,27 @@ class Trigger
$taskUid = $arrayDataUid["TAS_UID"];
//Verify data
$step = new \Step();
if (!$step->StepExists($stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$trigger = new \Triggers();
if (!$trigger->TriggerExists($triggerUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if ($this->existsRecord($stepUid, $type, $triggerUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", exists in table {1}")));
}
if (isset($arrayData["st_position"]) && $this->existsRecord($stepUid, $type, "", $arrayData["st_position"])) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["st_position"], $stepUid . ", " . $type . ", " . $arrayData["st_position"], "STEP_TRIGGER"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
}
//Create
$stepTrigger = new \StepTrigger();
@@ -31,7 +97,9 @@ class Trigger
$arrayData["st_position"] = $stepTrigger->getNextPosition($stepUid, $type, $taskUid) - 1;
}
$this->update($stepUid, $triggerUid, $type, $arrayData);
$arrayData = $this->update($stepUid, $type, $triggerUid, $arrayData);
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
@@ -41,13 +109,13 @@ class Trigger
* Update Trigger of a Step
*
* @param string $stepUid Unique id of Step
* @param string $triggerUid Unique id of Trigger
* @param string $type Type (BEFORE, AFTER)
* @param string $triggerUid Unique id of Trigger
* @param array $arrayData Data
*
* return void
* return array Data updated of the Trigger assigned to a Step
*/
public function update($stepUid, $triggerUid, $type, $arrayData)
public function update($stepUid, $type, $triggerUid, $arrayData)
{
try {
$step = new \BusinessModel\Step();
@@ -56,6 +124,23 @@ class Trigger
$taskUid = $arrayDataUid["TAS_UID"];
//Verify data
$step = new \Step();
if (!$step->StepExists($stepUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$trigger = new \Triggers();
if (!$trigger->TriggerExists($triggerUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
}
if (isset($arrayData["st_position"]) && $this->existsRecord($stepUid, $type, "", $arrayData["st_position"], $triggerUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["st_position"], $stepUid . ", " . $type . ", " . $arrayData["st_position"], "STEP_TRIGGER"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
}
//Update
$stepTrigger = new \StepTrigger();
@@ -75,6 +160,8 @@ class Trigger
}
$stepTrigger->update($arrayUpdateData);
return array_change_key_case($arrayUpdateData, CASE_LOWER);
} catch (\Exception $e) {
throw $e;
}
@@ -84,12 +171,12 @@ class Trigger
* Delete Trigger of a Step
*
* @param string $stepUid Unique id of Step
* @param string $triggerUid Unique id of Trigger
* @param string $type Type (BEFORE, AFTER)
* @param string $triggerUid Unique id of Trigger
*
* return void
*/
public function delete($stepUid, $triggerUid, $type)
public function delete($stepUid, $type, $triggerUid)
{
try {
$step = new \BusinessModel\Step();
@@ -98,6 +185,11 @@ class Trigger
$taskUid = $arrayDataUid["TAS_UID"];
//Verify data
if (!$this->existsRecord($stepUid, $type, $triggerUid)) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", doesn't exist in table {1}")));
}
//Get position
$stepTrigger = new \StepTrigger();

View File

@@ -79,5 +79,148 @@ class Trigger
throw $e;
}
}
/**
* List of Triggers in process
*
* return array
*/
public function getTriggersCriteria($sProcessUID = '')
{
$criteria = $this->getTriggerCriteria();
$criteria->add(\TriggersPeer::PRO_UID, $sProcessUID);
$criteria->addAscendingOrderByColumn('TRI_TITLE');
$oDataset = \TriggersPeer::doSelectRS($criteria);
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
$oDataset->next();
$triggersArray = "";
//$triggersArray[] = array('TRI_UID' => 'char', 'PRO_UID' => 'char', 'TRI_TITLE' => 'char', 'TRI_DESCRIPTION' => 'char');
while ($aRow = $oDataset->getRow()) {
if (($aRow['TRI_TITLE'] == null) || ($aRow['TRI_TITLE'] == "")) {
// There is no transaltion for this Trigger name, try to get/regenerate the label
$triggerObj = $this->getDataTrigger($aRow['TRI_UID']);
$aRow['TRI_TITLE'] = $triggerObj['tri_title'];
$aRow['TRI_DESCRIPTION'] = $triggerObj['tri_description'];
}
$triggersArray[] = array_change_key_case($aRow, CASE_LOWER);
$oDataset->next();
}
return $triggersArray;
}
/**
* Get data for TriggerUid
*
* return array
*/
public function getDataTrigger($sTriggerUID = '')
{
$triggerO = new \Triggers();
$triggerArray = $triggerO->load($sTriggerUID);
if (isset($triggerArray['PRO_UID'])) {
unset($triggerArray['PRO_UID']);
}
$triggerArray = array_change_key_case($triggerArray, CASE_LOWER);
return $triggerArray;
}
/**
* Delete Trigger
*
*/
public function deleteTrigger($sTriggerUID = '')
{
$oTrigger = new \Triggers();
$triggerObj = $oTrigger->load( $sTriggerUID );
$oTrigger->remove( $sTriggerUID );
$oStepTrigger = new \StepTrigger();
$oStepTrigger->removeTrigger( $sTriggerUID );
}
/**
* Save Data for Trigger
*
*/
public function saveTrigger($sProcessUID = '', $dataTrigger = array(), $create = false, $sTriggerUid = '')
{
if ( ($sProcessUID == '') || (count($dataTrigger) == 0) ) {
return false;
}
$dataTrigger = array_change_key_case($dataTrigger, CASE_UPPER);
if ( $create && (isset($dataTrigger['TRI_UID'])) ) {
unset($dataTrigger['TRI_UID']);
}
$dataTrigger= (array)$dataTrigger;
if (isset($dataTrigger['TRI_TYPE']) && $dataTrigger['TRI_TYPE'] == '') {
$dataTrigger['TRI_TYPE'] = 'SCRIPT';
}
if (isset($dataTrigger['TRI_TITLE'])) {
if (!$this->verifyNameTrigger($sProcessUID, $dataTrigger['TRI_TITLE'], $sTriggerUid)) {
throw new \Exception('There is a triggers with the same name in this process');
}
}
$dataTrigger['PRO_UID'] = $sProcessUID;
$oTrigger = new \Triggers();
if ($create) {
$oTrigger->create( $dataTrigger );
$dataTrigger['TRI_UID'] = $oTrigger->getTriUid();
}
$oTrigger->update( $dataTrigger );
if ($create) {
$dataResp = $oTrigger->load( $dataTrigger['TRI_UID'] );
$dataResp = array_change_key_case($dataResp, CASE_LOWER);
if (isset($dataResp['pro_uid'])) {
unset($dataResp['pro_uid']);
}
return $dataResp;
}
}
/**
* Verify name for trigger in process
*
* return boolean
*/
public function verifyNameTrigger($sProcessUID, $sTriggerName, $sTriggerUid = '')
{
$oCriteria = new \Criteria("workflow");
$oCriteria->addSelectColumn( \TriggersPeer::TRI_UID );
$oCriteria->add( \TriggersPeer::PRO_UID, $sProcessUID );
if ($sTriggerUid != '') {
$oCriteria->add( \TriggersPeer::TRI_UID, $sTriggerUid, \Criteria::NOT_EQUAL);
}
$oDataset = \TriggersPeer::doSelectRS( $oCriteria );
$oDataset->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
while ($oDataset->next()) {
$aRow = $oDataset->getRow();
$oCriteria1 = new \Criteria( 'workflow' );
$oCriteria1->addSelectColumn( 'COUNT(*) AS TRIGGERS' );
$oCriteria1->add( \ContentPeer::CON_CATEGORY, 'TRI_TITLE' );
$oCriteria1->add( \ContentPeer::CON_ID, $aRow['TRI_UID'] );
$oCriteria1->add( \ContentPeer::CON_VALUE, $sTriggerName );
$oCriteria1->add( \ContentPeer::CON_LANG, SYS_LANG );
$oDataset1 = \ContentPeer::doSelectRS( $oCriteria1 );
$oDataset1->setFetchmode( \ResultSet::FETCHMODE_ASSOC );
$oDataset1->next();
$aRow1 = $oDataset1->getRow();
if ($aRow1['TRIGGERS']) {
return false;
}
}
return true;
}
}