Merged in feature/PMCORE-503 (pull request #7344)

PMCORE-503

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Paula Quispe
2020-06-12 21:37:13 +00:00
committed by Julio Cesar Laura Avendaño
14 changed files with 2392 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ class PmDynaform
public $lang = SYS_LANG;
public $translations = null;
public $onPropertyRead = "onPropertyReadFormInstance";
public $onAfterPropertyRead = "onAfterPropertyReadFormInstance";
public $pathRTLCss = '';
public $record = null;
public $records = null;
@@ -545,6 +546,7 @@ class PmDynaform
if (isset($this->fields["APP_DATA"][$json->name . "_label"])) {
$json->data->label = $this->fields["APP_DATA"][$json->name . "_label"];
}
$this->setDependentOptionsForDatetime($json, $this->fields);
}
if ($key === "type" && ($value === "file") && isset($this->fields["APP_DATA"]["APPLICATION"])) {
$oCriteriaAppDocument = new Criteria("workflow");
@@ -771,6 +773,11 @@ class PmDynaform
}
}
}
//read event after
$fn = $this->onAfterPropertyRead;
if (is_callable($fn) || function_exists($fn)) {
$fn($json, $key, $value);
}
}
}
}
@@ -2489,4 +2496,38 @@ class PmDynaform
$json->dataSchema[$key] = $columnsData;
}
}
/**
* Sets the dependentOptions property for datetime control, if it contains dependent fields.
* @param stdClass $json
* @param array $fields
* @return void
*/
private function setDependentOptionsForDatetime(stdClass &$json, array $fields = []): void
{
if (!isset($json->type)) {
return;
}
if ($json->type !== 'datetime') {
return;
}
$json->dependentOptions = '';
$backup = $this->onAfterPropertyRead;
$properties = [
'defaultDate' => $json->defaultDate,
'minDate' => $json->minDate,
'maxDate' => $json->maxDate
];
$this->onAfterPropertyRead = function(stdClass &$json, $key, $value) use($backup, $properties) {
if (isset($json->type) && $json->type === 'datetime' && $key === "dependentOptions") {
$json->dependentOptions = new stdClass();
foreach ($properties as $property => $value) {
if (is_string($value) && in_array(substr($value, 0, 2), self::$prefixs)) {
$json->dependentOptions->{$property} = $value;
}
}
$this->onAfterPropertyRead = $backup;
}
};
}
}

View File

@@ -459,6 +459,123 @@ function evaluateFunction($aGrid, $sExpresion)
return $aGrid;
}
/**
*
* @method
*
* Executes operations in the grid fields, such as sum, average, median, minimum, maximun,
* stantard deviation, variance, percentile, count, count distinct
*
* @name PMFTotalCalculation
* @label PMFTotalCalculation Function
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFTotalCalculation.28.29
* @param array | $grid | Grid | The input grid.
* @param string (32) | $field | Name of field | The name of the field.
* @param string (32) | $function | Operation.
* @return int|float|array | $result | Result | Result according of the function
*
*/
function PMFTotalCalculation($grid, $field, $function)
{
$systemConfiguration = Bootstrap::getSystemConfiguration();
$floatPointNumber = $systemConfiguration['PMFTOTALCALCULATION_FLOATING_POINT_NUMBER'];
$function = strtolower($function);
$totalRows = count($grid);
$result = 0;
$sum = 0;
switch ($function) {
case "sum":
for ($i = 1; $i <= $totalRows; $i += 1) {
$result += $grid[$i][$field];
}
break;
case "average":
for ($i = 1; $i <= $totalRows; $i += 1) {
$result += $grid[$i][$field];
}
$result = $result / $totalRows;
break;
case "median":
$arrayAux = [];
for ($i = 1; $i <= $totalRows; $i += 1) {
$arrayAux[] = $grid[$i][$field];
}
sort($arrayAux);
$term = ($totalRows + 1) / 2;
if ($totalRows % 2 === 0) {
$term = floor($term);
$result = ($arrayAux[$term - 1] + $arrayAux[$term]) / 2;
} else {
$result = $arrayAux[$term - 1];
}
break;
case "minimum":
$result = $grid[1][$field];
for ($i = 2; $i <= $totalRows; $i += 1) {
if ($grid[$i][$field] < $result) {
$result = $grid[$i][$field];
}
}
break;
case "maximum":
$result = $grid[1][$field];
for ($i = 2; $i <= $totalRows; $i += 1) {
if ($grid[$i][$field] > $result) {
$result = $grid[$i][$field];
}
}
break;
case "standarddeviation":
$mean = 0;
for ($i = 1; $i <= $totalRows; $i += 1) {
$mean += $grid[$i][$field];
}
$mean = $mean / $totalRows;
for ($i = 1; $i <= $totalRows; $i += 1) {
$result += pow($grid[$i][$field] - $mean, 2);
}
$result = sqrt($result / $totalRows);
break;
case "variance":
$mean = 0;
for ($i = 1; $i <= $totalRows; $i += 1) {
$mean += $grid[$i][$field];
}
$mean = $mean / $totalRows;
for ($i = 1; $i <= $totalRows; $i += 1) {
$result += pow($grid[$i][$field] - $mean, 2);
}
$result = $result / $totalRows;
break;
case "percentile":
$result = [];
$arrayAux = [];
for ($i = 1; $i <= $totalRows; $i += 1) {
$sum += $grid[$i][$field];
$arrayAux[$i] = $grid[$i][$field];
}
for ($i = 1; $i <= count($arrayAux); $i += 1) {
$result[$i] = round(($arrayAux[$i] * 100) / $sum, $floatPointNumber);
}
break;
case "count":
$result = $totalRows;
break;
case "countdistinct":
$arrayAux = [];
for ($i = 1; $i <= $totalRows; $i += 1) {
$arrayAux[] = $grid[$i][$field];
}
$result = count(array_count_values($arrayAux));
break;
}
if ($function !== "percentile") {
return round($result, $floatPointNumber);
}
return $result;
}
/**
* Web Services Functions *
*/

