* Refactor the code for activating the story.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
$now = helper::now();
|
||||
$today = helper::today();
|
||||
|
||||
global $app, $lang;
|
||||
$config->story->form = new stdclass();
|
||||
$config->story->form->create = array();
|
||||
@@ -99,3 +102,17 @@ $config->story->form->review['estimate'] = array('type' => 'float', 'con
|
||||
$config->story->form->review['duplicateStory'] = array('type' => 'string', 'control' => 'text', 'required' => false, 'default' => '');
|
||||
$config->story->form->review['childStories'] = array('type' => 'string', 'control' => 'text', 'required' => false, 'default' => '');
|
||||
$config->story->form->review['status'] = array('type' => 'string', 'control' => 'hidden', 'required' => false, 'default' => '');
|
||||
|
||||
$config->story->form->activate = array();
|
||||
$config->story->form->activate['assignedTo'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->story->form->activate['activatedDate'] = array('type' => 'datetime', 'required' => false, 'default' => $now);
|
||||
$config->story->form->activate['lastEditedDate'] = array('type' => 'datetime', 'required' => false, 'default' => $now);
|
||||
$config->story->form->activate['lastEditedBy'] = array('type' => 'string', 'required' => false, 'default' => $app->user->account);
|
||||
$config->story->form->activate['closedBy'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->story->form->activate['closedReason'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->story->form->activate['closedDate'] = array('type' => 'datetime', 'required' => false, 'default' => null);
|
||||
$config->story->form->activate['reviewedBy'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
$config->story->form->activate['reviewedDate'] = array('type' => 'datetime', 'required' => false, 'default' => null);
|
||||
$config->story->form->activate['assignedDate'] = array('type' => 'datetime', 'required' => false, 'default' => $now);
|
||||
$config->story->form->activate['duplicateStory'] = array('type' => 'int', 'required' => false, 'default' => 0);
|
||||
$config->story->form->activate['childStories'] = array('type' => 'string', 'required' => false, 'default' => '');
|
||||
|
||||
@@ -626,6 +626,7 @@ class story extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活需求。
|
||||
* Activate a story.
|
||||
*
|
||||
* @param int $storyID
|
||||
@@ -633,11 +634,13 @@ class story extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function activate($storyID, $storyType = 'story')
|
||||
public function activate(int $storyID, string $storyType = 'story')
|
||||
{
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$changes = $this->story->activate($storyID);
|
||||
$postData = $this->storyZen->buildStoryForActivate();
|
||||
$changes = $this->story->activate($storyID, $postData);
|
||||
|
||||
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
|
||||
|
||||
if($changes)
|
||||
|
||||
+5
-21
@@ -2260,38 +2260,22 @@ class storyModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 激活需求。
|
||||
* Activate a story.
|
||||
*
|
||||
* @param int $storyID
|
||||
* @access public
|
||||
* @return bool
|
||||
* @return array|false
|
||||
*/
|
||||
public function activate($storyID)
|
||||
public function activate(int $storyID, object $postData): array|false
|
||||
{
|
||||
$oldStory = $this->dao->findById($storyID)->from(TABLE_STORY)->fetch();
|
||||
$now = helper::now();
|
||||
$story = fixer::input('post')
|
||||
->add('id', $storyID)
|
||||
->add('closedBy', '')
|
||||
->add('closedReason', '')
|
||||
->add('closedDate', null)
|
||||
->add('reviewedBy', '')
|
||||
->add('reviewedDate', null)
|
||||
->add('duplicateStory', 0)
|
||||
->add('childStories', '')
|
||||
->setDefault('lastEditedBy', $this->app->user->account)
|
||||
->setDefault('lastEditedDate', $now)
|
||||
->setDefault('assignedDate', $now)
|
||||
->setDefault('activatedDate', $now)
|
||||
->stripTags($this->config->story->editor->activate['id'], $this->config->allowedTags)
|
||||
->remove('comment')
|
||||
->get();
|
||||
|
||||
/* Get status after activation. */
|
||||
$story = $postData;
|
||||
$story->status = $this->getActivateStatus($storyID);
|
||||
|
||||
$story = $this->loadModel('file')->processImgURL($story, $this->config->story->editor->activate['id'], $this->post->uid);
|
||||
$this->dao->update(TABLE_STORY)->data($story)->autoCheck()->checkFlow()->where('id')->eq($storyID)->exec();
|
||||
$this->dao->update(TABLE_STORY)->data($story, 'comment')->autoCheck()->checkFlow()->where('id')->eq($storyID)->exec();
|
||||
|
||||
if($story->status == 'active')
|
||||
{
|
||||
|
||||
@@ -1256,4 +1256,16 @@ class storyZen extends story
|
||||
|
||||
return $showFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build story post data for activating the story.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
protected function buildStoryForActivate(): object
|
||||
{
|
||||
$postData = form::data($this->config->story->form->activate)->get();
|
||||
$story = $this->loadModel('file')->processImgURL($postData, $this->config->story->editor->activate['id'], $this->post->uid);
|
||||
return $story;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user