/** * Returns a list of all activities that can be reassigned * @param $api * @param $args * @return array * @throws SugarApiExceptionNotAuthorized * @throws SugarQueryException */ public function getReassignFlows($api, $args) { $this->checkACL($api, $args); $result = array('success' => true); // This is set to -1 because this API is not considering the max_num or // offset values and always will return all occurrences $result['next_offset'] = -1; $bpmFlow = BeanFactory::retrieveBean('pmse_BpmFlow'); $queryOptions = array('add_deleted' => !isset($options['add_deleted']) || $options['add_deleted'] ? true : false); if ($queryOptions['add_deleted'] == false) { $options['select'][] = 'deleted'; } $q = new SugarQuery(); $q->from($bpmFlow, $queryOptions); $q->distinct(false); $fields = array('cas_id', 'cas_index', 'cas_task_start_date', 'cas_delegate_date', 'cas_flow_status', 'cas_user_id', 'cas_due_date', 'bpmn_id'); $q->where()->equals('cas_flow_status', 'FORM'); if (!empty($args['record'])) { $q->where()->equals('cas_id', $args['record']); } //INNER JOIN BPMN ACTIVITY $q->joinTable('pmse_bpmn_activity', array('alias' => 'activity', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('activity.id', 'bpmn_id')->equals('activity.deleted', 0); $fields[] = array("activity.name", 'act_name'); //INNSER JOIN BPMN ACTIVITY DEFINTION $q->joinTable('pmse_bpm_activity_definition', array('alias' => 'activity_definition', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('activity_definition.id', 'activity.id')->equals('activity_definition.deleted', 0); $fields[] = array("activity_definition.act_assignment_method", 'act_assignment_method'); $fields[] = array("activity_definition.act_expected_time", 'act_expected_time'); $q->select($fields); $rows = $q->execute(); foreach ($rows as $key => $row) { //Expected time section $casData = new stdClass(); $casData->cas_task_start_date = $row['cas_task_start_date']; $casData->cas_delegate_date = $row['cas_delegate_date']; $expectedTime = !empty($row['act_expected_time']) ? json_decode(base64_decode($row['act_expected_time'])) : ''; $dueDate = !empty($expectedTime) && !empty($expectedTime->time) ? PMSEEngineUtils::processExpectedTime($expectedTime, $casData) : ''; $expectedTime = PMSEEngineUtils::getExpectedTimeLabel($expectedTime); $rows[$key]['cas_expected_time'] = $expectedTime; $delegateDate = $rows[$key]['cas_delegate_date']; $rows[$key]['cas_delegate_date'] = !empty($delegateDate) ? PMSEEngineUtils::getDateToFE($delegateDate, 'datetime') : ''; $rows[$key]['cas_due_date'] = !empty($dueDate) ? PMSEEngineUtils::getDateToFE($dueDate->format('Y-m-d H:i:s'), 'datetime') : ''; //User section $user = BeanFactory::getBean("Users", $row["cas_user_id"]); $rows[$key]['assigned_user'] = $user->full_name; if (isset($args['unattended']) && !empty($args['unattended'])) { if (!($user->status != 'Active' || $user->employee_status != 'Active')) { unset($rows[$key]); } } } if (!empty($args['q'])) { foreach ($rows as $key => $row) { if (strstr(strtolower($row['assigned_user']), strtolower($args['q']))) { $rowsLoad = $rows; } } $rows = $rowsLoad; } $rows = array_values($rows); $result['records'] = $rows; return $result; }
public function processFlowData($flowData) { $today = TimeDate::getInstance()->nowDb(); $_date = TimeDate::getInstance()->getNow()->add(new DateInterval('P1D')); $dueDate = $_date->asDb(); if ($flowData['bpmn_type'] === 'bpmnActivity') { $beanActivityDefinition = BeanFactory::getBean('pmse_BpmActivityDefinition', $flowData['bpmn_id']); $casData = new stdClass(); $casData->cas_task_start_date = null; $casData->cas_delegate_date = $today; $expectedTime = !empty($beanActivityDefinition->act_expected_time) ? json_decode(base64_decode($beanActivityDefinition->act_expected_time)) : ''; $_dueDate = !empty($expectedTime) && !empty($expectedTime->time) ? PMSEEngineUtils::processExpectedTime($expectedTime, $casData) : ''; if (!empty($_dueDate)) { $dueDate = $_dueDate->format('Y-m-d H:i:s'); } else { $dueDate = ''; } } $preparedFlow = array(); $preparedFlow['id'] = isset($flowData['id']) ? $flowData['id'] : ''; $preparedFlow['cas_id'] = $flowData['cas_id']; $preparedFlow['cas_index'] = $flowData['max_index'] + 1; $preparedFlow['cas_previous'] = $flowData['cas_current_index']; $preparedFlow['pro_id'] = $flowData['pro_id']; $preparedFlow['bpmn_id'] = $flowData['bpmn_id']; $preparedFlow['bpmn_type'] = $flowData['bpmn_type']; $preparedFlow['cas_user_id'] = $flowData['cas_user_id']; $preparedFlow['cas_thread'] = $flowData['cas_thread']; $preparedFlow['cas_flow_status'] = 'NEW'; $preparedFlow['cas_sugar_module'] = $flowData['cas_sugar_module']; $preparedFlow['cas_sugar_object_id'] = $flowData['cas_sugar_object_id']; $preparedFlow['cas_sugar_action'] = 'None'; $preparedFlow['cas_delegate_date'] = $today; $preparedFlow['cas_start_date'] = ''; $preparedFlow['cas_finish_date'] = ''; $preparedFlow['cas_due_date'] = $dueDate; $preparedFlow['cas_queue_duration'] = 0; $preparedFlow['cas_duration'] = 0; $preparedFlow['cas_delay_duration'] = 0; $preparedFlow['cas_started'] = 0; $preparedFlow['cas_finished'] = 0; $preparedFlow['cas_delayed'] = 0; $preparedFlow['new_with_id'] = true; //Set these attributes if a related record is being evaluated $preparedFlow['rel_process_module'] = isset($flowData['rel_process_module']) ? $flowData['rel_process_module'] : ''; $preparedFlow['rel_element_relationship'] = isset($flowData['rel_element_relationship']) ? $flowData['rel_element_relationship'] : ''; $preparedFlow['rel_element_module'] = isset($flowData['rel_element_module']) ? $flowData['rel_element_module'] : ''; //Set these attributes if a start event is being evaluated $preparedFlow['evn_criteria'] = isset($flowData['evn_criteria']) ? $flowData['evn_criteria'] : ''; return $preparedFlow; }
public function expectedTime($actExpected, $caseData) { global $timedate; global $current_user; $returnArray = array(); $returnArray['expected_time_warning'] = false; $returnArray['expected_time_message'] = false; $returnArray['expected_time_view'] = false; $returnArray['expected_time'] = ''; $expTime = json_decode(base64_decode($actExpected)); if (!empty($expTime) && !empty($expTime->time)) { $expectedTime = PMSEEngineUtils::processExpectedTime($expTime, $caseData); $currentDate = new DateTime($timedate->nowDb()); if ($currentDate > $expectedTime) { $returnArray['expected_time_warning'] = true; $returnArray['expected_time_message'] = true; } $returnArray['expected_time'] = $timedate->to_display_date_time($expectedTime->format('Y-m-d H:i:s'), true, true, $current_user); } return $returnArray; }