View File

@@ -1178,7 +1178,9 @@ class DynaForm
}
foreach ($oldColumns as $oldColumn) {
if (strtolower(AdditionalTables::getPHPName($column->id)) === strtolower(AdditionalTables::getPHPName($oldColumn->id))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
if (strtolower(AdditionalTables::getPHPName($column->var_name)) === strtolower(AdditionalTables::getPHPName($oldColumn->var_name))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
}
}
}
}

View File

@@ -26,6 +26,16 @@ class Variable
'object' => 10
];
/**
* Get the variables types accepted
*
* @return array
*/
public function getVariableTypes()
{
return $this->variableTypes;
}
/**
* Create Variable for a Process
*
@@ -355,6 +365,33 @@ class Variable
return $arrayVariables;
}
/**
* Get data of Variables related to the specific type
*
* @param string $processUid Unique id of Process
* @param int $typeVarId
* @param int $start
* @param int $limit
* @param string $search
* @param string $prefix
*
* @return array, return an array with varaibles filter by type
*/
public function getVariablesByType($processUid, $typeVarId = 0, $start = null, $limit = null, $search = null, $prefix = null)
{
//Verify data
$proId = Validator::proUid($processUid, '$prj_uid');
$variables = ProcessVariables::getVariablesByType($proId, $typeVarId, $start, $limit, $search);
$arrayVariables = [];
foreach ($variables as $var) {
$arrayVariables[] = [
'value' => is_null($prefix) ? $var['VAR_NAME'] : $prefix . $var['VAR_NAME'],
];
}
return $arrayVariables;
}
/**
* Verify field definition
*

View File

@@ -77,7 +77,8 @@ class System
'highlight_home_folder_enable' => 0,
'highlight_home_folder_refresh_time' => 10,
'highlight_home_folder_scope' => 'unassigned', // For now only this list is supported
'disable_advanced_search_case_title_fulltext' => 0
'disable_advanced_search_case_title_fulltext' => 0,
'PMFTOTALCALCULATION_FLOATING_POINT_NUMBER' => 10
];
/**

View File

@@ -72,8 +72,21 @@ class ProcessVariables extends Model
*/
public function scopeProcessId($query, int $proId)
{
return $query->where('PRO_ID', $proId);
return $query->where('PROCESS_VARIABLES.PRO_ID', $proId);
}
/**
* Scope a query to filter a specific type for variable
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $typeId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTypeId($query, int $typeId)
{
return $query->where('VAR_FIELD_TYPE_ID', $typeId);
}
/**
* Return the variables list
*
@@ -96,4 +109,46 @@ class ProcessVariables extends Model
return $variablesList;
}
/**
* Return the variables list
*
* @param int $proId
* @param int $typeId
* @param int $start
* @param int $limit
* @param string $search
*
* @return array
*/
public static function getVariablesByType(int $proId, int $typeId = 0, $start = null, $limit = null, $search = null)
{
$query = ProcessVariables::query()->select();
$query->leftJoin('DB_SOURCE', function ($join) {
$join->on('DB_SOURCE.PRO_ID', '=', 'PROCESS_VARIABLES.PRO_ID');
});
$query->processId($proId);
// Check if we need to filter the type of variables
if ($typeId > 0) {
$query->typeId($typeId);
}
// search a specific variable name
if (!empty($search)) {
$query->where('VAR_NAME', 'LIKE', "${search}%");
}
// order by varNane
$query->orderBy('VAR_NAME', 'ASC');
// Check if we need to add a pagination
if(!is_null($start) && !is_null($limit)) {
$query->offset($start)->limit($limit);
}
// Get records
$results = $query->get();
$variablesList = [];
$results->each(function ($item, $key) use (&$variablesList) {
$variablesList[] = $item->toArray();
});
return $variablesList;
}
}

View File

@@ -1,8 +1,12 @@
<?php
namespace ProcessMaker\Services\Api\Project;
use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;
use Exception;
use G;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Variable as BmVariable;
use ProcessMaker\Services\Api;
/**
* Project\Variable Api Controller
*
@@ -28,6 +32,43 @@ class Variable extends Api
}
}
/**
* Get variables by type
*
* @url GET /:prj_uid/process-variables/:typeVariable/paged
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $typeVariable {@from path}
* @param int $start {@from path}
* @param int $limit {@from path}
* @param string $search {@from path}
*/
public function doGetVariablesByType($prj_uid, $typeVariable, $start = null, $limit = null, $search = null)
{
try {
$variable = new BmVariable();
$typesAccepted = $variable::$varTypesValues;
if (!empty($typesAccepted[$typeVariable])) {
$typeVatId = $typesAccepted[$typeVariable];
} else {
throw new Exception(G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", ['$typeVariable', implode(',', $variable->getVariableTypes())]));
}
// Review if the word has the prefix
$count = preg_match_all('/\@(?:([\@\%\#\?\$\=\&Qq\!])|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/', $search, $match, PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE);
// Check if the search has some prefix
$prefix = '';
if ($count) {
$prefix = substr($search,0,2);
$search = substr($search,2);
}
$response = $variable->getVariablesByType($prj_uid, $typeVatId, $start, $limit, $search, $prefix);
return $response;
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url GET /:prj_uid/process-variable/:var_uid
*