获取层级的project任务 参考
启动javabridge
java -jar JavaBridge.jar SERVLET_LOCAL:8089
1.读取mpp文件
$file_path = "/new.mpp";
$file_path = getcwd() . $file_path;
if (!file_exists($file_path)) {
var_dump("文件不存在");
return;
}
$mppRead = new Java('net.sf.mpxj.mpp.MPPReader'); try { $Filecontent = $mppRead->read($file_path); } catch (Exception $e) { var_dump($e); return; }
2.获取任务
获取project的任务
$allTasks = $Filecontent->getChildTasks();
$tasks_size = java_values($allTasks->size());
if($tasks_size){
getChildren($allTasks[0]);
}
说明:
$Filecontent->getChildTasks()获取的是文件,即$allTasks[0]为project文件,再向下是任务
获取任务的基本信息及获取任务流
function getChildren($task) { $child = $task->getChildTasks(); $tasks_size = java_values($child->size()); $data = array(); for ($i = 0; $i < $tasks_size; $i++) { $tmp = getResource($child[$i]); $items = array(); $items['id'] = $child[$i]->getID() . ''; $items['name'] = $child[$i]->getName() . ''; //前置任务 $prev_task = getProcessors($child[$i]); if ($prev_task) { $items['prev_task'] = $prev_task; } //获取下一级任务 $children = getChildren($child[$i]); if ($children) { $items['children'] = $children; } $data[] = $items; } return $data; }
获取任务流(即前置任务)具体实现
function getProcessors($task) { $items = array(); $rs = ''; $predecessorLinks = $task->getPredecessors(); $size = java_values($predecessorLinks->size()); $data = array(); for ($i = 0; $i < $size; $i++) { $tmp = $predecessorLinks[$i]->getTargetTask()->getUniqueID() . ''; if ($tmp) { $items[] = $tmp; } } if ($items) { $rs = implode(',', $items); } return $rs; }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/20384.html