* Refactor batchUnlinkStory method.

This commit is contained in:
tianshujie
2023-10-10 11:25:10 +08:00
parent f7bbb5a11b
commit 92d70496be
2 changed files with 13 additions and 7 deletions
+2 -1
View File
@@ -490,6 +490,7 @@ class release extends control
}
/**
* 批量解除发布跟需求的关联。
* Batch unlink story.
*
* @param int $releaseID
@@ -498,7 +499,7 @@ class release extends control
*/
public function batchUnlinkStory(int $releaseID)
{
$this->release->batchUnlinkStory($releaseID);
$this->release->batchUnlinkStory($releaseID, (array)$this->post->storyIdList);
return $this->sendSuccess(array('load' => $this->createLink($this->app->rawModule, 'view', "releaseID={$releaseID}&type=story")));
}
+11 -6
View File
@@ -496,25 +496,30 @@ class releaseModel extends model
}
/**
* 批量解除发布跟需求的关联。
* Batch unlink story.
*
* @param int $releaseID
* @param array $storyIdList
* @access public
* @return void
* @return bool
*/
public function batchUnlinkStory($releaseID)
public function batchUnlinkStory(int $releaseID, array $storyIdList): bool
{
$storyList = $this->post->storyIdList;
if(empty($storyList)) return true;
if(empty($storyIdList)) return true;
$release = $this->getByID($releaseID);
if(!$release) return false;
$release->stories = ",$release->stories,";
foreach($storyList as $storyID) $release->stories = str_replace(",$storyID,", ',', $release->stories);
foreach($storyIdList as $storyID) $release->stories = str_replace(",$storyID,", ',', $release->stories);
$release->stories = trim($release->stories, ',');
$this->dao->update(TABLE_RELEASE)->set('stories')->eq($release->stories)->where('id')->eq((int)$releaseID)->exec();
$this->loadModel('action');
foreach($this->post->storyIdList as $unlinkStoryID) $this->action->create('story', $unlinkStoryID, 'unlinkedfromrelease', '', $releaseID);
foreach($storyIdList as $unlinkStoryID) $this->action->create('story', $unlinkStoryID, 'unlinkedfromrelease', '', $releaseID);
return !dao::isError();
}
/**