/**
  * Method to save record in database
  * @param $projectData
  * @return bool
  */
 public function saveProjectData($projectData)
 {
     $source_definition = json_decode($projectData['rst_source_definition']);
     if (isset($projectData[$this->suffix . 'name']) && !empty($projectData[$this->suffix . 'name'])) {
         $name = $this->getNameWithSuffix($projectData[$this->suffix . 'name']);
     } else {
         $name = $this->getNameWithSuffix($projectData[$this->name]);
     }
     $projectData['rst_uid'] = PMSEEngineUtils::generateUniqueID();
     $source_definition->name = $name;
     $source_definition->id = $projectData['rst_uid'];
     $projectData['rst_source_definition'] = json_encode($source_definition);
     unset($projectData[$this->id]);
     unset($projectData['rst_uid']);
     $new_uid = parent::saveProjectData($projectData);
     if ($new_uid) {
         // Update new id into 'rst_source_definition' field
         $br_bean = BeanFactory::getBean('pmse_Business_Rules', $new_uid);
         $def = json_decode($br_bean->rst_source_definition);
         $def->id = $new_uid;
         $br_bean->rst_source_definition = json_encode($def);
         $br_bean->save();
         return $new_uid;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 protected function updateBean(SugarBean $bean, ServiceBase $api, $args)
 {
     $id = parent::updateBean($bean, $api, $args);
     //retrieve a Bean created
     if (isset($args['record']) && !empty($args['record'])) {
         $projectBean = BeanFactory::retrieveBean($args['module'], $args['record']);
     } else {
         $projectBean = $bean;
     }
     //Create a Diagram row
     $diagramBean = BeanFactory::getBean('pmse_BpmnDiagram')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($diagramBean)) {
         $diagramBean = BeanFactory::newBean('pmse_BpmnDiagram');
         $diagramBean->dia_uid = PMSEEngineUtils::generateUniqueID();
     }
     $diagramBean->name = $projectBean->name;
     $diagramBean->description = $projectBean->description;
     $diagramBean->assigned_user_id = $projectBean->assigned_user_id;
     $diagramBean->prj_id = $id;
     $dia_id = $diagramBean->save();
     //Create a Process row
     $processBean = BeanFactory::getBean('pmse_BpmnProcess')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processBean)) {
         $processBean = BeanFactory::newBean('pmse_BpmnProcess');
         $processBean->pro_uid = PMSEEngineUtils::generateUniqueID();
     }
     $processBean->name = $projectBean->name;
     $processBean->description = $projectBean->description;
     $processBean->assigned_user_id = $projectBean->assigned_user_id;
     $processBean->prj_id = $id;
     $processBean->dia_id = $dia_id;
     $pro_id = $processBean->save();
     //Create a ProcessDefinition row
     $processDefinitionBean = BeanFactory::getBean('pmse_BpmProcessDefinition')->retrieve_by_string_fields(array('prj_id' => $id));
     if (empty($processDefinitionBean)) {
         $processDefinitionBean = BeanFactory::newBean('pmse_BpmProcessDefinition');
         $processDefinitionBean->id = $pro_id;
         $processDefinitionBean->new_with_id = true;
     }
     $processDefinitionBean->prj_id = $id;
     $processDefinitionBean->pro_module = $projectBean->prj_module;
     $processDefinitionBean->pro_status = $projectBean->prj_status;
     $processDefinitionBean->assigned_user_id = $projectBean->assigned_user_id;
     $processDefinitionBean->save();
     $relDepStatus = $projectBean->prj_status == 'ACTIVE' ? 'INACTIVE' : 'ACTIVE';
     while ($relatedDepBean = BeanFactory::getBean('pmse_BpmRelatedDependency')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_status' => $relDepStatus))) {
         $relatedDepBean->pro_status = $projectBean->prj_status;
         $relatedDepBean->save();
     }
     $keysArray = array('prj_id' => $id, 'pro_id' => $pro_id);
     $dynaF = BeanFactory::getBean('pmse_BpmDynaForm')->retrieve_by_string_fields(array('prj_id' => $id, 'pro_id' => $pro_id, 'name' => 'Default'));
     if (empty($dynaF)) {
         $editDyna = false;
     } else {
         $editDyna = true;
     }
     $dynaForm = new PMSEDynaForm();
     $dynaForm->generateDefaultDynaform($processDefinitionBean->pro_module, $keysArray, $editDyna);
     return $id;
 }
