* Fix workflow bug.

This commit is contained in:
wangyuting2
2022-05-12 13:07:37 +08:00
parent 5674160b7e
commit 6331cede38
2 changed files with 164 additions and 61 deletions
+144 -29
View File
@@ -26,12 +26,156 @@ class dao extends baseDAO
return parent::exec($sql);
}
/**
* 设置需要更新或插入的数据。
* Set the data to update or insert.
*
* @param object $data the data object or array
* @access public
* @return object the dao object self.
*/
public function data($data, $skipFields = '')
{
global $app, $config;
if(!is_object($data)) $data = (object)$data;
$app->loadLang('workflow');
$app->loadConfig('workflow');
/* Check current module is buildin workflow. */
if(isset($config->workflow->buildin->modules))
{
$currentModule = $app->rawModule;
foreach($config->workflow->buildin->modules as $appModules)
{
if(!empty($appModules->$currentModule))
{
$currentMainTable = zget($appModules->$currentModule, 'table', '');
break;
}
}
if(isset($currentMainTable))
{
if($currentMainTable == $this->table)
{
$data = $this->processData($data);
}
else
{
$workflowFields = array();
$stmt = $this->dbh->query("SELECT `field`,`type` FROM " . TABLE_WORKFLOWFIELD . " WHERE `module` = '{$currentModule}' AND `buildin` = '0'");
while($row = $stmt->fetch())
{
$workflowFields[$row->field] = $row->type;
}
$fields = $this->getFieldsType();
foreach($data as $field => $value)
{
if(!isset($fields[$field]) && isset($workflowFields[$field])) unset($data->$field);
}
}
}
}
$skipFields .= ',uid';
return parent::data($data, $skipFields);
}
/**
* Process workflow data
*
* @param object $data
* @access public
* @return object
*/
public function processData($data)
{
global $app,$config;
if(!isset($config->bizVersion)) return $this;
$module = $app->getModuleName();
$method = $app->getMethodName();
$action = $this->dbh->query("SELECT * FROM " . TABLE_WORKFLOWACTION . " WHERE `module` = '{$module}' AND `action` = '{$method}' AND `buildin` = '1' AND `vision` = '{$config->vision}' AND `extensionType` = 'extend'")->fetch(PDO::FETCH_OBJ);
if(!$action) return $data;
$fields = $this->dbh->query("SELECT t2.name,t2.rules,t2.control,t2.field,t2.type,t2.options,t1.layoutRules FROM " . TABLE_WORKFLOWLAYOUT . " AS t1 LEFT JOIN " . TABLE_WORKFLOWFIELD . " AS t2 ON t1.module = t2.module WHERE t1.field = t2.field AND t1.module = '{$module}' AND t1.action = '{$method}' AND `vision` = '{$config->vision}' AND t1.readonly = '0'")->fetchAll();
if(!$fields) return $data;
$app->loadLang('flow');
$app->loadLang('workflowfield');
$app->loadConfig('flow');
$app->loadConfig('workflowfield');
foreach($fields as $field)
{
if(isset($data->{$field->field}))
{
if($field->options && is_string($field->options) && strpos(',user,dept,', ",$field->options,") !== false)
{
if(!is_array($data->{$field->field})) $data->{$field->field} = explode(',', $data->{$field->field});
foreach($data->{$field->field} as $key => $value)
{
$data->{$field->field}[$key] = $this->getParamRealValue($value);
}
}
/* If data value is array, implode by comma. */
if(is_array($data->{$field->field}))
{
$dataValue = array_values(array_unique(array_filter($data->{$field->field})));
asort($dataValue);
$data->{$field->field} = implode(',', $dataValue);
}
}
else
{
if(strpos(',radio,checkbox,multi-select,', ",$field->control,") !== false) $data->{$field->field} = '';
}
}
foreach($data as $field => $value)
{
if(in_array($value, $config->flow->variables)) $data->$field = $this->getParamRealValue($value);
}
return $data;
}
/**
* Get param real value
*
* @param string $param
* @access public
* @return string
*/
public function getParamRealValue($param)
{
global $app;
if(empty($this->deptManager))
{
$dept = zget($app->user, 'dept', '');
$manager = $this->dbh->query("SELECT manager FROM " . TABLE_DEPT . " WHERE `id` = '{$dept}'")->fetch(PDO::FETCH_OBJ);
$this->deptManager = $manager ? trim($manager->manager, ',') : '';
}
switch((string)$param)
{
case 'today' : return date('Y-m-d');
case 'now' :
case 'currentTime' : return date('Y-m-d H:i:s');
case 'actor' :
case 'currentUser' : return $app->user->account;
case 'currentDept' : return $app->user->dept ? $app->user->dept : $param;
case 'deptManager' : return $this->deptManager ? $this->deptManager : $param;
default : return $param;
}
}
/**
* check workflow field rule.
*
@@ -145,35 +289,6 @@ class dao extends baseDAO
return $this;
}
/**
* Get param real value
*
* @param int $param
* @access public
* @return string
*/
public function getParamRealValue($param)
{
if(empty($this->deptManager))
{
$dept = zget($this->app->user, 'dept', '');
$manager = $this->dbh->query("SELECT moderators FROM " . TABLE_CATEGORY . " WHERE `type` = 'dept' AND `id` = '{$dept}'")->fetch(PDO::FETCH_OBJ);
$this->deptManager = $manager ? trim($manager->moderators, ',') : '';
}
switch((string)$param)
{
case 'today' : return date('Y-m-d');
case 'now' :
case 'currentTime' : return date('Y-m-d H:i:s');
case 'actor' :
case 'currentUser' : return $this->app->user->account;
case 'currentDept' : return $this->app->user->dept ? $this->app->user->dept : $param;
case 'deptManager' : return $this->deptManager ? $this->deptManager : $param;
default : return $param;
}
}
}
/**
+20 -32
View File
@@ -45,51 +45,39 @@ class fixer extends baseFixer
{
public function get($fields = '')
{
$fields = str_replace(' ', '', trim($fields));
/* Get extend field by flow. */
global $config;
$flowFields = array();
/* Get extend field by flow. */
if(isset($config->bizVersion))
{
global $app, $dbh;
$moduleName = $app->getModuleName();
$stmt = $dbh->query("SELECT * FROM " . TABLE_WORKFLOWFIELD . " WHERE `module` = '{$moduleName}' and `buildin` = '0'");
$flowFields = array();
$moduleName = $app->rawModule;
$stmt = $dbh->query("SELECT * FROM " . TABLE_WORKFLOWFIELD . " WHERE `module` = '{$moduleName}' and `buildin` = '0'");
while($flowField = $stmt->fetch()) $flowFields[$flowField->field] = $flowField;
}
foreach($this->data as $field => $value)
{
/* Implode array when form has array. */
if(isset($flowFields[$field]) and is_array($value))
foreach($flowFields as $field => $fieldObject)
{
$canImplode = true;
foreach($value as $k => $v)
if(!isset($this->data->$field)) continue;
$value = $this->data->$field;
if(is_array($value))
{
if(is_object($v) or is_array($v))
$canImplode = true;
foreach($value as $k => $v)
{
$canImplode = false;
break;
if(is_object($v) or is_array($v))
{
$canImplode = false;
break;
}
}
if($canImplode) $this->data->$field = implode(',', $value);
}
if($canImplode) $this->data->$field = implode(',', $value);
if($fieldObject->control == 'textarea' || $fieldObject->control == 'richtext') $this->skipSpecial($field);
}
if(isset($flowFields[$field]) and ($flowFields[$field]->control == 'textarea' or $flowFields[$field]->control == 'richtext')) $this->skipSpecial($field);
$this->specialChars($field);
$this->data->$field = $this->filterEmoji($value);
}
if(empty($fields)) return $this->data;
if(strpos($fields, ',') === false) return $this->data->$fields;
/* Process fields for check by key. */
$fields = array_flip(explode(',', $fields));
foreach($this->data as $field => $value)
{
if(!isset($fields[$field])) unset($this->data->$field);
if(!isset($this->stripedFields[$field])) $this->specialChars($field);
}
return $this->data;
return parent::get($fields);
}
/**