From 52866a6c5831c0e1de723cd8573fd5f1ee6da440 Mon Sep 17 00:00:00 2001 From: sunguangming Date: Thu, 21 Nov 2024 02:06:35 +0000 Subject: [PATCH] * [task#133040,doing,1.5h] build tree when export data. --- module/story/model.php | 9 +++++---- module/task/model.php | 34 ++++++++++------------------------ module/transfer/tao.php | 39 +++++++++++++++++++++------------------ 3 files changed, 36 insertions(+), 46 deletions(-) diff --git a/module/story/model.php b/module/story/model.php index d31d64eff1..e988d61503 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -4879,10 +4879,11 @@ class storyModel extends model foreach($reviewedByList as $i => $reviewedBy) $reviewedByList[$i] = zget($users, trim($reviewedBy)); $story->reviewedBy = implode(',', array_filter($reviewedByList)); - $gradePairs = zget($gradeGroup, $story->type, array()); - $grade = zget($gradePairs, $story->grade, ''); - $story->grade = $grade->name; - $story->parent = zget($parents, $story->parent, ''); + $gradePairs = zget($gradeGroup, $story->type, array()); + $grade = zget($gradePairs, $story->grade, ''); + $story->grade = $grade->name; + $story->parentId = $story->parent; + $story->parent = zget($parents, $story->parent, ''); } return $stories; diff --git a/module/task/model.php b/module/task/model.php index b69c142f9b..4d353e272b 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -2569,31 +2569,17 @@ class taskModel extends model } } - /* Process parent-child task task info. */ - if($tasks) + /* Process parent-child task info. */ + foreach($tasks as $task) { - $children = array(); - foreach($tasks as $task) - { - if($task->parent > 0 && isset($tasks[$task->parent])) - { - $children[$task->parent][$task->id] = $task; - unset($tasks[$task->id]); - } - } - if(!empty($children)) - { - $position = 0; - foreach($tasks as $task) - { - $position ++; - if(isset($children[$task->id])) - { - array_splice($tasks, $position, 0, $children[$task->id]); - $position += count($children[$task->id]); - } - } - } + if($task->parent > 0) $parentIdList[] = $task->parent; + } + + $parents = $this->dao->select('id, name')->from(TABLE_TASK)->where('id')->in($parentIdList)->fetchPairs(); + foreach($tasks as $task) + { + $task->parentId = $task->parent; + $task->parent = zget($parents, $task->parent, ''); } return $tasks; diff --git a/module/transfer/tao.php b/module/transfer/tao.php index 080bc6e1d4..14ec1f745b 100644 --- a/module/transfer/tao.php +++ b/module/transfer/tao.php @@ -234,34 +234,37 @@ class transferTao extends transferModel */ protected function updateChildDatas(array $datas) { - $children = array(); foreach($datas as $data) { - $id = $data->id; if(!empty($data->mode)) $datas[$id]->name = '[' . $this->lang->task->multipleAB . '] ' . $data->name; //任务类型(多人任务/单人任务) - if(!empty($data->parent) and isset($datas[$data->parent])) - { - /* 根据name或title获取父数据。*/ - /* Get parent data by name or title. */ - if(!empty($data->name)) $data->name = '>' . $data->name; - $children[$data->parent][$id] = $data; - unset($datas[$id]); - } } - if(empty($children)) return $datas; /* 如果存在子数据,则将子数据插入到父数据之后。*/ /* Move child data after parent data. */ - $position = 0; + $children = array(); foreach($datas as $data) { - $position ++; - if(!isset($children[$data->id])) continue; - - array_splice($datas, $position, 0, $children[$data->id]); - $position += count($children[$data->id]); + $parentId = isset($data->parentId) ? $data->parentId : $data->parent; + if(!isset($children[$parentId])) $children[$parentId] = array(); + $children[$parentId][] = $data; } - return $datas; + if(empty($children)) return $datas; + + $buildTree = function($parentId) use (&$buildTree, &$children) + { + $result = array(); + if(isset($children[$parentId])) + { + foreach($children[$parentId] as $child) + { + $result[] = $child; + $result = array_merge($result, $buildTree($child->id)); + } + } + return $result; + }; + + return $buildTree(0); } }