Exemplo n.º 3
0
 /**
  * This method prepares the response of the current element based on the
  * $bean object and the $flowData, an external action such as
  * ROUTE or ADHOC_REASSIGN could be also processed.
  *
  * This method probably should be override for each new element, but it's
  * not mandatory. However the response structure always must pass using
  * the 'prepareResponse' Method.
  *
  * As defined in the example:
  *
  * $response['route_action'] = 'ROUTE'; //The action that should process the Router
  * $response['flow_action'] = 'CREATE'; //The record action that should process the router
  * $response['flow_data'] = $flowData; //The current flowData
  * $response['flow_filters'] = array('first_id', 'second_id'); //This attribute is used to filter the execution of the following elements
  * $response['flow_id'] = $flowData['id']; // The flowData id if present
  *
  *
  * @param type $flowData
  * @param type $bean
  * @param type $externalAction
  * @return type
  */
 public function run($flowData, $bean, $externalAction = '', $arguments = array())
 {
     if (empty($externalAction)) {
         $eventDefinition = $this->retrieveDefinitionData($flowData['bpmn_id']);
         $flowData['cas_flow_status'] = 'SLEEPING';
         $eventCriteria = json_decode(html_entity_decode($eventDefinition['evn_criteria']));
         if (!is_array($eventCriteria)) {
             if (!empty($eventDefinition['evn_criteria'])) {
                 $date = TimeDate::getInstance()->getNow();
                 $date = PMSEEngineUtils::addDateInterval($date, $eventDefinition['evn_criteria'], $eventDefinition['evn_params']);
                 $flowData['cas_due_date'] = $date->asDb();
             } else {
                 throw new PMSEElementException('The TimeEvent probably doesn\'t have any configuration', $flowData, $this);
             }
             //$this->bpmLog('INFO', "[$cas_id][$newCasIndex] schedule a timer event for $dueDate");
         } else {
             $moduleName = $flowData['cas_sugar_module'];
             $object_id = $flowData['cas_sugar_object_id'];
             $bean = $this->caseFlowHandler->retrieveBean($moduleName, $object_id);
             $dueDate = $this->evaluator->evaluateExpression($eventDefinition['evn_criteria'], $bean);
             $date = TimeDate::getInstance()->fromIso($dueDate);
             $dateDB = $date->asDb();
             $flowData['cas_delegate_date'] = $dateDB;
             $flowData['cas_due_date'] = $dateDB;
             //$this->bpmLog('INFO', "[$cas_id][$newCasIndex] schedule a timer event for $dueDate");
         }
         $result = $this->prepareResponse($flowData, 'SLEEP', 'CREATE');
     } else {
         /*$flowDueDate = new DateTime($flowData['cas_due_date']);
                     $casDueDate = $flowDueDate->getTimestamp();
                     $evaluatedCondition = $this->getCurrentTime() > $casDueDate;
         
                     if ($evaluatedCondition) {*/
         $isEventBased = $this->checkIfUsesAnEventBasedGateway($flowData['cas_id'], $flowData['cas_previous']);
         $this->checkIfExistEventBased($flowData['cas_id'], $flowData['cas_previous'], $isEventBased);
         $result = $this->prepareResponse($flowData, 'ROUTE', 'UPDATE');
         /*} else {
               $result = $this->prepareResponse($flowData, 'SLEEP', 'NONE');
           }*/
     }
     return $result;
 }
Exemplo n.º 4
0
 private function getFields($module, $except = array(), $alias = '')
 {
     $result = array();
     $rows = array_flip(PMSEEngineUtils::getAllFieldsBean($module));
     $rows = PMSEEngineUtils::unsetCommonFields($rows, $except);
     foreach ($rows as $key => $value) {
         if (!empty($alias)) {
             $result[] = $alias . '.' . $key;
         } else {
             $result[] = $key;
         }
     }
     return $result;
 }
Exemplo n.º 5
0
 protected function formatBeans(ServiceBase $api, $args, $beans)
 {
     if (!empty($args['fields']) && !is_array($args['fields'])) {
         $args['fields'] = explode(',', $args['fields']);
     }
     $ret = array();
     foreach ($beans as $bean) {
         if (!is_subclass_of($bean, 'SugarBean')) {
             continue;
         }
         $arr_aux = array();
         $arr_aux['cas_id'] = isset($bean->fetched_row['cas_id']) ? $bean->fetched_row['cas_id'] : $bean->fetched_row['pmse_bpm_flow__cas_id'];
         $arr_aux['act_assignment_method'] = $bean->fetched_row['act_assignment_method'];
         $arr_aux['cas_title'] = $bean->fetched_row['cas_title'];
         $arr_aux['pro_title'] = $bean->fetched_row['pro_title'];
         $arr_aux['date_entered'] = PMSEEngineUtils::getDateToFE($bean->fetched_row['date_entered'], 'datetime');
         $arr_aux['name'] = $bean->fetched_row['cas_title'];
         $arr_aux['cas_create_date'] = PMSEEngineUtils::getDateToFE($bean->fetched_row['date_entered'], 'datetime');
         $arr_aux['flow_id'] = $bean->fetched_row['id'];
         $arr_aux['id2'] = $bean->fetched_row['inbox_id'];
         $arr_aux['task_name'] = $bean->fetched_row['act_name'];
         $arr_aux['cas_status'] = $bean->fetched_row['act_assignment_method'];
         $arr_aux['assigned_user_name'] = $bean->fetched_row['assigned_user_name'];
         $arr_aux['cas_sugar_module'] = $bean->fetched_row['cas_sugar_module'];
         $arr_aux['cas_sugar_object_id'] = $bean->fetched_row['cas_sugar_object_id'];
         $arr_aux['prj_id'] = $bean->fetched_row['prj_id'];
         $arr_aux['in_time'] = true;
         $arr_aux['id'] = $bean->fetched_row['inbox_id'];
         $arr_aux['cas_user_id'] = $bean->fetched_row['cas_user_id'];
         $arr_aux['prj_created_by'] = $bean->fetched_row['prj_created_by'];
         $casUsersBean = BeanFactory::getBean('Users', $bean->fetched_row['cas_user_id']);
         $arr_aux['cas_user_id_full_name'] = $casUsersBean->full_name;
         if (empty($casUsersBean->full_name)) {
             $arr_aux['cas_user_id_full_name'] = $arr_aux['cas_user_id'];
         }
         $prjUsersBean = BeanFactory::getBean('Users', $bean->fetched_row['prj_created_by']);
         $arr_aux['prj_user_id_full_name'] = $prjUsersBean->full_name;
         $assignedBean = BeanFactory::getBean($arr_aux['cas_sugar_module'], $arr_aux['cas_sugar_object_id']);
         $assignedUsersBean = BeanFactory::getBean('Users', $assignedBean->assigned_user_id);
         $arr_aux['assigned_user_name'] = $assignedUsersBean->full_name;
         $ret[] = array_merge($this->formatBean($api, $args, $bean), $arr_aux);
     }
     return $ret;
 }
