* testcaseModel: refactor the filterIdList method.
This commit is contained in:
@@ -1151,13 +1151,15 @@ class testcaseModel extends model
|
||||
* Filter id list: remove prefix.
|
||||
*
|
||||
* @param array $idList
|
||||
* @param string $prefix
|
||||
* @param string $type case|scene
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function filterIdList($idList, $prefix = 'case_')
|
||||
public function filterIdList($idList, $type = 'case')
|
||||
{
|
||||
return array_filter(array_map(function($id){return strpos($id, $prefix) !== false ? str_replace($prefix, '', $id) : (int)$id;}, $idList));
|
||||
if($type == 'case') return array_filter(array_map(function($id){return strpos($id, 'case_') !== false ? str_replace('case_', '', $id) : (int)$id;}, $idList));
|
||||
if($type == 'scene') return array_filter(array_map(function($id){return strpos($id, 'scene_') !== false ? str_replace('scene_', '', $id) : (int)$id;}, $idList));
|
||||
return $idList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1298,7 +1300,7 @@ class testcaseModel extends model
|
||||
public function batchDelete($caseIDList)
|
||||
{
|
||||
$caseIDList = $this->filterIdList($caseIDList);
|
||||
$sceneIDList = $this->filterIdList($caseIDList, 'scene_');
|
||||
$sceneIDList = $this->filterIdList($caseIDList, 'scene');
|
||||
if(!$caseIDList && !$sceneIDList) return false;
|
||||
|
||||
$this->loadModel('action');
|
||||
@@ -1366,7 +1368,7 @@ class testcaseModel extends model
|
||||
public function batchChangeModule($idList, $moduleID)
|
||||
{
|
||||
$caseIDList = $this->filterIdList($idList);
|
||||
$sceneIDList = $this->filterIdList($idList, 'scene_');
|
||||
$sceneIDList = $this->filterIdList($idList, 'scene');
|
||||
if(!$caseIDList && !$sceneIDList) return false;
|
||||
|
||||
$this->batchChangeCaseModule($caseIDList, $moduleID);
|
||||
|
||||
Reference in New Issue
Block a user