If you are using the Community Edition, then you will have to write your own SQL queries to calculate metrics.
If you want to do this via REST, then import my extraRest plugin:
(29 KiB) Downloaded 266 times
Then, you can call the
POST http://{your-domain}/api/1.0/workflow/extrarest/sql endpoint like this:
Code: Select all $url = "/api/1.0/workflow/extrarest/sql";
$sql = "SELECT APP_CURRENT_USER AS USER, COUNT(*) AS NUM_OVERDUE
FROM APP_CACHE_VIEW WHERE DATE(DEL_INIT_DATE) >= '2018-01-01' AND
DEL_FINISH_DATE IS NULL AND DEL_TASK_DUE_DATE < NOW()
GROUP BY USR_UID ORDER BY APP_CURRENT_USER";
$oRet = pmRestRequest("POST", $url, array("sql"=>$sql), $oToken->access_token);
if ($oRet->status == 200) {
foreach ($oRet->response as $aRow) {
print "User ".$aRow->USER." has ".$aRow->NUM_OVERDUE." overdue cases in year 2018.\n";
}
}
If it doesn't work, then delete the processmaker/shared/sites/{workspace}/routes.php file and try again.
If you want to modify this endpoint, then edit the following code in the file processmaker/workflow/engine/plugins/extraRest/src/Services/Api/ExtraRest/Extra.php:
Code: Select all /**
* Execute an SQL SELECT query in the current workspace's workflow database.
* By default, the initial workspace is named "wf_workflow". The results
* are returned in a numbered array starting from 1, just like executeQuery().
*
* Note: For security reasons, only SELECT statements in the current workspace's workflow
* database are allowed. If thinking of modifying this endpoint to allow UPDATE, INSERT and DELETE
* statements, then make sure to change the ProcessMaker configuration files. See:
* http://wiki.processmaker.com/3.0/Consulting_the_ProcessMaker_databases#Protecting_PM_Core_Tables
*
*
* @url POST /sql
* @access protected
*
* @param string $sql SQL SELECT statement to execute. {@from body}
*
* @return array
*
* @author Amos Batto <amos@processmaker.com>
* @copyright Public Domain
*/
public function postSql($sql) {
$g = new G();
$g->loadClass("pmFunctions");
try {
if (preg_match('/^\s*select\s/i', $sql) == 0) {
throw new Exception("SQL must be a SELECT statement.");
}
$aResult = executeQuery($sql);
}
catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
}
$aRows = array();
foreach ($aResult as $aRow) {
$aRows[] = $aRow;
}
return $aRows;
}