Exemplo n.º 6
0
 /**
  * Save the project elements data.
  * @param $elementsData
  * @param $keysArray
  * @param $beanType
  * @param bool $generateBound
  * @param bool $generateWithId
  * @param string $field_uid
  */
 public function saveProjectElementsData($elementsData, $keysArray, $beanType, $generateBound = false, $generateWithId = false, $field_uid = '')
 {
     foreach ($elementsData as $element) {
         $boundBean = BeanFactory::getBean('pmse_BpmnBound');
         $elementBean = BeanFactory::getBean($beanType);
         $element['prj_id'] = $keysArray['prj_id'];
         $element['pro_id'] = $keysArray['pro_id'];
         $element['dia_id'] = $keysArray['dia_id'];
         foreach ($element as $key => $value) {
             if (strpos($key, '_name') !== false) {
                 $elementBean->name = $value;
             } else {
                 $elementBean->{$key} = $value;
             }
             if ($generateBound) {
                 $boundBean->{$key} = $value;
             }
             if (strpos($key, '_uid') !== false) {
                 $uid = $key;
             }
         }
         $savedId = $elementBean->save();
         if (!empty($savedId)) {
             $this->savedElements[$beanType][$elementBean->{$uid}] = $savedId;
         }
         if (!empty($field_uid)) {
             $elementBean->{$field_uid} = PMSEEngineUtils::generateUniqueID();
         }
         if ($generateBound) {
             switch ($beanType) {
                 case 'pmse_BpmnArtifact':
                     $element_type = 'bpmnArtifact';
                     break;
                 default:
                     $element_type = '';
             }
             $boundBean->bou_uid = PMSEEngineUtils::generateUniqueID();
             $boundBean->dia_id = $keysArray['dia_id'];
             $boundBean->element_id = $keysArray['dia_id'];
             $boundBean->bou_element_type = $element_type;
             $boundBean->bou_element = $savedId;
             $boundBean->save();
         }
     }
 }
 /**
  *
  * Moved function from BpmInboxViewShowHistoryEntries class [view.showhistoryentries.php]
  * Using variable members and some fields added.
  */
 public function assemblyEntries()
 {
     $entries = array();
     $queryOptions = array('add_deleted' => true);
     $beanFlow = BeanFactory::getBean('pmse_BpmFlow');
     $fields = array('id', 'date_entered', 'date_modified', 'cas_id', 'cas_index', 'pro_id', 'cas_previous', 'cas_reassign_level', 'bpmn_id', 'bpmn_type', 'cas_user_id', 'cas_thread', 'cas_flow_status', 'cas_sugar_module', 'cas_sugar_object_id', 'cas_sugar_action', 'cas_adhoc_type', 'cas_adhoc_parent_id', 'cas_task_start_date', 'cas_delegate_date', 'cas_start_date', 'cas_finish_date', 'cas_due_date', 'cas_queue_duration', 'cas_duration', 'cas_delay_duration', 'cas_started', 'cas_finished', 'cas_delayed');
     $q = new SugarQuery();
     $q->from($beanFlow, $queryOptions);
     $q->distinct(false);
     $q->where()->equals('cas_id', $this->case_id);
     $q->orderBy('cas_index', 'ASC');
     $q->select($fields);
     $caseDerivations = $q->execute();
     foreach ($caseDerivations as $key => $caseData) {
         $entry = $this->fetchUserType($caseData);
         $currentDate = new DateTime();
         $entry['due_date'] = !empty($caseData['cas_due_date']) ? PMSEEngineUtils::getDateToFE($caseData['cas_due_date'], 'datetime') : '';
         $entry['end_date'] = !empty($caseData['cas_finish_date']) ? PMSEEngineUtils::getDateToFE($caseData['cas_finish_date'], 'datetime') : '';
         $entry['current_date'] = PMSEEngineUtils::getDateToFE(TimeDate::getInstance()->nowDb(), 'datetime');
         $entry['delegate_date'] = !empty($caseData['cas_delegate_date']) ? PMSEEngineUtils::getDateToFE($caseData['cas_delegate_date'], 'datetime') : '';
         $entry['start_date'] = !empty($caseData['cas_start_date']) ? PMSEEngineUtils::getDateToFE($caseData['cas_start_date'], 'datetime') : '';
         $entry['var_values'] = '';
         $entry['completed'] = true;
         $entry['cas_user_id'] = $caseData['cas_user_id'];
         if ($caseData['cas_previous'] == 0) {
             //cas_flow_status field should set something instead be empty.
             $dataString = sprintf(translate('LBL_PMSE_HISTORY_LOG_CREATED_CASE', 'pmse_Inbox'), $caseData['cas_id']);
         } else {
             if ($caseData['cas_flow_status'] == 'CLOSED') {
                 $dataString = sprintf(translate('LBL_PMSE_HISTORY_LOG_DERIVATED_CASE', 'pmse_Inbox'), $caseData['bpmn_id']);
             } else {
                 $dataString = sprintf(translate('LBL_PMSE_HISTORY_LOG_CURRENTLY_HAS_CASE', 'pmse_Inbox'), $caseData['bpmn_id']);
             }
         }
         $action = '';
         if ($caseData['bpmn_type'] == 'bpmnActivity') {
             $currentCaseState = $this->getActionStatusAndAction($caseData['cas_flow_status'], $caseData['cas_sugar_action']);
             $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_ACTIVITY_NAME', 'pmse_Inbox'), $this->getActivityName($caseData['bpmn_id']));
             if ($caseData['cas_flow_status'] != 'FORM') {
                 $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_MODULE_ACTION', 'pmse_Inbox'), $this->getActivityModule($caseData), $currentCaseState);
                 $res = $this->formAction->retrieve_by_string_fields(array('cas_id' => $caseData['cas_id'], 'act_id' => $caseData['bpmn_id'], 'user_id' => $caseData['cas_user_id']));
                 if (isset($this->formAction->frm_action) && !empty($this->formAction->frm_action)) {
                     $action = strtoupper($this->formAction->frm_action);
                 } else {
                     $action = translate('LBL_PMSE_HISTORY_LOG_NOT_REGISTED_ACTION', 'pmse_Inbox');
                 }
                 $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_ACTION_PERFORMED', 'pmse_Inbox'), $action);
                 if (isset($this->formAction->cas_pre_data)) {
                     $logdata = unserialize($this->formAction->cas_pre_data);
                     $entry['var_values'] = $logdata;
                 }
             } else {
                 $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_ACTION_STILL_ASSIGNED', 'pmse_Inbox'));
                 $entry['completed'] = false;
             }
         } else {
             if ($caseData['bpmn_type'] == 'bpmnEvent') {
                 $name = sprintf(translate('LBL_PMSE_HISTORY_LOG_ACTIVITY_NAME', 'pmse_Inbox'), $this->getEventName($caseData['bpmn_id']));
                 $currentCaseState = sprintf(translate('LBL_PMSE_HISTORY_LOG_WITH_EVENT', 'pmse_Inbox'), $name);
                 $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_MODULE_ACTION', 'pmse_Inbox'), $this->getActivityModule($caseData), $currentCaseState);
             } else {
                 if ($caseData['bpmn_type'] == 'bpmnGateway') {
                     $name = sprintf(translate('LBL_PMSE_HISTORY_LOG_ACTIVITY_NAME', 'pmse_Inbox'), $this->getEventName($caseData['bpmn_id']));
                     $currentCaseState = sprintf(translate('LBL_PMSE_HISTORY_LOG_WITH_GATEWAY', 'pmse_Inbox'), $name);
                     $dataString .= sprintf(translate('LBL_PMSE_HISTORY_LOG_MODULE_ACTION', 'pmse_Inbox'), $this->getActivityModule($caseData), $currentCaseState);
                 }
             }
         }
         $entry['data_info'] = $dataString;
         $entries[] = $entry;
     }
     return $entries;
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 public function retrieveFields($filter, $orderBy, $limit, $offset, $baseModule)
 {
     global $beanList;
     $pmseRelatedModule = new PMSERelatedModule();
     if (isset($beanList[$filter])) {
         $newModuleFilter = $filter;
     } else {
         $newModuleFilter = $pmseRelatedModule->getRelatedModuleName($baseModule, $filter);
     }
     $output = array();
     $moduleBean = BeanFactory::getBean($newModuleFilter);
     $fieldsData = isset($moduleBean->field_defs) ? $moduleBean->field_defs : array();
     foreach ($fieldsData as $field) {
         //$retrieveId = isset($additionalArgs['retrieveId']) && !empty($additionalArgs['retrieveId']) && $field['name'] == 'id' ? $additionalArgs['retrieveId'] : false;
         if (isset($field['vname']) && PMSEEngineUtils::isValidField($field, 'ET')) {
             $tmpField = array();
             $tmpField['id'] = $field['name'];
             $tmpField['_module'] = $newModuleFilter;
             $tmpField['name'] = str_replace(':', '', translate($field['vname'], $newModuleFilter));
             $tmpField['rhs_module'] = $filter;
             $output[] = $tmpField;
         }
     }
     $text = array();
     foreach ($output as $key => $row) {
         $text[$key] = strtolower($row['name']);
     }
     if ($orderBy == "ASC") {
         array_multisort($text, SORT_ASC, $output);
     } else {
         array_multisort($text, SORT_DESC, $output);
     }
     $start = $offset;
     $end = $offset + $limit;
     $count = 0;
     $outputTmp = array();
     foreach ($output as $field) {
         if ($count >= $start && $count < $end) {
             $outputTmp[] = $field;
         }
         $count++;
     }
     return array('totalRecords' => count($output), 'records' => $outputTmp);
 }
Exemplo n.º 10
0
 public function selectCasesList($api, $args)
 {
     $this->checkACL($api, $args);
     $q = new SugarQuery();
     $inboxBean = BeanFactory::getBean('pmse_Inbox');
     if ($args['order_by'] == 'cas_due_date:asc') {
         $args['order_by'] = 'cas_create_date:asc';
     }
     $options = self::parseArguments($api, $args, $inboxBean);
     $fields = array('a.*');
     $q->from($inboxBean, array('alias' => 'a'));
     //INNER USER TABLE
     $q->joinTable('users', array('alias' => 'u', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('u.id', 'a.created_by')->equals('u.deleted', 0);
     $fields[] = array("u.last_name", 'assigned_user_name');
     //INNER PROCESS TABLE
     $q->joinTable('pmse_bpmn_process', array('alias' => 'pr', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('pr.id', 'a.pro_id')->equals('pr.deleted', 0);
     $fields[] = array("pr.prj_id", 'prj_id');
     //INNER PROJECT TABLE
     $q->joinTable('pmse_project', array('alias' => 'prj', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('prj.id', 'pr.prj_id')->equals('prj.deleted', 0);
     $fields[] = array("prj.assigned_user_id", 'prj_created_by');
     $fields[] = array("prj.prj_module", 'prj_module');
     $q->select($fields);
     $q->where()->in('prj.prj_module', PMSEEngineUtils::getSupportedModules());
     if (!empty($args['q'])) {
         $q->where()->queryAnd()->addRaw("a.cas_title LIKE '%" . $args['q'] . "%' OR a.pro_title LIKE '%" . $args['q'] . "%' OR a.cas_status LIKE '%" . $args['q'] . "%' OR prj.assigned_user_id LIKE '%" . $args['q'] . "%' OR pr.prj_id LIKE '%" . $args['q'] . "%' OR last_name LIKE '%" . $args['q'] . "%'");
     }
     if (!empty($args['module_list'])) {
         switch ($args['module_list']) {
             case translate('LBL_STATUS_COMPLETED', 'pmse_Inbox'):
                 $q->where()->queryAnd()->addRaw("cas_status = 'COMPLETED'");
                 break;
             case translate('LBL_STATUS_TERMINATED', 'pmse_Inbox'):
                 $q->where()->queryAnd()->addRaw("cas_status = 'TERMINATED'");
                 break;
             case translate('LBL_STATUS_IN_PROGRESS', 'pmse_Inbox'):
                 $q->where()->queryAnd()->addRaw("cas_status = 'IN PROGRESS'");
                 break;
             case translate('LBL_STATUS_CANCELLED', 'pmse_Inbox'):
                 $q->where()->queryAnd()->addRaw("cas_status = 'CANCELLED'");
                 break;
             case translate('LBL_STATUS_ERROR', 'pmse_Inbox'):
                 $q->where()->queryAnd()->addRaw("cas_status = 'ERROR'");
                 break;
         }
     }
     foreach ($options['order_by'] as $orderBy) {
         $q->orderBy($orderBy[0], $orderBy[1]);
     }
     // Add an extra record to the limit so we can detect if there are more records to be found
     $q->limit($options['limit']);
     $q->offset($options['offset']);
     $offset = $options['offset'] + $options['limit'];
     $count = 0;
     $list = $q->execute();
     foreach ($list as $key => $value) {
         if ($value["cas_status"] === 'IN PROGRESS') {
             $list[$key]["cas_status"] = '<data class="label label-Leads">' . $value["cas_status"] . '</data>';
         } elseif ($value["cas_status"] === 'COMPLETED' || $value["cas_status"] === 'TERMINATED') {
             $list[$key]["cas_status"] = '<data class="label label-success">' . $value["cas_status"] . '</data>';
         } elseif ($value["cas_status"] === 'CANCELLED') {
             $list[$key]["cas_status"] = '<data class="label label-warning">' . $value["cas_status"] . '</data>';
         } else {
             $list[$key]["cas_status"] = '<data class="label label-important">' . $value["cas_status"] . '</data>';
         }
         $list[$key]['cas_create_date'] = PMSEEngineUtils::getDateToFE($value['cas_create_date'], 'datetime');
         $list[$key]['date_entered'] = PMSEEngineUtils::getDateToFE($value['date_entered'], 'datetime');
         $list[$key]['date_modified'] = PMSEEngineUtils::getDateToFE($value['date_modified'], 'datetime');
         $prjUsersBean = BeanFactory::getBean('Users', $list[$key]['prj_created_by']);
         $list[$key]['prj_user_id_full_name'] = $prjUsersBean->full_name;
         $qA = new SugarQuery();
         $flowBean = BeanFactory::getBean('pmse_BpmFlow');
         $qA->select->fieldRaw('*');
         $qA->from($flowBean);
         $qA->where()->equals('cas_id', $list[$key]['cas_id']);
         $processUsers = $qA->execute();
         $processUsersNames = array();
         foreach ($processUsers as $k => $v) {
             if ($processUsers[$k]['cas_flow_status'] != 'CLOSED') {
                 $casUsersBean = BeanFactory::getBean('Users', $processUsers[$k]['cas_user_id']);
                 $processUsersNames[] = !empty($casUsersBean->full_name) ? $casUsersBean->full_name : '';
             }
             $cas_sugar_module = $processUsers[$k]['cas_sugar_module'];
             $cas_sugar_object_id = $processUsers[$k]['cas_sugar_object_id'];
         }
         if (empty($processUsersNames)) {
             $userNames = '';
         } else {
             $processUsersNames = array_unique($processUsersNames);
             $userNames = implode(', ', $processUsersNames);
         }
         $list[$key]['cas_user_id_full_name'] = $userNames;
         $assignedBean = BeanFactory::getBean($cas_sugar_module, $cas_sugar_object_id);
         $assignedUsersBean = BeanFactory::getBean('Users', $assignedBean->assigned_user_id);
         $list[$key]['assigned_user_name'] = $assignedUsersBean->full_name;
         $count++;
     }
     if ($count == $options['limit']) {
         $offset = $options['offset'] + $options['limit'];
     } else {
         $offset = -1;
     }
     $data = array();
     $data['next_offset'] = $offset;
     $data['records'] = $list;
     return $data;
 }
Exemplo n.º 11
0
 /**
  * Method to save record in database
  * @param $projectData
  * @return bool
  */
 public function saveProjectData($projectData)
 {
     global $current_user;
     //Unset common fields
     $projectData = PMSEEngineUtils::unsetCommonFields($projectData, array('name', 'description'));
     //unset($projectData['assigned_user_id']);
     if (!isset($projectData['assigned_user_id'])) {
         $projectData['assigned_user_id'] = $current_user->id;
     }
     //Check Name of project
     if (isset($projectData[$this->suffix . 'name']) && !empty($projectData[$this->suffix . 'name'])) {
         $name = $this->getNameWithSuffix($projectData[$this->suffix . 'name']);
     } else {
         $name = $this->getNameWithSuffix($projectData[$this->name]);
     }
     $projectData[$this->name] = $name;
     foreach ($projectData as $key => $field) {
         $this->bean->{$key} = $field;
     }
     //$this->bean->new_with_id = true;
     //$this->bean->validateUniqueUid();
     $new_id = $this->bean->save();
     if (!$this->bean->in_save) {
         return $new_id;
     } else {
         return false;
     }
 }
Exemplo n.º 12
0
 public function getRelatedBeans($filter, $relationship = 'all')
 {
     global $beanList;
     if (isset($beanList[$filter])) {
         $newModuleFilter = $filter;
     } else {
         $newModuleFilter = array_search($filter, $beanList);
     }
     $output_11 = array();
     // Logic container for one-to-one and many-to-one
     $output_1m = array();
     // Logic container for one-to-many and many-to-many(not implemented yet)
     $output = array();
     $moduleBean = $this->getBean($newModuleFilter);
     foreach ($moduleBean->get_linked_fields() as $link => $def) {
         if (!empty($def['type']) && $def['type'] == 'link' && $moduleBean->load_relationship($link)) {
             $relatedModule = $moduleBean->{$link}->getRelatedModuleName();
             if (!in_array($relatedModule, PMSEEngineUtils::getSupportedModules('related'))) {
                 continue;
             }
             if (in_array($link, PMSEEngineUtils::$relatedBlacklistedLinks)) {
                 continue;
             }
             $relType = $moduleBean->{$link}->getType();
             //returns 'one' or 'many' for the cardinality of the link
             $label = empty($def['vname']) ? $link : translate($def['vname'], $filter);
             $moduleLabel = translate("LBL_MODULE_NAME", $relatedModule);
             if ($moduleLabel == "LBL_MODULE_NAME") {
                 $moduleLabel = translate($relatedModule);
             }
             // Parentheses value
             $pval = "{$moduleLabel} (" . trim($label, ':') . ": {$link})";
             $ret = array('value' => $link, 'text' => $pval, 'module' => $moduleLabel, 'relationship' => $def['relationship']);
             if ($relType == 'one') {
                 $output_11[] = $ret;
             } else {
                 $output_1m[] = $ret;
             }
         }
     }
     switch ($relationship) {
         case 'one-to-one':
         case 'one':
             $output = $output_11;
             break;
         case 'one-to-many':
         case 'many':
             $output = $output_1m;
             break;
         case 'all':
         default:
             $output = array_merge($output_11, $output_1m);
             break;
     }
     // Needed to multisort on the label
     foreach ($output as $k => $o) {
         $labels[$k] = $o['text'];
     }
     // Sort on the label
     array_multisort($labels, SORT_ASC, $output);
     $filterArray = array('value' => $filter, 'text' => '<' . $filter . '>', 'module' => $filter, 'relationship' => $filter);
     array_unshift($output, $filterArray);
     $res['search'] = $filter;
     $res['success'] = true;
     $res['result'] = $output;
     return $res;
 }
Exemplo n.º 13
0
 /**
  * Generates a default dynaform based in the base module name.
  * @param string $baseModule
  * @param array $keys
  * @param boolean $update
  * @return boolean
  */
 public function generateDefaultDynaform($baseModule, $keys, $update = false)
 {
     $this->baseModule = $baseModule;
     $params = array();
     if ($update) {
         $this->dynaform->retrieve_by_string_fields(array('prj_id' => $keys['prj_id'], 'pro_id' => $keys['pro_id'], 'name' => 'Default'));
     } else {
         $params['dyn_uid'] = PMSEEngineUtils::generateUniqueID();
     }
     $params['name'] = 'Default';
     $params['description'] = 'Default';
     $params['prj_id'] = isset($keys['prj_id']) ? $keys['prj_id'] : null;
     $params['pro_id'] = isset($keys['pro_id']) ? $keys['prj_id'] : null;
     $params['dyn_module'] = $this->baseModule;
     $params['dyn_name'] = "Default";
     $params['dyn_description'] = "Default";
     $moduleViewDefs = get_custom_file_if_exists('modules/' . $baseModule . '/metadata/editviewdefs.php');
     $viewdefs = array();
     if (!@(include_once $moduleViewDefs)) {
         return false;
     } else {
         $params['dyn_view_defs'] = array('BpmView' => $viewdefs[$baseModule]['EditView']);
         return $this->saveDynaform($baseModule, $params);
     }
 }
 /**
  * This method gets the list of default required fields based on the process definition.
  * @return array
  */
 public function getDefaultRequiredFields()
 {
     $this->processDefinition->retrieve_by_string_fields(array('id' => $this->activityDefinition->pro_id));
     $bean = $this->factory->getBean($this->processDefinition->pro_module);
     $fieldsData = isset($bean->field_defs) ? $bean->field_defs : array();
     $output = array();
     foreach ($fieldsData as $field) {
         if (isset($field['vname']) && PMSEEngineUtils::isValidField($field, 'RR')) {
             if ($field['type'] != 'bool' && $field['type'] != 'radioenum') {
                 if (!(isset($field['required']) && $field['required'])) {
                     $tmpField = array();
                     $tmpField['name'] = $field['name'];
                     $tmpField['label'] = str_replace(':', '', translate($field['vname'], $this->processDefinition->pro_module));
                     $tmpField['required'] = false;
                     $output[] = $tmpField;
                 }
             }
         }
     }
     $text = array();
     foreach ($output as $key => $row) {
         $text[$key] = strtolower($row['label']);
     }
     array_multisort($text, SORT_ASC, $output);
     return $output;
 }
Exemplo n.º 15
0
 /**
  * Method to remove fields
  * @param string $row
  * @return string
  */
 public static function sanitizeFields($row)
 {
     $row = PMSEEngineUtils::sanitizeKeyFields($row);
     $row = PMSEEngineUtils::sanitizeBoundFields($row);
     return $row;
 }
 /**
  *
  * @param array $args
  * @return type
  */
 public function _get(array $args)
 {
     $result = array();
     $this->event->retrieve_by_string_fields(array('evn_uid' => $args['record']));
     if ($this->event->fetched_row != false) {
         $this->eventDefinition->retrieve_by_string_fields(array('id' => $this->event->id));
         if ($this->eventDefinition->fetched_row != false) {
             $result = array_merge($result, $this->eventDefinition->fetched_row);
             $result['evn_uid'] = $this->event->fetched_row['evn_uid'];
         }
     }
     $relatedOutput = array();
     if (isset($args['related'])) {
         $related = explode(',', $args['related']);
         $output = array();
         if (is_array($related)) {
             foreach ($related as $search) {
                 $output[$search] = $this->crmDataWrapper->getRelatedSearch($search, $args);
             }
         }
         $relatedOutput['related'] = $output;
     }
     $result = array_merge($result, $relatedOutput);
     $result = PMSEEngineUtils::sanitizeKeyFields($result);
     return $result;
 }
Exemplo n.º 17
0
 /**
  * Saving the bean data if sent through the engine
  * @param type $beanData
  * @codeCoverageIgnore
  */
 public function saveBeanData($beanData)
 {
     $fields = $beanData;
     $bpmInboxId = $fields['flow_id'];
     $moduleName = $fields['moduleName'];
     $moduleId = $fields['beanId'];
     foreach ($beanData as $key => $value) {
         if (in_array($key, $this->engineFields)) {
             unset($fields[$key]);
         }
     }
     //modified_by_name => Current
     if (!isset($moduleName) || $moduleName == '') {
         $GLOBALS['log']->fatal('moduleName Empty cannot complete the route case');
         header('Location: #Home');
     }
     //If Process is Completed break...
     $bpmI = PMSEEngineUtils::getBPMInboxStatus($bpmInboxId);
     if ($bpmI === false) {
         header('Location: #pmse_Inbox/$bpmInboxId/layout/no-show-case/$bpmFlowId');
         die;
     }
     $beanObject = BeanFactory::getBean($moduleName, $moduleId);
     $historyData = new PMSEHistoryData($moduleName);
     foreach ($fields as $key => $value) {
         $historyData->lock(!array_key_exists($key, $beanObject->fetched_row));
         if (isset($beanObject->{$key})) {
             $historyData->verifyRepeated($beanObject->{$key}, $value);
             $historyData->savePredata($key, $beanObject->{$key});
             $beanObject->{$key} = $value;
             $historyData->savePostdata($key, $value);
         }
     }
     //If a module includes custom save/editview logic in Save.php, use that instead of a direct save.
     if (isModuleBWC($beanObject->module_dir) && SugarAutoLoader::fileExists("modules/{$beanObject->module_dir}/Save.php")) {
         global $disable_redirects;
         $disable_redirects = true;
         $_REQUEST['record'] = $beanObject->id;
         include "modules/{$beanObject->module_dir}/Save.php";
         $disable_redirects = false;
     } else {
         $beanObject->save();
     }
     $fields['log_data'] = $historyData->getLog();
     $this->caseFlowHandler->saveFormAction($fields);
 }
Exemplo n.º 18
0
 /**
  * Method that returns a list of type date fields
  * @param $filter
  * @return object
  */
 public function retrieveDateFields($filter)
 {
     if (isset($this->beanList[$filter])) {
         $newModuleFilter = $filter;
     } else {
         $related = $this->getRelationshipData($filter);
         $newModuleFilter = $related['rhs_module'];
     }
     $res = array();
     //new stdClass();
     $res['name'] = $newModuleFilter;
     $res['search'] = $filter;
     $res['success'] = true;
     $output = array();
     $moduleBean = $this->getModuleFilter($newModuleFilter);
     $fieldsData = isset($moduleBean->field_defs) ? $moduleBean->field_defs : array();
     foreach ($fieldsData as $field) {
         if (isset($field['vname']) && PMSEEngineUtils::isValidField($field)) {
             if ($field['type'] == 'date' || $field['type'] == 'datetimecombo' || $field['type'] == 'datetime') {
                 $tmpField = array();
                 $tmpField['value'] = $field['name'];
                 $tmpField['text'] = str_replace(':', '', translate($field['vname'], $newModuleFilter));
                 $output[] = $tmpField;
             }
         }
     }
     $arr_Now = array();
     $arr_Now['value'] = 'current_date_time';
     $arr_Now['text'] = 'Current Date Time';
     array_unshift($output, $arr_Now);
     $res['result'] = $output;
     return $res;
 }
Exemplo n.º 19
0
 /**
  * Process the content of a license string.
  * @param string $lic
  * @return \stdClass
  */
 public function processLicense($lic)
 {
     $result = new stdClass();
     $result->success = false;
     $key = blowfishGetKey('ProcessMaker');
     //        $lic = preg_replace('/\n|\r\n/', '', $lic);
     //        print_r($lic);
     try {
         $license = json_decode($this->crypt->openLicense($key, $lic));
     } catch (Exception $e) {
         $result->message = $e->getMessage();
         return $result;
     }
     if (empty($license)) {
         $result->message = translate('LBL_PMSE_ADAM_LICENSEMANAGER_MESSAGE_NOTVALID', $this->moduleName);
         return $result;
     } else {
         if (!isset($license->lic_activation_code)) {
             $result->message = translate('LBL_PMSE_ADAM_LICENSEMANAGER_MESSAGE_ACTIVATIONCODEMISSING' . $this->moduleName);
             return $result;
         }
     }
     //Verify if activationCode exist in DB
     $rs = $this->amBean->retrieve_by_string_fields(array('acm_key' => $license->lic_activation_code));
     if (empty($rs)) {
         $result->message = translate('LBL_PMSE_ADAM_LICENSEMANAGER_MESSAGE_ALREADYINSTALLED', $this->moduleName);
         return $result;
     }
     $sql = "UPDATE pmse_ bpm_access_management SET acm_status = 'INACTIVE'";
     $GLOBALS["db"]->query($sql);
     //Insert into DataBase
     $this->amBean->new_with_id = true;
     $this->amBean->acm_key = $license->lic_activation_code;
     $this->amBean->acm_type = $license->lic_type;
     $this->amBean->acm_status = 'ACTIVE';
     //$license->lic_status;
     $this->amBean->acm_expiration_date = date("Y-m-d H:i:s", strtotime($license->lic_product_expiration_date));
     $this->amBean->acm_data = $lic;
     $this->amBean->acm_uid = PMSEEngineUtils::generateUniqueID();
     $this->amBean->save();
     if (!$this->amBean->in_save) {
         $result->success = true;
         $result->message = translate('LBL_PMSE_ADAM_LICENSEMANAGER_MESSAGE_INSTALLSUCCESSFULLY', $this->moduleName);
     }
     return $result;
 }
Exemplo n.º 20
0
 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;
 }
Exemplo n.º 21
-15
 private function getUnattendedCasesByFlow()
 {
     $queryOptions = array('add_deleted' => true);
     //GET CASES ID WITH INACTIVE USERS
     $beanFlow = BeanFactory::getBean('pmse_BpmFlow');
     $q = new SugarQuery();
     $q->from($beanFlow, $queryOptions);
     $q->distinct(true);
     $fields = array('cas_id', 'cas_sugar_module', 'cas_sugar_object_id', 'cas_user_id');
     //INNER JOIN USERS TABLE
     $q->joinTable('users', array('alias' => 'users', 'joinType' => 'INNER', 'linkingTable' => true))->on()->equalsField('users.id', 'cas_user_id')->equals('users.deleted', 0);
     $q->where()->equals('cas_flow_status', 'FORM')->in('cas_sugar_module', PMSEEngineUtils::getSupportedModules());
     $q->where()->queryOr()->notequals('users.status', 'Active')->notequals('users.employee_status', 'Active');
     $q->select($fields);
     $rows = $q->execute();
     return $rows;
 }