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:
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 *
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user