2015-03-27 17:10:11 -04:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* AppDelegation.php
|
|
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
|
|
|
|
*
|
|
|
|
|
* ProcessMaker Open Source Edition
|
|
|
|
|
* Copyright (C) 2004 - 2011 Colosa Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
|
|
|
|
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2017-08-04 09:32:25 -04:00
|
|
|
use ProcessMaker\Plugins\PluginRegistry;
|
|
|
|
|
|
2015-03-27 17:10:11 -04:00
|
|
|
/**
|
|
|
|
|
* Skeleton subclass for representing a row from the 'APP_DELEGATION' 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.
|
|
|
|
|
*
|
|
|
|
|
* @package workflow.engine.classes.model
|
|
|
|
|
*/
|
|
|
|
|
class AppDelegation extends BaseAppDelegation
|
|
|
|
|
{
|
2016-08-15 16:54:43 -04:00
|
|
|
/**
|
|
|
|
|
* Get previous delegation (Valid Task)
|
|
|
|
|
*
|
|
|
|
|
* @param string $applicationUid Unique id of Case
|
|
|
|
|
* @param int $delIndex Delegation index
|
|
|
|
|
* @param bool $flagIncludeCurrentDel Include current delegation
|
|
|
|
|
*
|
|
|
|
|
* @return array Returns previous delegation, FALSE otherwise
|
|
|
|
|
*/
|
|
|
|
|
public function getPreviousDelegationValidTask($applicationUid, $delIndex, $flagIncludeCurrentDel = false)
|
|
|
|
|
{
|
|
|
|
|
$arrayAppDelegationPrevious = false;
|
|
|
|
|
$flagPrevious = true;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
$criteria = new Criteria('workflow');
|
|
|
|
|
|
|
|
|
|
$criteria->addSelectColumn(AppDelegationPeer::TABLE_NAME . '.*');
|
|
|
|
|
$criteria->addSelectColumn(TaskPeer::TAS_TYPE);
|
|
|
|
|
|
|
|
|
|
$criteria->addJoin(AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::INNER_JOIN);
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_UID, $applicationUid, Criteria::EQUAL);
|
|
|
|
|
$criteria->add(AppDelegationPeer::DEL_INDEX, $delIndex, Criteria::EQUAL);
|
|
|
|
|
|
|
|
|
|
$rsCriteria = AppDelegationPeer::doSelectRS($criteria);
|
|
|
|
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteria->next()) {
|
|
|
|
|
$record = $rsCriteria->getRow();
|
|
|
|
|
|
|
|
|
|
if ($flagIncludeCurrentDel) {
|
|
|
|
|
if (preg_match('/^(?:' . 'NORMAL|SCRIPT\-TASK|WEBENTRYEVENT|START\-MESSAGE\-EVENT|START\-TIMER\-EVENT' . ')$/', $record['TAS_TYPE'])) {
|
|
|
|
|
$arrayAppDelegationPrevious = $record;
|
|
|
|
|
$flagPrevious = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$delIndex = $record['DEL_PREVIOUS'];
|
|
|
|
|
} else {
|
|
|
|
|
$flagPrevious = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$flagIncludeCurrentDel = true;
|
|
|
|
|
} while ($flagPrevious);
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $arrayAppDelegationPrevious;
|
|
|
|
|
}
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* create an application delegation
|
|
|
|
|
*
|
|
|
|
|
* @param $sProUid process Uid
|
|
|
|
|
* @param $sAppUid Application Uid
|
|
|
|
|
* @param $sTasUid Task Uid
|
|
|
|
|
* @param $sUsrUid User Uid
|
|
|
|
|
* @param $iPriority delegation priority
|
|
|
|
|
* @param $isSubprocess is a subprocess inside a process?
|
|
|
|
|
* @return delegation index of the application delegation.
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public function createAppDelegation($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null, $flagControl = false, $flagControlMulInstance = false, $delPrevious = 0, $appNumber = 0, $taskId = 0, $userId = 0, $proId = 0)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sProUid) || strlen($sProUid) == 0) {
|
|
|
|
|
throw (new Exception('Column "PRO_UID" cannot be null.'));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sAppUid) || strlen($sAppUid) == 0) {
|
|
|
|
|
throw (new Exception('Column "APP_UID" cannot be null.'));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sTasUid) || strlen($sTasUid) == 0) {
|
|
|
|
|
throw (new Exception('Column "TAS_UID" cannot be null.'));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sUsrUid) /*|| strlen($sUsrUid ) == 0*/) {
|
|
|
|
|
throw (new Exception('Column "USR_UID" cannot be null.'));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (! isset($sAppThread) || strlen($sAppThread) == 0) {
|
|
|
|
|
throw (new Exception('Column "APP_THREAD" cannot be null.'));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 17:51:08 -04:00
|
|
|
$this->delegation_id = null;
|
2015-03-27 17:10:11 -04:00
|
|
|
//Get max DEL_INDEX
|
|
|
|
|
$criteria = new Criteria("workflow");
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_UID, $sAppUid);
|
|
|
|
|
$criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1);
|
2016-04-14 15:51:36 -04:00
|
|
|
$criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
$criteriaIndex = clone $criteria;
|
|
|
|
|
|
|
|
|
|
$rs = AppDelegationPeer::doSelectRS($criteriaIndex);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
$delIndex = 1;
|
2015-04-30 13:55:56 -04:00
|
|
|
$delPreviusUsrUid = $sUsrUid;
|
2016-08-23 16:56:41 -04:00
|
|
|
$delPreviousFather = $sPrevious;
|
2015-03-27 17:10:11 -04:00
|
|
|
if ($rs->next()) {
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
|
|
|
|
$delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
|
|
|
|
|
$delPreviusUsrUid = $row["USR_UID"];
|
2016-07-07 13:41:43 -04:00
|
|
|
$delPreviousFather = $row["DEL_PREVIOUS"];
|
2015-03-27 17:10:11 -04:00
|
|
|
} else {
|
|
|
|
|
$criteriaDelIndex = new Criteria("workflow");
|
|
|
|
|
|
|
|
|
|
$criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
$criteriaDelIndex->add(AppDelegationPeer::APP_UID, $sAppUid);
|
|
|
|
|
$criteriaDelIndex->addDescendingOrderByColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
|
|
|
|
|
$rsCriteriaDelIndex = AppDelegationPeer::doSelectRS($criteriaDelIndex);
|
|
|
|
|
$rsCriteriaDelIndex->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
if ($rsCriteriaDelIndex->next()) {
|
|
|
|
|
$row = $rsCriteriaDelIndex->getRow();
|
|
|
|
|
|
|
|
|
|
$delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-14 15:51:36 -04:00
|
|
|
//Verify successors: parrallel submit in the same time
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($flagControl) {
|
2016-04-14 15:51:36 -04:00
|
|
|
$nextTaskUid = $sTasUid;
|
2016-07-07 13:41:43 -04:00
|
|
|
$index = $this->getAllTasksBeforeSecJoin($nextTaskUid, $sAppUid, $delPreviousFather);
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($this->createThread($index, $sAppUid)) {
|
2016-04-14 15:51:36 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($flagControlMulInstance) {
|
2016-04-15 16:46:47 -04:00
|
|
|
$nextTaskUid = $sTasUid;
|
2016-08-23 16:56:41 -04:00
|
|
|
$index = $this->getAllTheardMultipleInstance($delPreviousFather, $sAppUid);
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($this->createThread($index, $sAppUid, $sUsrUid)) {
|
2016-04-15 16:46:47 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-27 17:10:11 -04:00
|
|
|
//Update set
|
|
|
|
|
$criteriaUpdate = new Criteria('workflow');
|
|
|
|
|
$criteriaUpdate->add(AppDelegationPeer::DEL_LAST_INDEX, 0);
|
|
|
|
|
BasePeer::doUpdate($criteria, $criteriaUpdate, Propel::getConnection('workflow'));
|
|
|
|
|
|
2020-04-30 16:08:24 -04:00
|
|
|
// Define the status of the thread, if is subprocess we need to CLOSED the thread
|
|
|
|
|
$theadStatus = !$isSubprocess ? 'OPEN' : 'CLOSED';
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setAppUid($sAppUid);
|
|
|
|
|
$this->setProUid($sProUid);
|
|
|
|
|
$this->setTasUid($sTasUid);
|
|
|
|
|
$this->setDelIndex($delIndex);
|
2015-03-27 17:10:11 -04:00
|
|
|
$this->setDelLastIndex(1);
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setDelPrevious($sPrevious == - 1 ? 0 : $sPrevious);
|
|
|
|
|
$this->setUsrUid($sUsrUid);
|
|
|
|
|
$this->setDelType('NORMAL');
|
|
|
|
|
$this->setDelPriority(($iPriority != '' ? $iPriority : '3'));
|
|
|
|
|
$this->setDelThread($sAppThread);
|
2020-04-30 16:08:24 -04:00
|
|
|
$this->setDelThreadStatus($theadStatus);
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setDelDelegateDate('now');
|
2017-01-10 17:51:08 -04:00
|
|
|
$this->setAppNumber($appNumber);
|
|
|
|
|
$this->setTasId($taskId);
|
|
|
|
|
$this->setUsrId($userId);
|
|
|
|
|
$this->setProId($proId);
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
//The function return an array now. By JHL
|
2015-04-15 14:52:15 -04:00
|
|
|
$delTaskDueDate = $this->calculateDueDate($sNextTasParam);
|
2015-04-27 17:05:44 -04:00
|
|
|
$delRiskDate = $this->calculateRiskDate($sNextTasParam, $this->getRisk());
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
//$this->setDelTaskDueDate( $delTaskDueDate['DUE_DATE'] ); // Due date formatted
|
2015-04-15 14:52:15 -04:00
|
|
|
$this->setDelTaskDueDate($delTaskDueDate);
|
|
|
|
|
$this->setDelRiskDate($delRiskDate);
|
2015-03-27 17:10:11 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if ((defined("DEBUG_CALENDAR_LOG")) && (DEBUG_CALENDAR_LOG)) {
|
2015-03-27 17:10:11 -04:00
|
|
|
//$this->setDelData( $delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setDelData($delTaskDueDate);
|
2015-03-27 17:10:11 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setDelData('');
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this condition assures that an internal delegation like a subprocess dont have an initial date setted
|
|
|
|
|
if ($delIndex == 1 && ! $isSubprocess) {
|
|
|
|
|
//the first delegation, init date this should be now for draft applications, in other cases, should be null.
|
2017-12-04 13:25:35 +00:00
|
|
|
$this->setDelInitDate('now');
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->validate()) {
|
|
|
|
|
try {
|
|
|
|
|
$res = $this->save();
|
|
|
|
|
} catch (PropelException $e) {
|
2016-04-14 15:51:36 -04:00
|
|
|
return;
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Something went wrong. We can now get the validationFailures and handle them.
|
|
|
|
|
$msg = '';
|
|
|
|
|
$validationFailuresArray = $this->getValidationFailures();
|
|
|
|
|
foreach ($validationFailuresArray as $objValidationFailure) {
|
|
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
|
|
|
|
}
|
2017-12-04 13:25:35 +00:00
|
|
|
throw (new Exception('Failed Data validation. ' . $msg));
|
2015-04-15 14:52:15 -04:00
|
|
|
}
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
$delIndex = $this->getDelIndex();
|
|
|
|
|
|
|
|
|
|
// Hook for the trigger PM_CREATE_NEW_DELEGATION
|
2017-12-04 13:25:35 +00:00
|
|
|
if (defined('PM_CREATE_NEW_DELEGATION')) {
|
2015-09-21 13:02:43 -04:00
|
|
|
$bpmn = new \ProcessMaker\Project\Bpmn();
|
|
|
|
|
$flagActionsByEmail = true;
|
|
|
|
|
|
2016-08-15 16:54:43 -04:00
|
|
|
$arrayAppDelegationPrevious = $this->getPreviousDelegationValidTask($sAppUid, $delIndex);
|
|
|
|
|
|
2015-03-27 17:10:11 -04:00
|
|
|
$data = new stdclass();
|
|
|
|
|
$data->TAS_UID = $sTasUid;
|
|
|
|
|
$data->APP_UID = $sAppUid;
|
|
|
|
|
$data->DEL_INDEX = $delIndex;
|
|
|
|
|
$data->USR_UID = $sUsrUid;
|
2016-08-15 16:54:43 -04:00
|
|
|
$data->PREVIOUS_USR_UID = ($arrayAppDelegationPrevious !== false)? $arrayAppDelegationPrevious['USR_UID'] : $delPreviusUsrUid;
|
2015-09-21 13:02:43 -04:00
|
|
|
|
|
|
|
|
if ($bpmn->exists($sProUid)) {
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
// this section evaluates the actions by email trigger execution please
|
|
|
|
|
// modify this section carefully, the if evaluation checks if the license has been
|
|
|
|
|
// activated in order to send the mail according to the configuration table
|
|
|
|
|
if (PMLicensedFeatures
|
|
|
|
|
::getSingleton()
|
|
|
|
|
->verifyfeature('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=')) {
|
|
|
|
|
$criteriaAbe = new Criteria();
|
|
|
|
|
$criteriaAbe->add(AbeConfigurationPeer::PRO_UID, $sProUid);
|
|
|
|
|
$criteriaAbe->add(AbeConfigurationPeer::TAS_UID, $sTasUid);
|
|
|
|
|
$resultAbe = AbeConfigurationPeer::doSelectRS($criteriaAbe);
|
|
|
|
|
$resultAbe->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
if ($resultAbe->next()) {
|
|
|
|
|
$dataAbe = $resultAbe->getRow();
|
2015-11-27 16:54:35 -04:00
|
|
|
$flagActionsByEmail = false;
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($dataAbe['ABE_TYPE']!='' && $data->USR_UID!='') {
|
2017-08-11 11:53:15 -04:00
|
|
|
$actionsByEmail = new ActionsByEmailCoreClass();
|
2016-11-21 18:01:37 -04:00
|
|
|
$actionsByEmail->sendActionsByEmail($data, $dataAbe);
|
2015-09-21 13:02:43 -04:00
|
|
|
}
|
2015-06-17 11:25:04 -04:00
|
|
|
}
|
2015-06-17 10:17:07 -04:00
|
|
|
}
|
2015-09-21 13:02:43 -04:00
|
|
|
/*----------------------------------********---------------------------------*/
|
|
|
|
|
|
2016-03-28 11:53:07 -04:00
|
|
|
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
2017-12-04 13:25:35 +00:00
|
|
|
$licensedFeatures = PMLicensedFeatures::getSingleton();
|
|
|
|
|
if ($licensedFeatures->verifyfeature('7qhYmF1eDJWcEdwcUZpT0k4S0xTRStvdz09')) {
|
|
|
|
|
try {
|
|
|
|
|
$pmGoogle = new PmGoogleApi();
|
2016-03-28 11:53:07 -04:00
|
|
|
if ($pmGoogle->getServiceGmailStatus()) {
|
|
|
|
|
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
|
|
|
|
$Pmgmail->gmailsForRouting($sUsrUid, $sTasUid, $sAppUid, $delIndex, $isSubprocess);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
error_log($oError->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*----------------------------------********---------------------------------*/
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
2015-09-21 13:02:43 -04:00
|
|
|
|
2016-03-28 11:53:07 -04:00
|
|
|
if ($flagActionsByEmail) {
|
2017-08-01 12:16:06 -04:00
|
|
|
$oPluginRegistry = PluginRegistry::loadSingleton();
|
2015-09-21 13:02:43 -04:00
|
|
|
$oPluginRegistry->executeTriggers(PM_CREATE_NEW_DELEGATION, $data);
|
2016-03-28 11:53:07 -04:00
|
|
|
}
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $delIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load the Application Delegation row specified in [app_id] column value.
|
|
|
|
|
*
|
2018-04-04 09:21:59 -04:00
|
|
|
* @param string $appUid the uid of the application
|
|
|
|
|
* @param integer $delIndex
|
|
|
|
|
*
|
2015-03-27 17:10:11 -04:00
|
|
|
* @return array $Fields the fields
|
2018-04-04 09:21:59 -04:00
|
|
|
*
|
|
|
|
|
* @throws Exception
|
2015-03-27 17:10:11 -04:00
|
|
|
*/
|
|
|
|
|
|
2018-04-04 09:21:59 -04:00
|
|
|
public function Load ($appUid, $delIndex)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2018-04-04 09:21:59 -04:00
|
|
|
$con = Propel::getConnection(AppDelegationPeer::DATABASE_NAME);
|
2015-03-27 17:10:11 -04:00
|
|
|
try {
|
2018-04-04 09:21:59 -04:00
|
|
|
$oAppDel = AppDelegationPeer::retrieveByPk($appUid, $delIndex);
|
|
|
|
|
if (is_object($oAppDel) && get_class($oAppDel) == 'AppDelegation') {
|
|
|
|
|
$fields = $oAppDel->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->fromArray($fields, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
|
|
|
|
|
return $fields;
|
2015-03-27 17:10:11 -04:00
|
|
|
} else {
|
2018-04-04 09:21:59 -04:00
|
|
|
throw (new Exception("The row '$appUid, $delIndex' in table AppDelegation doesn't exist!"));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 08:57:55 -04:00
|
|
|
/**
|
|
|
|
|
* Load the Application Delegation row specified in [app_id] column value.
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid the uid of the application
|
|
|
|
|
* @param integer $index the index of the delegation
|
2015-03-27 17:10:11 -04:00
|
|
|
*
|
|
|
|
|
* @return array $Fields the fields
|
|
|
|
|
*/
|
2018-04-20 08:57:55 -04:00
|
|
|
public function LoadParallel($appUid, $index = 0)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2018-04-20 08:57:55 -04:00
|
|
|
$cases = [];
|
2015-03-27 17:10:11 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::APP_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::PRO_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::TAS_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::USR_UID);
|
2018-04-20 08:57:55 -04:00
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_THREAD);
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_PREVIOUS);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN');
|
2018-04-20 08:57:55 -04:00
|
|
|
$c->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
|
|
|
|
|
if ($index > 0) {
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->add(AppDelegationPeer::DEL_INDEX, $index);
|
|
|
|
|
}
|
2018-04-20 08:57:55 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$c->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$rs = AppDelegationPeer::doSelectRS($c);
|
2018-04-20 08:57:55 -04:00
|
|
|
$row = $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-03-27 17:10:11 -04:00
|
|
|
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
|
|
|
|
while (is_array($row)) {
|
2018-04-20 08:57:55 -04:00
|
|
|
$cases[] = $row;
|
2015-03-27 17:10:11 -04:00
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 08:57:55 -04:00
|
|
|
return $cases;
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the application row
|
|
|
|
|
*
|
|
|
|
|
* @param array $aData
|
|
|
|
|
* @return variant
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function update($aData)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$con = Propel::getConnection(AppDelegationPeer::DATABASE_NAME);
|
2015-03-27 17:10:11 -04:00
|
|
|
try {
|
|
|
|
|
$con->begin();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oApp = AppDelegationPeer::retrieveByPK($aData['APP_UID'], $aData['DEL_INDEX']);
|
|
|
|
|
if (is_object($oApp) && get_class($oApp) == 'AppDelegation') {
|
|
|
|
|
$oApp->fromArray($aData, BasePeer::TYPE_FIELDNAME);
|
2015-03-27 17:10:11 -04:00
|
|
|
if ($oApp->validate()) {
|
|
|
|
|
$res = $oApp->save();
|
|
|
|
|
$con->commit();
|
|
|
|
|
return $res;
|
|
|
|
|
} else {
|
|
|
|
|
$msg = '';
|
|
|
|
|
foreach ($this->getValidationFailures() as $objValidationFailure) {
|
|
|
|
|
$msg .= $objValidationFailure->getMessage() . "<br/>";
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
throw (new PropelException('The row cannot be created!', new PropelException($msg)));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$con->rollback();
|
2017-12-04 13:25:35 +00:00
|
|
|
throw (new Exception("This AppDelegation row doesn't exist!"));
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
} catch (Exception $oError) {
|
|
|
|
|
throw ($oError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function remove($sApplicationUID, $iDelegationIndex)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$oConnection = Propel::getConnection(StepTriggerPeer::DATABASE_NAME);
|
2015-03-27 17:10:11 -04:00
|
|
|
try {
|
|
|
|
|
$oConnection->begin();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oApp = AppDelegationPeer::retrieveByPK($sApplicationUID, $iDelegationIndex);
|
|
|
|
|
if (is_object($oApp) && get_class($oApp) == 'AppDelegation') {
|
2015-03-27 17:10:11 -04:00
|
|
|
$result = $oApp->delete();
|
|
|
|
|
}
|
|
|
|
|
$oConnection->commit();
|
|
|
|
|
return $result;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
$oConnection->rollback();
|
|
|
|
|
throw ($e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TasTypeDay = 1 => working days
|
|
|
|
|
// TasTypeDay = 2 => calendar days
|
2017-12-04 13:25:35 +00:00
|
|
|
public function calculateDueDate($sNextTasParam)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
|
|
|
|
//Get Task properties
|
2017-12-04 13:25:35 +00:00
|
|
|
$task = TaskPeer::retrieveByPK($this->getTasUid());
|
2015-03-27 17:10:11 -04:00
|
|
|
|
2017-02-01 12:28:15 -04:00
|
|
|
$aData = array();
|
2015-03-27 17:10:11 -04:00
|
|
|
$aData['TAS_UID'] = $this->getTasUid();
|
|
|
|
|
//Added to allow User defined Timing Control at Run time from Derivation screen
|
2017-12-04 13:25:35 +00:00
|
|
|
if (isset($sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY']) && $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') {
|
2015-03-27 17:10:11 -04:00
|
|
|
$aData['TAS_DURATION'] = $sNextTasParam['NEXT_TASK']['TAS_DURATION'];
|
|
|
|
|
$aData['TAS_TIMEUNIT'] = $sNextTasParam['NEXT_TASK']['TAS_TIMEUNIT'];
|
|
|
|
|
$aData['TAS_TYPE_DAY'] = $sNextTasParam['NEXT_TASK']['TAS_TYPE_DAY'];
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if (isset($sNextTasParam['NEXT_TASK']['TAS_CALENDAR']) && $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'] != '') {
|
2015-03-27 17:10:11 -04:00
|
|
|
$aCalendarUID = $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'];
|
|
|
|
|
} else {
|
|
|
|
|
$aCalendarUID = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Updating the task Table , so that user will see updated values in the assign screen in consequent cases
|
|
|
|
|
$oTask = new Task();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oTask->update($aData);
|
2015-03-27 17:10:11 -04:00
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
if (is_null($task)) {
|
2015-03-27 17:10:11 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
$aData['TAS_DURATION'] = $task->getTasDuration();
|
|
|
|
|
$aData['TAS_TIMEUNIT'] = $task->getTasTimeUnit();
|
|
|
|
|
$aData['TAS_TYPE_DAY'] = $task->getTasTypeDay();
|
|
|
|
|
$aCalendarUID = '';
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:04:16 -04:00
|
|
|
//Calendar - Use the dates class to calculate dates
|
2017-08-04 10:13:09 -04:00
|
|
|
$calendar = new Calendar();
|
2015-03-27 17:10:11 -04:00
|
|
|
|
2017-02-01 12:28:15 -04:00
|
|
|
$arrayCalendarData = $calendar->getCalendarData($aCalendarUID);
|
2015-04-15 14:52:15 -04:00
|
|
|
|
|
|
|
|
if ($calendar->pmCalendarUid == "") {
|
2015-04-16 16:04:16 -04:00
|
|
|
$calendar->getCalendar(null, $this->getProUid(), $this->getTasUid());
|
2015-04-15 14:52:15 -04:00
|
|
|
|
|
|
|
|
$arrayCalendarData = $calendar->getCalendarData();
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:04:16 -04:00
|
|
|
//Due date
|
2017-02-01 12:28:15 -04:00
|
|
|
$initDate = $this->getDelDelegateDate();
|
|
|
|
|
$timeZone = \ProcessMaker\Util\DateTime::convertUtcToTimeZone($initDate);
|
|
|
|
|
$dueDate = $calendar->dashCalculateDate($timeZone, $aData["TAS_DURATION"], $aData["TAS_TIMEUNIT"], $arrayCalendarData);
|
2015-03-27 17:10:11 -04:00
|
|
|
|
2017-02-01 12:28:15 -04:00
|
|
|
$dueDate = \ProcessMaker\Util\DateTime::convertDataToUtc($dueDate);
|
2015-04-15 14:52:15 -04:00
|
|
|
return $dueDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calculateRiskDate($dueDate, $risk)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2015-04-27 17:05:44 -04:00
|
|
|
$data = array();
|
2017-12-04 13:25:35 +00:00
|
|
|
if (isset($sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY']) && $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') {
|
2015-04-27 17:05:44 -04:00
|
|
|
$data['TAS_DURATION'] = $sNextTasParam['NEXT_TASK']['TAS_DURATION'];
|
|
|
|
|
$data['TAS_TIMEUNIT'] = $sNextTasParam['NEXT_TASK']['TAS_TIMEUNIT'];
|
|
|
|
|
} else {
|
2017-12-04 13:25:35 +00:00
|
|
|
$task = TaskPeer::retrieveByPK($this->getTasUid());
|
2015-04-27 17:05:44 -04:00
|
|
|
$data['TAS_DURATION'] = $task->getTasDuration();
|
|
|
|
|
$data['TAS_TIMEUNIT'] = $task->getTasTimeUnit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$riskTime = $data['TAS_DURATION'] - ($data['TAS_DURATION'] * $risk);
|
2015-04-15 14:52:15 -04:00
|
|
|
|
2015-04-16 16:04:16 -04:00
|
|
|
//Calendar - Use the dates class to calculate dates
|
2017-08-04 10:13:09 -04:00
|
|
|
$calendar = new Calendar();
|
2015-04-16 16:04:16 -04:00
|
|
|
|
|
|
|
|
$arrayCalendarData = array();
|
|
|
|
|
|
|
|
|
|
if ($calendar->pmCalendarUid == "") {
|
|
|
|
|
$calendar->getCalendar(null, $this->getProUid(), $this->getTasUid());
|
|
|
|
|
|
|
|
|
|
$arrayCalendarData = $calendar->getCalendarData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Risk date
|
2015-04-29 11:24:06 -04:00
|
|
|
$riskDate = $calendar->dashCalculateDate($this->getDelDelegateDate(), $riskTime, $data['TAS_TIMEUNIT'], $arrayCalendarData);
|
2015-04-15 14:52:15 -04:00
|
|
|
|
|
|
|
|
return $riskDate;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function getDiffDate($date1, $date2)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
|
|
|
|
return ($date1 - $date2) / (24 * 60 * 60); //days
|
|
|
|
|
return ($date1 - $date2) / 3600;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
//usually this function is called when routing in the flow, so by default cron =0
|
|
|
|
|
public function calculateDuration($cron = 0)
|
|
|
|
|
{
|
|
|
|
|
$this->writeFileIfCalledFromCronForCalculateDuration($cron);
|
|
|
|
|
$this->patchDataWithValuesForCalculateDuration();
|
|
|
|
|
$rs = $this->recordSetForCalculateDuration();
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$i = 0;
|
|
|
|
|
$calendar = new Calendar();
|
|
|
|
|
$now = new DateTime();
|
|
|
|
|
while (is_array($row)) {
|
|
|
|
|
$oAppDel = AppDelegationPeer::retrieveByPk($row['APP_UID'], $row['DEL_INDEX']);
|
2017-08-04 10:13:09 -04:00
|
|
|
$calendar = new Calendar();
|
2015-06-02 17:27:14 -04:00
|
|
|
$calendar->getCalendar($row['USR_UID'], $row['PRO_UID'], $row['TAS_UID']);
|
|
|
|
|
$calData = $calendar->getCalendarData();
|
2015-06-03 09:37:28 -04:00
|
|
|
$calculatedValues = $this->getValuesToStoreForCalculateDuration($row, $calendar, $calData, $now);
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
$oAppDel->setDelStarted($calculatedValues['isStarted']);
|
|
|
|
|
$oAppDel->setDelFinished($calculatedValues['isFinished']);
|
|
|
|
|
$oAppDel->setDelDelayed($calculatedValues['isDelayed']);
|
|
|
|
|
$oAppDel->setDelQueueDuration($calculatedValues['queueTime']);
|
|
|
|
|
$oAppDel->setDelDelayDuration($calculatedValues['delayTime']);
|
|
|
|
|
$oAppDel->setDelDuration($calculatedValues['durationTime']);
|
|
|
|
|
$oAppDel->setAppOverduePercentage($calculatedValues['percentDelay']);
|
|
|
|
|
$RES = $oAppDel->save();
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getValuesToStoreForCalculateDuration($row, $calendar, $calData, $nowDate)
|
|
|
|
|
{
|
2015-06-03 09:37:28 -04:00
|
|
|
$rowValues = $this->completeRowDataForCalculateDuration($row, $nowDate);
|
2017-12-04 13:25:35 +00:00
|
|
|
return array(
|
2015-06-02 17:27:14 -04:00
|
|
|
'isStarted' => $this->createDateFromString($row['DEL_INIT_DATE']) != null ? 1 : 0,
|
|
|
|
|
'isFinished' => $this->createDateFromString($row['DEL_FINISH_DATE']) != null ? 1: 0,
|
|
|
|
|
'isDelayed' => $this->calculateDelayTime($calendar, $calData, $rowValues) > 0 ? 1 : 0,
|
|
|
|
|
'queueTime' => $this->calculateQueueTime($calendar, $calData, $rowValues),
|
|
|
|
|
'delayTime' => $this->calculateDelayTime($calendar, $calData, $rowValues),
|
|
|
|
|
'durationTime' => $this->calculateNetProcessingTime($calendar, $calData, $rowValues),
|
|
|
|
|
'percentDelay' => $this->calculateOverduePercentage($calendar, $calData, $rowValues)
|
2017-12-04 13:25:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
private function calculateOverduePercentage($calendar, $calData, $rowValues)
|
|
|
|
|
{
|
2015-06-02 17:27:14 -04:00
|
|
|
if ($rowValues['fTaskDuration'] == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//TODO 8 daily/hours must be extracted from calendar
|
2016-08-15 16:54:43 -04:00
|
|
|
$taskTime = ($rowValues['cTaskDurationUnit'] == 'DAYS')
|
2015-06-02 17:41:19 -04:00
|
|
|
? $rowValues['fTaskDuration'] * 8 / 24
|
2015-06-02 17:27:14 -04:00
|
|
|
: $rowValues['fTaskDuration'] / 24;
|
|
|
|
|
|
|
|
|
|
return $this->calculateDelayTime($calendar, $calData, $rowValues) * 100/ $taskTime;
|
2017-12-04 13:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//time in days from init or delegate date to finish or today's date
|
|
|
|
|
private function calculateNetProcessingTime($calendar, $calData, $rowValues)
|
|
|
|
|
{
|
|
|
|
|
$initDateForCalc = $this->selectDate($rowValues['dInitDate'], $rowValues['dDelegateDate'], 'max');
|
|
|
|
|
$endDateForCalc = $this->selectDate($rowValues['dFinishDate'], $rowValues['dNow'], 'min');
|
|
|
|
|
return $calendar->dashCalculateDurationWithCalendar(
|
|
|
|
|
$initDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$endDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$calData
|
|
|
|
|
)/(24*60*60);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//time in days from delegate date to init date
|
|
|
|
|
private function calculateQueueTime($calendar, $calData, $rowValues)
|
|
|
|
|
{
|
|
|
|
|
$initDateForCalc = $rowValues['dDelegateDate'];
|
|
|
|
|
$endDateForCalc = $this->selectDate($rowValues['dInitDate'], $rowValues['dNow'], 'min');
|
|
|
|
|
return $calendar->dashCalculateDurationWithCalendar(
|
|
|
|
|
$initDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$endDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$calData
|
|
|
|
|
)/(24*60*60);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//time in days from due date to finish or today date
|
|
|
|
|
private function calculateDelayTime($calendar, $calData, $rowValues)
|
|
|
|
|
{
|
|
|
|
|
$initDateForCalc = $this->selectDate($rowValues['dDueDate'], $rowValues['dDelegateDate'], 'max');
|
|
|
|
|
$endDateForCalc = $this->selectDate($rowValues['dFinishDate'], $rowValues['dNow'], 'min');
|
|
|
|
|
return $calendar->dashCalculateDurationWithCalendar(
|
|
|
|
|
$initDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$endDateForCalc->format('Y-m-d H:i:s'),
|
|
|
|
|
$calData
|
|
|
|
|
)/(24*60*60);
|
|
|
|
|
}
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2015-06-03 09:37:28 -04:00
|
|
|
//to avoid aplying many times the same conversions and functions the row data
|
2016-08-15 16:54:43 -04:00
|
|
|
//is used to create dates as DateTime objects and other fields are stracted also,
|
2015-06-03 09:37:28 -04:00
|
|
|
//so the array returned will work as a "context" object for the rest of the functions.
|
2017-12-04 13:25:35 +00:00
|
|
|
private function completeRowDataForCalculateDuration($row, $nowDate)
|
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
'dDelegateDate' => $this->createDateFromString($row['DEL_DELEGATE_DATE']),
|
|
|
|
|
'dInitDate' => $this->createDateFromString($row['DEL_INIT_DATE']),
|
|
|
|
|
'dDueDate' => $this->createDateFromString($row['DEL_TASK_DUE_DATE']),
|
|
|
|
|
'dFinishDate' => $this->createDateFromString($row['DEL_FINISH_DATE']),
|
|
|
|
|
'fTaskDuration' => $row['TAS_DURATION'] * 1.0,
|
|
|
|
|
'cTaskDurationUnit' => $row['TAS_TIMEUNIT'],
|
|
|
|
|
'dNow' => $nowDate,
|
|
|
|
|
'row' => $row
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//by default min function returns de null value if one of the params is null
|
2015-06-03 09:37:28 -04:00
|
|
|
//to avoid that behaviour this function was created so the function returns the first
|
|
|
|
|
//not null date or if both are not null the mix/max date
|
|
|
|
|
//NOTE date1 and date2 are DateTime objects.
|
2017-12-04 13:25:35 +00:00
|
|
|
private function selectDate($date1, $date2, $compareFunction)
|
|
|
|
|
{
|
|
|
|
|
if ($date1 == null) {
|
|
|
|
|
return $date2;
|
|
|
|
|
}
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($date2 == null) {
|
|
|
|
|
return $date1;
|
|
|
|
|
}
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
return $compareFunction($date1, $date2);
|
|
|
|
|
}
|
2015-06-02 17:27:14 -04:00
|
|
|
|
2015-06-03 09:37:28 -04:00
|
|
|
//Creates a DateTime object from a string. If the string is null or empty a null object is returned
|
2017-12-04 13:25:35 +00:00
|
|
|
private function createDateFromString($stringDate)
|
|
|
|
|
{
|
|
|
|
|
if ($stringDate == null || $stringDate == '') {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new DateTime($stringDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function recordSetForCalculateDuration()
|
|
|
|
|
{
|
|
|
|
|
//walk in all rows with DEL_STARTED = 0 or DEL_FINISHED = 0
|
|
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->clearSelectColumns();
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::APP_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::USR_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::PRO_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::TAS_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_QUEUE_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELAY_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_STARTED);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISHED);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELAYED);
|
|
|
|
|
$c->addSelectColumn(TaskPeer::TAS_DURATION);
|
|
|
|
|
$c->addSelectColumn(TaskPeer::TAS_TIMEUNIT);
|
|
|
|
|
$c->addSelectColumn(TaskPeer::TAS_TYPE_DAY);
|
|
|
|
|
|
|
|
|
|
$c->addJoin(AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$cton1 = $c->getNewCriterion(AppDelegationPeer::DEL_STARTED, 0);
|
|
|
|
|
$cton2 = $c->getNewCriterion(AppDelegationPeer::DEL_FINISHED, 0);
|
|
|
|
|
$cton1->addOR($cton2);
|
|
|
|
|
$c->add($cton1);
|
|
|
|
|
$rs = AppDelegationPeer::doSelectRS($c);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
return $rs;
|
|
|
|
|
}
|
2016-08-15 16:54:43 -04:00
|
|
|
private function writeFileIfCalledFromCronForCalculateDuration($cron)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($cron == 1) {
|
|
|
|
|
$arrayCron = unserialize(trim(@file_get_contents(PATH_DATA . "cron")));
|
|
|
|
|
$arrayCron["processcTimeStart"] = time();
|
|
|
|
|
@file_put_contents(PATH_DATA . "cron", serialize($arrayCron));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function patchDataWithValuesForCalculateDuration()
|
|
|
|
|
{
|
|
|
|
|
//patch rows with initdate = null and finish_date
|
|
|
|
|
$c = new Criteria();
|
|
|
|
|
$c->clearSelectColumns();
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::APP_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_INIT_DATE, null, Criteria::ISNULL);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL);
|
|
|
|
|
//$c->add(AppDelegationPeer::DEL_INDEX, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$rs = AppDelegationPeer::doSelectRS($c);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
|
|
|
|
|
while (is_array($row)) {
|
|
|
|
|
$oAppDel = AppDelegationPeer::retrieveByPk($row['APP_UID'], $row['DEL_INDEX']);
|
|
|
|
|
if (isset($row['DEL_FINISH_DATE'])) {
|
|
|
|
|
$oAppDel->setDelInitDate($row['DEL_FINISH_DATE']);
|
|
|
|
|
} else {
|
|
|
|
|
$oAppDel->setDelInitDate($row['DEL_INIT_DATE']);
|
|
|
|
|
}
|
|
|
|
|
$oAppDel->save();
|
|
|
|
|
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getLastDeleration($APP_UID)
|
|
|
|
|
{
|
|
|
|
|
$c = new Criteria('workflow');
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::APP_UID);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_INIT_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_TASK_DUE_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISH_DATE);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_QUEUE_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELAY_DURATION);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_STARTED);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_FINISHED);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::DEL_DELAYED);
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::USR_UID);
|
|
|
|
|
|
|
|
|
|
$c->add(AppDelegationPeer::APP_UID, $APP_UID);
|
|
|
|
|
$c->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$rs = AppDelegationPeer::doSelectRS($c);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-03-27 17:10:11 -04:00
|
|
|
$rs->next();
|
|
|
|
|
return $rs->getRow();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function getCurrentIndex($appUid)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
$oCriteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oRuleSet = AppDelegationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oRuleSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-03-27 17:10:11 -04:00
|
|
|
$oRuleSet->next();
|
|
|
|
|
$data = $oRuleSet->getRow();
|
|
|
|
|
return (int)$data['DEL_INDEX'];
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function getCurrentTask($appUid)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
|
|
|
|
$oCriteria = new Criteria();
|
2017-12-04 13:25:35 +00:00
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::TAS_UID);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
$oCriteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$oRuleSet = AppDelegationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oRuleSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2015-03-27 17:10:11 -04:00
|
|
|
$oRuleSet->next();
|
|
|
|
|
$data = $oRuleSet->getRow();
|
|
|
|
|
return $data['TAS_UID'];
|
|
|
|
|
}
|
2015-04-15 14:52:15 -04:00
|
|
|
|
2017-10-05 14:54:41 -04:00
|
|
|
/**
|
|
|
|
|
* This function get the current user related to the specific case and index
|
|
|
|
|
* @param string $appUid, Uid related to the case
|
|
|
|
|
* @param integer $index, Index to review
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2019-05-29 09:53:13 -04:00
|
|
|
public static function getCurrentUsers($appUid, $index)
|
2016-08-12 15:59:23 -04:00
|
|
|
{
|
2017-12-04 13:25:35 +00:00
|
|
|
$oCriteria = new Criteria();
|
|
|
|
|
$oCriteria->addSelectColumn(AppDelegationPeer::USR_UID);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN');
|
|
|
|
|
$oCriteria->add(AppDelegationPeer::DEL_INDEX, $index);
|
|
|
|
|
$oRuleSet = AppDelegationPeer::doSelectRS($oCriteria);
|
|
|
|
|
$oRuleSet->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$oRuleSet->next();
|
|
|
|
|
$data = $oRuleSet->getRow();
|
|
|
|
|
return $data;
|
2016-08-12 15:59:23 -04:00
|
|
|
}
|
|
|
|
|
|
2015-03-27 17:10:11 -04:00
|
|
|
/**
|
|
|
|
|
* Verify if the current case is already routed.
|
|
|
|
|
*
|
|
|
|
|
* @param string $AppUid the uid of the application
|
|
|
|
|
* @return array $Fields the fields
|
|
|
|
|
*/
|
|
|
|
|
|
2017-12-04 13:25:35 +00:00
|
|
|
public function alreadyRouted($appUid, $sDelIndex)
|
2015-03-27 17:10:11 -04:00
|
|
|
{
|
|
|
|
|
$c = new Criteria("workflow");
|
|
|
|
|
$c->clearSelectColumns();
|
|
|
|
|
$c->addSelectColumn(AppDelegationPeer::APP_UID);
|
|
|
|
|
$c->add(AppDelegationPeer::APP_UID, $appUid);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_INDEX, $sDelIndex);
|
|
|
|
|
$c->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL);
|
|
|
|
|
$result = AppDelegationPeer::doSelectRS($c);
|
|
|
|
|
$result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($result->next()) {
|
2015-03-27 17:10:11 -04:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-15 14:52:15 -04:00
|
|
|
public function getRisk()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$risk = 0.2;
|
|
|
|
|
|
|
|
|
|
//Return
|
|
|
|
|
return $risk;
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-04-14 15:51:36 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all task before Join Threads
|
|
|
|
|
*
|
|
|
|
|
* @param string $nextTaskUid
|
|
|
|
|
* @param string $sAppUid
|
|
|
|
|
* @return array $index
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function getAllTasksBeforeSecJoin($nextTaskUid, $sAppUid, $sDelPrevious, $threadStatus = '')
|
|
|
|
|
{
|
2016-04-14 15:51:36 -04:00
|
|
|
$criteriaR = new Criteria('workflow');
|
|
|
|
|
$criteriaR->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
2016-07-07 13:41:43 -04:00
|
|
|
$criteriaR->addSelectColumn(AppDelegationPeer::DEL_PREVIOUS);
|
2016-04-14 15:51:36 -04:00
|
|
|
$criteriaR->addJoin(RoutePeer::TAS_UID, AppDelegationPeer::TAS_UID, Criteria::LEFT_JOIN);
|
|
|
|
|
$criteriaR->add(RoutePeer::ROU_NEXT_TASK, $nextTaskUid, Criteria::EQUAL);
|
|
|
|
|
$criteriaR->add(RoutePeer::ROU_TYPE, 'SEC-JOIN', Criteria::EQUAL);
|
|
|
|
|
$criteriaR->add(AppDelegationPeer::APP_UID, $sAppUid, Criteria::EQUAL);
|
2016-07-07 13:41:43 -04:00
|
|
|
$criteriaR->add(AppDelegationPeer::DEL_PREVIOUS, $sDelPrevious, Criteria::EQUAL);
|
2017-03-22 20:52:26 -04:00
|
|
|
if (!empty($threadStatus)) {
|
|
|
|
|
$criteriaR->add(AppDelegationPeer::DEL_THREAD_STATUS, $threadStatus, Criteria::EQUAL);
|
|
|
|
|
}
|
2016-04-14 15:51:36 -04:00
|
|
|
$rsCriteriaR = RoutePeer::doSelectRS($criteriaR);
|
|
|
|
|
$rsCriteriaR->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$index = array();
|
|
|
|
|
$c = 0;
|
2017-12-04 13:25:35 +00:00
|
|
|
while ($rsCriteriaR->next()) {
|
2016-04-14 15:51:36 -04:00
|
|
|
$row = $rsCriteriaR->getRow();
|
|
|
|
|
$index[$c++] = $row['DEL_INDEX'];
|
|
|
|
|
}
|
|
|
|
|
return $index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify if we need to create a new Thread
|
|
|
|
|
*
|
|
|
|
|
* @param array $index
|
|
|
|
|
* @param string $sAppUid
|
2016-08-23 16:56:41 -04:00
|
|
|
* @param string $sUsrUid
|
2016-04-14 15:51:36 -04:00
|
|
|
* @return boolean $res
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function createThread($index, $sAppUid, $sUsrUid = '')
|
|
|
|
|
{
|
2016-04-14 15:51:36 -04:00
|
|
|
$criteriaDel = new Criteria("workflow");
|
|
|
|
|
$criteriaDel->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$criteriaDel->addSelectColumn(AppDelegationPeer::DEL_PREVIOUS);
|
|
|
|
|
$criteriaDel->add(AppDelegationPeer::APP_UID, $sAppUid);
|
|
|
|
|
$criteriaDel->add(AppDelegationPeer::DEL_PREVIOUS, $index, Criteria::IN);
|
2017-12-04 13:25:35 +00:00
|
|
|
if ($sUsrUid !== '') {
|
2016-08-23 16:56:41 -04:00
|
|
|
$criteriaDel->add(AppDelegationPeer::USR_UID, $sUsrUid);
|
|
|
|
|
}
|
2016-04-14 15:51:36 -04:00
|
|
|
$criteriaDel = AppDelegationPeer::doSelectRS($criteriaDel);
|
|
|
|
|
$criteriaDel->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$res = $criteriaDel->next();
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-15 16:46:47 -04:00
|
|
|
/**
|
|
|
|
|
* Get all Threads for Multiple Instance
|
|
|
|
|
*
|
|
|
|
|
* @param string $sPrevious
|
|
|
|
|
* @param string $sAppUid
|
|
|
|
|
* @return array $index
|
|
|
|
|
*/
|
2017-12-04 13:25:35 +00:00
|
|
|
public static function getAllTheardMultipleInstance($sPrevious, $sAppUid)
|
|
|
|
|
{
|
2016-04-15 16:46:47 -04:00
|
|
|
$criteriaR = new Criteria('workflow');
|
|
|
|
|
$criteriaR->addSelectColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$criteriaR->add(AppDelegationPeer::APP_UID, $sAppUid, Criteria::EQUAL);
|
|
|
|
|
$criteriaR->add(AppDelegationPeer::DEL_PREVIOUS, $sPrevious, Criteria::EQUAL);
|
|
|
|
|
$rsCriteriaR = AppDelegationPeer::doSelectRS($criteriaR);
|
|
|
|
|
$rsCriteriaR->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$index = array();
|
|
|
|
|
$c = 0;
|
2017-12-04 13:25:35 +00:00
|
|
|
while ($rsCriteriaR->next()) {
|
2016-04-15 16:46:47 -04:00
|
|
|
$row = $rsCriteriaR->getRow();
|
|
|
|
|
$index[$c++] = $row['DEL_INDEX'];
|
|
|
|
|
}
|
|
|
|
|
return $index;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-06 14:27:06 -04:00
|
|
|
/**
|
|
|
|
|
* This function get the columns by Id indexing
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param integer $delIndex
|
|
|
|
|
*
|
|
|
|
|
* @return array|null
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function getColumnIds($appUid, $delIndex)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$columnsId = [];
|
|
|
|
|
if ($delIndex > 0) {
|
|
|
|
|
$row = AppDelegationPeer::retrieveByPK($appUid, $delIndex);
|
|
|
|
|
if (!is_null($row)) {
|
|
|
|
|
$fields = $row->toArray(BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$this->fromArray($fields, BasePeer::TYPE_FIELDNAME);
|
|
|
|
|
$columnsId['APP_NUMBER'] = $fields['APP_NUMBER'];
|
|
|
|
|
$columnsId['USR_ID'] = $fields['USR_ID'];
|
|
|
|
|
$columnsId['TAS_ID'] = $fields['TAS_ID'];
|
|
|
|
|
$columnsId['PRO_ID'] = $fields['PRO_ID'];
|
|
|
|
|
return $columnsId;
|
|
|
|
|
} else {
|
|
|
|
|
throw (new Exception("The row '" . $appUid . "' , '" . $delIndex . "' in table APP_DELEGATION doesn't exist!"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 09:21:59 -04:00
|
|
|
/**
|
|
|
|
|
* Get the user assigned in the index
|
|
|
|
|
*
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param string $delIndex
|
|
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
*/
|
|
|
|
|
public function getUserAssignedInThread($appUid, $delIndex)
|
|
|
|
|
{
|
|
|
|
|
$currentUserUid = null;
|
|
|
|
|
|
|
|
|
|
$result = $this->Load($appUid, $delIndex);
|
|
|
|
|
if (isset($result["USR_UID"])) {
|
|
|
|
|
$currentUserUid = $result["USR_UID"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $currentUserUid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get column PRO_ID related to the APP_NUMBER
|
|
|
|
|
*
|
|
|
|
|
* @param integer $appNumber
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public function getProcessId($appNumber)
|
|
|
|
|
{
|
|
|
|
|
$proId = 0;
|
|
|
|
|
$criteria = new Criteria("workflow");
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_NUMBER, $appNumber);
|
|
|
|
|
$dataset = AppDelegationPeer::doSelectOne($criteria);
|
|
|
|
|
if (!is_null($dataset)) {
|
|
|
|
|
$proId = $dataset->getProId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $proId;
|
|
|
|
|
}
|
2018-05-30 09:19:46 -04:00
|
|
|
/**
|
|
|
|
|
* Get the last index by a specific status
|
|
|
|
|
*
|
|
|
|
|
* @param integer $appNumber
|
|
|
|
|
* @param string $status
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public static function getLastIndexByStatus($appNumber, $status = 'OPEN')
|
|
|
|
|
{
|
|
|
|
|
$delIndex = 0;
|
|
|
|
|
$criteria = new Criteria();
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_NUMBER, $appNumber);
|
|
|
|
|
$criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, $status);
|
|
|
|
|
$criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$dataset = AppDelegationPeer::doSelectOne($criteria);
|
|
|
|
|
if (!is_null($dataset)) {
|
|
|
|
|
$delIndex = $dataset->getDelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $delIndex;
|
|
|
|
|
}
|
2018-04-04 09:21:59 -04:00
|
|
|
|
2018-05-30 09:19:46 -04:00
|
|
|
/**
|
|
|
|
|
* Get the last index assigned to the user by a specific status
|
|
|
|
|
*
|
|
|
|
|
* @param integer $appNumber
|
|
|
|
|
* @param integer $usrId
|
|
|
|
|
* @param string $status
|
|
|
|
|
*
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public static function getLastIndexByUserAndStatus($appNumber, $usrId, $status = 'OPEN')
|
|
|
|
|
{
|
|
|
|
|
$delIndex = 0;
|
|
|
|
|
$criteria = new Criteria();
|
|
|
|
|
$criteria->add(AppDelegationPeer::APP_NUMBER, $appNumber);
|
|
|
|
|
$criteria->add(AppDelegationPeer::USR_ID, $usrId);
|
|
|
|
|
$criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, $status);
|
|
|
|
|
$criteria->addDescendingOrderByColumn(AppDelegationPeer::DEL_INDEX);
|
|
|
|
|
$dataset = AppDelegationPeer::doSelectOne($criteria);
|
|
|
|
|
if (!is_null($dataset)) {
|
|
|
|
|
$delIndex = $dataset->getDelIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $delIndex;
|
|
|
|
|
}
|
2019-03-01 16:03:45 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the priority in AppDelegation table, using the defined variable in task
|
|
|
|
|
*
|
|
|
|
|
* @param integer $delIndex
|
|
|
|
|
* @param string $tasUid
|
|
|
|
|
* @param string $appUid
|
|
|
|
|
* @param array $fieldAppData
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*
|
|
|
|
|
* @see Cases->update()
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function updatePriority($delIndex, $tasUid, $appUid, $fieldAppData)
|
|
|
|
|
{
|
|
|
|
|
if (!empty($delIndex) && !empty($tasUid)) {
|
|
|
|
|
//Optimized code to avoid load task content row.
|
|
|
|
|
$criteria = new Criteria();
|
|
|
|
|
$criteria->clearSelectColumns();
|
|
|
|
|
$criteria->addSelectColumn(TaskPeer::TAS_PRIORITY_VARIABLE);
|
|
|
|
|
$criteria->add(TaskPeer::TAS_UID, $tasUid);
|
|
|
|
|
$rs = TaskPeer::doSelectRS($criteria);
|
|
|
|
|
$rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
$rs->next();
|
|
|
|
|
$row = $rs->getRow();
|
|
|
|
|
$tasPriority = substr($row['TAS_PRIORITY_VARIABLE'], 2);
|
|
|
|
|
//End optimized code.
|
|
|
|
|
|
|
|
|
|
$x = $fieldAppData;
|
|
|
|
|
if (!empty($x[$tasPriority])) {
|
|
|
|
|
$array = [];
|
|
|
|
|
$array['APP_UID'] = $appUid;
|
|
|
|
|
$array['DEL_INDEX'] = $delIndex;
|
|
|
|
|
$array['TAS_UID'] = $tasUid;
|
|
|
|
|
$array['DEL_PRIORITY'] = (isset($x[$tasPriority]) ?
|
|
|
|
|
($x[$tasPriority] >= 1 && $x[$tasPriority] <= 5 ? $x[$tasPriority] : '3') : '3');
|
|
|
|
|
$this->update($array);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-03-27 17:10:11 -04:00
|
|
|
}
|