2013-12-23 09:34:43 -04:00
|
|
|
<?php
|
|
|
|
|
namespace BusinessModel;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*/
|
|
|
|
|
class Event
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get list for Events
|
|
|
|
|
* @var string $sProcessUID. Uid for Process
|
|
|
|
|
* @var string $filter.
|
|
|
|
|
* @var string $sEventUID. Uid for Process
|
|
|
|
|
*
|
2014-01-06 16:54:36 -04:00
|
|
|
* @access public
|
2013-12-23 09:34:43 -04:00
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*
|
2014-01-06 16:54:36 -04:00
|
|
|
* @return array
|
2013-12-23 09:34:43 -04:00
|
|
|
*/
|
|
|
|
|
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':
|
2014-01-06 10:44:46 -04:00
|
|
|
$oCriteria->add(\EventPeer::EVN_ACTION, "EXECUTE_CONDITIONAL_TRIGGER");
|
2013-12-23 09:34:43 -04:00
|
|
|
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();
|
|
|
|
|
}
|
2014-01-06 10:44:46 -04:00
|
|
|
|
|
|
|
|
if ($sEventUID != '' && empty($eventsArray)) {
|
|
|
|
|
throw (new \Exception( 'This row doesn\'t exist!' ));
|
|
|
|
|
} else if ($sEventUID != '' && !empty($eventsArray)) {
|
|
|
|
|
return current($eventsArray);
|
|
|
|
|
}
|
2013-12-23 09:34:43 -04:00
|
|
|
return $eventsArray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-01-06 16:54:36 -04:00
|
|
|
* Save Event Post Put
|
2013-12-23 09:34:43 -04:00
|
|
|
*
|
|
|
|
|
* @param string $eventUid
|
|
|
|
|
*
|
2014-01-06 16:54:36 -04:00
|
|
|
* @access public
|
|
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function saveEvents($sProcessUID, $dataEvent, $create = false)
|
|
|
|
|
{
|
|
|
|
|
if ( ($sProcessUID == '') || (count($dataEvent) == 0) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$dataEvent = array_change_key_case($dataEvent, CASE_UPPER);
|
|
|
|
|
|
|
|
|
|
if ( $create && (isset($dataEvent['ENV_UID'])) ) {
|
|
|
|
|
unset($dataEvent['ENV_UID']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$dataEvent['PRO_UID'] = $sProcessUID;
|
|
|
|
|
$oEvent = new \Event();
|
|
|
|
|
$uidNewEvent = $oEvent->create( $dataEvent );
|
|
|
|
|
$dataEvent = $this->getEvents($sProcessUID, '', $uidNewEvent);
|
|
|
|
|
$dataEvent = array_change_key_case($dataEvent, CASE_LOWER);
|
|
|
|
|
return $dataEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update Event Put
|
|
|
|
|
*
|
|
|
|
|
* @param string $eventUid
|
2013-12-23 09:34:43 -04:00
|
|
|
*
|
|
|
|
|
* @access public
|
2014-01-06 16:54:36 -04:00
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function updateEvent($dataEvent)
|
|
|
|
|
{
|
|
|
|
|
$dataEvent = array_change_key_case($dataEvent, CASE_UPPER);
|
|
|
|
|
try {
|
|
|
|
|
$oEvent = new \Event();
|
|
|
|
|
$oEvent->update( $dataEvent );
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete Event
|
|
|
|
|
*
|
|
|
|
|
* @param string $eventUid
|
|
|
|
|
*
|
|
|
|
|
* @access public
|
|
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
2013-12-23 09:34:43 -04:00
|
|
|
*/
|
|
|
|
|
public function deleteEvent($eventUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oEvent = new \Event();
|
|
|
|
|
$oEvent->remove( $eventUid );
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|