diff --git a/workflow/engine/src/BusinessModel/Event.php b/workflow/engine/src/BusinessModel/Event.php new file mode 100644 index 000000000..6f9cf41f3 --- /dev/null +++ b/workflow/engine/src/BusinessModel/Event.php @@ -0,0 +1,92 @@ + + * @copyright Colosa - Bolivia + */ +class Event +{ + /** + * Get list for Events + * @var string $sProcessUID. Uid for Process + * @var string $filter. + * @var string $sEventUID. Uid for Process + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @return boolean + */ + public function getEvents($sProcessUID, $filter = '', $sEventUID = '') + { + $sDelimiter = \DBAdapter::getStringDelimiter(); + $oCriteria = new \Criteria('workflow'); + $oCriteria->addSelectColumn(\EventPeer::EVN_UID); + $oCriteria->addSelectColumn(\EventPeer::EVN_ACTION); + $oCriteria->addSelectColumn(\EventPeer::EVN_STATUS); + $oCriteria->addSelectColumn(\EventPeer::EVN_WHEN_OCCURS); + $oCriteria->addSelectColumn(\EventPeer::EVN_RELATED_TO); + + $oCriteria->addAsColumn('EVN_DESCRIPTION', \ContentPeer::CON_VALUE); + $aConditions = array(); + $aConditions[] = array(\EventPeer::EVN_UID, \ContentPeer::CON_ID ); + $aConditions[] = array(\ContentPeer::CON_CATEGORY, $sDelimiter . 'EVN_DESCRIPTION' . $sDelimiter ); + $aConditions[] = array(\ContentPeer::CON_LANG, $sDelimiter . SYS_LANG . $sDelimiter ); + $oCriteria->addJoinMC($aConditions, \Criteria::LEFT_JOIN); + $oCriteria->add(\EventPeer::PRO_UID, $sProcessUID); + if ($sEventUID != '') { + $oCriteria->add(\EventPeer::EVN_UID, $sEventUID); + } + + switch ($filter) { + case 'message': + $oCriteria->add(\EventPeer::EVN_ACTION, "SEND_MESSAGE"); + break; + case 'conditional': + $oCriteria->add(\EventPeer::EVN_ACTION, "SEND_MESSAGE"); + break; + case 'multiple': + $oCriteria->add(\EventPeer::EVN_ACTION, "EXECUTE_TRIGGER"); + break; + } + + $eventsArray = array(); + + $oDataset = \EventPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + $oDataset->next(); + while ($aRow = $oDataset->getRow()) { + $oEvent = new \Event(); + $aFields = $oEvent->load( $aRow['EVN_UID'] ); + $aRow = array_merge($aRow, $aFields); + $eventsArray[] = array_change_key_case($aRow, CASE_LOWER); + $oDataset->next(); + } + return $eventsArray; + } + + /** + * Delete Event + * + * @param string $eventUid + * + * return void + * + * @access public + */ + public function deleteEvent($eventUid) + { + try { + $oEvent = new \Event(); + $oEvent->remove( $eventUid ); + } catch (Exception $e) { + throw $e; + } + } + + + + +} + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php new file mode 100644 index 000000000..93cde491f --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php @@ -0,0 +1,98 @@ + + * @copyright Colosa - Bolivia + * + * @protected + */ +class Event extends Api +{ + /** + * @param string $projectUid {@min 1} {@max 32} + * @param string $filter {@choice message,conditional,,multiple} + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * @return array + * + * @url GET /:projectUid/events + */ + public function doGetEvents($projectUid, $filter = '') + { + try { + $hiddenFields = array('pro_uid', 'evn_action_parameters', + 'evn_posx', 'evn_posy', 'evn_type', 'tas_evn_uid' + ); + $event = new \BusinessModel\Event(); + $response = $event->getEvents($projectUid, $filter); + foreach ($response as &$eventData) { + foreach ($eventData as $key => $value) { + if (in_array($key, $hiddenFields)) { + unset($eventData[$key]); + } + } + } + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @param string $projectUid {@min 1} {@max 32} + * @param string $EventUid {@min 1} {@max 32} + * @return array + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url GET /:projectUid/event/:EventUid + */ + public function doGetEvent($projectUid, $EventUid) + { + try { + $hiddenFields = array('pro_uid', 'evn_action_parameters', + 'evn_posx', 'evn_posy', 'evn_type', 'tas_evn_uid' + ); + $event = new \BusinessModel\Event(); + $response = $event->getEvents($projectUid, '', $EventUid); + foreach ($response as &$eventData) { + foreach ($eventData as $key => $value) { + if (in_array($key, $hiddenFields)) { + unset($eventData[$key]); + } + } + } + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @param string $projectUid {@min 1} {@max 32} + * @param string $EventUid {@min 1} {@max 32} + * @return void + * + * @author Brayan Pereyra (Cochalo) + * @copyright Colosa - Bolivia + * + * @url DELETE /:projectUid/event/:eventUid + */ + public function doDeleteEvent($projectUid, $eventUid) + { + try { + $event = new \BusinessModel\Event(); + $response = $event->deleteEvent($eventUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } +} + diff --git a/workflow/engine/src/Services/api.ini b/workflow/engine/src/Services/api.ini index 3f8527e19..5d8ee1784 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -19,6 +19,7 @@ debug = 1 trigger = "Services\Api\ProcessMaker\Project\Activity\Step\Trigger" project = "Services\Api\ProcessMaker\Project" trigger2 = "Services\Api\ProcessMaker\Project\Trigger" + event = "Services\Api\ProcessMaker\Project\Event" input-document = "Services\Api\ProcessMaker\Project\InputDocument" output-documents = "Services\Api\ProcessMaker\Project\OutputDocuments"