Files
luos/workflow/engine/classes/model/AppDelay.php

244 lines
7.6 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
/**
* Skeleton subclass for representing a row from the 'APP_DELAY' table.
*
*
*
* You should add additional methods to this class to meet the
* application requirements. This class will only be generated as
* long as it does not already exist in the output directory.
2011-01-22 12:20:08 +00:00
* /**
2011-01-31 14:14:55 +00:00
* @package workflow.engine.classes.model
2010-12-02 23:34:41 +00:00
*/
2012-10-22 05:57:53 -04:00
class AppDelay extends BaseAppDelay
{
2018-04-20 08:57:55 -04:00
const APP_TYPE_CANCEL = 'CANCEL';
2018-05-18 16:54:37 -04:00
const APP_TYPE_UNCANCEL = 'UNCANCEL';
2018-04-20 08:57:55 -04:00
const APP_TYPE_PAUSE = 'PAUSE';
2012-10-22 05:57:53 -04:00
/**
* Create the application delay registry
2018-04-20 08:57:55 -04:00
*
* @param array $data
*
2012-10-22 05:57:53 -04:00
* @return string
2018-04-20 08:57:55 -04:00
* @throws Exception
2012-10-22 05:57:53 -04:00
**/
2018-04-20 08:57:55 -04:00
public function create($data)
2012-10-22 05:57:53 -04:00
{
2018-04-20 08:57:55 -04:00
$connection = Propel::getConnection(AppDelayPeer::DATABASE_NAME);
2012-10-22 05:57:53 -04:00
try {
2018-04-20 08:57:55 -04:00
if (isset ($data['APP_DELAY_UID']) && $data['APP_DELAY_UID'] == '') {
unset ($data['APP_DELAY_UID']);
2012-10-22 05:57:53 -04:00
}
2018-04-20 08:57:55 -04:00
if (!isset ($data['APP_DELAY_UID'])) {
$data['APP_DELAY_UID'] = G::generateUniqueID();
2012-10-22 05:57:53 -04:00
}
2018-04-20 08:57:55 -04:00
$appDelay = new AppDelay();
$appDelay->fromArray($data, BasePeer::TYPE_FIELDNAME);
if ($appDelay->validate()) {
$connection->begin();
$result = $appDelay->save();
$connection->commit();
return $data['APP_DELAY_UID'];
2012-10-22 05:57:53 -04:00
} else {
2018-04-20 08:57:55 -04:00
$message = '';
$validationFailures = $appDelay->getValidationFailures();
foreach ($validationFailures as $validationFailure) {
$message .= $validationFailure->getMessage() . '<br />';
2012-10-22 05:57:53 -04:00
}
2018-04-20 08:57:55 -04:00
throw(new Exception('The registry cannot be created!<br />' . $message));
2012-10-22 05:57:53 -04:00
}
2018-04-20 08:57:55 -04:00
} catch (Exception $error) {
$connection->rollback();
throw($error);
2010-12-02 23:34:41 +00:00
}
}
2012-10-22 05:57:53 -04:00
/**
* Update the application delay registry
2018-04-20 08:57:55 -04:00
*
* @param array $data
*
2012-10-22 05:57:53 -04:00
* @return string
2018-04-20 08:57:55 -04:00
* @throws Exception
2012-10-22 05:57:53 -04:00
**/
2018-04-20 08:57:55 -04:00
public function update($data)
2012-10-22 05:57:53 -04:00
{
2018-04-20 08:57:55 -04:00
$connection = Propel::getConnection(AppDelayPeer::DATABASE_NAME);
2012-10-22 05:57:53 -04:00
try {
2018-04-20 08:57:55 -04:00
$appDelay = AppDelayPeer::retrieveByPK($data['APP_DELAY_UID']);
if (!is_null($appDelay)) {
$appDelay->fromArray($data, BasePeer::TYPE_FIELDNAME);
if ($appDelay->validate()) {
$connection->begin();
$result = $appDelay->save();
$connection->commit();
return $result;
2012-10-22 05:57:53 -04:00
} else {
2018-04-20 08:57:55 -04:00
$message = '';
$validationFailures = $appDelay->getValidationFailures();
foreach ($validationFailures as $validationFailure) {
$message .= $validationFailure->getMessage() . '<br />';
2012-10-22 05:57:53 -04:00
}
2018-04-20 08:57:55 -04:00
throw(new Exception('The registry cannot be updated!<br />'.$message));
2012-10-22 05:57:53 -04:00
}
} else {
throw(new Exception('This row doesn\'t exist!'));
}
2018-04-20 08:57:55 -04:00
} catch (Exception $error) {
$connection->rollback();
throw($error);
2010-12-02 23:34:41 +00:00
}
}
2018-04-20 08:57:55 -04:00
/**
* Review if the application in a specific index is paused
*
* @param string $appUid
* @param integer $delIndex
*
* @return boolean
*/
2012-10-22 05:57:53 -04:00
public function isPaused($appUid, $delIndex)
{
2018-04-20 08:57:55 -04:00
$criteria = new Criteria('workflow');
$criteria->add(AppDelayPeer::APP_UID, $appUid);
$criteria->add(AppDelayPeer::APP_DEL_INDEX, $delIndex);
$criteria->add(AppDelayPeer::APP_TYPE, AppDelay::APP_TYPE_PAUSE);
$criteria->add(
$criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, 0, Criteria::EQUAL)->addOr(
$criteria->getNewCriterion(AppDelayPeer::APP_DISABLE_ACTION_USER, null, Criteria::ISNULL))
2012-10-22 05:57:53 -04:00
);
2018-04-20 08:57:55 -04:00
$dataset = AppDelayPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$row = $dataset->getRow();
2012-10-22 05:57:53 -04:00
2018-04-20 08:57:55 -04:00
if ($row) {
2012-10-22 05:57:53 -04:00
return true;
} else {
return false;
}
}
2017-04-17 10:34:30 -04:00
/**
* Verify if the case is Paused or cancelled
*
* @param $appUid string
2018-04-20 08:57:55 -04:00
*
* @return array|null
2017-04-17 10:34:30 -04:00
*/
public function getCasesCancelOrPaused($appUid)
{
2018-04-20 08:57:55 -04:00
$criteria = new Criteria('workflow');
$criteria->addSelectColumn(AppDelayPeer::APP_UID);
$criteria->addSelectColumn(AppDelayPeer::APP_DEL_INDEX);
$criteria->add(AppDelayPeer::APP_UID, $appUid);
$criteria->add(
$criteria->getNewCriterion(AppDelayPeer::APP_TYPE, AppDelay::APP_TYPE_PAUSE)->addOr(
$criteria->getNewCriterion(AppDelayPeer::APP_TYPE, AppDelay::APP_TYPE_CANCEL)
)
);
$criteria->addAscendingOrderByColumn(AppDelayPeer::APP_ENABLE_ACTION_DATE);
$dataset = AppDelayPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
return $dataset->getRow();
}
/**
* Build the row for the appDelay to be inserted
*
* @param string $proUid
* @param integer $proId
* @param string $appUid
* @param integer $appNumber
* @param integer $appThreadIndex
* @param integer $delIndex
* @param string $appType
* @param string $appStatus
* @param string $usrUid
2018-05-18 16:54:37 -04:00
* @param integer $usrId
2018-04-20 08:57:55 -04:00
*
* @return array
*/
public static function buildAppDelayRow(
$proUid = '',
$proId = 0,
$appUid = '',
$appNumber = 0,
$appThreadIndex = 0,
$delIndex = 0,
$appType = 'CANCEL',
$appStatus = 'CANCELLED',
2018-05-18 16:54:37 -04:00
$usrUid = '',
$usrId = 0
2018-04-20 08:57:55 -04:00
) {
$row = [];
$row['PRO_UID'] = $proUid;
$row['APP_UID'] = $appUid;
$row['APP_NUMBER'] = $appNumber;
$row['APP_THREAD_INDEX'] = $appThreadIndex;
$row['APP_DEL_INDEX'] = $delIndex;
$row['APP_TYPE'] = $appType;
$row['APP_STATUS'] = $appStatus;
$row['APP_ENABLE_ACTION_DATE'] = date('Y-m-d H:i:s');
2018-05-18 16:54:37 -04:00
//Load the PRO_ID if does not exit
if (empty($proId) || $proId === 0) {
$u = new Process();
$proId = $u->load($proUid)['PRO_ID'];
}
$row['PRO_ID'] = $proId;
2018-04-20 08:57:55 -04:00
//Define the user that execute the insert
if (empty($usrUid)) {
global $RBAC;
$usrUid = $RBAC->aUserInfo['USER_INFO']['USR_UID'];
2018-05-18 16:54:37 -04:00
$u = new Users();
$usrId = $u->load($usrUid)['USR_ID'];
2018-04-20 08:57:55 -04:00
}
$row['APP_DELEGATION_USER'] = $usrUid;
$row['APP_ENABLE_ACTION_USER'] = $usrUid;
2018-05-18 16:54:37 -04:00
$row['APP_DELEGATION_USER_ID'] = $usrId;
2018-04-20 08:57:55 -04:00
return $row;
2017-04-17 10:34:30 -04:00
}
2018-05-18 16:54:37 -04:00
/**
* Return all threads with the status canceled
*
* @param string $appUid
* @param string $status
*
* @return array
* @throws Exception
*/
public function getThreadByStatus($appUid, $status)
{
try {
$criteria = new Criteria('workflow');
$criteria->add(AppDelayPeer::APP_UID, $appUid);
$criteria->add(AppDelayPeer::APP_STATUS, $status);
$criteria->addDescendingOrderByColumn(AppDelayPeer::APP_ENABLE_ACTION_DATE);
$dataset = AppDelayPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$result = [];
while ($row = $dataset->getRow()) {
$result[] = $row;
$dataset->next();
}
return $result;
} catch (Exception $error) {
throw $error;
}
}
2012-10-22 05:57:53 -04:00
}
2010-12-02 23:34:41 +00:00