PM-444 "0013316: Be able to assign users to different time zone (user's time zone)" SOLVED
Issue:
PM-444: 0013316: Be able to assign users to different time zone
PM-3493: Agregar soporte multiple timezone a los endpoints usando formato fecha ISO 8601
Cause:
New feature
Solution:
Added functionality for time zone
This commit is contained in:
@@ -169,32 +169,32 @@ class Process
|
||||
public function throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, $flagValidateRequired = true)
|
||||
{
|
||||
try {
|
||||
|
||||
\G::LoadSystem('inputfilter');
|
||||
$filter = new \InputFilter();
|
||||
|
||||
if ($flagValidateRequired) {
|
||||
foreach ($arrayFieldDefinition as $key => $value) {
|
||||
$fieldName = $key;
|
||||
|
||||
$fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : "";
|
||||
$fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]['fieldNameAux']]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]['fieldNameAux']] : $fieldName;
|
||||
|
||||
if ($arrayFieldDefinition[$fieldName]["required"] && !isset($arrayData[$fieldName])) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_UNDEFINED_VALUE_IS_REQUIRED", array($fieldNameAux)));
|
||||
throw new \Exception(\G::LoadTranslation('ID_UNDEFINED_VALUE_IS_REQUIRED', [$fieldNameAux]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$arrayType1 = array("int", "integer", "float", "real", "double", "bool", "boolean", "string", "date", "hour", "datetime");
|
||||
$arrayType2 = array("array", "object");
|
||||
$arrayType1 = [
|
||||
'int', 'integer', 'float', 'real', 'double',
|
||||
'bool', 'boolean',
|
||||
'string',
|
||||
'date', 'hour', 'datetime'
|
||||
];
|
||||
$arrayType2 = ['array', 'object'];
|
||||
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$fieldName = $key;
|
||||
$fieldValue = $value;
|
||||
|
||||
|
||||
if (isset($arrayFieldDefinition[$fieldName])) {
|
||||
$fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : "";
|
||||
$fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]['fieldNameAux']]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]['fieldNameAux']] : $fieldName;
|
||||
|
||||
$arrayFieldDefinition[$fieldName]["type"] = strtolower($arrayFieldDefinition[$fieldName]["type"]);
|
||||
|
||||
@@ -205,38 +205,43 @@ class Process
|
||||
switch ($optionType) {
|
||||
case 1:
|
||||
//empty
|
||||
if (!$arrayFieldDefinition[$fieldName]["empty"] && trim($fieldValue) . "" == "") {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($fieldNameAux)));
|
||||
if (!$arrayFieldDefinition[$fieldName]['empty'] && trim($fieldValue) == '') {
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_CAN_NOT_BE_EMPTY', [$fieldNameAux]));
|
||||
}
|
||||
|
||||
//defaultValues
|
||||
if (count($arrayFieldDefinition[$fieldName]["defaultValues"]) > 0 && !in_array($fieldValue, $arrayFieldDefinition[$fieldName]["defaultValues"], true)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array($fieldNameAux, implode("|", $arrayFieldDefinition[$fieldName]["defaultValues"]))));
|
||||
if (isset($arrayFieldDefinition[$fieldName]['defaultValues']) &&
|
||||
!empty($arrayFieldDefinition[$fieldName]['defaultValues']) &&
|
||||
!in_array($fieldValue, $arrayFieldDefinition[$fieldName]['defaultValues'], true)
|
||||
) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES', [$fieldNameAux, implode('|', $arrayFieldDefinition[$fieldName]['defaultValues'])]));
|
||||
}
|
||||
|
||||
//type
|
||||
$fieldValue = (!is_array($fieldValue)) ? $fieldValue : '';
|
||||
$fieldValue = (!is_array($fieldValue))? $fieldValue : '';
|
||||
|
||||
if ($arrayFieldDefinition[$fieldName]["empty"] && $fieldValue . "" == "") {
|
||||
//
|
||||
} else {
|
||||
$regexpDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])";
|
||||
$regexpHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)(?:\:[0-5]\d)?";
|
||||
$regexpDatetime = $regexpDate . "\s" . $regexpHour;
|
||||
$regexpDate = \ProcessMaker\Util\DateTime::REGEXPDATE;
|
||||
$regexpTime = \ProcessMaker\Util\DateTime::REGEXPTIME;
|
||||
|
||||
$regexpDatetime = $regexpDate . '\s' . $regexpTime;
|
||||
|
||||
switch ($arrayFieldDefinition[$fieldName]["type"]) {
|
||||
case "date":
|
||||
if (!preg_match("/^" . $regexpDate . "$/", $fieldValue)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE', [$fieldNameAux]));
|
||||
}
|
||||
break;
|
||||
case "hour":
|
||||
if (!preg_match("/^" . $regexpHour . "$/", $fieldValue)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
|
||||
if (!preg_match('/^' . $regexpTime . '$/', $fieldValue)) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE', [$fieldNameAux]));
|
||||
}
|
||||
break;
|
||||
case "datetime":
|
||||
if (!preg_match("/^" . $regexpDatetime . "$/", $fieldValue)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE", array($fieldNameAux)));
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE', [$fieldNameAux]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -251,7 +256,7 @@ class Process
|
||||
//type
|
||||
if (!is_array($fieldValue)) {
|
||||
if ($fieldValue != "" && !preg_match("/^" . $regexpArray1 . ".*" . $regexpArray2 . "$/", $fieldValue)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_THIS_MUST_BE_ARRAY", array($fieldNameAux)));
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_THIS_MUST_BE_ARRAY', [$fieldNameAux]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,37 +268,38 @@ class Process
|
||||
$arrayAux = $fieldValue;
|
||||
}
|
||||
|
||||
if (is_string($fieldValue) && trim($fieldValue) . "" != "") {
|
||||
if (is_string($fieldValue) && trim($fieldValue) != '') {
|
||||
//eval("\$arrayAux = $fieldValue;");
|
||||
|
||||
if (preg_match("/^" . $regexpArray1 . "(.*)" . $regexpArray2 . "$/", $fieldValue, $arrayMatch)) {
|
||||
if (trim($arrayMatch[1], " ,") != "") {
|
||||
$arrayAux = array(0);
|
||||
$arrayAux = [0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arrayAux) == 0) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_CAN_NOT_BE_EMPTY", array($fieldNameAux)));
|
||||
if (empty($arrayAux)) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_CAN_NOT_BE_EMPTY', [$fieldNameAux]));
|
||||
}
|
||||
}
|
||||
|
||||
//defaultValues
|
||||
if (count($arrayFieldDefinition[$fieldName]["defaultValues"]) > 0) {
|
||||
$arrayAux = array();
|
||||
if (isset($arrayFieldDefinition[$fieldName]['defaultValues']) &&
|
||||
!empty($arrayFieldDefinition[$fieldName]['defaultValues'])
|
||||
) {
|
||||
$arrayAux = [];
|
||||
|
||||
if (is_array($fieldValue)) {
|
||||
$arrayAux = $fieldValue;
|
||||
}
|
||||
|
||||
if (is_string($fieldValue) && trim($fieldValue) . "" != "") {
|
||||
$fieldValue = $filter->validateInput($fieldValue);
|
||||
if (is_string($fieldValue) && trim($fieldValue) != '') {
|
||||
eval("\$arrayAux = $fieldValue;");
|
||||
}
|
||||
|
||||
foreach ($arrayAux as $value) {
|
||||
if (!in_array($value, $arrayFieldDefinition[$fieldName]["defaultValues"], true)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES", array($fieldNameAux, implode("|", $arrayFieldDefinition[$fieldName]["defaultValues"]))));
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_ONLY_ACCEPTS_VALUES', [$fieldNameAux, implode('|', $arrayFieldDefinition[$fieldName]['defaultValues'])]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,10 +326,10 @@ class Process
|
||||
{
|
||||
try {
|
||||
foreach ($arrayData as $key => $value) {
|
||||
$nameForException = (isset($arrayFieldNameForException[$key]))? $arrayFieldNameForException[$key] : "";
|
||||
$nameForException = (isset($arrayFieldNameForException[$key]))? $arrayFieldNameForException[$key] : $key;
|
||||
|
||||
if (!is_null($value) && ($value . "" == "" || !preg_match("/^(?:\+|\-)?(?:0|[1-9]\d*)$/", $value . "") || (int)($value) < 0)) {
|
||||
throw new \Exception(\G::LoadTranslation("ID_INVALID_VALUE_EXPECTING_POSITIVE_INTEGER", array($nameForException)));
|
||||
throw new \Exception(\G::LoadTranslation('ID_INVALID_VALUE_EXPECTING_POSITIVE_INTEGER', [$nameForException]));
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -32,7 +32,8 @@ class User
|
||||
"USR_COST_BY_HOUR" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "usrCostByHour"),
|
||||
"USR_UNIT_COST" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "usrUnitCost"),
|
||||
/*----------------------------------********---------------------------------*/
|
||||
"USR_LOGGED_NEXT_TIME" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "usrLoggedNextTime")
|
||||
'USR_LOGGED_NEXT_TIME' => ['type' => 'int', 'required' => false, 'empty' => false, 'defaultValues' => [0, 1], 'fieldNameAux' => 'usrLoggedNextTime'],
|
||||
'USR_TIME_ZONE' => ['type' => 'string', 'required' => false, 'empty' => true, 'defaultValues' => [], 'fieldNameAux' => 'usrTimeZone']
|
||||
);
|
||||
|
||||
private $formatFieldNameInUppercase = true;
|
||||
@@ -295,6 +296,12 @@ class User
|
||||
throw new \Exception(\G::LoadTranslation("ID_DEPARTMENT_NOT_EXIST", array($this->arrayFieldNameForException["depUid"], $arrayData["DEP_UID"])));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData['USR_TIME_ZONE']) && $arrayData['USR_TIME_ZONE'] != '') {
|
||||
if (!in_array($arrayData['USR_TIME_ZONE'], \DateTimeZone::listIdentifiers())) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_TIME_ZONE_DOES_NOT_EXIST', [$this->arrayFieldNameForException['usrTimeZone'], $arrayData['USR_TIME_ZONE']]));
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -343,48 +350,62 @@ class User
|
||||
$pathPhotoUser = PATH_HOME . "public_html" . PATH_SEP . "images" . PATH_SEP . "user.gif";
|
||||
}
|
||||
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("USR_UID") => $record["USR_UID"],
|
||||
$this->getFieldNameByFormatFieldName("USR_USERNAME") => $record["USR_USERNAME"],
|
||||
//$this->getFieldNameByFormatFieldName("USR_PASSWORD") => $record["USR_PASSWORD"],
|
||||
$this->getFieldNameByFormatFieldName("USR_FIRSTNAME") => $record["USR_FIRSTNAME"],
|
||||
$this->getFieldNameByFormatFieldName("USR_LASTNAME") => $record["USR_LASTNAME"],
|
||||
$this->getFieldNameByFormatFieldName("USR_EMAIL") => $record["USR_EMAIL"],
|
||||
$this->getFieldNameByFormatFieldName("USR_DUE_DATE") => $record["USR_DUE_DATE"],
|
||||
$this->getFieldNameByFormatFieldName("USR_CREATE_DATE") => $record["USR_CREATE_DATE"],
|
||||
$this->getFieldNameByFormatFieldName("USR_UPDATE_DATE") => $record["USR_UPDATE_DATE"],
|
||||
$this->getFieldNameByFormatFieldName("USR_STATUS") => $record["USR_STATUS"],
|
||||
$this->getFieldNameByFormatFieldName("USR_COUNTRY") => $record["USR_COUNTRY"],
|
||||
$this->getFieldNameByFormatFieldName("USR_CITY") => $record["USR_CITY"],
|
||||
$this->getFieldNameByFormatFieldName("USR_LOCATION") => $record["USR_LOCATION"],
|
||||
$this->getFieldNameByFormatFieldName("USR_ADDRESS") => $record["USR_ADDRESS"],
|
||||
$this->getFieldNameByFormatFieldName("USR_PHONE") => $record["USR_PHONE"],
|
||||
$this->getFieldNameByFormatFieldName("USR_FAX") => $record["USR_FAX"],
|
||||
$this->getFieldNameByFormatFieldName("USR_CELLULAR") => $record["USR_CELLULAR"],
|
||||
$this->getFieldNameByFormatFieldName("USR_ZIP_CODE") => $record["USR_ZIP_CODE"],
|
||||
$this->getFieldNameByFormatFieldName("DEP_UID") => $record["DEP_UID"],
|
||||
$this->getFieldNameByFormatFieldName("USR_POSITION") => $record["USR_POSITION"],
|
||||
$this->getFieldNameByFormatFieldName("USR_RESUME") => $record["USR_RESUME"],
|
||||
$this->getFieldNameByFormatFieldName("USR_BIRTHDAY") => $record["USR_BIRTHDAY"],
|
||||
$this->getFieldNameByFormatFieldName("USR_ROLE") => $record["USR_ROLE"],
|
||||
$this->getFieldNameByFormatFieldName("USR_REPORTS_TO") => $record["USR_REPORTS_TO"],
|
||||
$this->getFieldNameByFormatFieldName("USR_REPLACED_BY") => $record["USR_REPLACED_BY"],
|
||||
$this->getFieldNameByFormatFieldName("USR_CALENDAR_UID") => $aFields["USR_CALENDAR_UID"],
|
||||
$this->getFieldNameByFormatFieldName("USR_CALENDAR_NAME") => $aFields["USR_CALENDAR"],
|
||||
$this->getFieldNameByFormatFieldName("USR_UX") => $record["USR_UX"],
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$this->getFieldNameByFormatFieldName("USR_COST_BY_HOUR") => $record["USR_COST_BY_HOUR"],
|
||||
$this->getFieldNameByFormatFieldName("USR_UNIT_COST") => $record["USR_UNIT_COST"],
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_INBOX") => $record["USR_TOTAL_INBOX"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_DRAFT") => $record["USR_TOTAL_DRAFT"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_CANCELLED") => $record["USR_TOTAL_CANCELLED"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_PARTICIPATED") => $record["USR_TOTAL_PARTICIPATED"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_PAUSED") => $record["USR_TOTAL_PAUSED"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_COMPLETED") => $record["USR_TOTAL_COMPLETED"],
|
||||
$this->getFieldNameByFormatFieldName("USR_TOTAL_UNASSIGNED") => $record["USR_TOTAL_UNASSIGNED"],
|
||||
$this->getFieldNameByFormatFieldName("USR_PHOTO_PATH") => $pathPhotoUser
|
||||
);
|
||||
$arrayResult = [];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_UID')] = $record['USR_UID'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_USERNAME')] = $record['USR_USERNAME'];
|
||||
//$arrayResult[$this->getFieldNameByFormatFieldName('USR_PASSWORD')] = $record['USR_PASSWORD'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_FIRSTNAME')] = $record['USR_FIRSTNAME'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_LASTNAME')] = $record['USR_LASTNAME'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_EMAIL')] = $record['USR_EMAIL'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_DUE_DATE')] = $record['USR_DUE_DATE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_CREATE_DATE')] = $record['USR_CREATE_DATE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_UPDATE_DATE')] = $record['USR_UPDATE_DATE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_STATUS')] = $record['USR_STATUS'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_COUNTRY')] = $record['USR_COUNTRY'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_CITY')] = $record['USR_CITY'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_LOCATION')] = $record['USR_LOCATION'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_ADDRESS')] = $record['USR_ADDRESS'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_PHONE')] = $record['USR_PHONE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_FAX')] = $record['USR_FAX'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_CELLULAR')] = $record['USR_CELLULAR'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_ZIP_CODE')] = $record['USR_ZIP_CODE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('DEP_UID')] = $record['DEP_UID'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_POSITION')] = $record['USR_POSITION'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_RESUME')] = $record['USR_RESUME'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_BIRTHDAY')] = $record['USR_BIRTHDAY'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_ROLE')] = $record['USR_ROLE'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_REPORTS_TO')] = $record['USR_REPORTS_TO'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_REPLACED_BY')] = $record['USR_REPLACED_BY'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_CALENDAR_UID')] = $aFields['USR_CALENDAR_UID'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_CALENDAR_NAME')] = $aFields['USR_CALENDAR'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_UX')] = $record['USR_UX'];
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_COST_BY_HOUR')] = $record['USR_COST_BY_HOUR'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_UNIT_COST')] = $record['USR_UNIT_COST'];
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_INBOX')] = $record['USR_TOTAL_INBOX'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_DRAFT')] = $record['USR_TOTAL_DRAFT'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_CANCELLED')] = $record['USR_TOTAL_CANCELLED'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_PARTICIPATED')] = $record['USR_TOTAL_PARTICIPATED'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_PAUSED')] = $record['USR_TOTAL_PAUSED'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_COMPLETED')] = $record['USR_TOTAL_COMPLETED'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TOTAL_UNASSIGNED')] = $record['USR_TOTAL_UNASSIGNED'];
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_PHOTO_PATH')] = $pathPhotoUser;
|
||||
|
||||
if (isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__']) {
|
||||
$userTimeZone = $record['USR_TIME_ZONE'];
|
||||
|
||||
if (trim($userTimeZone) == '') {
|
||||
$arraySystemConfiguration = \System::getSystemConfiguration('', '', SYS_SYS);
|
||||
|
||||
$userTimeZone = $arraySystemConfiguration['time_zone'];
|
||||
}
|
||||
|
||||
$arrayResult[$this->getFieldNameByFormatFieldName('USR_TIME_ZONE')] = $userTimeZone;
|
||||
}
|
||||
|
||||
//Return
|
||||
return $arrayResult;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -437,7 +458,9 @@ class User
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_TOTAL_PAUSED);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_TOTAL_COMPLETED);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_TOTAL_UNASSIGNED);
|
||||
$criteria->addSelectColumn(\UsersPeer::USR_TIME_ZONE);
|
||||
|
||||
//Return
|
||||
return $criteria;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
@@ -1250,5 +1273,28 @@ class User
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User-Logged Time Zone
|
||||
*
|
||||
* @return string Return the User-Logged Time Zone; Time Zone system settings otherwise
|
||||
*/
|
||||
public static function getUserLoggedTimeZone()
|
||||
{
|
||||
try {
|
||||
$timeZone = 'UTC';
|
||||
|
||||
if (isset($_SESSION['USR_TIME_ZONE'])) {
|
||||
$tz = trim($_SESSION['USR_TIME_ZONE']);
|
||||
|
||||
$timeZone = ($tz != '')? $tz : $timeZone;
|
||||
}
|
||||
|
||||
//Return
|
||||
return $timeZone;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -328,5 +328,51 @@ class Validator
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate data by ISO 8601 format
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param mixed $field Fields
|
||||
*
|
||||
* @return void Throw exception if data has an invalid value
|
||||
*/
|
||||
public static function throwExceptionIfDataNotMetIso8601Format($data, $field = null)
|
||||
{
|
||||
try {
|
||||
if (!(isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$regexpDate = \ProcessMaker\Util\DateTime::REGEXPDATE;
|
||||
$regexpTime = \ProcessMaker\Util\DateTime::REGEXPTIME;
|
||||
|
||||
$regexpIso8601 = $regexpDate . 'T' . $regexpTime . '[\+\-]\d{2}:\d{2}';
|
||||
|
||||
switch (gettype($data)) {
|
||||
case 'string':
|
||||
if (trim($data) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data)) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [(!is_null($field) && is_string($field))? $field : $data]));
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
if (!is_null($field) && is_array($field)) {
|
||||
foreach ($field as $value) {
|
||||
$fieldName = $value;
|
||||
|
||||
$fieldName = (isset($data[strtoupper($fieldName)]))? strtoupper($fieldName) : $fieldName;
|
||||
$fieldName = (isset($data[strtolower($fieldName)]))? strtolower($fieldName) : $fieldName;
|
||||
|
||||
if (isset($data[$fieldName]) && trim($data[$fieldName]) != '' && !preg_match('/^' . $regexpIso8601 . '$/', $data[$fieldName])) {
|
||||
throw new \Exception(\G::LoadTranslation('ID_ISO8601_INVALID_FORMAT', [$fieldName]));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,16 @@ use \Luracast\Restler\RestException;
|
||||
*/
|
||||
class Lists extends Api
|
||||
{
|
||||
private $arrayFieldIso8601 = [
|
||||
'app_paused_date',
|
||||
'app_restart_date',
|
||||
'del_delegate_date',
|
||||
'del_init_date',
|
||||
'del_due_date',
|
||||
'del_task_due_date',
|
||||
'app_update_date'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get list Inbox
|
||||
*
|
||||
@@ -74,7 +84,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('inbox', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -179,7 +190,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('participated_last', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -283,7 +295,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('participated_history', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -389,7 +402,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('paused', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -494,7 +508,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('canceled', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -598,7 +613,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('completed', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -702,7 +718,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('completed', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -806,7 +823,8 @@ class Lists extends Api
|
||||
|
||||
$lists = new \ProcessMaker\BusinessModel\Lists();
|
||||
$response = $lists->getList('unassigned', $dataList);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
|
||||
@@ -13,6 +13,12 @@ class TimerEvent extends Api
|
||||
{
|
||||
private $timerEvent;
|
||||
|
||||
private $arrayFieldIso8601 = [
|
||||
'tmrevn_next_run_date',
|
||||
'tmrevn_last_run_date',
|
||||
'tmrevn_last_execution_date'
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
@@ -39,7 +45,7 @@ class TimerEvent extends Api
|
||||
try {
|
||||
$response = $this->timerEvent->getTimerEvents($prj_uid);
|
||||
|
||||
return $response;
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
@@ -56,7 +62,7 @@ class TimerEvent extends Api
|
||||
try {
|
||||
$response = $this->timerEvent->getTimerEvent($tmrevn_uid);
|
||||
|
||||
return $response;
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
@@ -73,7 +79,7 @@ class TimerEvent extends Api
|
||||
try {
|
||||
$response = $this->timerEvent->getTimerEventByEvent($prj_uid, $evn_uid);
|
||||
|
||||
return $response;
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
@@ -90,11 +96,13 @@ class TimerEvent extends Api
|
||||
public function doPostTimerEvent($prj_uid, array $request_data)
|
||||
{
|
||||
try {
|
||||
$arrayData = $this->timerEvent->create($prj_uid, $request_data);
|
||||
\ProcessMaker\BusinessModel\Validator::throwExceptionIfDataNotMetIso8601Format($request_data, $this->arrayFieldIso8601);
|
||||
|
||||
$arrayData = $this->timerEvent->create($prj_uid, \ProcessMaker\Util\DateTime::convertDataToUtc($request_data, $this->arrayFieldIso8601));
|
||||
|
||||
$response = $arrayData;
|
||||
|
||||
return $response;
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ use \Luracast\Restler\RestException;
|
||||
*/
|
||||
class User extends Api
|
||||
{
|
||||
private $arrayFieldIso8601 = [
|
||||
'usr_create_date',
|
||||
'usr_update_date'
|
||||
];
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
*
|
||||
@@ -47,7 +52,7 @@ class User extends Api
|
||||
|
||||
$response = $user->getUsers($arrayFilterData, null, null, $start, $limit);
|
||||
|
||||
return $response["data"];
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response['data'], $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||
}
|
||||
@@ -65,7 +70,8 @@ class User extends Api
|
||||
$user->setFormatFieldNameInUppercase(false);
|
||||
|
||||
$response = $user->getUser($usr_uid);
|
||||
return $response;
|
||||
|
||||
return \ProcessMaker\Util\DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
|
||||
@@ -357,6 +357,21 @@ class Server implements iAuthenticate
|
||||
|
||||
setcookie($session->getSessionName(), $_COOKIE[$session->getSessionName()], time() + $lifetime, "/", null, false, true);
|
||||
}
|
||||
|
||||
//Set User Time Zone
|
||||
$user = \UsersPeer::retrieveByPK(self::$userId);
|
||||
|
||||
if (!is_null($user)) {
|
||||
$userTimeZone = $user->getUsrTimeZone();
|
||||
|
||||
if (trim($userTimeZone) == '') {
|
||||
$arraySystemConfiguration = \System::getSystemConfiguration('', '', SYS_SYS);
|
||||
|
||||
$userTimeZone = $arraySystemConfiguration['time_zone'];
|
||||
}
|
||||
|
||||
$_SESSION['USR_TIME_ZONE'] = $userTimeZone;
|
||||
}
|
||||
}
|
||||
|
||||
return $allowed;
|
||||
|
||||
361
workflow/engine/src/ProcessMaker/Util/DateTime.php
Normal file
361
workflow/engine/src/ProcessMaker/Util/DateTime.php
Normal file
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Util;
|
||||
|
||||
class DateTime
|
||||
{
|
||||
const ISO8601 = 'Y-m-d\TH:i:sP';
|
||||
|
||||
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';
|
||||
|
||||
/**
|
||||
* Get Time Zone Offset by Time Zone ID
|
||||
*
|
||||
* @param string $timeZoneId Time Zone ID
|
||||
*
|
||||
* @return int Return the Time Zone Offset; false otherwise
|
||||
*/
|
||||
public function getTimeZoneOffsetByTimeZoneId($timeZoneId)
|
||||
{
|
||||
try {
|
||||
$dt = new \DateTime(null, new \DateTimeZone($timeZoneId));
|
||||
|
||||
//Return
|
||||
return $dt->getOffset();
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Time Zone ID by Time Zone Offset
|
||||
*
|
||||
* @param int $offset Time Zone Offset
|
||||
*
|
||||
* @return string Return the Time Zone ID; UTC ID otherwise
|
||||
*/
|
||||
public function getTimeZoneIdByTimeZoneOffset($offset)
|
||||
{
|
||||
try {
|
||||
foreach (\DateTimeZone::listIdentifiers() as $value) {
|
||||
$timeZoneOffset = self::getTimeZoneOffsetByTimeZoneId($value);
|
||||
|
||||
if ($timeZoneOffset !== false && $timeZoneOffset == $offset) {
|
||||
//Return
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
//Return
|
||||
return 'UTC';
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Time Zone ID by UTC Offset
|
||||
*
|
||||
* @param string $utcOffset UTC Offset
|
||||
*
|
||||
* @return string Return the Time Zone ID; UTC ID otherwise
|
||||
*/
|
||||
public function getTimeZoneIdByUtcOffset($utcOffset)
|
||||
{
|
||||
try {
|
||||
if (preg_match('/^([\+\-])(\d{2}):(\d{2})$/', $utcOffset, $arrayMatch)) {
|
||||
$sign = $arrayMatch[1];
|
||||
$h = (int)($arrayMatch[2]);
|
||||
$m = (int)($arrayMatch[3]);
|
||||
} else {
|
||||
//Return
|
||||
return 'UTC';
|
||||
}
|
||||
|
||||
$offset = (($sign == '+')? '' : '-') . (($h * 60 * 60) + ($m * 60)); //Convert UTC Offset to seconds
|
||||
|
||||
//Return
|
||||
return self::getTimeZoneIdByTimeZoneOffset((int)($offset));
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert date from Time Zone to Time Zone
|
||||
*
|
||||
* @param string $date Date
|
||||
* @param string $fromTimeZone Time Zone source
|
||||
* @param string $toTimeZone Time Zone to convert
|
||||
* @param string $format Format to return date
|
||||
*
|
||||
* @return string Return date
|
||||
*/
|
||||
public function convertTimeZone($date, $fromTimeZone, $toTimeZone, $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
try {
|
||||
$dt = new \DateTime($date, new \DateTimeZone($fromTimeZone)); //From Time Zone
|
||||
$dt->setTimeZone(new \DateTimeZone($toTimeZone)); //To Time Zone
|
||||
|
||||
//Return
|
||||
return $dt->format($format);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ISO-8601 to Time Zone
|
||||
*
|
||||
* @param string $dateIso8601 Date
|
||||
* @param string $toTimeZone Time Zone to convert
|
||||
* @param string $format Format to return date
|
||||
*
|
||||
* @return string Return date
|
||||
*/
|
||||
public function convertIso8601ToTimeZone($dateIso8601, $toTimeZone, $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
try {
|
||||
$fromTimeZone = 'UTC';
|
||||
|
||||
if (preg_match('/^.+([\+\-]\d{2}:\d{2})$/', $dateIso8601, $arrayMatch)) {
|
||||
$fromTimeZone = self::getTimeZoneIdByUtcOffset($arrayMatch[1]);
|
||||
}
|
||||
|
||||
$dt = \DateTime::createFromFormat(self::ISO8601, $dateIso8601, new \DateTimeZone($fromTimeZone)); //From ISO-8601
|
||||
$dt->setTimeZone(new \DateTimeZone($toTimeZone)); //To Time Zone
|
||||
|
||||
//Return
|
||||
return $dt->format($format);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ISO-8601/datetime/array-ISO-8601-datetime-data to Time Zone
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param string $fromTimeZone Time Zone source
|
||||
* @param string $toTimeZone Time Zone to convert
|
||||
* @param array $arrayKey Keys that convert to Time Zone
|
||||
* @param string $format Format to return data
|
||||
*
|
||||
* @return mixed Return data
|
||||
*/
|
||||
public function convertDataToTimeZone($data, $fromTimeZone, $toTimeZone, array $arrayKey = [], $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
try {
|
||||
$regexpDatetime = '/^' . self::REGEXPDATE . '\s' . self::REGEXPTIME . '$/';
|
||||
$regexpIso8601 = '/^' . self::REGEXPDATE . 'T' . self::REGEXPTIME . '[\+\-]\d{2}:\d{2}$/';
|
||||
|
||||
if (empty($data)) {
|
||||
//Return
|
||||
return $data;
|
||||
}
|
||||
|
||||
switch (gettype($data)) {
|
||||
case 'string':
|
||||
if (is_string($data) && preg_match($regexpDatetime, $data)) {
|
||||
if ($fromTimeZone != $toTimeZone) {
|
||||
$data = self::convertTimeZone($data, $fromTimeZone, $toTimeZone, $format);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($data) && preg_match($regexpIso8601, $data)) {
|
||||
$data = self::convertIso8601ToTimeZone($data, $toTimeZone, $format);
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
$regexpKey = (!empty($arrayKey))? '/^(?:' . implode('|', $arrayKey) . ')$/i': '';
|
||||
|
||||
array_walk_recursive(
|
||||
$data,
|
||||
function (&$value, $key, $arrayData)
|
||||
{
|
||||
try {
|
||||
if ($arrayData['regexpKey'] == '' || preg_match($arrayData['regexpKey'], $key)) {
|
||||
if (is_string($value) && preg_match($arrayData['regexpDatetime'], $value)) {
|
||||
if ($arrayData['fromTimeZone'] != $arrayData['toTimeZone']) {
|
||||
$value = self::convertTimeZone($value, $arrayData['fromTimeZone'], $arrayData['toTimeZone'], $arrayData['format']);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($value) && preg_match($arrayData['regexpIso8601'], $value)) {
|
||||
$value = self::convertIso8601ToTimeZone($value, $arrayData['toTimeZone'], $arrayData['format']);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
},
|
||||
['fromTimeZone' => $fromTimeZone, 'toTimeZone' => $toTimeZone, 'format' => $format, 'regexpDatetime' => $regexpDatetime, 'regexpIso8601' => $regexpIso8601, 'regexpKey' => $regexpKey]
|
||||
);
|
||||
break;
|
||||
case 'object':
|
||||
$data = json_decode(json_encode($data), true);
|
||||
$data = self::convertDataToTimeZone($data, $fromTimeZone, $toTimeZone, $arrayKey, $format);
|
||||
$data = json_decode(json_encode($data));
|
||||
break;
|
||||
}
|
||||
|
||||
//Return
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert datetime/array-datetime-data to ISO-8601
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param string $fromTimeZone Time Zone source
|
||||
* @param string $toTimeZone Time Zone to convert
|
||||
* @param array $arrayKey Keys that convert to ISO-8601
|
||||
*
|
||||
* @return mixed Return data
|
||||
*/
|
||||
public function convertDataToIso8601($data, $fromTimeZone, $toTimeZone, array $arrayKey = [])
|
||||
{
|
||||
try {
|
||||
$regexpDatetime = '/^' . self::REGEXPDATE . '\s' . self::REGEXPTIME . '$/';
|
||||
|
||||
if (empty($data)) {
|
||||
//Return
|
||||
return $data;
|
||||
}
|
||||
|
||||
switch (gettype($data)) {
|
||||
case 'string':
|
||||
if (is_string($data) && preg_match($regexpDatetime, $data)) {
|
||||
if ($fromTimeZone != $toTimeZone) {
|
||||
$data = self::convertTimeZone($data, $fromTimeZone, $toTimeZone);
|
||||
}
|
||||
|
||||
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $data, new \DateTimeZone($toTimeZone));
|
||||
|
||||
$data = $dt->format(self::ISO8601);
|
||||
}
|
||||
break;
|
||||
case 'array':
|
||||
$regexpKey = (!empty($arrayKey))? '/^(?:' . implode('|', $arrayKey) . ')$/i': '';
|
||||
|
||||
array_walk_recursive(
|
||||
$data,
|
||||
function (&$value, $key, $arrayData)
|
||||
{
|
||||
try {
|
||||
if (($arrayData['regexpKey'] == '' || preg_match($arrayData['regexpKey'], $key)) &&
|
||||
is_string($value) && preg_match($arrayData['regexpDatetime'], $value)
|
||||
) {
|
||||
if ($arrayData['fromTimeZone'] != $arrayData['toTimeZone']) {
|
||||
$value = self::convertTimeZone($value, $arrayData['fromTimeZone'], $arrayData['toTimeZone']);
|
||||
}
|
||||
|
||||
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $value, new \DateTimeZone($arrayData['toTimeZone']));
|
||||
|
||||
$value = $dt->format(self::ISO8601);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
},
|
||||
['fromTimeZone' => $fromTimeZone, 'toTimeZone' => $toTimeZone, 'regexpDatetime' => $regexpDatetime, 'regexpKey' => $regexpKey]
|
||||
);
|
||||
break;
|
||||
case 'object':
|
||||
$data = json_decode(json_encode($data), true);
|
||||
$data = self::convertDataToIso8601($data, $fromTimeZone, $toTimeZone, $arrayKey);
|
||||
$data = json_decode(json_encode($data));
|
||||
break;
|
||||
}
|
||||
|
||||
//Return
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert ISO-8601/datetime/array-ISO-8601-datetime-data to UTC
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param array $arrayKey Keys that convert to UTC
|
||||
* @param string $format Format to return data
|
||||
*
|
||||
* @return mixed Return data
|
||||
*/
|
||||
public static function convertDataToUtc($data, array $arrayKey = [], $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
try {
|
||||
if (!(isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__'])) {
|
||||
//Return
|
||||
return $data;
|
||||
}
|
||||
|
||||
$fromTimeZone = \ProcessMaker\BusinessModel\User::getUserLoggedTimeZone();
|
||||
$toTimeZone = 'UTC';
|
||||
|
||||
//Return
|
||||
return self::convertDataToTimeZone($data, $fromTimeZone, $toTimeZone, $arrayKey, $format);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UTC to Time Zone
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param array $arrayKey Keys that convert to Time Zone
|
||||
* @param string $format Format to return data
|
||||
*
|
||||
* @return mixed Return data
|
||||
*/
|
||||
public static function convertUtcToTimeZone($data, array $arrayKey = [], $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
try {
|
||||
if (!(isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__'])) {
|
||||
//Return
|
||||
return $data;
|
||||
}
|
||||
|
||||
$fromTimeZone = 'UTC';
|
||||
$toTimeZone = \ProcessMaker\BusinessModel\User::getUserLoggedTimeZone();
|
||||
|
||||
//Return
|
||||
return self::convertDataToTimeZone($data, $fromTimeZone, $toTimeZone, $arrayKey, $format);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert UTC to ISO-8601
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @param array $arrayKey Keys that convert to ISO-8601
|
||||
*
|
||||
* @return mixed Return data
|
||||
*/
|
||||
public static function convertUtcToIso8601($data, array $arrayKey = [])
|
||||
{
|
||||
try {
|
||||
if (!(isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__'])) {
|
||||
//Return
|
||||
return $data;
|
||||
}
|
||||
|
||||
$fromTimeZone = 'UTC';
|
||||
$toTimeZone = \ProcessMaker\BusinessModel\User::getUserLoggedTimeZone();
|
||||
|
||||
//Return
|
||||
return self::convertDataToIso8601($data, $fromTimeZone, $toTimeZone, $arrayKey);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user