diff --git a/workflow/engine/methods/cases/casesMenuLoader.php b/workflow/engine/methods/cases/casesMenuLoader.php index 425f6560e..df87147e0 100755 --- a/workflow/engine/methods/cases/casesMenuLoader.php +++ b/workflow/engine/methods/cases/casesMenuLoader.php @@ -80,7 +80,7 @@ function getLoadTreeMenuData () $index = $i; list($childs, $index) = getChilds($oMenu, ++$index); - + $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]]['childs'] = $childs; $i = $index; @@ -274,7 +274,7 @@ function getProcess () function getAllCounters () { $userUid = (isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null; - $oAppCache = new AppCacheView(); + $aTypes = Array (); $aTypes['to_do'] = 'CASES_INBOX'; $aTypes['draft'] = 'CASES_DRAFT'; @@ -285,29 +285,9 @@ function getAllCounters () $aTypes['selfservice'] = 'CASES_SELFSERVICE'; //$aTypes['to_revise'] = 'CASES_TO_REVISE'; //$aTypes['to_reassign'] = 'CASES_TO_REASSIGN'; - $solrEnabled = false; - if ((($solrConf = System::solrEnv()) !== false)) { - G::LoadClass( 'AppSolr' ); - $ApplicationSolrIndex = new AppSolr( $solrConf['solr_enabled'], $solrConf['solr_host'], $solrConf['solr_instance'] ); - - if ($ApplicationSolrIndex->isSolrEnabled() && $solrConf['solr_enabled'] == true) { - $solrEnabled = true; - } - } - - if ($solrEnabled) { - $aCount = $ApplicationSolrIndex->getCasesCount( $userUid ); - - //get paused count - $aCountMissing = $oAppCache->getAllCounters( array ('completed','cancelled'), $userUid ); - - $aCount = array_merge( $aCount, $aCountMissing ); - } else { - - $aCount = $oAppCache->getAllCounters( array_keys( $aTypes ), $userUid ); - - } + $case = new \ProcessMaker\BusinessModel\Cases(); + $aCount = $case->getListCounters($userUid, array_keys($aTypes)); $response = Array (); $i = 0; @@ -326,7 +306,7 @@ function getChilds($menu, $index) for ($i = $index; $i < count($menu->Options); $i++) { if ($menu->Types[$i] == 'childNode') { - + $childs[$menu->Id[$i]] = array( 'label' => $menu->Labels[$i], 'link' => $menu->Options[$i], diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 462f919c3..b84b50b0c 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -75,6 +75,50 @@ class Cases } } + /** + * Get list counters + * + * @param string $userUid Unique id of User + * @param array $arrayType Type lists + * + * @return array Return the list counters + */ + public function getListCounters($userUid, array $arrayType) + { + try { + $solrEnabled = false; + $solrConf = \System::solrEnv(); + + if ($solrConf !== false) { + $ApplicationSolrIndex = new \AppSolr( + $solrConf['solr_enabled'], + $solrConf['solr_host'], + $solrConf['solr_instance'] + ); + + if ($ApplicationSolrIndex->isSolrEnabled() && $solrConf['solr_enabled'] == true) { + $solrEnabled = true; + } + } + + $appCacheView = new \AppCacheView(); + + if ($solrEnabled) { + $arrayListCounter = array_merge( + $ApplicationSolrIndex->getCasesCount($userUid), + $appCacheView->getAllCounters(['completed', 'cancelled'], $userUid) + ); + } else { + $arrayListCounter = $appCacheView->getAllCounters($arrayType, $userUid); + } + + //Return + return $arrayListCounter; + } catch (\Exception $e) { + throw $e; + } + } + /** * Get list for Cases * diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Light.php b/workflow/engine/src/ProcessMaker/Services/Api/Light.php index 91e2eda75..d83a1a013 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Light.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Light.php @@ -39,9 +39,25 @@ class Light extends Api { try { $userId = $this->getUserId(); - $lists = new \ProcessMaker\BusinessModel\Lists(); - $response = $lists->getCounters($userId); - $result = $this->parserCountersCases($response); + + /*----------------------------------********---------------------------------*/ + if (true) { + //In enterprise version this block of code should always be executed + //In community version this block of code is deleted and is executed the other + $list = new \ProcessMaker\BusinessModel\Lists(); + $arrayListCounter = $list->getCounters($userId); + } else { + /*----------------------------------********---------------------------------*/ + $case = new \ProcessMaker\BusinessModel\Cases(); + $arrayListCounter = $case->getListCounters( + $userId, + ['to_do', 'draft', 'sent', 'selfservice', 'paused', 'completed', 'cancelled'] + ); + /*----------------------------------********---------------------------------*/ + } + /*----------------------------------********---------------------------------*/ + + $result = $this->parserCountersCases($arrayListCounter); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } @@ -58,12 +74,23 @@ class Light extends Api "CASES_PAUSED" => "paused", "CASES_COMPLETED" => "completed", "CASES_SELFSERVICE" => "unassigned", + 'to_do' => 'toDo', + 'draft' => 'draft', + 'cancelled' => 'cancelled', + 'sent' => 'participated', + 'paused' => 'paused', + 'completed' => 'completed', + 'selfservice' => 'unassigned' ); $response = array(); - foreach ($data as $counterList) { + foreach ($data as $key => $counterList) { if(isset($structure[$counterList['item']])){ $name = $structure[$counterList['item']]; $response[$name] = $counterList['count']; + } else { + if (isset($structure[$key])) { + $response[$structure[$key]] = $counterList; + } } } return $response; @@ -105,7 +132,6 @@ class Light extends Api $filter = '', $date_from = '', $date_to = '', - $action = '', $newestthan = '', $oldestthan ='' ) { @@ -123,14 +149,26 @@ class Light extends Api $dataList['filter'] = $filter; $dataList['dateFrom'] = $date_from; $dataList['dateTo'] = $date_to; - $dataList['action'] = $action; $dataList['newestthan'] = $newestthan; $dataList['oldestthan'] = $oldestthan; Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); $dataList = DateTime::convertDataToUtc($dataList, $this->arrayFieldIso8601); - $lists = new \ProcessMaker\BusinessModel\Lists(); - $response = $lists->getList('inbox', $dataList); + + /*----------------------------------********---------------------------------*/ + if (true) { + //In enterprise version this block of code should always be executed + //In community version this block of code is deleted and is executed the other + $list = new \ProcessMaker\BusinessModel\Lists(); + $response = $list->getList('inbox', $dataList); + } else { + /*----------------------------------********---------------------------------*/ + $case = new \ProcessMaker\BusinessModel\Cases(); + $response = $case->getList($dataList); + /*----------------------------------********---------------------------------*/ + } + /*----------------------------------********---------------------------------*/ + if ($newestthan != '') { $response['data'] = array_reverse($response['data']); } @@ -209,8 +247,21 @@ class Light extends Api Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); $dataList = DateTime::convertDataToUtc($dataList, $this->arrayFieldIso8601); - $oCases = new \ProcessMaker\BusinessModel\Lists(); - $response = $oCases->getList('inbox', $dataList); + + /*----------------------------------********---------------------------------*/ + if (true) { + //In enterprise version this block of code should always be executed + //In community version this block of code is deleted and is executed the other + $list = new \ProcessMaker\BusinessModel\Lists(); + $response = $list->getList('inbox', $dataList); + } else { + /*----------------------------------********---------------------------------*/ + $case = new \ProcessMaker\BusinessModel\Cases(); + $response = $case->getList($dataList); + /*----------------------------------********---------------------------------*/ + } + /*----------------------------------********---------------------------------*/ + if ($newestthan != '') { $response['data'] = array_reverse($response['data']); } @@ -279,6 +330,7 @@ class Light extends Api ) { try { $dataList['userId'] = $this->getUserId(); + $dataList['action'] = 'sent'; $dataList['paged'] = $paged; $dataList['count'] = $count; @@ -298,8 +350,21 @@ class Light extends Api Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); $dataList = DateTime::convertDataToUtc($dataList, $this->arrayFieldIso8601); - $oCases = new \ProcessMaker\BusinessModel\Lists(); - $response = $oCases->getList('participated_last', $dataList); + + /*----------------------------------********---------------------------------*/ + if (true) { + //In enterprise version this block of code should always be executed + //In community version this block of code is deleted and is executed the other + $list = new \ProcessMaker\BusinessModel\Lists(); + $response = $list->getList('participated_last', $dataList); + } else { + /*----------------------------------********---------------------------------*/ + $case = new \ProcessMaker\BusinessModel\Cases(); + $response = $case->getList($dataList); + /*----------------------------------********---------------------------------*/ + } + /*----------------------------------********---------------------------------*/ + if ($newestthan != '') { $response['data'] = array_reverse($response['data']); } @@ -380,8 +445,21 @@ class Light extends Api $dataList['filter'] = $filter; $dataList['dateFrom'] = $date_from; $dataList['dateTo'] = $date_to; - $lists = new \ProcessMaker\BusinessModel\Lists(); - $response = $lists->getList('paused', $dataList); + + /*----------------------------------********---------------------------------*/ + if (true) { + //In enterprise version this block of code should always be executed + //In community version this block of code is deleted and is executed the other + $list = new \ProcessMaker\BusinessModel\Lists(); + $response = $list->getList('paused', $dataList); + } else { + /*----------------------------------********---------------------------------*/ + $case = new \ProcessMaker\BusinessModel\Cases(); + $response = $case->getList($dataList); + /*----------------------------------********---------------------------------*/ + } + /*----------------------------------********---------------------------------*/ + $result = $this->parserDataParticipated($response['data']); return DateTime::convertUtcToIso8601($result, $this->arrayFieldIso8601); } catch (\Exception $e) { @@ -511,13 +589,25 @@ class Light extends Api if (is_array($d)) { $newData = array(); foreach ($d as $field => $value) { - if (array_key_exists($field, $structure)) { - $newName = $structure[$field]; + if ( + preg_match( + '/\|(' . $field . ')\|/i', + '|' . implode('|', array_keys($structure)) . '|', + $arrayMatch + ) + ) { + $newName = $structure[$arrayMatch[1]]; $newData[$newName] = is_null($value) ? "":$value; } else { foreach ($structure as $name => $str) { - if (is_array($str) && array_key_exists($field, $str)) { - $newName = $str[$field]; + if (is_array($str) && + preg_match( + '/\|(' . $field . ')\|/i', + '|' . implode('|', array_keys($str)) . '|', + $arrayMatch + ) + ) { + $newName = $str[$arrayMatch[1]]; $newData[$name][$newName] = is_null($value) ? "":$value; } } @@ -526,13 +616,25 @@ class Light extends Api if (count($newData) > 0) $response[] = $newData; } else { - if (array_key_exists($field, $structure)) { - $newName = $structure[$field]; + if ( + preg_match( + '/\|(' . $field . ')\|/i', + '|' . implode('|', array_keys($structure)) . '|', + $arrayMatch + ) + ) { + $newName = $structure[$arrayMatch[1]]; $response[$newName] = is_null($d) ? "":$d; } else { foreach ($structure as $name => $str) { - if (is_array($str) && array_key_exists($field, $str)) { - $newName = $str[$field]; + if (is_array($str) && + preg_match( + '/\|(' . $field . ')\|/i', + '|' . implode('|', array_keys($str)) .'|', + $arrayMatch + ) + ) { + $newName = $str[$arrayMatch[1]]; $response[$name][$newName] = is_null($d) ? "":$d; } }