diff --git a/module/programplan/config/form.php b/module/programplan/config/form.php index 6a82bfec6c..514387b34f 100644 --- a/module/programplan/config/form.php +++ b/module/programplan/config/form.php @@ -54,3 +54,6 @@ $config->programplan->form->updateDateByGantt['id'] = array('required' => $config->programplan->form->updateDateByGantt['startDate'] = array('required' => false, 'type' => 'string', 'default' => null); $config->programplan->form->updateDateByGantt['endDate'] = array('required' => false, 'type' => 'string', 'default' => ''); $config->programplan->form->updateDateByGantt['type'] = array('required' => false, 'type' => 'string', 'default' => ''); + +$config->programplan->form->updateTaskOrderByGantt['id'] = array('required' => false, 'type' => 'string', 'default' => ''); +$config->programplan->form->updateTaskOrderByGantt['tasks'] = array('required' => false, 'type' => 'array', 'default' => array()); diff --git a/module/programplan/control.php b/module/programplan/control.php index 39417ec850..0ae0dccf3d 100644 --- a/module/programplan/control.php +++ b/module/programplan/control.php @@ -227,7 +227,8 @@ class programplan extends control $taskID = !empty($idList[1]) ? $idList[1] : 0; if(empty($taskID)) return $this->send(array('result' => 'fail', 'message' => '')); - $this->loadModel('task')->updateOrderByGantt(); + $postData = form::data($this->config->programplan->form->updateTaskOrderByGantt)->get(); + $this->loadModel('task')->updateOrderByGantt($postData); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action')->create('task', $taskID, 'ganttMove'); diff --git a/module/task/model.php b/module/task/model.php index 952f18b71d..2403699a94 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -2645,23 +2645,24 @@ class taskModel extends model } /** + * 拖动甘特图更新任务的顺序。 * Update order by gantt. * + * @param object $postData * @access public - * @return void + * @return bool */ - public function updateOrderByGantt() + public function updateOrderByGantt(object $postData): bool { - $data = fixer::input('post')->get(); - $order = 1; - foreach($data->tasks as $task) + foreach($postData->tasks as $task) { $idList = explode('-', $task); $taskID = $idList[1]; $this->dao->update(TABLE_TASK)->set('`order`')->eq($order)->where('id')->eq($taskID)->exec(); $order ++; } + return !dao::isError(); } /** diff --git a/module/task/test/model/updateorderbygantt.php b/module/task/test/model/updateorderbygantt.php new file mode 100644 index 0000000000..c2cefbdcb3 --- /dev/null +++ b/module/task/test/model/updateorderbygantt.php @@ -0,0 +1,25 @@ +#!/usr/bin/env php +config('task', true)->gen(30); + +/** + +title=taskModel->updateOrderByGantt(); +timeout=0 +cid=1 + +*/ + +$taskIdList[0] = array(1, 2, 3, 4, 5); +$taskIdList[1] = array(2, 3, 1, 4, 5); +$taskIdList[2] = array(4, 2, 3, 1, 5); + +$taskTester = new taskTest(); + +r($taskTester->updateOrderByGanttTest(3, 1, $taskIdList[0])) && p() && e('1,2,3,4,5'); // 测试更新开发任务11的顺序 +r($taskTester->updateOrderByGanttTest(3, 1, $taskIdList[1])) && p() && e('3,1,2,4,5'); // 测试更新开发任务11的顺序 +r($taskTester->updateOrderByGanttTest(3, 4, $taskIdList[2])) && p() && e('4,2,3,1,5'); // 测试更新开发任务14的顺序 diff --git a/module/task/test/task.class.php b/module/task/test/task.class.php index b7cb05a05f..ec827bf7b7 100755 --- a/module/task/test/task.class.php +++ b/module/task/test/task.class.php @@ -2147,4 +2147,25 @@ class taskTest if(dao::isError()) return dao::getError(); return true; } + + /** + * 拖动甘特图更新任务的顺序。 + * Update order by gantt. + * + * @param int $executionID + * @param int $taskID + * @param array $taskIdList + * @access public + * @return string + */ + public function updateOrderByGanttTest(int $executionID, int $taskID, array $taskIdList): string + { + $postData = new stdclass(); + $postData->id = "{$executionID}-{$taskID}"; + + foreach($taskIdList as $id) $postData->tasks[] = "{$executionID}-{$id}"; + + $this->objectModel->updateOrderByGantt($postData); + return $this->objectModel->dao->select('GROUP_CONCAT(`order`) as taskOrder')->from(TABLE_TASK)->where('id')->in($taskIdList)->fetch('taskOrder'); + } }