2012-10-09 10:45:20 -04:00
< ? php
2017-08-01 12:16:06 -04:00
use ProcessMaker\Plugins\PluginRegistry ;
2012-10-09 10:45:20 -04:00
class Applications
{
2017-03-01 09:58:38 -04:00
/**
* This function return information by searching cases
*
2019-03-12 09:34:45 -04:00
* The query is related to advanced search with different filters
2017-03-01 09:58:38 -04:00
* We can search by process , status of case , category of process , users , delegate date from and to
*
* @ param string $userUid
* @ param integer $start for the pagination
* @ param integer $limit for the pagination
* @ param string $search
* @ param integer $process the pro_id
* @ param integer $status of the case
* @ param string $dir if the order is DESC or ASC
2019-03-12 09:34:45 -04:00
* @ param string $sort name of column by sort , can be :
* [ APP_NUMBER , APP_TITLE , APP_PRO_TITLE , APP_TAS_TITLE , APP_CURRENT_USER , APP_UPDATE_DATE , DEL_DELEGATE_DATE , DEL_TASK_DUE_DATE , APP_STATUS_LABEL ]
2017-03-01 09:58:38 -04:00
* @ param string $category uid for the process
* @ param date $dateFrom
* @ param date $dateTo
2019-03-12 09:34:45 -04:00
* @ param string $filterBy name of column for a specific search , can be : [ APP_NUMBER , APP_TITLE , TAS_TITLE ]
2017-03-01 09:58:38 -04:00
* @ return array $result result of the query
*/
2017-01-10 13:41:43 -04:00
public function searchAll (
$userUid ,
$start = null ,
$limit = null ,
$search = null ,
$process = null ,
$status = null ,
$dir = null ,
$sort = null ,
2017-01-13 19:11:14 -04:00
$category = null ,
$dateFrom = null ,
2017-08-29 16:09:57 -04:00
$dateTo = null ,
2019-03-12 09:34:45 -04:00
$filterBy = 'APP_TITLE'
2017-01-10 13:41:43 -04:00
) {
2017-03-01 09:58:38 -04:00
//Start the connection to database
2017-02-09 15:17:13 -04:00
$con = Propel :: getConnection ( AppDelegationPeer :: DATABASE_NAME );
2018-07-20 00:28:45 +00:00
//Sanitize input variables
$inputFilter = new InputFilter ();
2018-07-23 14:11:27 -04:00
$userUid = ( int ) $inputFilter -> validateInput ( $userUid , 'int' );
$start = ( int ) $inputFilter -> validateInput ( $start , 'int' );
$limit = ( int ) $inputFilter -> validateInput ( $limit , 'int' );
2018-07-20 00:28:45 +00:00
$search = $inputFilter -> escapeUsingConnection ( $search , $con );
2018-07-23 14:11:27 -04:00
$process = ( int ) $inputFilter -> validateInput ( $process , 'int' );
2018-07-25 14:37:42 -04:00
2018-07-20 00:28:45 +00:00
//$status doesn't require sanitization
$dir = in_array ( $dir , [ 'ASC' , 'DESC' ]) ? $dir : 'DESC' ;
$sort = $inputFilter -> escapeUsingConnection ( $sort , $con );
$category = $inputFilter -> escapeUsingConnection ( $category , $con );
$dateFrom = $inputFilter -> escapeUsingConnection ( $dateFrom , $con );
$dateTo = $inputFilter -> escapeUsingConnection ( $dateTo , $con );
2019-03-12 09:34:45 -04:00
$filterBy = $inputFilter -> escapeUsingConnection ( $filterBy , $con );
2018-07-20 00:28:45 +00:00
//Start the transaction
2017-02-09 15:17:13 -04:00
$con -> begin ();
2017-03-01 09:58:38 -04:00
$stmt = $con -> createStatement ();
$sqlData = " SELECT
2017-02-09 15:17:13 -04:00
STRAIGHT_JOIN APPLICATION . APP_NUMBER ,
APPLICATION . APP_UID ,
APPLICATION . APP_STATUS ,
APPLICATION . APP_STATUS AS APP_STATUS_LABEL ,
APPLICATION . PRO_UID ,
APPLICATION . APP_CREATE_DATE ,
APPLICATION . APP_FINISH_DATE ,
APPLICATION . APP_UPDATE_DATE ,
APPLICATION . APP_TITLE ,
APP_DELEGATION . USR_UID ,
APP_DELEGATION . TAS_UID ,
APP_DELEGATION . DEL_INDEX ,
APP_DELEGATION . DEL_LAST_INDEX ,
APP_DELEGATION . DEL_DELEGATE_DATE ,
APP_DELEGATION . DEL_INIT_DATE ,
APP_DELEGATION . DEL_FINISH_DATE ,
APP_DELEGATION . DEL_TASK_DUE_DATE ,
APP_DELEGATION . DEL_RISK_DATE ,
APP_DELEGATION . DEL_THREAD_STATUS ,
APP_DELEGATION . DEL_PRIORITY ,
APP_DELEGATION . DEL_DURATION ,
APP_DELEGATION . DEL_QUEUE_DURATION ,
APP_DELEGATION . DEL_STARTED ,
APP_DELEGATION . DEL_DELAY_DURATION ,
APP_DELEGATION . DEL_FINISHED ,
APP_DELEGATION . DEL_DELAYED ,
APP_DELEGATION . DEL_DELAY_DURATION ,
TASK . TAS_TITLE AS APP_TAS_TITLE ,
2017-05-18 09:46:19 -04:00
TASK . TAS_TYPE AS APP_TAS_TYPE ,
2017-02-09 15:17:13 -04:00
USERS . USR_LASTNAME ,
USERS . USR_FIRSTNAME ,
USERS . USR_USERNAME ,
PROCESS . PRO_TITLE AS APP_PRO_TITLE
FROM APP_DELEGATION
" ;
2017-03-01 09:58:38 -04:00
$sqlData .= " LEFT JOIN APPLICATION ON (APP_DELEGATION.APP_NUMBER = APPLICATION.APP_NUMBER) " ;
2019-03-12 09:34:45 -04:00
$sqlData .= " LEFT JOIN TASK ON (APP_DELEGATION.TAS_ID = TASK.TAS_ID " ;
//Exclude the Task Dummies in the delegations
$sqlData .= " AND TASK.TAS_TYPE <> 'WEBENTRYEVENT' AND TASK.TAS_TYPE <> 'END-MESSAGE-EVENT' AND TASK.TAS_TYPE <> 'START-MESSAGE-EVENT' AND TASK.TAS_TYPE <> 'INTERMEDIATE-THROW') " ;
2017-03-01 09:58:38 -04:00
$sqlData .= " LEFT JOIN USERS ON (APP_DELEGATION.USR_ID = USERS.USR_ID) " ;
$sqlData .= " LEFT JOIN PROCESS ON (APP_DELEGATION.PRO_ID = PROCESS.PRO_ID) " ;
2017-02-09 15:17:13 -04:00
2019-03-12 09:34:45 -04:00
$sqlData .= " WHERE 1 " ;
2017-01-10 13:41:43 -04:00
switch ( $status ) {
case 1 : //DRAFT
2019-03-12 09:34:45 -04:00
$sqlData .= " AND APP_DELEGATION.DEL_THREAD_STATUS = 'OPEN' " ;
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APPLICATION.APP_STATUS_ID = 1 " ;
2017-01-10 13:41:43 -04:00
break ;
case 2 : //TO_DO
2019-03-12 09:34:45 -04:00
$sqlData .= " AND APP_DELEGATION.DEL_THREAD_STATUS = 'OPEN' " ;
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APPLICATION.APP_STATUS_ID = 2 " ;
2017-01-10 13:41:43 -04:00
break ;
case 3 : //COMPLETED
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APPLICATION.APP_STATUS_ID = 3 " ;
$sqlData .= " AND APP_DELEGATION.DEL_LAST_INDEX = 1 " ;
2017-01-10 13:41:43 -04:00
break ;
case 4 : //CANCELLED
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APPLICATION.APP_STATUS_ID = 4 " ;
$sqlData .= " AND APP_DELEGATION.DEL_LAST_INDEX = 1 " ;
2017-01-10 13:41:43 -04:00
break ;
case " PAUSED " : //This status is not considered in the search, maybe we can add in the new versions
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APPLICATION.APP_STATUS = 'TO_DO' " ;
2017-01-10 13:41:43 -04:00
break ;
2017-01-13 19:11:14 -04:00
default : //All status
2017-09-26 14:53:05 -04:00
//When the status is TO_DO, we will get all the open threads
2017-03-01 09:58:38 -04:00
$sqlData .= " AND (APP_DELEGATION.DEL_THREAD_STATUS = 'OPEN' " ;
2018-03-22 11:49:23 -04:00
//When the status is COMPLETED or CANCELLED, we will get the last task that with completed/cancelled the case
$sqlData .= " OR (APP_DELEGATION.DEL_THREAD_STATUS = 'CLOSED' AND APP_DELEGATION.DEL_LAST_INDEX = 1 AND APPLICATION.APP_STATUS_ID IN (3,4))) " ;
2017-01-10 13:41:43 -04:00
break ;
}
2017-03-01 09:58:38 -04:00
2017-01-10 13:41:43 -04:00
if ( ! empty ( $userUid )) {
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APP_DELEGATION.USR_ID = " . $userUid ;
2017-01-10 13:41:43 -04:00
}
2017-03-01 09:58:38 -04:00
2017-01-10 13:41:43 -04:00
if ( ! empty ( $process )) {
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APP_DELEGATION.PRO_ID = " . $process ;
2017-01-10 13:41:43 -04:00
}
2017-03-01 09:58:38 -04:00
2017-01-10 13:41:43 -04:00
if ( ! empty ( $category )) {
2017-12-04 13:25:35 +00:00
$category = mysqli_real_escape_string ( $con -> getResource (), $category );
2017-03-01 09:58:38 -04:00
$sqlData .= " AND PROCESS.PRO_CATEGORY = ' { $category } ' " ;
2017-01-10 13:41:43 -04:00
}
2017-03-01 09:58:38 -04:00
2017-01-10 13:41:43 -04:00
if ( ! empty ( $search )) {
2019-03-12 09:34:45 -04:00
//Search: we need to considerate the filterBy and the sortColumn
$appColumns = [ 'APP_NUMBER' , 'APP_TITLE' ];
if ( in_array ( $sort , $appColumns ) && in_array ( $filterBy , $appColumns )) {
$sqlData .= " AND APP_DELEGATION.APP_NUMBER IN ( " ;
//Sub query: get the appNumber(s) that match with the search
$sqlData .= " SELECT APPLICATION.APP_NUMBER FROM APPLICATION WHERE APPLICATION. { $filterBy } LIKE '% { $search } %' " ;
$sqlData .= " ORDER BY APPLICATION. { $sort } " . $dir ;
//End sub query
$sqlData .= " ) " ;
} else {
//If the filter is related to the APP_DELEGATION table: APP_NUMBER
if ( $filterBy === 'APP_NUMBER' ) {
$sqlData .= " AND APP_DELEGATION.APP_NUMBER LIKE '% { $search } %' " ;
}
//If the filter is related to the APPLICATION table: APP_TITLE
if ( $filterBy === 'APP_TITLE' ) {
$sqlData .= " AND APPLICATION.APP_TITLE LIKE '% { $search } %' " ;
}
//If the filter is related to the TASK table: TAS_TITLE
if ( $filterBy === 'TAS_TITLE' ) {
$sqlData .= " AND TASK.TAS_TITLE LIKE '% { $search } %' " ;
}
2017-08-29 16:09:57 -04:00
}
2017-01-10 13:41:43 -04:00
}
2017-03-01 09:58:38 -04:00
2017-02-09 15:17:13 -04:00
if ( ! empty ( $dateFrom )) {
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APP_DELEGATION.DEL_DELEGATE_DATE >= ' { $dateFrom } ' " ;
2017-01-13 19:11:14 -04:00
}
2017-03-01 09:58:38 -04:00
2017-02-09 15:17:13 -04:00
if ( ! empty ( $dateTo )) {
2017-01-13 19:11:14 -04:00
$dateTo = $dateTo . " 23:59:59 " ;
2017-03-01 09:58:38 -04:00
$sqlData .= " AND APP_DELEGATION.DEL_DELEGATE_DATE <= ' { $dateTo } ' " ;
2017-01-13 19:11:14 -04:00
}
2017-01-10 13:41:43 -04:00
2018-06-14 11:07:50 -04:00
//Sorts the records in descending order by default
if ( ! empty ( $sort )) {
2017-02-16 15:00:57 -04:00
switch ( $sort ) {
case 'APP_NUMBER' :
//The order by APP_DELEGATION.APP_NUMBER is must be fast than APPLICATION.APP_NUMBER
2018-06-14 11:07:50 -04:00
$orderBy = 'APP_DELEGATION.APP_NUMBER ' . $dir ;
2017-02-16 15:00:57 -04:00
break ;
case 'APP_CURRENT_USER' :
2019-03-12 09:34:45 -04:00
//@todo: this section needs to use 'User Name Display Format', currently in the extJs is defined this
2017-03-01 09:58:38 -04:00
//The column APP_CURRENT_USER is result of concat those fields
2018-06-14 11:07:50 -04:00
$orderBy = 'USR_LASTNAME ' . $dir . ' ,USR_FIRSTNAME ' . $dir ;
2017-02-16 15:00:57 -04:00
break ;
2018-06-14 11:07:50 -04:00
default :
$orderBy = $sort . " " . $dir ;
2017-02-09 15:17:13 -04:00
}
2018-06-14 11:07:50 -04:00
$sqlData .= " ORDER BY " . $orderBy ;
2017-02-09 15:17:13 -04:00
}
2017-03-01 09:58:38 -04:00
//Define the number of records by return
2017-12-04 13:25:35 +00:00
if ( empty ( $limit )) {
2017-05-15 08:55:44 -04:00
$limit = 25 ;
}
2018-10-08 09:56:48 -04:00
if ( ! empty ( $start )) {
2017-03-01 09:58:38 -04:00
$sqlData .= " LIMIT $start , " . $limit ;
2017-01-10 13:41:43 -04:00
} else {
2017-03-01 09:58:38 -04:00
$sqlData .= " LIMIT " . $limit ;
2017-01-10 13:41:43 -04:00
}
2018-10-08 09:56:48 -04:00
2018-06-14 11:07:50 -04:00
$dataset = $stmt -> executeQuery ( $sqlData );
$result = [];
2017-03-01 09:58:38 -04:00
//By performance enable always the pagination
$result [ 'totalCount' ] = $start + $limit + 1 ;
2018-06-14 11:07:50 -04:00
$rows = [];
$priorities = [ '1' => 'VL' , '2' => 'L' , '3' => 'N' , '4' => 'H' , '5' => 'VH' ];
while ( $dataset -> next ()) {
$row = $dataset -> getRow ();
if ( isset ( $row [ 'APP_STATUS' ] )) {
$row [ 'APP_STATUS_LABEL' ] = G :: LoadTranslation ( " ID_ { $row [ 'APP_STATUS' ] } " );
2017-01-10 13:41:43 -04:00
}
2018-06-14 11:07:50 -04:00
if ( isset ( $row [ 'DEL_PRIORITY' ] )) {
$row [ 'DEL_PRIORITY' ] = G :: LoadTranslation ( " ID_PRIORITY_ { $priorities [ $row [ 'DEL_PRIORITY' ]] } " );
2017-01-10 13:41:43 -04:00
}
2019-03-12 09:34:45 -04:00
//@todo: this section needs to use 'User Name Display Format', currently in the extJs is defined this
2018-06-14 11:07:50 -04:00
$row [ " APP_CURRENT_USER " ] = $row [ " USR_LASTNAME " ] . ' ' . $row [ " USR_FIRSTNAME " ];
$row [ " APPDELCR_APP_TAS_TITLE " ] = '' ;
$row [ " USRCR_USR_UID " ] = $row [ " USR_UID " ];
$row [ " USRCR_USR_FIRSTNAME " ] = $row [ " USR_FIRSTNAME " ];
$row [ " USRCR_USR_LASTNAME " ] = $row [ " USR_LASTNAME " ];
$row [ " USRCR_USR_USERNAME " ] = $row [ " USR_USERNAME " ];
$row [ " APP_OVERDUE_PERCENTAGE " ] = '' ;
$rows [] = $row ;
2017-01-10 13:41:43 -04:00
}
$result [ 'data' ] = $rows ;
2018-06-14 11:07:50 -04:00
2017-01-10 13:41:43 -04:00
return $result ;
}
2012-10-09 10:45:20 -04:00
//TODO: Encapsulates these and another default generation functions inside a class
/**
* generate all the default fields
*
* @ return Array $fields
*/
2017-12-04 13:25:35 +00:00
public function setDefaultFields ()
2012-10-09 10:45:20 -04:00
{
2017-12-04 13:25:35 +00:00
$fields = [];
$fields [ 'APP_NUMBER' ] = array ( 'name' => 'APP_NUMBER' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_NUMBER' ), 'width' => 40 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_UID' ] = array ( 'name' => 'APP_UID' , 'fieldType' => 'key' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_UID' ), 'width' => 80 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'DEL_INDEX' ] = array ( 'name' => 'DEL_INDEX' , 'fieldType' => 'key' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_DEL_INDEX' ), 'width' => 50 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'TAS_UID' ] = array ( 'name' => 'TAS_UID' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_TAS_UID' ), 'width' => 80 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'USR_UID' ] = array ( 'name' => 'USR_UID' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_USR_UID' ), 'width' => 80 , 'align' => 'left' , 'hidden' => true
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'PREVIOUS_USR_UID' ] = array ( 'name' => 'PREVIOUS_USR_UID' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_PREVIOUS_USR_UID' ), 'width' => 80 , 'align' => 'left' , 'hidden' => true
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_TITLE' ] = array ( 'name' => 'APP_TITLE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_TITLE' ), 'width' => 140 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_PRO_TITLE' ] = array ( 'name' => 'APP_PRO_TITLE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_PRO_TITLE' ), 'width' => 140 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_TAS_TITLE' ] = array ( 'name' => 'APP_TAS_TITLE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_TAS_TITLE' ), 'width' => 140 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DEL_PREVIOUS_USER' ] = array ( 'name' => 'APP_DEL_PREVIOUS_USER' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DEL_PREVIOUS_USER' ), 'width' => 120 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_CURRENT_USER' ] = array ( 'name' => 'APP_CURRENT_USER' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_CURRENT_USER' ), 'width' => 120 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'USR_FIRSTNAME' ] = array ( 'name' => 'USR_FIRSTNAME' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_CURRENT_USER' ), 'width' => 120 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'USR_LASTNAME' ] = array ( 'name' => 'USR_LASTNAME' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_CURRENT_USER' ), 'width' => 120 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'DEL_TASK_DUE_DATE' ] = array ( 'name' => 'DEL_TASK_DUE_DATE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_DEL_TASK_DUE_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_UPDATE_DATE' ] = array ( 'name' => 'APP_UPDATE_DATE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_UPDATE_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'DEL_PRIORITY' ] = array ( 'name' => 'DEL_PRIORITY' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_DEL_PRIORITY' ), 'width' => 80 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_STATUS' ] = array ( 'name' => 'APP_STATUS' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_STATUS' ), 'width' => 80 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_FINISH_DATE' ] = array ( 'name' => 'APP_FINISH_DATE' , 'fieldType' => 'case field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_FINISH_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DELAY_UID' ] = array ( 'name' => 'APP_DELAY_UID' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DELAY_UID' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_THREAD_INDEX' ] = array ( 'name' => 'APP_THREAD_INDEX' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_THREAD_INDEX' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DEL_INDEX' ] = array ( 'name' => 'APP_DEL_INDEX' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DEL_INDEX' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_TYPE' ] = array ( 'name' => 'APP_TYPE' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_TYPE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DELEGATION_USER' ] = array ( 'name' => 'APP_DELEGATION_USER' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DELEGATION_USER' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_ENABLE_ACTION_USER' ] = array ( 'name' => 'APP_ENABLE_ACTION_USER' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_ENABLE_ACTION_USER' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_ENABLE_ACTION_DATE' ] = array ( 'name' => 'APP_ENABLE_ACTION_DATE' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_AAPP_ENABLE_ACTION_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DISABLE_ACTION_USER' ] = array ( 'name' => 'APP_DISABLE_ACTION_USER' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DISABLE_ACTION_USER' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_DISABLE_ACTION_DATE' ] = array ( 'name' => 'APP_DISABLE_ACTION_DATE' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_DISABLE_ACTION_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
2017-12-04 13:25:35 +00:00
$fields [ 'APP_AUTOMATIC_DISABLED_DATE' ] = array ( 'name' => 'APP_AUTOMATIC_DISABLED_DATE' , 'fieldType' => 'delay field' , 'label' => G :: loadTranslation ( 'ID_CASESLIST_APP_AUTOMATIC_DISABLED_DATE' ), 'width' => 100 , 'align' => 'left'
2012-10-09 10:45:20 -04:00
);
return $fields ;
}
/**
* this function return the default fields for a default case list
*
* @ param $action
* @ return an array with the default fields for an specific case list ( action )
*/
2017-12-04 13:25:35 +00:00
public function getDefaultFields ( $action )
2012-10-09 10:45:20 -04:00
{
2017-12-04 13:25:35 +00:00
$rows = [];
2012-10-09 10:45:20 -04:00
switch ( $action ) {
case 'todo' : // #, Case, task, process, sent by, due date, Last Modify, Priority
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'DEL_TASK_DUE_DATE' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'DEL_PRIORITY' ];
break ;
case 'draft' : //#, Case, task, process, due date, Last Modify, Priority },
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'DEL_TASK_DUE_DATE' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'DEL_PRIORITY' ];
break ;
case 'sent' : // #, Case, task, process, current user, sent by, Last Modify, Status
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_CURRENT_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'APP_STATUS' ];
$rows [] = $fields [ 'USR_FIRSTNAME' ];
$rows [] = $fields [ 'USR_LASTNAME' ];
break ;
case 'unassigned' : //#, Case, task, process, completed by user, finish date
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
break ;
case 'paused' : //#, Case, task, process, sent by
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'APP_THREAD_INDEX' ];
$rows [] = $fields [ 'APP_DEL_INDEX' ];
break ;
case 'completed' : //#, Case, task, process, completed by user, finish date
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
break ;
case 'cancelled' : //#, Case, task, process, due date, Last Modify
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
break ;
case 'to_revise' : //#, Case, task, process, due date, Last Modify
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_CURRENT_USER' ];
$rows [] = $fields [ 'DEL_PRIORITY' ];
$rows [] = $fields [ 'APP_STATUS' ];
break ;
case 'to_reassign' : //#, Case, task, process, due date, Last Modify
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'TAS_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_CURRENT_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'APP_STATUS' ];
break ;
case 'all' : //#, Case, task, process, due date, Last Modify
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_CURRENT_USER' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'APP_STATUS' ];
break ;
case 'gral' : //#, Case, task, process, due date, Last Modify
$fields = $this -> setDefaultFields ();
$rows [] = $fields [ 'APP_UID' ];
$rows [] = $fields [ 'DEL_INDEX' ];
$rows [] = $fields [ 'USR_UID' ];
$rows [] = $fields [ 'PREVIOUS_USR_UID' ];
$rows [] = $fields [ 'APP_NUMBER' ];
$rows [] = $fields [ 'APP_TITLE' ];
$rows [] = $fields [ 'APP_PRO_TITLE' ];
$rows [] = $fields [ 'APP_TAS_TITLE' ];
$rows [] = $fields [ 'APP_CURRENT_USER' ];
$rows [] = $fields [ 'APP_DEL_PREVIOUS_USER' ];
$rows [] = $fields [ 'APP_UPDATE_DATE' ];
$rows [] = $fields [ 'APP_STATUS' ];
break ;
}
return $rows ;
}
/**
* set the generic Json Response , using two array for the grid stores and a string for the pmtable name
*
* @ param string $pmtable
* @ param array $first
* @ param array $second
* @ return $response a json string
*/
2017-12-04 13:25:35 +00:00
public function genericJsonResponse ( $pmtable , $first , $second , $rowsperpage , $dateFormat )
2012-10-09 10:45:20 -04:00
{
2017-12-04 13:25:35 +00:00
$firstGrid [ 'totalCount' ] = count ( $first );
2012-10-09 10:45:20 -04:00
$firstGrid [ 'data' ] = $first ;
2017-12-04 13:25:35 +00:00
$secondGrid [ 'totalCount' ] = count ( $second );
2012-10-09 10:45:20 -04:00
$secondGrid [ 'data' ] = $second ;
2017-12-04 13:25:35 +00:00
$result = [];
2012-10-09 10:45:20 -04:00
$result [ 'first' ] = $firstGrid ;
$result [ 'second' ] = $secondGrid ;
2017-12-04 13:25:35 +00:00
$result [ 'PMTable' ] = isset ( $pmtable ) ? $pmtable : '' ;
$result [ 'rowsperpage' ] = isset ( $rowsperpage ) ? $rowsperpage : 20 ;
$result [ 'dateformat' ] = isset ( $dateFormat ) && $dateFormat != '' ? $dateFormat : 'M d, Y' ;
2012-10-09 10:45:20 -04:00
return $result ;
}
2017-12-04 13:25:35 +00:00
public function getSteps ( $appUid , $index , $tasUid , $proUid )
2012-10-09 10:45:20 -04:00
{
2017-12-04 13:25:35 +00:00
$steps = [];
2012-10-09 10:45:20 -04:00
$case = new Cases ();
$step = new Step ();
$appDocument = new AppDocument ();
2017-12-04 13:25:35 +00:00
$caseSteps = $step -> getAllCaseSteps ( $proUid , $tasUid , $appUid );
2012-10-09 10:45:20 -04:00
//getting externals steps
2017-08-01 12:16:06 -04:00
$oPluginRegistry = PluginRegistry :: loadSingleton ();
2012-10-09 10:45:20 -04:00
$eSteps = $oPluginRegistry -> getSteps ();
2017-12-04 13:25:35 +00:00
$externalSteps = [];
2017-08-01 12:16:06 -04:00
/** @var \ProcessMaker\Plugins\Interfaces\StepDetail $externalStep */
2012-10-09 10:45:20 -04:00
foreach ( $eSteps as $externalStep ) {
2017-08-01 12:16:06 -04:00
$externalSteps [ $externalStep -> getStepId ()] = $externalStep ;
2012-10-09 10:45:20 -04:00
}
//getting the case record
if ( $appUid ) {
2017-12-04 13:25:35 +00:00
$caseData = $case -> loadCase ( $appUid );
2012-10-09 10:45:20 -04:00
$pmScript = new PMScript ();
2017-12-04 13:25:35 +00:00
$pmScript -> setFields ( $caseData [ 'APP_DATA' ]);
2012-10-09 10:45:20 -04:00
}
$externalStepCount = 0 ;
foreach ( $caseSteps as $caseStep ) {
// if it has a condition
2017-12-04 13:25:35 +00:00
if ( trim ( $caseStep -> getStepCondition ()) != '' ) {
$pmScript -> setScript ( $caseStep -> getStepCondition ());
2018-10-30 13:41:00 -04:00
$pmScript -> setExecutedOn ( PMScript :: CONDITION );
2012-10-09 10:45:20 -04:00
if ( ! $pmScript -> evaluate ()) {
//evaluated false, jump & continue with the others steps
continue ;
}
}
$stepUid = $caseStep -> getStepUidObj ();
$stepType = $caseStep -> getStepTypeObj ();
$stepPosition = $caseStep -> getStepPosition ();
2017-12-04 13:25:35 +00:00
$stepItem = [];
2012-10-09 10:45:20 -04:00
$stepItem [ 'id' ] = $stepUid ;
$stepItem [ 'type' ] = $stepType ;
switch ( $stepType ) {
case 'DYNAFORM' :
2017-12-04 13:25:35 +00:00
$oDocument = DynaformPeer :: retrieveByPK ( $stepUid );
2012-10-09 10:45:20 -04:00
$stepItem [ 'title' ] = $oDocument -> getDynTitle ();
$stepItem [ 'url' ] = " cases/cases_Step?UID= $stepUid &TYPE= $stepType &POSITION= $stepPosition &ACTION=EDIT " ;
2015-01-10 12:05:27 -04:00
$stepItem [ 'version' ] = $oDocument -> getDynVersion ();
2012-10-09 10:45:20 -04:00
break ;
case 'OUTPUT_DOCUMENT' :
2017-12-04 13:25:35 +00:00
$oDocument = OutputDocumentPeer :: retrieveByPK ( $caseStep -> getStepUidObj ());
$outputDoc = $appDocument -> getObject ( $appUid , $index , $caseStep -> getStepUidObj (), 'OUTPUT' );
2012-10-09 10:45:20 -04:00
$stepItem [ 'title' ] = $oDocument -> getOutDocTitle ();
2022-06-06 16:56:29 -04:00
if ( ! empty ( $outputDoc [ 'APP_DOC_UID' ])) {
2012-10-09 10:45:20 -04:00
$stepItem [ 'url' ] = " cases/cases_Step?UID= $stepUid &TYPE= $stepType &POSITION= $stepPosition &ACTION=VIEW&DOC= { $outputDoc [ 'APP_DOC_UID' ] } " ;
} else {
$stepItem [ 'url' ] = " cases/cases_Step?UID= $stepUid &TYPE= $stepType &POSITION= $stepPosition &ACTION=GENERATE " ;
}
break ;
case 'INPUT_DOCUMENT' :
2017-12-04 13:25:35 +00:00
$oDocument = InputDocumentPeer :: retrieveByPK ( $stepUid );
2012-10-09 10:45:20 -04:00
$stepItem [ 'title' ] = $oDocument -> getInpDocTitle ();
$stepItem [ 'url' ] = " cases/cases_Step?UID= $stepUid &TYPE= $stepType &POSITION= $stepPosition &ACTION=ATTACH " ;
break ;
case 'EXTERNAL' :
$stepTitle = 'unknown ' . $caseStep -> getStepUidObj ();
2017-08-01 12:16:06 -04:00
$oPluginRegistry = PluginRegistry :: loadSingleton ();
2018-06-13 13:33:23 -04:00
if ( empty ( $externalSteps [ $caseStep -> getStepUidObj ()])) {
throw new Exception ( G :: LoadTranslation ( 'ID_EXTERNAL_STEP_MISSING' , SYS_LANG , [ 'plugin' => $stepTitle ]));
}
2012-10-09 10:45:20 -04:00
$externalStep = $externalSteps [ $caseStep -> getStepUidObj ()];
2017-08-01 12:16:06 -04:00
$stepItem [ 'id' ] = $externalStep -> getStepId ();
$stepItem [ 'title' ] = $externalStep -> getStepTitle ();
$stepItem [ 'url' ] = " cases/cases_Step?UID= { $externalStep -> getStepId () } &TYPE=EXTERNAL&POSITION= $stepPosition &ACTION=EDIT " ;
2012-10-09 10:45:20 -04:00
break ;
}
$steps [] = $stepItem ;
}
//last, assign task
2017-12-04 13:25:35 +00:00
$stepItem = [];
2012-10-09 10:45:20 -04:00
$stepItem [ 'id' ] = '-1' ;
$stepItem [ 'type' ] = '' ;
2017-12-04 13:25:35 +00:00
$stepItem [ 'title' ] = G :: LoadTranslation ( 'ID_ASSIGN_TASK' );
2012-10-09 10:45:20 -04:00
$stepItem [ 'url' ] = " cases/cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN " ;
$steps [] = $stepItem ;
return $steps ;
}
}