static function createForRequestPagination($data) { $obj = new Entity_SolrRequestData(); $obj->initializeObject($data); $requiredFields = array('workspace'); $obj->validateRequiredFields($requiredFields); return $obj; }
/** * Get case list * * @param string $userId * @return $result will return an object */ public function caseList($userUid) { try { $solrEnabled = 0; if (($solrEnv = System::solrEnv()) !== false) { G::LoadClass("AppSolr"); $appSolr = new AppSolr( $solrEnv["solr_enabled"], $solrEnv["solr_host"], $solrEnv["solr_instance"] ); if ($appSolr->isSolrEnabled() && $solrEnv["solr_enabled"] == true) { //Check if there are missing records to reindex and reindex them $appSolr->synchronizePendingApplications(); $solrEnabled = 1; } } if ($solrEnabled == 1) { try { G::LoadClass("searchIndex"); $arrayData = array(); $delegationIndexes = array(); $columsToInclude = array("APP_UID"); $solrSearchText = null; //Todo $solrSearchText = $solrSearchText . (($solrSearchText != null)? " OR " : null) . "(APP_STATUS:TO_DO AND APP_ASSIGNED_USERS:" . $userUid . ")"; $delegationIndexes[] = "APP_ASSIGNED_USER_DEL_INDEX_" . $userUid . "_txt"; //Draft $solrSearchText = $solrSearchText . (($solrSearchText != null)? " OR " : null) . "(APP_STATUS:DRAFT AND APP_DRAFT_USER:"******")"; //Index is allways 1 $solrSearchText = "($solrSearchText)"; //Add del_index dynamic fields to list of resulting columns $columsToIncludeFinal = array_merge($columsToInclude, $delegationIndexes); $solrRequestData = Entity_SolrRequestData::createForRequestPagination( array( "workspace" => $solrEnv["solr_instance"], "startAfter" => 0, "pageSize" => 1000, "searchText" => $solrSearchText, "numSortingCols" => 1, "sortCols" => array("APP_NUMBER"), "sortDir" => array(strtolower("DESC")), "includeCols" => $columsToIncludeFinal, "resultFormat" => "json" ) ); //Use search index to return list of cases $searchIndex = new BpmnEngine_Services_SearchIndex($appSolr->isSolrEnabled(), $solrEnv["solr_host"]); //Execute query $solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData); //$rows = array(); //Number of found records //$numRecTotal = $solrQueryResult->iTotalDisplayRecords; //print_r($solrQueryResult->aaData); exit(0); //Get the missing data from database $arrayApplicationUid = array(); foreach ($solrQueryResult->aaData as $i => $data) { $arrayApplicationUid[] = $data["APP_UID"]; } $aaappsDBData = $appSolr->getListApplicationDelegationData($arrayApplicationUid); foreach ($solrQueryResult->aaData as $i => $data) { //Initialize array $delIndexes = array(); //Store all the delegation indexes //Complete empty values $applicationUid = $data["APP_UID"]; //APP_UID //Get all the indexes returned by Solr as columns for($i = count($columsToInclude); $i <= count($data) - 1; $i++) { if (is_array($data[$columsToIncludeFinal[$i]])) { foreach ($data[$columsToIncludeFinal[$i]] as $delIndex) { $delIndexes[] = $delIndex; } } } //Verify if the delindex is an array //if is not check different types of repositories //the delegation index must always be defined. if (count($delIndexes) == 0) { ////if is draft //if ($action == "draft") { $delIndexes[] = 1; // the first default index //} else { // //error an index must always be defined // print date("Y-m-d H:i:s:u") . " Delegation not defined\n"; //} } //Remove duplicated $delIndexes = array_unique($delIndexes); //Get records foreach ($delIndexes as $delIndex) { $aRow = array(); //Copy result values to new row from Solr server $aRow["APP_UID"] = $data["APP_UID"]; //Get delegation data from DB //Filter data from db $indexes = $appSolr->aaSearchRecords($aaappsDBData, array( "APP_UID" => $applicationUid, "DEL_INDEX" => $delIndex )); foreach ($indexes as $index) { $row = $aaappsDBData[$index]; } if(!isset($row)) { //$fh = fopen("SolrAppWithoutDelIndex.txt", "a") or die("can't open file to store Solr search time."); //fwrite($fh, sprintf("Solr AppUid: %s DelIndex: %s not found.\r\n", $applicationUid, $delIndex)); //fclose($fh); continue; } $aRow["APP_NUMBER"] = $row["APP_NUMBER"]; $aRow["APP_STATUS"] = $row["APP_STATUS"]; $aRow["PRO_UID"] = $row["PRO_UID"]; $aRow["DEL_INDEX"] = $row["DEL_INDEX"]; //$rows[] = $aRow; $arrayData[] = array( "guid" => $aRow["APP_UID"], "name" => $aRow["APP_NUMBER"], "status" => $aRow["APP_STATUS"], "delIndex" => $aRow["DEL_INDEX"], "processId" => $aRow["PRO_UID"] ); } } return $arrayData; } catch (InvalidIndexSearchTextException $e) { $arrayData = array(); $arrayData[] = array ( "guid" => $e->getMessage(), "name" => $e->getMessage(), "status" => $e->getMessage(), "delIndex" => $e->getMessage(), "processId" => $e->getMessage() ); return $arrayData; } } else { $arrayData = array(); $criteria = new Criteria("workflow"); $criteria->addSelectColumn(AppCacheViewPeer::APP_UID); $criteria->addSelectColumn(AppCacheViewPeer::DEL_INDEX); $criteria->addSelectColumn(AppCacheViewPeer::APP_NUMBER); $criteria->addSelectColumn(AppCacheViewPeer::APP_STATUS); $criteria->addSelectColumn(AppCacheViewPeer::PRO_UID); $criteria->add(AppCacheViewPeer::USR_UID, $userUid); $criteria->add( //ToDo - getToDo() $criteria->getNewCriterion(AppCacheViewPeer::APP_STATUS, "TO_DO", CRITERIA::EQUAL)->addAnd( $criteria->getNewCriterion(AppCacheViewPeer::DEL_FINISH_DATE, null, Criteria::ISNULL))->addAnd( $criteria->getNewCriterion(AppCacheViewPeer::APP_THREAD_STATUS, "OPEN"))->addAnd( $criteria->getNewCriterion(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN")) )->addOr( //Draft - getDraft() $criteria->getNewCriterion(AppCacheViewPeer::APP_STATUS, "DRAFT", CRITERIA::EQUAL)->addAnd( $criteria->getNewCriterion(AppCacheViewPeer::APP_THREAD_STATUS, "OPEN"))->addAnd( $criteria->getNewCriterion(AppCacheViewPeer::DEL_THREAD_STATUS, "OPEN")) ); $criteria->addDescendingOrderByColumn(AppCacheViewPeer::APP_NUMBER); $rsCriteria = AppCacheViewPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC); while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); $arrayData[] = array( "guid" => $row["APP_UID"], "name" => $row["APP_NUMBER"], "status" => $row["APP_STATUS"], "delIndex" => $row["DEL_INDEX"], "processId" => $row["PRO_UID"] ); } return $arrayData; } } catch (Exception $e) { $arrayData = array(); $arrayData[] = array ( "guid" => $e->getMessage(), "name" => $e->getMessage(), "status" => $e->getMessage(), "delIndex" => $e->getMessage(), "processId" => $e->getMessage() ); return $arrayData; } }
/** * Gets the information of Grids using Solr server. * * Returns the list of records for the grid depending of the function * conditions * If doCount is true only the count of records is returned. * * @param string $userUid current logged user. * @param int $start the offset to return the group of records. Used for pagination. * @param int $limit The number of records to return in the set. * @param string $action the action: todo, participated, draft, unassigned * @param string $filter filter the results posible values ('read', 'unread', 'started', * 'completed') * @param string $search search string * @param string $process PRO_UID to filter results by specified process. * @param string $user USR_UID to filter results by specified user. * @param string $status filter by an application Status : TO_DO, COMPLETED, DRAFT * @param string $type default extjs * @param string $dateFrom filter by DEL_DELEGATE_DATE, not used * @param string $dateTo filter by DEL_DELEGATE_DATE, not used * @param string $callback default stcCallback1001 not used * @param string $dir sort direction ASC, DESC * @param string $sort sort field * @param boolean $doCount default=false, if true only the count of records is returned. * @return array return the list of cases */ public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = "APP_CACHE_VIEW.APP_NUMBER", $category = null, $doCount = false) { $callback = isset($callback) ? $callback : 'stcCallback1001'; $dir = isset($dir) ? $dir : 'DESC'; // direction of sort column // (ASC, DESC) $sort = isset($sort) ? $sort : ''; // sort column (APP_NUMBER, // CASE_SUMMARY, // CASE_NOTES_COUNT, APP_TITLE, // APP_PRO_TITLE, APP_TAS_TITLE, // APP_DEL_PREVIOUS_USER, // DEL_TASK_DUE_DATE, // APP_UPDATE_DATE, DEL_PRIORITY) $start = isset($start) ? $start : '0'; $limit = isset($limit) ? $limit : '25'; $filter = isset($filter) ? $filter : ''; // posible values ('read', // 'unread', 'started', // 'completed') $search = isset($search) ? $search : ''; // search in fields, plain text $process = isset($process) ? $process : ''; // filter by an specific // process // uid $status = isset($status) ? strtoupper($status) : ''; // filter by an // specific // app_status $action = isset($action) ? $action : 'todo'; // todo, paused $type = isset($type) ? $type : 'extjs'; $dateFrom = isset($dateFrom) ? $dateFrom : ''; // filter by // DEL_DELEGATE_DATE $dateTo = isset($dateTo) ? $dateTo : ''; // filter by DEL_DELEGATE_DATE $swErrorInSearchText = false; $solrQueryResult = null; $aPriorities = array('1' => 'VL', '2' => 'L', '3' => 'N', '4' => 'H', '5' => 'VH'); $delegationIndexes = array(); $result = array(); $result['totalCount'] = 0; $result['data'] = array(); $result['success'] = false; $result['message'] = "Error description."; G::LoadClass('searchIndex'); try { if ($this->debug) { $this->initTimeAll = microtime(true); } // the array of data that must be returned with placeholders $columsToInclude = array('APP_CREATE_DATE', '', '', '', 'APP_NUMBER', '', 'APP_PRO_TITLE', 'APP_STATUS', '', '', 'APP_TITLE', 'APP_UID', 'DEL_LAST_UPDATE_DATE', '', '', '', '', '', '', '', '', 'DEL_MAX_PRIORITY', '', '', '', '', '', 'PRO_UID', '', ''); // create pagination data $solrSearchText = null; $sortableCols = array(); $sortCols = array(); $sortDir = array(); $numSortingCols = 0; // define sort conditions, default APP_NUMBER, desc // only one column is sorted $dir = strtolower($dir); if (!empty($sort)) { switch ($sort) { case 'APP_CACHE_VIEW.APP_NUMBER': case 'APP_NUMBER': $sortCols[0] = 4; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; // multivalue field can't be ordered // multivalue field can't be ordered case 'APP_TITLE': $sortCols[0] = 10; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; case 'APP_PRO_TITLE': $sortCols[0] = 6; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; case 'APP_UPDATE_DATE': $sortCols[0] = 12; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; default: $sortCols[0] = 4; $sortableCols[0] = 'true'; $sortDir[0] = 'desc'; break; } $numSortingCols++; } //Define conditions for the $action $arrayAux = array(); switch ($action) { case "todo": $arrayAux = $this->getToDoSolrString($userUid, $filter); break; case "draft": $arrayAux = $this->getDraftSolrString($userUid); break; case "paused": $arrayAux = $this->getPausedSolrString($userUid); break; case "selfservice": case "unassigned": if (!empty($userUid)) { //Get the list of groups to which belongs the user. $userGroups = $this->getUserGroups($userUid); $solrSearchText = $solrSearchText . "(APP_UNASSIGNED_USERS:" . $userUid; if (count($userGroups) > 0) { $solrSearchText = $solrSearchText . " OR "; foreach ($userGroups as $group) { $solrSearchText = $solrSearchText . "APP_UNASSIGNED_GROUPS:" . $group["GRP_UID"] . " OR "; } //Remove last OR in condition if ($solrSearchText != null) { $solrSearchText = substr_replace($solrSearchText, null, -4); } } $solrSearchText = $solrSearchText . ") AND "; $delegationIndexes[] = "APP_UNASSIGNED_USER_GROUP_DEL_INDEX_" . $userUid . "_txt"; foreach ($userGroups as $group) { $delegationIndexes[] = "APP_UNASSIGNED_USER_GROUP_DEL_INDEX_" . $group["GRP_UID"] . "_txt"; } } break; case "sent": $arrayAux = $this->getSentSolrString($userUid, $filter); break; case "search": switch ($status) { case "TO_DO": $arrayAux = $this->getToDoSolrString($userUid, $filter); break; case "DRAFT": $arrayAux = $this->getDraftSolrString($userUid); break; case "PAUSED": $arrayAux = $this->getPausedSolrString($userUid); break; case "CANCELLED": $arrayAux = $this->getCancelledSolrString($userUid); break; case "COMPLETED": $arrayAux = $this->getCompletedSolrString($userUid); break; default: //All status $arrayAux = $this->getAllSolrString($userUid); break; } break; } if (count($arrayAux) > 0) { switch ($action) { case "sent": if (!empty($status)) { $solrSearchText = $solrSearchText . "APP_STATUS:" . $status . " AND "; } break; } $solrSearchText = $solrSearchText . (!empty($arrayAux[0]) ? $arrayAux[0] . " AND " : null); if (is_array($arrayAux[1])) { foreach ($arrayAux[1] as $index => $value) { $delegationIndexes[] = $value; } } else { $delegationIndexes[] = $arrayAux[1]; } } //Get DEL_INDEX field $delIndexDynaField = null; //Process filter if (!empty($process)) { $solrSearchText = $solrSearchText . "PRO_UID:" . $process . " AND "; } //Category filter if (!empty($category)) { $solrSearchText = $solrSearchText . "PRO_CATEGORY_UID_s:" . $category . " AND "; } //search action if (!empty($dateFrom) && !empty($dateTo)) { $fromDate = date("Y-m-d", strtotime($dateFrom)); $toDate = date("Y-m-d", strtotime($dateTo)); $searchDateOriginal = "DEL_LAST_UPDATE_DATE:[" . $fromDate . " TO " . $toDate . "]"; //FechaRegistro:[2011-04-15 TO 2011-04-30] $searchDateFormatedSolr = $this->getSearchText($searchDateOriginal); $solrSearchText .= "(" . $searchDateFormatedSolr . ") AND "; } // remove last AND in condition if ($solrSearchText != '') { $solrSearchText = substr_replace($solrSearchText, "", -5); } // add parenthesis to Solr search text if ($solrSearchText != "") { $solrSearchText = "(" . $solrSearchText . ")"; } // create query string, add query conditions if ($search != '') { // format search string // return exception in case of invalid text $search = $this->getSearchText($search); if ($solrSearchText != "" && $search != "") { $solrSearchText .= " AND "; } if ($search != "") { $solrSearchText .= "(" . $search . ")"; } } // add del_index dynamic fields to list of resulting columns // the fields begin in the 30th column and more $columsToInclude = array_merge($columsToInclude, $delegationIndexes); // if is a counter no records are returned if ($doCount) { $start = 0; $limit = 0; $numSortingCols = 0; $columsToInclude = array(); } $data = array('workspace' => $this->_solrInstance, 'startAfter' => intval($start), 'pageSize' => intval($limit), 'searchText' => $solrSearchText, 'filterText' => '', 'numSortingCols' => $numSortingCols, 'sortableCols' => $sortableCols, 'sortCols' => $sortCols, 'sortDir' => $sortDir, 'includeCols' => $columsToInclude, 'resultFormat' => 'json'); $solrRequestData = Entity_SolrRequestData::createForRequestPagination($data); // use search index to return list of cases $searchIndex = new BpmnEngine_Services_SearchIndex($this->_solrIsEnabled, $this->_solrHost); // execute query $solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData); if ($this->debug) { $this->afterSolrQueryTime = microtime(true); } //return inmediatelly if ($doCount) { $result['totalCount'] = $solrQueryResult->iTotalDisplayRecords; $result['data'] = array(); $result['success'] = true; $result['result'] = true; $result['message'] = ""; return $result; } // complete return data, complete list of columns in grid $resultColumns = array("APP_CREATE_DATE", "APP_CURRENT_USER", "APP_DEL_PREVIOUS_USER", "APP_FINISH_DATE", "APP_NUMBER", "APP_OVERDUE_PERCENTAGE", "APP_PRO_TITLE", "APP_STATUS", "APP_TAS_TITLE", "APP_THREAD_STATUS", "APP_TITLE", "APP_UID", "APP_UPDATE_DATE", "DEL_DELAYED", "DEL_DELAY_DURATION", "DEL_DELEGATE_DATE", "DEL_DURATION", "DEL_FINISHED", "DEL_FINISH_DATE", "DEL_INDEX", "DEL_INIT_DATE", "DEL_PRIORITY", "DEL_QUEUE_DURATION", "DEL_STARTED", "DEL_TASK_DUE_DATE", "DEL_THREAD_STATUS", "PREVIOUS_USR_UID", "PRO_UID", "TAS_UID", "USR_UID"); $rows = array(); // number of found records $result['totalCount'] = $solrQueryResult->iTotalDisplayRecords; //get all the data from database $appUids = array(); foreach ($solrQueryResult->aaData as $i => $data) { $appUids[] = $data[11]; } $aaappsDBData = $this->getListApplicationDelegationData($appUids, $action, $status); if ($this->debug) { $this->afterDbQueryTime = microtime(true); } // complete the missing data to display it in the grid. $delIndexes = array(); //store all the delegation indexes foreach ($solrQueryResult->aaData as $i => $data) { //initialize array $delIndexes = array(); // complete empty values $appUID = $data[11]; //get all the delindexes for ($i = 30; $i < count($data); $i++) { if (is_array($data[$i])) { foreach ($data[$i] as $delIndex) { $delIndexes[] = $delIndex; } } } // verify if the delindex is an array // if is not check different types of repositories // the delegation index must always be defined. if (count($delIndexes) == 0) { if ($action == "search") { //Get all the indexes //$delIndexes = $this->getApplicationDelegationsIndex ($appUID); $indexes = $this->aaSearchRecords($aaappsDBData, array('APP_UID' => $appUID)); foreach ($indexes as $index) { $delIndexes[] = $aaappsDBData[$index]['DEL_INDEX']; } } else { //error an index must always be defined print "Delegation not defined\n"; } /* * elseif ($action == 'unassigned'){ $delIndexes = $this->getApplicationDelegationsIndex ($appUID); } */ } $arrayRowAux = array(); foreach ($resultColumns as $j => $columnName) { $arrayRowAux[$columnName] = $data[$j]; } //Remove duplicated $delIndexes = array_unique($delIndexes); //Gets the last DEL_INDEX sort($delIndexes); $delIndexAux = array_pop($delIndexes); $delIndexes = array($delIndexAux); //Set register foreach ($delIndexes as $delIndex) { $aRow = $arrayRowAux; // convert date from solr format UTC to local time in MySQL format $solrdate = $data[0]; $localDate = date('Y-m-d H:i:s', strtotime($solrdate)); $aRow['APP_CREATE_DATE'] = $localDate; $solrdate = $data[12]; $localDate = date('Y-m-d H:i:s', strtotime($solrdate)); $aRow['APP_UPDATE_DATE'] = $localDate; // get delegation data from DB //filter data from db $indexes = $this->aaSearchRecords($aaappsDBData, array('APP_UID' => $appUID, 'DEL_INDEX' => $delIndex)); foreach ($indexes as $index) { $row = $aaappsDBData[$index]; } if (!isset($row)) { $fh = fopen("SolrAppWhitoutDelIndex.txt", 'a') or die("can't open file to store Solr search time."); fwrite($fh, sprintf("Solr AppUid: %s DelIndex: %s not found.\r\n", $appUID, $delIndex)); fclose($fh); continue; } //$row = $this->getAppDelegationData ($appUID, $delIndex); $aRow['APP_FINISH_DATE'] = null; $aRow['APP_CURRENT_USER'] = $row['USR_NAME'] . " " . $row['USR_LAST']; $aRow['APP_DEL_PREVIOUS_USER'] = $row['USR_PREV_NAME'] . " " . $row['USR_PREV_LAST']; $aRow['APP_OVERDUE_PERCENTAGE'] = $row['APP_OVERDUE_PERCENTAGE']; $aRow['APP_TAS_TITLE'] = $row['APP_TAS_TITLE']; $aRow['APP_THREAD_STATUS'] = $row['APP_THREAD_STATUS']; $aRow['DEL_DELAYED'] = $row['DEL_DELAYED']; $aRow['DEL_DELAY_DURATION'] = $row['DEL_DELAY_DURATION']; $aRow['DEL_DELEGATE_DATE'] = $row['DEL_DELEGATE_DATE']; $aRow['DEL_DURATION'] = $row['DEL_DURATION']; $aRow['DEL_FINISHED'] = isset($row['DEL_FINISH_DATE']) && $row['DEL_FINISH_DATE'] != '' ? 1 : 0; $aRow['DEL_FINISH_DATE'] = $row['DEL_FINISH_DATE']; $aRow['DEL_INDEX'] = $row['DEL_INDEX']; $aRow['DEL_INIT_DATE'] = $row['DEL_INIT_DATE']; $aRow['DEL_QUEUE_DURATION'] = $row['DEL_QUEUE_DURATION']; $aRow['DEL_STARTED'] = isset($row['DEL_INIT_DATE']) && $row['DEL_INIT_DATE'] != '' ? 1 : 0; $aRow['DEL_TASK_DUE_DATE'] = $row['DEL_TASK_DUE_DATE']; $aRow['DEL_THREAD_STATUS'] = $row['DEL_THREAD_STATUS']; $aRow['PREVIOUS_USR_UID'] = $row['PREVIOUS_USR_UID']; $aRow['TAS_UID'] = $row['TAS_UID']; $aRow['USR_UID'] = $userUid; $aRow['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}"); if (isset($aRow["APP_STATUS"])) { $aRow["APP_STATUS"] = G::LoadTranslation("ID_" . $aRow["APP_STATUS"]); } $rows[] = $aRow; } } $result['data'] = $rows; $result['success'] = true; $result['result'] = true; $result['message'] = ""; /** * ****************************************** */ if ($this->debug) { $this->afterPrepareResultTime = microtime(true); $fh = fopen("SolrSearchTime.txt", 'a') or die("can't open file to store Solr search time."); //fwrite($fh, sprintf("Solr Query time: %s DB Query time: %s Prepare result time: %s \n", gmdate ('H:i:s:u', ($this->afterSolrQueryTime - $this->initTimeAll)), gmdate ('H:i:s:u', ($this->afterDbQueryTime - $this->afterSolrQueryTime)), gmdate ('H:i:s:u', ($this->afterPrepareResultTime - $this->afterDbQueryTime)) )); fwrite($fh, sprintf("Solr Query time: %s DB Query time: %s Prepare result time: %s Total:%s \r\n", $this->afterSolrQueryTime - $this->initTimeAll, $this->afterDbQueryTime - $this->afterSolrQueryTime, $this->afterPrepareResultTime - $this->afterDbQueryTime, $this->afterPrepareResultTime - $this->initTimeAll)); fclose($fh); } /** * ************************************ */ return $result; } catch (InvalidIndexSearchTextException $ex) { // return empty result with description of error $result = array(); $result['totalCount'] = 0; $result['data'] = array(); $result['success'] = true; $result['result'] = false; $result['message'] = $ex->getMessage(); return $result; } }
/** * Gets the information of Grids using Solr server. * * Returns the list of records for the grid depending of the function * conditions * If doCount is true only the count of records is returned. * * @param string $userUid * current logged user. * @param int $start * the offset to return the group of records. Used for pagination. * @param int $limit * The number of records to return in the set. * @param string $action * the action: todo, participated, draft, unassigned * @param string $filter * filter the results posible values ('read', 'unread', 'started', * 'completed') * @param string $search * search string * @param string $process * PRO_UID to filter results by specified process. * @param string $user * USR_UID to filter results by specified user. * @param string $status * filter by an application Status : TO_DO, COMPLETED, DRAFT * @param string $type * default extjs * @param string $dateFrom * filter by DEL_DELEGATE_DATE, not used * @param string $dateTo * filter by DEL_DELEGATE_DATE, not used * @param string $callback * default stcCallback1001 not used * @param string $dir * sort direction ASC, DESC * @param string $sort * sort field * @param boolean $doCount * default=false, if true only the count of records is returned. * @return array return the list of cases */ public function getAppGridData($userUid, $start = null, $limit = null, $action = null, $filter = null, $search = null, $process = null, $user = null, $status = null, $type = null, $dateFrom = null, $dateTo = null, $callback = null, $dir = null, $sort = 'APP_CACHE_VIEW.APP_NUMBER', $doCount = false) { $callback = isset($callback) ? $callback : 'stcCallback1001'; $dir = isset($dir) ? $dir : 'DESC'; // direction of sort column // (ASC, DESC) $sort = isset($sort) ? $sort : ''; // sort column (APP_NUMBER, // CASE_SUMMARY, // CASE_NOTES_COUNT, APP_TITLE, // APP_PRO_TITLE, APP_TAS_TITLE, // APP_DEL_PREVIOUS_USER, // DEL_TASK_DUE_DATE, // APP_UPDATE_DATE, DEL_PRIORITY) $start = isset($start) ? $start : '0'; $limit = isset($limit) ? $limit : '25'; $filter = isset($filter) ? $filter : ''; // posible values ('read', // 'unread', 'started', // 'completed') $search = isset($search) ? $search : ''; // search in fields, plain text $process = isset($process) ? $process : ''; // filter by an specific // process // uid $user = isset($user) ? $user : ''; // filter by an specific user uid $status = isset($status) ? strtoupper($status) : ''; // filter by an // specific // app_status $action = isset($action) ? $action : 'todo'; // todo, paused $type = isset($type) ? $type : 'extjs'; $dateFrom = isset($dateFrom) ? $dateFrom : ''; // filter by // DEL_DELEGATE_DATE $dateTo = isset($dateTo) ? $dateTo : ''; // filter by DEL_DELEGATE_DATE $swErrorInSearchText = false; $solrQueryResult = null; $aPriorities = array('1' => 'VL', '2' => 'L', '3' => 'N', '4' => 'H', '5' => 'VH'); $result = array(); $result['totalCount'] = 0; $result['data'] = array(); $result['success'] = false; $result['message'] = "Error description."; G::LoadClass('searchIndex'); try { // the array of data that must be returned with placeholders $columsToInclude = array('APP_CREATE_DATE', '', '', '', 'APP_NUMBER', '', 'APP_PRO_TITLE', 'APP_STATUS', '', '', 'APP_TITLE', 'APP_UID', 'DEL_LAST_UPDATE_DATE', '', '', '', '', '', '', '', '', 'DEL_MAX_PRIORITY', '', '', '', '', '', 'PRO_UID', '', ''); // create pagination data $solrSearchText = ""; $sortableCols = array(); $sortCols = array(); $sortDir = array(); $numSortingCols = 0; // define sort conditions, default APP_NUMBER, desc // only one column is sorted $dir = strtolower($dir); if (!empty($sort)) { switch ($sort) { case 'APP_CACHE_VIEW.APP_NUMBER': case 'APP_NUMBER': $sortCols[0] = 4; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; // multivalue field can't be ordered // multivalue field can't be ordered case 'APP_TITLE': $sortCols[0] = 10; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; case 'APP_PRO_TITLE': $sortCols[0] = 6; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; case 'APP_UPDATE_DATE': $sortCols[0] = 12; $sortableCols[0] = 'true'; $sortDir[0] = $dir; break; default: $sortCols[0] = 4; $sortableCols[0] = 'true'; $sortDir[0] = 'desc'; break; } $numSortingCols++; } // get del_index field $delIndexDynaField = ""; // process filter if ($process != '') { $solrSearchText .= "PRO_UID:" . $process . " AND "; } // status filter if ($status != '') { $solrSearchText .= "APP_STATUS:" . $status . " AND "; } // todo list, add condition if ($userUid != null && $action == 'todo') { if ($filter == 'read') { $solrSearchText .= "APP_ASSIGNED_USERS_READ:" . $userUid . " AND "; $delIndexDynaField = "APP_ASSIGNED_USER_READ_DEL_INDEX_" . trim($userUid) . '_txt'; } elseif ($filter == 'unread') { $solrSearchText .= "APP_ASSIGNED_USERS_UNREAD:" . $userUid . " AND "; $delIndexDynaField = "APP_ASSIGNED_USER_UNREAD_DEL_INDEX_" . trim($userUid) . '_txt'; } else { $solrSearchText .= "APP_ASSIGNED_USERS:" . $userUid . " AND "; $delIndexDynaField = "APP_ASSIGNED_USER_DEL_INDEX_" . trim($userUid) . '_txt'; } } // participated, add condition if ($userUid != null && $action == 'sent') { if ($filter == 'started') { $solrSearchText .= "APP_PARTICIPATED_USERS_STARTED:" . $userUid . " AND "; $delIndexDynaField = "APP_PARTICIPATED_USER_STARTED_DEL_INDEX_" . trim($userUid) . '_txt'; } elseif ($filter == 'completed') { $solrSearchText .= "APP_PARTICIPATED_USERS_COMPLETED:" . $userUid . " AND "; $delIndexDynaField = "APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_" . trim($userUid) . '_txt'; } else { $solrSearchText .= "APP_PARTICIPATED_USERS:" . $userUid . " AND "; $delIndexDynaField = "APP_PARTICIPATED_USER_DEL_INDEX_" . trim($userUid) . '_txt'; } } // draft, add condition if ($userUid != null && $action == 'draft') { $solrSearchText .= "APP_DRAFT_USER:"******" AND "; // index is allways 1 } // unassigned, add condition if ($userUid != null && $action == 'unassigned') { // get the list of groups to which belongs the user. $userGroups = $this->getUserGroups($userUid); $solrSearchText .= "(APP_UNASSIGNED_USERS:" . $userUid; if (count($userGroups) > 0) { $solrSearchText .= " OR "; foreach ($userGroups as $group) { $solrSearchText .= "APP_UNASSIGNED_GROUPS:" . $group['GRP_UID'] . " OR "; } // remove last OR in condition if ($solrSearchText != '') { $solrSearchText = substr_replace($solrSearchText, "", -4); } } $solrSearchText .= ") AND "; $delIndexDynaField = "APP_UNASSIGNED_USER_GROUP_DEL_INDEX_" . trim($userUid) . '_txt'; } // remove last AND in condition if ($solrSearchText != '') { $solrSearchText = substr_replace($solrSearchText, "", -5); } // add parenthesis to Solr search text if ($solrSearchText != "") { $solrSearchText = "(" . $solrSearchText . ")"; } // create query string, add query conditions if ($search != '') { // format search string // return exception in case of invalid text $search = $this->getSearchText($search); if ($solrSearchText != "" && $search != "") { $solrSearchText .= " AND "; } if ($search != "") { $solrSearchText .= "(" . $search . ")"; } } // add del_index dynamic field to list of resulting columns $columsToInclude = array_merge($columsToInclude, array($delIndexDynaField)); // if is a counter no records are returned if ($doCount) { $start = 0; $limit = 0; $numSortingCols = 0; $columsToInclude = array(); } $data = array('workspace' => $this->_solrInstance, 'startAfter' => intval($start), 'pageSize' => intval($limit), 'searchText' => $solrSearchText, 'filterText' => '', 'numSortingCols' => $numSortingCols, 'sortableCols' => $sortableCols, 'sortCols' => $sortCols, 'sortDir' => $sortDir, 'includeCols' => $columsToInclude, 'resultFormat' => 'json'); $solrRequestData = Entity_SolrRequestData::createForRequestPagination($data); // use search index to return list of cases $searchIndex = new BpmnEngine_Services_SearchIndex($this->_solrIsEnabled, $this->_solrHost); // execute query $solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData); // complete return data, complete list of columns in grid $resultColumns = array("APP_CREATE_DATE", "APP_CURRENT_USER", "APP_DEL_PREVIOUS_USER", "APP_FINISH_DATE", "APP_NUMBER", "APP_OVERDUE_PERCENTAGE", "APP_PRO_TITLE", "APP_STATUS", "APP_TAS_TITLE", "APP_THREAD_STATUS", "APP_TITLE", "APP_UID", "APP_UPDATE_DATE", "DEL_DELAYED", "DEL_DELAY_DURATION", "DEL_DELEGATE_DATE", "DEL_DURATION", "DEL_FINISHED", "DEL_FINISH_DATE", "DEL_INDEX", "DEL_INIT_DATE", "DEL_PRIORITY", "DEL_QUEUE_DURATION", "DEL_STARTED", "DEL_TASK_DUE_DATE", "DEL_THREAD_STATUS", "PREVIOUS_USR_UID", "PRO_UID", "TAS_UID", "USR_UID"); $rows = array(); // number of found records $result['totalCount'] = $solrQueryResult->iTotalDisplayRecords; // complete the missing data to display it in the grid. foreach ($solrQueryResult->aaData as $i => $data) { // complete empty values $appUID = $data[11]; $delIndexes = $data[30]; // verify if the delindex is an array // if is not an array all the indexed must be returned if (!is_array($delIndexes)) { // if is draft if ($action == 'draft') { $delIndexes[] = 1; // the first default index } elseif ($action == 'search') { // get all the indexes $delIndexes = $this->getApplicationDelegationsIndex($appUID); } } foreach ($delIndexes as $delIndex) { $aRow = array(); foreach ($resultColumns as $j => $columnName) { $aRow[$columnName] = $data[$j]; } // convert date from solr format UTC to local time in MySQL format $solrdate = $data[0]; $localDate = date('Y-m-d H:i:s', strtotime($solrdate)); $aRow['APP_CREATE_DATE'] = $localDate; $solrdate = $data[12]; $localDate = date('Y-m-d H:i:s', strtotime($solrdate)); $aRow['APP_UPDATE_DATE'] = $localDate; // get delegation data from DB $row = $this->getAppDelegationData($appUID, $delIndex); $aRow['APP_FINISH_DATE'] = null; $aRow['APP_CURRENT_USER'] = $row['USR_NAME'] . " " . $row['USR_LAST']; $aRow['APP_DEL_PREVIOUS_USER'] = $row['USR_PREV_NAME'] . " " . $row['USR_PREV_LAST']; $aRow['APP_OVERDUE_PERCENTAGE'] = $row['APP_OVERDUE_PERCENTAGE']; $aRow['APP_TAS_TITLE'] = $row['APP_TAS_TITLE']; $aRow['APP_THREAD_STATUS'] = $row['APP_THREAD_STATUS']; $aRow['DEL_DELAYED'] = $row['DEL_DELAYED']; $aRow['DEL_DELAY_DURATION'] = $row['DEL_DELAY_DURATION']; $aRow['DEL_DELEGATE_DATE'] = $row['DEL_DELEGATE_DATE']; $aRow['DEL_DURATION'] = $row['DEL_DURATION']; $aRow['DEL_FINISHED'] = isset($row['DEL_FINISH_DATE']) && $row['DEL_FINISH_DATE'] != '' ? 1 : 0; $aRow['DEL_FINISH_DATE'] = $row['DEL_FINISH_DATE']; $aRow['DEL_INDEX'] = $row['DEL_INDEX']; $aRow['DEL_INIT_DATE'] = $row['DEL_INIT_DATE']; $aRow['DEL_QUEUE_DURATION'] = $row['DEL_QUEUE_DURATION']; $aRow['DEL_STARTED'] = isset($row['DEL_INIT_DATE']) && $row['DEL_INIT_DATE'] != '' ? 1 : 0; $aRow['DEL_TASK_DUE_DATE'] = $row['DEL_TASK_DUE_DATE']; $aRow['DEL_THREAD_STATUS'] = $row['DEL_THREAD_STATUS']; $aRow['PREVIOUS_USR_UID'] = $row['PREVIOUS_USR_UID']; $aRow['TAS_UID'] = $row['TAS_UID']; $aRow['USR_UID'] = $userUid; $aRow['DEL_PRIORITY'] = G::LoadTranslation("ID_PRIORITY_{$aPriorities[$aRow['DEL_PRIORITY']]}"); $rows[] = $aRow; } } $result['data'] = $rows; $result['success'] = true; $result['result'] = true; $result['message'] = ""; return $result; } catch (InvalidIndexSearchTextException $e) { // return empty result with description of error $result = array(); $result['totalCount'] = 0; $result['data'] = array(); $result['success'] = true; $result['result'] = false; $result['message'] = $e->getMessage(); return $result; } }
/** * Get data of a Case * * @param string $applicationUid Unique id of Case * @param string $userUid Unique id of User * * return array Return an array with data of Case Info */ public function getCaseInfo($applicationUid, $userUid) { try { $solrEnabled = 0; if (($solrEnv = \System::solrEnv()) !== false) { \G::LoadClass("AppSolr"); $appSolr = new \AppSolr( $solrEnv["solr_enabled"], $solrEnv["solr_host"], $solrEnv["solr_instance"] ); if ($appSolr->isSolrEnabled() && $solrEnv["solr_enabled"] == true) { //Check if there are missing records to reindex and reindex them $appSolr->synchronizePendingApplications(); $solrEnabled = 1; } } if ($solrEnabled == 1) { try { \G::LoadClass("searchIndex"); $arrayData = array(); $delegationIndexes = array(); $columsToInclude = array("APP_UID"); $solrSearchText = null; //Todo $solrSearchText = $solrSearchText . (($solrSearchText != null)? " OR " : null) . "(APP_STATUS:TO_DO AND APP_ASSIGNED_USERS:" . $userUid . ")"; $delegationIndexes[] = "APP_ASSIGNED_USER_DEL_INDEX_" . $userUid . "_txt"; //Draft $solrSearchText = $solrSearchText . (($solrSearchText != null)? " OR " : null) . "(APP_STATUS:DRAFT AND APP_DRAFT_USER:"******")"; //Index is allways 1 $solrSearchText = "($solrSearchText)"; //Add del_index dynamic fields to list of resulting columns $columsToIncludeFinal = array_merge($columsToInclude, $delegationIndexes); $solrRequestData = \Entity_SolrRequestData::createForRequestPagination( array( "workspace" => $solrEnv["solr_instance"], "startAfter" => 0, "pageSize" => 1000, "searchText" => $solrSearchText, "numSortingCols" => 1, "sortCols" => array("APP_NUMBER"), "sortDir" => array(strtolower("DESC")), "includeCols" => $columsToIncludeFinal, "resultFormat" => "json" ) ); //Use search index to return list of cases $searchIndex = new \BpmnEngine_Services_SearchIndex($appSolr->isSolrEnabled(), $solrEnv["solr_host"]); //Execute query $solrQueryResult = $searchIndex->getDataTablePaginatedList($solrRequestData); //Get the missing data from database $arrayApplicationUid = array(); foreach ($solrQueryResult->aaData as $i => $data) { $arrayApplicationUid[] = $data["APP_UID"]; } $aaappsDBData = $appSolr->getListApplicationDelegationData($arrayApplicationUid); foreach ($solrQueryResult->aaData as $i => $data) { //Initialize array $delIndexes = array(); //Store all the delegation indexes //Complete empty values $applicationUid = $data["APP_UID"]; //APP_UID //Get all the indexes returned by Solr as columns for ($i = count($columsToInclude); $i <= count($data) - 1; $i++) { if (is_array($data[$columsToIncludeFinal[$i]])) { foreach ($data[$columsToIncludeFinal[$i]] as $delIndex) { $delIndexes[] = $delIndex; } } } //Verify if the delindex is an array //if is not check different types of repositories //the delegation index must always be defined. if (count($delIndexes) == 0) { $delIndexes[] = 1; // the first default index } //Remove duplicated $delIndexes = array_unique($delIndexes); //Get records foreach ($delIndexes as $delIndex) { $aRow = array(); //Copy result values to new row from Solr server $aRow["APP_UID"] = $data["APP_UID"]; //Get delegation data from DB //Filter data from db $indexes = $appSolr->aaSearchRecords($aaappsDBData, array( "APP_UID" => $applicationUid, "DEL_INDEX" => $delIndex )); foreach ($indexes as $index) { $row = $aaappsDBData[$index]; } if (!isset($row)) { continue; } \G::LoadClass('wsBase'); $ws = new \wsBase(); $fields = $ws->getCaseInfo($applicationUid, $row["DEL_INDEX"]); $array = json_decode(json_encode($fields), true); if ($array ["status_code"] != 0) { throw (new \Exception($array ["message"])); } else { $array['app_uid'] = $array['caseId']; $array['app_number'] = $array['caseNumber']; $array['app_name'] = $array['caseName']; $array['app_status'] = $array['caseStatus']; $array['app_init_usr_uid'] = $array['caseCreatorUser']; $array['app_init_usr_username'] = trim($array['caseCreatorUserName']); $array['pro_uid'] = $array['processId']; $array['pro_name'] = $array['processName']; $array['app_create_date'] = $array['createDate']; $array['app_update_date'] = $array['updateDate']; $array['current_task'] = $array['currentUsers']; for ($i = 0; $i<=count($array['current_task'])-1; $i++) { $current_task = $array['current_task'][$i]; $current_task['usr_uid'] = $current_task['userId']; $current_task['usr_name'] = trim($current_task['userName']); $current_task['tas_uid'] = $current_task['taskId']; $current_task['tas_title'] = $current_task['taskName']; $current_task['del_index'] = $current_task['delIndex']; $current_task['del_thread'] = $current_task['delThread']; $current_task['del_thread_status'] = $current_task['delThreadStatus']; unset($current_task['userId']); unset($current_task['userName']); unset($current_task['taskId']); unset($current_task['taskName']); unset($current_task['delIndex']); unset($current_task['delThread']); unset($current_task['delThreadStatus']); $aCurrent_task[] = $current_task; } unset($array['status_code']); unset($array['message']); unset($array['timestamp']); unset($array['caseParalell']); unset($array['caseId']); unset($array['caseNumber']); unset($array['caseName']); unset($array['caseStatus']); unset($array['caseCreatorUser']); unset($array['caseCreatorUserName']); unset($array['processId']); unset($array['processName']); unset($array['createDate']); unset($array['updateDate']); unset($array['currentUsers']); $current_task = json_decode(json_encode($aCurrent_task), false); $oResponse = json_decode(json_encode($array), false); $oResponse->current_task = $current_task; } //Return return $oResponse; } } } catch (\InvalidIndexSearchTextException $e) { $arrayData = array(); $arrayData[] = array ("app_uid" => $e->getMessage(), "app_name" => $e->getMessage(), "del_index" => $e->getMessage(), "pro_uid" => $e->getMessage()); throw (new \Exception($arrayData)); } } else { \G::LoadClass("wsBase"); //Verify data $this->throwExceptionIfNotExistsCase($applicationUid, 0, $this->getFieldNameByFormatFieldName("APP_UID")); $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\AppDelegationPeer::APP_UID); $criteria->add(\AppDelegationPeer::APP_UID, $applicationUid); $criteria->add(\AppDelegationPeer::USR_UID, $userUid); $rsCriteria = \AppDelegationPeer::doSelectRS($criteria); if (!$rsCriteria->next()) { throw new \Exception(\G::LoadTranslation("ID_NO_PERMISSION_NO_PARTICIPATED")); } //Get data $ws = new \wsBase(); $fields = $ws->getCaseInfo($applicationUid, 0); $array = json_decode(json_encode($fields), true); if ($array ["status_code"] != 0) { throw (new \Exception($array ["message"])); } else { $array['app_uid'] = $array['caseId']; $array['app_number'] = $array['caseNumber']; $array['app_name'] = $array['caseName']; $array["app_status"] = $array["caseStatus"]; $array['app_init_usr_uid'] = $array['caseCreatorUser']; $array['app_init_usr_username'] = trim($array['caseCreatorUserName']); $array['pro_uid'] = $array['processId']; $array['pro_name'] = $array['processName']; $array['app_create_date'] = $array['createDate']; $array['app_update_date'] = $array['updateDate']; $array['current_task'] = $array['currentUsers']; $aCurrent_task = array(); for ($i = 0; $i<=count($array['current_task'])-1; $i++) { $current_task = $array['current_task'][$i]; $current_task['usr_uid'] = $current_task['userId']; $current_task['usr_name'] = trim($current_task['userName']); $current_task['tas_uid'] = $current_task['taskId']; $current_task['tas_title'] = $current_task['taskName']; $current_task['del_index'] = $current_task['delIndex']; $current_task['del_thread'] = $current_task['delThread']; $current_task['del_thread_status'] = $current_task['delThreadStatus']; $current_task["del_init_date"] = $current_task["delInitDate"] . ""; $current_task["del_task_due_date"] = $current_task["delTaskDueDate"]; unset($current_task['userId']); unset($current_task['userName']); unset($current_task['taskId']); unset($current_task['taskName']); unset($current_task['delIndex']); unset($current_task['delThread']); unset($current_task['delThreadStatus']); $aCurrent_task[] = $current_task; } unset($array['status_code']); unset($array['message']); unset($array['timestamp']); unset($array['caseParalell']); unset($array['caseId']); unset($array['caseNumber']); unset($array['caseName']); unset($array['caseStatus']); unset($array['caseCreatorUser']); unset($array['caseCreatorUserName']); unset($array['processId']); unset($array['processName']); unset($array['createDate']); unset($array['updateDate']); unset($array['currentUsers']); } $current_task = json_decode(json_encode($aCurrent_task), false); $oResponse = json_decode(json_encode($array), false); $oResponse->current_task = $current_task; //Return return $oResponse; } } catch (\Exception $e) { throw $e; } }