Merge remote-tracking branch 'origin/release/3.3.10' into bugfix/PMC-580

This commit is contained in:
Paula Quispe
2019-05-07 14:47:08 -04:00
8 changed files with 183 additions and 62 deletions

View File

@@ -21,6 +21,7 @@ use BpmnEngineServicesSearchIndex;
use Cases as ClassesCases;
use CasesPeer;
use Configurations;
use CreoleTypes;
use Criteria;
use DBAdapter;
use EntitySolrRequestData;
@@ -32,6 +33,7 @@ use InputDocument;
use InvalidIndexSearchTextException;
use ListParticipatedLast;
use PmDynaform;
use PmTable;
use ProcessMaker\BusinessModel\ProcessSupervisor as BmProcessSupervisor;
use ProcessMaker\BusinessModel\Task as BmTask;
use ProcessMaker\BusinessModel\User as BmUser;
@@ -39,16 +41,16 @@ use ProcessMaker\Core\System;
use ProcessMaker\Exception\UploadException;
use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Services\OAuth2\Server;
use ProcessMaker\Util\DateTime as UtilDateTime;
use ProcessMaker\Validation\ExceptionRestApi;
use ProcessMaker\Validation\Validator as FileValidator;
use ProcessPeer;
use ProcessUser;
use ProcessUserPeer;
use RBAC;
use ResultSet;
use RoutePeer;
use SubApplication;
use SubProcessPeer;
use Task as ModelTask;
use TaskPeer;
use Tasks as ClassesTasks;
@@ -3502,7 +3504,7 @@ class Cases
* @param string $listPeer , name of the list class
* @param string $search , the parameter for search in the table
* @param string $additionalClassName , name of the className of pmtable
* @param array $additionalColumns , columns related to the custom cases list
* @param array $additionalColumns , columns related to the custom cases list ex: TABLE_NAME.COLUMN_NAME
*
* @throws PropelException
*/
@@ -3511,31 +3513,35 @@ class Cases
$listPeer,
$search,
$additionalClassName = '',
$additionalColumns = array()
$additionalColumns = []
) {
$oTmpCriteria = '';
$tmpCriteria = '';
//If we have additional tables configured in the custom cases list, prepare the variables for search
if (count($additionalColumns) > 0) {
require_once(PATH_DATA_SITE . 'classes' . PATH_SEP . $additionalClassName . '.php');
$oNewCriteria = new Criteria("workflow");
$oTmpCriteria = $oNewCriteria->getNewCriterion(current($additionalColumns), "%" . $search . "%",
Criteria::LIKE);
$columnPivot = current($additionalColumns);
$tableAndColumn = explode(".", $columnPivot);
$type = PmTable::getTypeOfColumn($listPeer, $tableAndColumn[0], $tableAndColumn[1]);
$tmpCriteria = $this->defineCriteriaByColumnType($type, $columnPivot, $search);
//We prepare the query related to the custom cases list
foreach (array_slice($additionalColumns, 1) as $value) {
$oTmpCriteria = $oNewCriteria->getNewCriterion($value, "%" . $search . "%",
Criteria::LIKE)->addOr($oTmpCriteria);
foreach (array_slice($additionalColumns, 1) as $column) {
$tableAndColumn = explode(".", $column);
$type = PmTable::getTypeOfColumn($listPeer, $tableAndColumn[0], $tableAndColumn[1]);
$tmpCriteria = $this->defineCriteriaByColumnType($type, $column, $search)->addOr($tmpCriteria);
}
}
if (!empty($oTmpCriteria)) {
if (!empty($tmpCriteria)) {
$criteria->add(
$criteria->getNewCriterion($listPeer::APP_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
$criteria->getNewCriterion($listPeer::APP_TAS_TITLE, '%' . $search . '%', Criteria::LIKE)->addOr(
$criteria->getNewCriterion($listPeer::APP_PRO_TITLE, '%' . $search . '%',
Criteria::LIKE)->addOr(
$criteria->getNewCriterion($listPeer::APP_NUMBER, $search, Criteria::EQUAL)->addOr(
$oTmpCriteria
$tmpCriteria
))))
);
} else {
@@ -3549,6 +3555,58 @@ class Cases
}
}
/**
* Define the criteria according to the column type
*
* @param string $fieldType
* @param string $column
* @param string $search
*
* @return Criteria
*/
private function defineCriteriaByColumnType($fieldType, $column, $search)
{
$newCriteria = new Criteria("workflow");
switch ($fieldType) {
case CreoleTypes::BOOLEAN:
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
break;
case CreoleTypes::BIGINT:
case CreoleTypes::INTEGER:
case CreoleTypes::SMALLINT:
case CreoleTypes::TINYINT:
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
break;
case CreoleTypes::REAL:
case CreoleTypes::DECIMAL:
case CreoleTypes::DOUBLE:
case CreoleTypes::FLOAT:
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::LIKE);
break;
case CreoleTypes::CHAR:
case CreoleTypes::LONGVARCHAR:
case CreoleTypes::VARCHAR:
$criteria = $newCriteria->getNewCriterion($column, "%" . $search . "%", Criteria::LIKE);
break;
case CreoleTypes::DATE:
case CreoleTypes::TIME:
case CreoleTypes::TIMESTAMP://DATETIME
//@todo use the same constant in other places
if (preg_match(UtilDateTime::REGEX_IS_DATE,
$search, $arrayMatch)) {
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::GREATER_EQUAL);
} else {
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
}
break;
default:
$criteria = $newCriteria->getNewCriterion($column, $search, Criteria::EQUAL);
}
return $criteria;
}
/**
* This function get the table.column by order by the result
* We can include the additional table related to the custom cases list

View File

@@ -7,6 +7,7 @@ class DateTime
const REGEXPDATE = '[1-9]\d{3}\-(?:0[1-9]|1[0-2])\-(?:0[1-9]|[12][0-9]|3[01])';
const REGEXPTIME = '(?:[0-1]\d|2[0-3])\:[0-5]\d\:[0-5]\d';
const REGEX_IS_DATE = '/^([1-9]\d{3})\-(0[1-9]|1[0-2])\-(0[1-9]|[12][0-9]|3[01])(?:\s([0-1]\d|2[0-3])\:([0-5]\d)\:([0-5]\d))?$/';
/**
* Get Time Zone Offset by Time Zone ID

View File

@@ -401,27 +401,27 @@ function verifyCsrfToken($request)
}
/**
* Get the difference between to multidimensional array
* Get the difference between to arrays
* If the element is an array we will to keep the value from $array1
* If the element is an object we will to keep the value from $array1
*
* @param array $array1
* @param array $array2
*
* @return array
*/
function arrayDiffRecursive(array $array1, array $array2)
*/
function getDiffBetweenModifiedVariables(array $array1, array $array2)
{
$difference = [];
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if (!isset($array2[$key])) {
if ($value !== $array2[$key]) {
$difference[$key] = $value;
} elseif (!is_array($array2[$key])) {
}
} elseif (is_object($value)) {
// When using ===, it means object variables are identical and they refer to the same instance of the same class.
if ($value != $array2[$key]) {
$difference[$key] = $value;
} else {
$new_diff = arrayDiffRecursive($value, $array2[$key]);
if (!empty($new_diff)) {
$difference[$key] = $new_diff;
}
}
} elseif (!isset($array2[$key]) || $array2[$key] != $value) {
$difference[$key] = $value;