HOR-124 "(Cases List Backend) En la version community..." SOLVED

Issue:
    (Cases List Backend) En la version community el end point no devuelven los casos para mobile
Cause:
    No se considero la version community para el end-point light
Solution:
    Se agrego codigo para la version community para el end-point light

Fixes
This commit is contained in:
Victor Saisa Lopez
2016-01-27 16:42:40 -04:00
parent a99e0a7aa0
commit a07e08fe42
3 changed files with 173 additions and 47 deletions

View File

@@ -80,7 +80,7 @@ function getLoadTreeMenuData ()
$index = $i; $index = $i;
list($childs, $index) = getChilds($oMenu, ++$index); list($childs, $index) = getChilds($oMenu, ++$index);
$menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]]['childs'] = $childs; $menuCases[$CurrentBlockID]['blockItems'][$oMenu->Id[$i]]['childs'] = $childs;
$i = $index; $i = $index;
@@ -274,7 +274,7 @@ function getProcess ()
function getAllCounters () function getAllCounters ()
{ {
$userUid = (isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null; $userUid = (isset( $_SESSION['USER_LOGGED'] ) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null;
$oAppCache = new AppCacheView();
$aTypes = Array (); $aTypes = Array ();
$aTypes['to_do'] = 'CASES_INBOX'; $aTypes['to_do'] = 'CASES_INBOX';
$aTypes['draft'] = 'CASES_DRAFT'; $aTypes['draft'] = 'CASES_DRAFT';
@@ -285,29 +285,9 @@ function getAllCounters ()
$aTypes['selfservice'] = 'CASES_SELFSERVICE'; $aTypes['selfservice'] = 'CASES_SELFSERVICE';
//$aTypes['to_revise'] = 'CASES_TO_REVISE'; //$aTypes['to_revise'] = 'CASES_TO_REVISE';
//$aTypes['to_reassign'] = 'CASES_TO_REASSIGN'; //$aTypes['to_reassign'] = 'CASES_TO_REASSIGN';
$solrEnabled = false;
if ((($solrConf = System::solrEnv()) !== false)) { $case = new \ProcessMaker\BusinessModel\Cases();
G::LoadClass( 'AppSolr' ); $aCount = $case->getListCounters($userUid, array_keys($aTypes));
$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 );
}
$response = Array (); $response = Array ();
$i = 0; $i = 0;
@@ -326,7 +306,7 @@ function getChilds($menu, $index)
for ($i = $index; $i < count($menu->Options); $i++) { for ($i = $index; $i < count($menu->Options); $i++) {
if ($menu->Types[$i] == 'childNode') { if ($menu->Types[$i] == 'childNode') {
$childs[$menu->Id[$i]] = array( $childs[$menu->Id[$i]] = array(
'label' => $menu->Labels[$i], 'label' => $menu->Labels[$i],
'link' => $menu->Options[$i], 'link' => $menu->Options[$i],

View File

@@ -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 * Get list for Cases
* *

View File

@@ -39,9 +39,25 @@ class Light extends Api
{ {
try { try {
$userId = $this->getUserId(); $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) { } catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
} }
@@ -58,12 +74,23 @@ class Light extends Api
"CASES_PAUSED" => "paused", "CASES_PAUSED" => "paused",
"CASES_COMPLETED" => "completed", "CASES_COMPLETED" => "completed",
"CASES_SELFSERVICE" => "unassigned", "CASES_SELFSERVICE" => "unassigned",
'to_do' => 'toDo',
'draft' => 'draft',
'cancelled' => 'cancelled',
'sent' => 'participated',
'paused' => 'paused',
'completed' => 'completed',
'selfservice' => 'unassigned'
); );
$response = array(); $response = array();
foreach ($data as $counterList) { foreach ($data as $key => $counterList) {
if(isset($structure[$counterList['item']])){ if(isset($structure[$counterList['item']])){
$name = $structure[$counterList['item']]; $name = $structure[$counterList['item']];
$response[$name] = $counterList['count']; $response[$name] = $counterList['count'];
} else {
if (isset($structure[$key])) {
$response[$structure[$key]] = $counterList;
}
} }
} }
return $response; return $response;
@@ -105,7 +132,6 @@ class Light extends Api
$filter = '', $filter = '',
$date_from = '', $date_from = '',
$date_to = '', $date_to = '',
$action = '',
$newestthan = '', $newestthan = '',
$oldestthan ='' $oldestthan =''
) { ) {
@@ -123,14 +149,26 @@ class Light extends Api
$dataList['filter'] = $filter; $dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from; $dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to; $dataList['dateTo'] = $date_to;
$dataList['action'] = $action;
$dataList['newestthan'] = $newestthan; $dataList['newestthan'] = $newestthan;
$dataList['oldestthan'] = $oldestthan; $dataList['oldestthan'] = $oldestthan;
Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601);
$dataList = DateTime::convertDataToUtc($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 != '') { if ($newestthan != '') {
$response['data'] = array_reverse($response['data']); $response['data'] = array_reverse($response['data']);
} }
@@ -209,8 +247,21 @@ class Light extends Api
Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601);
$dataList = DateTime::convertDataToUtc($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 != '') { if ($newestthan != '') {
$response['data'] = array_reverse($response['data']); $response['data'] = array_reverse($response['data']);
} }
@@ -279,6 +330,7 @@ class Light extends Api
) { ) {
try { try {
$dataList['userId'] = $this->getUserId(); $dataList['userId'] = $this->getUserId();
$dataList['action'] = 'sent';
$dataList['paged'] = $paged; $dataList['paged'] = $paged;
$dataList['count'] = $count; $dataList['count'] = $count;
@@ -298,8 +350,21 @@ class Light extends Api
Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601); Validator::throwExceptionIfDataNotMetIso8601Format($dataList, $this->arrayFieldIso8601);
$dataList = DateTime::convertDataToUtc($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 != '') { if ($newestthan != '') {
$response['data'] = array_reverse($response['data']); $response['data'] = array_reverse($response['data']);
} }
@@ -380,8 +445,21 @@ class Light extends Api
$dataList['filter'] = $filter; $dataList['filter'] = $filter;
$dataList['dateFrom'] = $date_from; $dataList['dateFrom'] = $date_from;
$dataList['dateTo'] = $date_to; $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']); $result = $this->parserDataParticipated($response['data']);
return DateTime::convertUtcToIso8601($result, $this->arrayFieldIso8601); return DateTime::convertUtcToIso8601($result, $this->arrayFieldIso8601);
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -511,13 +589,25 @@ class Light extends Api
if (is_array($d)) { if (is_array($d)) {
$newData = array(); $newData = array();
foreach ($d as $field => $value) { foreach ($d as $field => $value) {
if (array_key_exists($field, $structure)) { if (
$newName = $structure[$field]; preg_match(
'/\|(' . $field . ')\|/i',
'|' . implode('|', array_keys($structure)) . '|',
$arrayMatch
)
) {
$newName = $structure[$arrayMatch[1]];
$newData[$newName] = is_null($value) ? "":$value; $newData[$newName] = is_null($value) ? "":$value;
} else { } else {
foreach ($structure as $name => $str) { foreach ($structure as $name => $str) {
if (is_array($str) && array_key_exists($field, $str)) { if (is_array($str) &&
$newName = $str[$field]; preg_match(
'/\|(' . $field . ')\|/i',
'|' . implode('|', array_keys($str)) . '|',
$arrayMatch
)
) {
$newName = $str[$arrayMatch[1]];
$newData[$name][$newName] = is_null($value) ? "":$value; $newData[$name][$newName] = is_null($value) ? "":$value;
} }
} }
@@ -526,13 +616,25 @@ class Light extends Api
if (count($newData) > 0) if (count($newData) > 0)
$response[] = $newData; $response[] = $newData;
} else { } else {
if (array_key_exists($field, $structure)) { if (
$newName = $structure[$field]; preg_match(
'/\|(' . $field . ')\|/i',
'|' . implode('|', array_keys($structure)) . '|',
$arrayMatch
)
) {
$newName = $structure[$arrayMatch[1]];
$response[$newName] = is_null($d) ? "":$d; $response[$newName] = is_null($d) ? "":$d;
} else { } else {
foreach ($structure as $name => $str) { foreach ($structure as $name => $str) {
if (is_array($str) && array_key_exists($field, $str)) { if (is_array($str) &&
$newName = $str[$field]; preg_match(
'/\|(' . $field . ')\|/i',
'|' . implode('|', array_keys($str)) .'|',
$arrayMatch
)
) {
$newName = $str[$arrayMatch[1]];
$response[$name][$newName] = is_null($d) ? "":$d; $response[$name][$newName] = is_null($d) ? "":$d;
} }
} }