* Refactor myModel::getReviewingFlows.

This commit is contained in:
liumengyi
2023-11-27 15:08:21 +08:00
parent 0a43796f37
commit 44e5cc0d4a
4 changed files with 96 additions and 35 deletions
+9 -35
View File
@@ -1116,69 +1116,43 @@ class myModel extends model
}
/**
* 获取审批中的工作流设置。
* Get reviewing for flows setting.
*
* @param string $objectType
* @param string $orderBy
* @param bool $checkExists
* @access public
* @return array
* @return array|bool
*/
public function getReviewingFlows($objectType = 'all', $orderBy = 'id_desc', $checkExists = false)
public function getReviewingFlows($objectType = 'all', $orderBy = 'id_desc', $checkExists = false): array|bool
{
if($this->config->edition != 'max') return array();
$stmt = $this->dao->select('t2.objectType,t2.objectID')->from(TABLE_APPROVALNODE)->alias('t1')
->leftJoin(TABLE_APPROVALOBJECT)->alias('t2')
->on('t2.approval = t1.approval')
->leftJoin(TABLE_APPROVALOBJECT)->alias('t2')->on('t2.approval = t1.approval')
->where('t2.objectType')->ne('review')
->beginIF($objectType != 'all')->andWhere('t2.objectType')->eq($objectType)->fi()
->andWhere('t1.account')->eq($this->app->user->account)
->andWhere('t1.status')->eq('doing')
->orderBy($orderBy)
->query();
$objectIdList = array();
while($object = $stmt->fetch()) $objectIdList[$object->objectType][$object->objectID] = $object->objectID;
if($checkExists) return array_keys($objectIdList);
$flows = $this->dao->select('module,`table`,name,titleField')->from(TABLE_WORKFLOW)->where('module')->in(array_keys($objectIdList))->andWhere('buildin')->eq(0)->fetchAll('module');
$flows = $this->dao->select('module,`table`,name,titleField')->from(TABLE_WORKFLOW)->where('module')->in(array_keys($objectIdList))->andWhere('buildin')->eq(0)->fetchAll('module');
$objectGroup = array();
foreach($objectIdList as $objectType => $idList)
{
$table = zget($this->config->objectTables, $objectType, '');
if(empty($table) and isset($flows[$objectType])) $table = $flows[$objectType]->table;
if(empty($table)) continue;
if(empty($table) && isset($flows[$objectType])) $table = $flows[$objectType]->table;
$objectGroup[$objectType] = $this->dao->select('*')->from($table)->where('id')->in($idList)->fetchAll('id');
if(!empty($table)) $objectGroup[$objectType] = $this->dao->select('*')->from($table)->where('id')->in($idList)->fetchAll('id');
}
$this->app->loadConfig('action');
$approvalList = array();
foreach($objectGroup as $objectType => $objects)
{
$title = '';
$titleFieldName = zget($this->config->action->objectNameFields, $objectType, '');
$openedDateField = 'openedDate';
if(in_array($objectType, array('product', 'productplan', 'release', 'build', 'testtask'))) $openedDateField = 'createdDate';
if(in_array($objectType, array('testsuite', 'caselib')))$openedDateField = 'addedDate';
if(empty($titleFieldName) and isset($flows[$objectType]))
{
if(!empty($flows[$objectType]->titleField)) $titleFieldName = $flows[$objectType]->titleField;
if(empty($flows[$objectType]->titleField)) $title = $flows[$objectType]->name;
$openedDateField = 'createdDate';
}
foreach($objects as $object)
{
$data = new stdclass();
$data->id = $object->id;
$data->title = (empty($titleFieldName) or !isset($object->$titleFieldName)) ? $title . " #{$object->id}" : $object->$titleFieldName;
$data->type = $objectType;
$data->time = $object->$openedDateField;
$data->status = 'doing';
$approvalList[] = $data;
}
}
return $approvalList;
return $this->myTao->buildApprovalList($objectGroup, $flows, $this->config->action->objectNameFields);
}
/**
+41
View File
@@ -215,4 +215,45 @@ class myTao extends myModel
}
return $requirements;
}
/**
* 构建待审批的审批数据。
* Build the data of the approval to be approved.
*
* @param array $objectGroup
* @param array $flows
* @param array $objectNameFields
* @access protected
* @return array
*/
protected function buildReviewingFlows(array $objectGroup, array $flows, array $objectNameFields): array
{
$approvalList = array();
foreach($objectGroup as $objectType => $objects)
{
$title = '';
$titleFieldName = zget($objectNameFields, $objectType, '');
$openedDateField = 'openedDate';
if(in_array($objectType, array('product', 'productplan', 'release', 'build', 'testtask'))) $openedDateField = 'createdDate';
if(in_array($objectType, array('testsuite', 'caselib')))$openedDateField = 'addedDate';
if(empty($titleFieldName) && isset($flows[$objectType]))
{
if(!empty($flows[$objectType]->titleField)) $titleFieldName = $flows[$objectType]->titleField;
if(empty($flows[$objectType]->titleField)) $title = $flows[$objectType]->name;
$openedDateField = 'createdDate';
}
foreach($objects as $object)
{
$data = new stdclass();
$data->id = $object->id;
$data->title = empty($titleFieldName) || !isset($object->$titleFieldName) ? $title . " #{$object->id}" : $object->{$titleFieldName};
$data->type = $objectType;
$data->time = $object->{$openedDateField};
$data->status = 'doing';
$approvalList[] = $data;
}
}
return $approvalList;
}
}
@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/my.class.php';
zdTable('user')->gen('2');
su('admin');
/**
title=测试 myModel->getReviewingFlows();
cid=1
pid=1
*/
$my = new myTest();
$orderBy = array('id_desc', 'id_asc');
$checkExist = array(false, true);
r($my->getReviewingFlowsTest($orderBy[0], $checkExist[0])) && p() && e('empty'); // 测试获取排序 id_desc 的审批id。
r($my->getReviewingFlowsTest($orderBy[0], $checkExist[1])) && p() && e('empty'); // 测试获取排序 id_desc 的审批是否存在。
r($my->getReviewingFlowsTest($orderBy[1], $checkExist[0])) && p() && e('empty'); // 测试获取排序 id_asc 的审批id。
r($my->getReviewingFlowsTest($orderBy[1], $checkExist[1])) && p() && e('empty'); // 测试获取排序 id_asc 的审批是否存在。
+19
View File
@@ -464,4 +464,23 @@ class myTest
if($return === true) return 'exist';
return !empty($return) ? implode(',', array_column($return, 'id')) : 'empty';
}
/**
* 测试获取审批中的审批。
* Test get reviewing flows.
*
* @param string $orderBy
* @param bool $checkExist
* @access public
* @return int|string|array
*/
public function getReviewingFlowsTest(string $orderBy, bool $checkExist): int|string|array
{
$return = $this->objectModel->getReviewingFlows($orderBy, $checkExist);
if(dao::isError()) return dao::getError();
if($return === true) return 'exist';
return !empty($return) ? implode(',', array_column($return, 'id')) : 'empty';
}
}